:root {
  --bg: #0e1014;
  --panel: #171a20;
  --panel-2: #1e222a;
  --border: #2a2f39;
  --text: #dde0e5;
  --muted: #858c99;
  --faint: #5c6370;
  --accent: #6aa9ff;
  --accent-dim: #2b4a73;
  --ok: #4cc47a;
  --warn: #e0b341;
  --bad: #e05a5a;
  --hp: #c8434b;
  --mp: #3f78d6;
  --sp: #d6a93f;
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, sans-serif;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
           env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

input[type="text"], input[type="password"], button, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button {
  background: var(--panel-2);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent-dim); border-color: #3b6297; }
button.danger { background: #4a2226; border-color: #6b3036; }
button.danger:hover:not(:disabled) { border-color: var(--bad); }
button.ghost { background: none; }

/* ---- top bar ---- */

#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  font-size: 16px;
}
#status-text { color: var(--muted); font-size: 13px; }
.spacer { flex: 1; }

.dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.dot.on { background: var(--ok); }
.dot.pending { background: var(--warn); }
.dot.off { background: var(--bad); }

#settings { position: relative; }
#settings summary {
  list-style: none;
  cursor: pointer;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  user-select: none;
}
#settings summary::-webkit-details-marker { display: none; }
#settings[open] summary { border-color: var(--accent); }
.settings-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  width: min(320px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px #000c;
}
#connect-form { display: flex; flex-direction: column; gap: 4px; }
#connect-form label { color: var(--muted); font-size: 12px; }
#server-url { font-family: var(--mono); width: 100%; }
.settings-menu .toggle { display: flex; align-items: center; gap: 8px; user-select: none; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
button.small { padding: 2px 8px; font-size: 12px; }
/* Volume: in the top bar, or in Settings on phones where there's no room. */
.volume { width: 110px; accent-color: var(--accent); }
#sound-controls { display: flex; align-items: center; gap: 6px; }
#mute-btn { padding: 4px 8px; line-height: 1; }
#mute-btn[aria-pressed="true"] { opacity: 0.6; }
.settings-volume { display: none; }
/* Art style: a Pixel | Smooth switch in the top bar; in Settings on phones. */
.segmented { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented button { border: none; border-radius: 0; padding: 5px 10px; font-size: 13px; background: var(--panel-2); color: var(--muted); }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-checked="true"] { background: var(--accent-dim); color: var(--text); }
.settings-art { display: none !important; }
@media (max-width: 600px) {
  .top-volume { display: none; }
  .settings-volume { display: block; }
  #art-toggle { display: none; }
  .settings-art { display: flex !important; }
}

/* ---- play area: map, side column (cards and tabs) and chat ----
 *
 * A grid, so the chat can sit under the side column or run the whole
 * width along the bottom like the Java client (body.chat-bottom, a switch
 * in Settings). On a phone everything stacks: map, cards, chat. */

#play-area {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "map" "side" "log";
  grid-template-rows: auto minmax(0, max-content) minmax(140px, 1fr);
}

/* The renderer fills the largest square that fits in #map-wrap. */
#map-wrap {
  grid-area: map;
  display: none;
  height: min(100vw, 48vh);
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}
body.playing #map-wrap { display: flex; }
#map-stage { position: relative; }

#map {
  display: block;
  cursor: pointer;
  image-rendering: pixelated;
}

#side {
  grid-area: side;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 8px 0;
  overflow-y: auto;
}

@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  #play-area {
    grid-template-columns: minmax(0, 1fr) clamp(360px, 30vw, 440px);
    grid-template-areas: "map side" "map log";
    grid-template-rows: minmax(0, max-content) minmax(200px, 1fr);
  }
  #map-wrap { height: auto; border-right: 1px solid var(--border); }
  /* Chat across the bottom: the side column gets the full height. */
  body.chat-bottom #play-area {
    grid-template-areas: "map side" "log log";
    grid-template-rows: minmax(0, 1fr) clamp(150px, 28vh, 320px);
  }
  body.chat-bottom #map-wrap { border-bottom: 1px solid var(--border); }
  body.chat-bottom #side { padding-bottom: 8px; }
  body.chat-bottom #panel { flex: 1 1 auto; max-height: none; }
}

.card {
  flex: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---- character card ---- */

#char-card { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.card-head { display: flex; align-items: baseline; gap: 8px; }
#char-name {
  flex: 1;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: capitalize;
}
#stat-loc { color: var(--muted); font-family: var(--mono); font-size: 12px; }

.bars { display: flex; flex-direction: column; gap: 5px; }
/* --pct is set from JS. */
.bar {
  --pct: 0%;
  --fill: var(--accent);
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.bar-label { color: var(--muted); font-weight: 600; letter-spacing: 0.03em; }
.bar-track {
  height: 8px;
  border-radius: 4px;
  background: #0a0b0e;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px #ffffff0a;
}
.bar-fill {
  display: block;
  height: 100%;
  width: var(--pct);
  background: var(--fill);
  border-radius: 4px;
  transition: width 0.25s ease-out;
}
.bar-num { font-family: var(--mono); color: var(--text); min-width: 52px; text-align: right; }
.bar.hp { --fill: var(--hp); }
.bar.hp.low .bar-fill { background: #ff4b55; }
.bar.mp { --fill: var(--mp); }
.bar.sp { --fill: var(--sp); }
.bar.target { --fill: var(--hp); grid-template-columns: 1fr auto; }
@media (prefers-reduced-motion: reduce) { .bar-fill { transition: none; } }

#target-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  margin: 0 -4px -4px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid #4a2a2e;
}
.target-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.eyebrow { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
#target-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target-actions { display: flex; gap: 6px; }
.target-actions button { padding: 4px 12px; font-size: 13px; }
.target-actions .ghost { margin-left: auto; }

/* ---- tabbed panel ---- */

#panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 45vh;
  overflow: hidden;
}

#panel-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
}
#panel.collapsed #panel-tabs { border-bottom: none; }
#panel-tabs [role="tablist"] {
  display: flex;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}
[role="tab"] {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 9px 10px 7px;
  color: var(--muted);
  white-space: nowrap;
}
[role="tab"]:hover:not(:disabled) { color: var(--text); border-color: transparent; }
[role="tab"][aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
#panel.collapsed [role="tab"][aria-selected="true"] { border-bottom-color: transparent; }
[role="tab"] .count { color: var(--faint); font-size: 12px; }

#actions {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 45%;
  padding: 4px 6px;
}

.tab {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 0;
}

.summary {
  display: flex;
  justify-content: space-between;
  padding: 2px 12px 6px;
  font-size: 13px;
  color: var(--muted);
}
.summary .gold { color: var(--warn); font-weight: 600; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 3px 8px 3px 12px;
  border-radius: 6px;
  margin: 0 4px;
}
.rows li:hover { background: var(--panel-2); }
.rows .info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}
.rows .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .count { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.pill {
  flex: none;
  font-size: 11px;
  color: #a9c6ee;
  background: #1f2c40;
  border-radius: 999px;
  padding: 1px 8px;
}
.rows .acts { flex: none; display: flex; gap: 4px; opacity: 0.75; }
.rows li:hover .acts, .rows li:focus-within .acts { opacity: 1; }
.rows .acts button { padding: 3px 10px; font-size: 13px; }
.rows .acts button.armed { border-color: var(--bad); color: var(--bad); opacity: 1; }

/* Equipment: a 3x3 grid, head at the top and feet-ish at the bottom. */
.doll-wrap { position: relative; margin: 6px 10px 2px; }
.doll-body {
  position: absolute;
  left: 50%;
  top: 0;
  height: 100%;
  transform: translateX(-50%);
  fill: color-mix(in srgb, var(--accent) 14%, var(--panel-2));
  stroke: color-mix(in srgb, var(--accent) 45%, var(--border));
  stroke-width: 1.5;
  pointer-events: none;
}
.doll {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 1fr);
  grid-template-areas:
    ".     skull .    "
    ".     eyes  .    "
    "arms  neck  .    "
    "arms  torso hands"
    "wield waist hands"
    "wield legs  .    ";
  gap: 5px 8px;
}
.doll-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 38px;
  padding: 3px 22px 3px 6px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  border: 1px solid var(--border);
}
.doll-slot[data-slot="skull"] { grid-area: skull; }
.doll-slot[data-slot="eyes"] { grid-area: eyes; }
.doll-slot[data-slot="neck"] { grid-area: neck; }
.doll-slot[data-slot="torso"] { grid-area: torso; }
.doll-slot[data-slot="waist"] { grid-area: waist; }
.doll-slot[data-slot="legs"] { grid-area: legs; }
.doll-slot[data-slot="arms"] { grid-area: arms; }
.doll-slot[data-slot="wield"] { grid-area: wield; }
.doll-slot[data-slot="hands"] { grid-area: hands; }
.doll-slot.empty-slot { border-style: dashed; background: color-mix(in srgb, var(--panel) 35%, transparent); }
.doll-slot .slot-icon { position: absolute; right: 4px; bottom: 3px; width: 26px; height: 26px; opacity: 0.95; pointer-events: none; }
.doll-slot:has(.slot-icon) { padding-right: 32px; }
.doll-slot .slot-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.doll-slot .slot-item { font-size: 12px; line-height: 1.2; overflow-wrap: anywhere; }
.doll-slot .remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  padding: 0;
  line-height: 1;
  font-size: 13px;
  background: none;
  border-color: transparent;
  color: var(--muted);
}
.doll-slot:has(.slot-icon) .remove { top: 1px; }
.doll-slot .remove:hover { color: var(--bad); border-color: var(--bad); }

/* Stats */
#stats-body { padding: 0 12px; }
.stat-section + .stat-section { margin-top: 10px; }
.stat-section h4 {
  margin: 4px 0 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.stat-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stat-table td { padding: 2px 0; }
.stat-table td.num { text-align: right; font-family: var(--mono); width: 3.5em; }
.stat-table td.bonus { text-align: right; font-family: var(--mono); width: 3em; font-size: 12px; }
.bonus.up { color: var(--ok); }
.bonus.down { color: var(--bad); }
.bonus.zero { color: var(--faint); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); }
.none { color: var(--faint); font-size: 13px; font-style: italic; }
.plain { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; color: var(--muted); }

.empty { margin: 0; padding: 8px 12px; color: var(--muted); font-style: italic; }

/* ---- log ---- */

#log {
  position: relative;
  grid-area: log;
  min-height: 0;
  margin: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#output {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: calc(13px * var(--chat-scale, 1));
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 4;
}
#output .line { min-height: 1.4em; }
#output-latest {
  position: absolute;
  right: 22px;
  bottom: 58px;
  z-index: 2;
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
#output .sys { color: var(--muted); font-style: italic; }
#output .err { color: var(--bad); }
#output .echo { color: var(--accent); }
#output .trace { color: var(--faint); font-size: 11px; }

/* The chat's tabs, combat summary and options. */
#chat-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 4px 8px 0;
  border-bottom: 1px solid var(--border);
}
#chat-tabs { display: flex; gap: 2px; }
#chat-tabs button {
  position: relative;
  padding: 4px 12px;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
}
#chat-tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
#chat-tabs .unread {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
#combat-tally {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 12px;
  flex: 1;
  font-size: 12px;
  color: var(--muted);
}
#combat-tally[hidden] { display: none; }
#combat-tally b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
#combat-tally button { padding: 1px 8px; font-size: 11px; }
#chat-opts { position: relative; margin-left: auto; }
#chat-opts summary {
  list-style: none;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 15px;
}
#chat-opts summary::-webkit-details-marker { display: none; }
#chat-opts[open] summary, #chat-opts summary:hover { color: var(--text); background: var(--panel-2); }
.chat-opts-menu {
  position: fixed;
  z-index: 60;
  display: grid;
  gap: 8px;
  min-width: 250px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 13px;
}
.chat-opts-menu label:not(.toggle) { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#output.size-s { --chat-scale: 0.85; }
#output.size-l { --chat-scale: 1.2; }
#output.size-xl { --chat-scale: 1.45; }
#output .stamp { display: none; color: var(--faint); font-size: 0.85em; }
#output.stamps .stamp { display: inline; }
#output[data-view="general"]:not(.mixed) .line.k-combat:not(.k-both) { display: none; }
#output[data-view="combat"] .line:not(.k-combat) { display: none; }
#output .line.k-combat { color: #e6b98a; }
#output[data-view="combat"] .line.k-combat { color: inherit; }

#input-form {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--border);
}
#input { flex: 1; min-width: 0; font-family: var(--mono); }

/* ---- on the map: minimap and click menu ---- */

#minimap {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 180px;
  height: 180px;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 2px 8px #000a;
  cursor: grab;
}
#minimap.dragging { cursor: grabbing; box-shadow: 0 6px 18px #000d; }
@media (max-width: 600px) {
  #minimap { width: 104px; height: 104px; bottom: 6px; right: 6px; }
}

#entity-menu {
  position: absolute;
  z-index: 2;
  min-width: 150px;
  max-width: min(240px, calc(100% - 16px));
  max-height: calc(100% - 16px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px #000c;
  padding: 4px;
}
#entity-menu section + section { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
#entity-menu h3 {
  margin: 0;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#entity-menu h3 .hp { color: #ff8a8a; font-weight: normal; font-family: var(--mono); font-size: 12px; }
#entity-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 4px;
  padding: 8px 10px;
  min-height: 36px;
}
#entity-menu button:hover:not(:disabled),
#entity-menu button:focus-visible { background: var(--panel-2); outline: none; }
#entity-menu button .hint { color: var(--muted); font-size: 12px; }

/* ---- phones: keep the command box on screen ---- */

@media (max-width: 899px), (max-aspect-ratio: 1/1) {
  #side { gap: 6px; padding: 6px; }
  #char-card { padding: 8px 10px; gap: 6px; }
  /* HP / MP / SP side by side, number over the track. */
  .bars { flex-direction: row; gap: 10px; }
  .bars .bar {
    flex: 1;
    min-width: 0;
    grid-template-columns: auto 1fr;
    grid-template-areas: "label num" "track track";
    row-gap: 3px;
  }
  .bars .bar-label { grid-area: label; }
  .bars .bar-num { grid-area: num; min-width: 0; }
  .bars .bar-track { grid-area: track; }
  #target-card { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 6px 8px; }
  .target-head { flex: 1 1 100%; }
  #bar-target { flex: 1 1 120px; }
  .target-actions button { padding: 3px 10px; }
  #panel { max-height: 30vh; }
  #log { margin: 6px; }
  [role="tab"] { padding: 9px 7px 7px; }
  #actions { max-width: 30%; }
}


/* ---- hotbar (in the black space beside the map) ---- */

#map-wrap { position: relative; }
#hotbar {
  position: absolute;
  z-index: 3;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #13161bdd;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px #000a;
  user-select: none;
}
#hotbar.vertical { flex-direction: column; }
#hotbar.horizontal { flex-direction: row; }
#hotbar.dragging { opacity: 0.85; box-shadow: 0 8px 24px #000d; }
#hotbar .grip {
  flex: none;
  cursor: grab;
  border-radius: 4px;
  background: repeating-linear-gradient(90deg, #ffffff22 0 2px, transparent 2px 5px);
  touch-action: none;
}
#hotbar.vertical .grip { height: 12px; background: repeating-linear-gradient(0deg, #ffffff22 0 2px, transparent 2px 5px); }
#hotbar.horizontal .grip { width: 12px; }
#hotbar.dragging .grip { cursor: grabbing; }

#hotbar .slot {
  position: relative;
  width: 58px;
  height: 52px;
  padding: 14px 3px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  background: var(--panel-2);
  border-radius: 6px;
  overflow: hidden;
}
#hotbar .slot.empty { background: none; border-style: dashed; color: var(--faint); }
#hotbar .slot .key { position: absolute; top: 2px; left: 5px; font-size: 10px; color: var(--muted); font-family: var(--mono); }
#hotbar .slot .aim { position: absolute; top: 1px; right: 4px; font-size: 10px; color: #ff9a9a; }
#hotbar .slot .icon { font-size: 15px; line-height: 1; }
#hotbar .slot .label {
  max-width: 100%;
  font-size: 10px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#hotbar .slot.heal .icon { color: #3dff7a; }
#hotbar .slot.holy .icon { color: #ffe27a; }
#hotbar .slot.fire .icon { color: #ff7a2e; }
#hotbar .slot.earth .icon { color: #d0a064; }
#hotbar .slot.dark .icon { color: #c07aff; }
#hotbar .slot.arcane .icon { color: #6ab8ff; }
#hotbar .slot.cmd .icon { color: var(--accent); }
#hotbar .slot.fired { animation: slot-fired 0.35s ease-out; }
@keyframes slot-fired { from { background: #3b6297; } to { background: var(--panel-2); } }
@media (prefers-reduced-motion: reduce) { #hotbar .slot.fired { animation: none; } }

.popover {
  position: absolute;
  z-index: 4;
  width: 250px;
  max-height: calc(100% - 16px);
  overflow-y: auto;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px #000c;
}
.popover h3 { margin: 0 0 6px; font-size: 13px; }
.popover h4 { margin: 8px 0 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.popover .current { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.popover .current span { flex: 1 1 100%; font-weight: 600; }
.popover .current button { padding: 3px 8px; font-size: 12px; }
.popover .choices { display: flex; flex-wrap: wrap; gap: 4px; }
.popover .choices button { padding: 3px 8px; font-size: 12px; }
.popover .custom { display: flex; gap: 4px; }
.popover .custom input { flex: 1; min-width: 0; padding: 4px 6px; font-size: 12px; font-family: var(--mono); }
.popover .custom button { padding: 3px 8px; font-size: 12px; }
.popover .hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

/* When the bar doesn't fit along its edge (hotbar.js adds these). */
#hotbar.compact .slot { width: 50px; height: 42px; padding-top: 12px; }
#hotbar.compact .slot .label { font-size: 9px; }
#hotbar.tiny .slot { width: 34px; height: 32px; padding-top: 10px; }
#hotbar.tiny .slot .label { display: none; }

/* Phones: a smaller bar. */
@media (max-width: 600px) {
  #hotbar { gap: 3px; padding: 3px; }
  #hotbar .slot { width: 30px; height: 30px; padding-top: 9px; }
  #hotbar .slot .key { top: 0; left: 3px; font-size: 9px; }
  #hotbar .slot .label { display: none; }
  #hotbar .slot .icon { font-size: 13px; }
}

/* ---- spellbook: an open book in the tab ---- */

.book {
  position: relative;
  margin: 2px 10px 8px;
  padding: 12px 14px 12px 22px;
  color: #3b2a17;
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  background:
    radial-gradient(ellipse at 20% 0%, #fff6dc88, transparent 60%),
    linear-gradient(180deg, #efe2c2, #e2cfa2);
  border: 1px solid #8a6a3a;
  border-left: 9px solid #5e3519;
  border-radius: 3px 10px 10px 3px;
  box-shadow: inset 10px 0 12px -8px #00000066, inset 0 0 40px #a0783a44, 0 2px 8px #0008;
}
/* Stitching along the spine. */
.book::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 8px;
  bottom: 8px;
  border-left: 2px dashed #c9a36a88;
}
.book-title {
  margin: 0 0 6px;
  text-align: center;
  font-size: 18px;
  font-variant: small-caps;
  letter-spacing: 0.08em;
  color: #6b2410;
}
.book-title::after {
  content: "❦";
  display: block;
  font-size: 12px;
  color: #8a5a2a;
}
.book-empty { margin: 12px 0; text-align: center; font-style: italic; color: #6d5536; }
.book .chapter {
  margin: 12px 0 4px;
  font-size: 13px;
  font-variant: small-caps;
  letter-spacing: 0.1em;
  text-transform: capitalize;
  color: #7a2e14;
  border-bottom: 3px double #b08a5a;
}
.book .school-skill { float: right; font-variant: normal; letter-spacing: 0; font-size: 12px; color: #6d5536; }
.book .spell { padding: 6px 0 8px; border-bottom: 1px dotted #b08a5a88; }
.book .spell:last-child { border-bottom: none; }
.spell-head { display: flex; align-items: center; gap: 8px; }
.spell-head h5 {
  flex: 1;
  margin: 0;
  font-size: 15px;
  font-variant: small-caps;
  text-transform: capitalize;
  letter-spacing: 0.03em;
}
.glyph {
  flex: none;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 13px;
  background: #3b2a17;
  box-shadow: 0 0 0 2px #c9a36a;
}
.spell.heal .glyph { color: #3dff7a; }
.spell.holy .glyph { color: #ffe27a; }
.spell.fire .glyph { color: #ff8a3d; }
.spell.earth .glyph { color: #d0a064; }
.spell.dark .glyph { color: #c07aff; }
.spell.arcane .glyph { color: #7ac0ff; }
.needs { font-size: 11px; font-style: italic; color: #7a6040; }
.book .cost { font-size: 11px; font-weight: 600; color: #2f4f8a; }
.book .desc { margin: 3px 0 5px 32px; font-size: 13px; font-style: italic; line-height: 1.35; }
.spell-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-left: 32px; }
.spell-acts button {
  padding: 2px 10px;
  font: inherit;
  font-size: 12px;
  color: #3b2a17;
  background: #f6ecd2;
  border: 1px solid #a07a48;
  border-radius: 999px;
}
.spell-acts button:hover:not(:disabled) { background: #fff6de; border-color: #6b2410; }
.spell-acts button:disabled { opacity: 0.45; }

/* ---- shop ---- */

.list-head {
  margin: 6px 12px 2px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.shop-list .price { font-size: 12px; font-family: var(--mono); color: var(--warn); white-space: nowrap; }
.shop-list .price.exp { color: #b69cff; }
.shop-list .price.short { color: var(--bad); }
.shop-list .qty {
  width: 52px;
  padding: 3px 4px;
  font: inherit;
  font-size: 13px;
  text-align: right;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.shop-list .acts { opacity: 1; }
.shop-manual { display: flex; gap: 6px; padding: 0 12px 6px; }
.shop-manual input[name="item"] { flex: 1; min-width: 0; padding: 3px 6px; font-size: 13px; }
.shop-manual .qty { width: 52px; padding: 3px 4px; text-align: right; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; font: inherit; font-size: 13px; }
[role="tab"][data-tab="shop"] { color: var(--warn); }
[role="tab"][data-tab="store"] { color: var(--ok); }
[role="tab"][data-tab="store"][aria-selected="true"] { border-bottom-color: var(--ok); }
.store-head { display: flex; align-items: center; gap: 8px; padding-right: 12px; }
.store-note { flex: 1; margin: 8px 12px 2px; font-size: 12px; color: var(--muted); }
.store-head button { padding: 3px 10px; font-size: 12px; }

/* ---- god ---- */

[role="tab"][data-tab="god"] { color: #d7a6ff; }
[role="tab"][data-tab="god"][aria-selected="true"] { border-bottom-color: #d7a6ff; }
#tab-god { padding-bottom: 10px; }
.god-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px 4px; font-size: 12px; }
.god-where { font-family: var(--mono); color: var(--text); }
.god-unsaved { flex: 1; color: var(--muted); }
.god-unsaved.dirty { color: var(--warn); }
.god-head button { padding: 3px 10px; font-size: 12px; }
.god-kinds { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 12px 6px; }
.god-kinds button { padding: 3px 9px; font-size: 12px; border-radius: 999px; }
.god-kinds button[aria-checked="true"] { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
.god-row { display: flex; gap: 6px; align-items: center; padding: 2px 12px 4px; }
.god-row input, .god-row select { min-width: 0; padding: 3px 6px; font: inherit; font-size: 13px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
.god-search, .god-text { flex: 1; }
.god-level { width: 70px; }
.god-num { width: 76px; }
.god-label { font-size: 12px; color: var(--muted); }
.god-row button { padding: 3px 10px; font-size: 13px; }
.god-list { list-style: none; margin: 2px 12px; padding: 0; max-height: 190px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }
.god-list li { padding: 3px 8px; font-size: 13px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.god-list li:hover { background: var(--panel-2); }
.god-list li[aria-selected="true"] { background: var(--accent-dim); color: #fff; }
.god-listbox .empty { padding: 2px 12px; margin: 0; font-size: 12px; }
.god-tiles { display: flex; flex-wrap: wrap; gap: 2px; margin: 2px 12px; max-height: 190px; overflow-y: auto; }
.god-tiles canvas { width: 32px; height: 32px; cursor: pointer; border: 2px solid transparent; image-rendering: pixelated; }
.god-tiles canvas.chosen { border-color: var(--accent); }
.god-place { display: flex; align-items: center; gap: 8px; padding: 6px 12px; }
.god-preview { width: 40px; height: 40px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; flex: none; }
.god-choice { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.god-sec { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 2px; }
.god-wares li { display: flex; justify-content: space-between; align-items: center; }
.god-wares button { padding: 2px 8px; font-size: 12px; }
.god-hint { margin: 8px 12px 0; font-size: 12px; color: var(--muted); }
.god-pop { padding: 2px 8px !important; font-size: 14px !important; }
.god-float {
  position: fixed;
  z-index: 40;
  width: min(380px, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  padding: 0 0 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.god-float-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  cursor: move;
  user-select: none;
  touch-action: none;
  font-weight: 600;
  color: #d7a6ff;
}
.god-float-bar button { padding: 2px 10px; font-size: 12px; cursor: pointer; }
[role="tab"][data-tab="shop"][aria-selected="true"] { border-bottom-color: var(--warn); }

/* ---- login screen ---- */

#login-screen { display: none; }
body.in-login #login-screen {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-y: auto;
}
body.in-login #play-area { display: none; }
.login-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 40px #000a;
}
.login-title { margin: 0; font-size: 28px; letter-spacing: 0.06em; color: var(--accent); }
.login-sub { margin: 0 0 10px; color: var(--muted); }
.login-card label:not(.toggle) { margin-top: 6px; font-size: 12px; color: var(--muted); }
.login-card input[type="text"], .login-card input[type="password"] { padding: 9px 10px; }
.login-card .remember { display: flex; align-items: center; gap: 8px; margin: 8px 0 4px; color: var(--muted); font-size: 13px; }
#login-play { margin-top: 6px; padding: 9px; font-weight: 600; }
#login-msg { min-height: 1.4em; margin: 6px 0 0; font-size: 13px; color: var(--muted); }
#login-msg.error { color: var(--bad); }
.login-new { margin-top: 8px; padding: 10px; border: 1px solid var(--accent-dim); border-radius: 8px; background: var(--panel-2); }
.login-new p { margin: 0 0 8px; }
.login-new-acts { display: flex; gap: 8px; }
.race-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.race-buttons { display: grid; grid-template-columns: 1fr; }
.race-buttons .race {
  display: grid;
  grid-template-columns: 40px 1fr;
  grid-template-areas: "pic name" "pic tags" "pic note";
  align-items: center;
  column-gap: 10px;
  padding: 8px 10px;
  text-align: left;
}
.race-pic { grid-area: pic; width: 40px; height: 40px; image-rendering: pixelated; border-radius: 6px; background: #0a0b0e; }
.race-name { grid-area: name; font-weight: 600; text-transform: capitalize; }
.race-tags { grid-area: tags; font-family: var(--mono); font-size: 11px; color: var(--ok); white-space: pre-wrap; }
.race-note { grid-area: note; font-size: 11px; color: var(--warn); font-style: italic; }
.login-server { margin: 10px 0 0; font-size: 11px; color: var(--faint); }
.login-server code { font-family: var(--mono); color: var(--muted); }

/* ---- connection lost ---- */

#overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  background: #000b;
}
.overlay-card {
  width: min(340px, calc(100% - 32px));
  padding: 18px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 40px #000c;
}
.overlay-card h3 { margin: 0 0 6px; }
#overlay-text { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.overlay-acts { display: flex; justify-content: center; gap: 8px; }

/* ---- death ---- */

#death {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, #3a060a88 0%, #1a0003dd 70%, #000000f0 100%);
  animation: death-in 1.2s ease-out;
}
/* The world behind goes grey while you're dead. */
body.dead #map { filter: grayscale(1) brightness(0.55); transition: filter 1s; }
#map { transition: filter 0.6s; }
.death-card {
  width: min(360px, calc(100% - 32px));
  padding: 22px 20px 18px;
  text-align: center;
  background: #120708ee;
  border: 1px solid #6b1c22;
  border-radius: 12px;
  box-shadow: 0 0 40px #8a141e66, 0 16px 40px #000c;
}
#death-title {
  margin: 0 0 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #e0424c;
  text-shadow: 0 0 18px #b3121e99;
  animation: death-title 1.6s ease-out;
}
#death-loss { margin: 0 0 6px; color: #f0c9c9; }
#death-loss:empty { display: none; }
#death-text { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
@keyframes death-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes death-title { from { opacity: 0; letter-spacing: 0.4em; } to { opacity: 1; letter-spacing: 0.06em; } }
@media (prefers-reduced-motion: reduce) {
  #death, #death-title { animation: none; }
  #map, body.dead #map { transition: none; }
}

/* ---- yes / no questions ---- */

#prompt-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--warn);
  background: #2a2412;
}
#prompt-text { flex: 1; min-width: 0; font-size: 13px; }
#prompt-bar button { padding: 4px 14px; }

/* ---- dialogs (bug report) ---- */

dialog {
  width: min(460px, calc(100vw - 24px));
  padding: 0;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px #000c;
}
dialog::backdrop { background: #000a; }
#bug-form { display: flex; flex-direction: column; gap: 6px; padding: 18px; }
#bug-form h2 { margin: 0; font-size: 18px; }
#bug-form label:not(.toggle) { margin-top: 6px; font-size: 12px; color: var(--muted); }
#bug-form .toggle { display: flex; align-items: flex-start; gap: 8px; margin-top: 6px; font-size: 13px; color: var(--muted); }
#bug-form textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  resize: vertical;
}
.dialog-sub { margin: 0; font-size: 13px; color: var(--muted); }
.dialog-acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

/* ---- stats under the HP/MP bars ---- */

.char-stats { padding: 6px 12px 8px; border-top: 1px solid var(--border); margin-top: 4px; }
.cs-attrs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.cs-attr {
  display: flex; flex-direction: column; align-items: center;
  padding: 3px 0 2px; border-radius: 6px; background: var(--bg); border: 1px solid var(--border);
  line-height: 1.1;
}
.cs-attr .cs-key { font-size: 10px; letter-spacing: 0.06em; color: var(--muted); }
.cs-attr .cs-val { font-family: var(--mono); font-size: 14px; color: var(--text); }
.cs-bonus { font-family: var(--mono); font-size: 10px; }
.cs-bonus.up { color: var(--ok); }
.cs-bonus.down { color: var(--bad); }
.cs-facts { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 12px; }
.cs-fact .cs-key { color: var(--muted); }
.cs-fact .cs-val { font-family: var(--mono); color: var(--text); }
.cs-fact.gold .cs-val { color: var(--warn); }
.cs-fact.exp .cs-val { color: #b69cff; }
.cs-conds { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.cs-cond { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--accent-dim); color: var(--text); }

/* ---- what NPCs say ---- */

#speech {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 6;
  width: min(440px, calc(100% - 24px));
  transform: translateX(-50%);
  padding: 10px 14px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px #000c;
}
.speech-head { display: flex; align-items: baseline; gap: 6px; }
#speech-who { font-size: 15px; }
#speech-verb { flex: 1; color: var(--muted); font-size: 12px; }
#speech-close { padding: 0 8px; font-size: 16px; line-height: 1.2; }
#speech-text { margin: 6px 0 8px; line-height: 1.4; }
#speech-choices { display: flex; flex-wrap: wrap; gap: 6px; }
#speech-choices:empty { display: none; }
#speech-choices button { text-transform: capitalize; }
#speech.nudge { animation: speech-nudge 0.4s; }
@keyframes speech-nudge { 25% { transform: translateX(calc(-50% - 6px)); } 75% { transform: translateX(calc(-50% + 6px)); } }
.speech-note { margin: -2px 0 8px; font-style: italic; color: var(--muted); }
.store-buy-row { margin: 4px 12px 8px; }

/* ---- world map ---- */

#world-map {
  position: fixed;
  inset: 5vh 5vw;
  z-index: 30;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px #000d;
}
#world-map[hidden] { display: none; }
.wm-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.wm-bar strong { font-size: 15px; }
.wm-info { flex: 1; color: var(--muted); font-size: 12px; }
.wm-bar button { padding: 3px 10px; }
#world-map canvas { flex: 1; min-height: 0; width: 100%; cursor: grab; touch-action: none; }
#world-map canvas.dragging { cursor: grabbing; }

/* ---- dialogue editor (a God tool: always the Modern look) ---- */

.editor-dialog {
  position: fixed;
  z-index: 35;
  top: 4vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 16px));
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  color: #dde0e5;
  background: #171a20;
  border: 1px solid #2a2f39;
  border-radius: 8px;
  box-shadow: 0 16px 48px #000d;
  font: 14px/1.4 system-ui, sans-serif;
}
.editor-dialog[hidden] { display: none; }
.de-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid #2a2f39; }
.de-title { font-size: 15px; }
.de-warn { margin: 8px 14px 0; padding: 6px 10px; color: #e0b341; background: #3a3018; border-radius: 6px; font-size: 13px; }
.de-body { flex: 1; overflow-y: auto; padding: 4px 14px 10px; }
.de-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid #2a2f39; }
.de-hint { margin: 2px 0 6px; font-size: 12px; color: #858c99; }
.de-sec, .de-stage { margin: 8px 0; }
.de-stage { padding: 8px 10px; border: 1px solid #2a2f39; border-radius: 8px; background: #1b1f26; }
.de-stage-head strong { font-size: 13px; }
.de-row { display: flex; gap: 6px; align-items: center; margin: 4px 0; flex-wrap: wrap; }
.de-grow { flex: 1; }
.de-label-text { width: 64px; font-size: 12px; color: #858c99; }
.de-answers { margin-left: 50px; }
.de-answer { padding: 6px 8px; margin: 6px 0; border-left: 3px solid #2b4a73; background: #171a20; border-radius: 4px; }
.de-effect { margin-left: 16px; }
.editor-dialog input, .editor-dialog select, .editor-dialog textarea {
  font: inherit; font-size: 13px; color: #dde0e5; background: #0e1014; border: 1px solid #2a2f39; border-radius: 6px; padding: 4px 7px;
}
.editor-dialog textarea { flex: 1; min-width: 200px; resize: vertical; }
.editor-dialog .de-row > input:not(.de-num):not(.de-label) { flex: 1; min-width: 120px; }
.editor-dialog .de-label { width: 130px; }
.editor-dialog .de-num { width: 80px; }
.editor-dialog button { font: inherit; font-size: 13px; color: #dde0e5; background: #1e222a; border: 1px solid #2a2f39; border-radius: 6px; padding: 3px 10px; cursor: pointer; text-shadow: none; filter: none; }
.editor-dialog button.primary { background: #2b4a73; border-color: #3b6297; }
.editor-dialog button.ghost { background: none; }
.editor-dialog button:hover { border-color: #6aa9ff; }
.editor-dialog .de-small { font-size: 12px; padding: 2px 8px; }
.editor-dialog .list-head { margin: 10px 0 2px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: #858c99; font-family: system-ui, sans-serif; }
.de-follow { margin: 6px 0 4px 16px; padding: 6px 8px; border-left: 3px dashed #3b6297; background: #1b1f26; border-radius: 4px; }
.de-follow .de-answers { margin-left: 20px; }
.god-col { flex-direction: column; align-items: stretch; }
.god-cmds { max-height: 260px; overflow-y: auto; margin: 2px 12px 4px; }
.god-cmd-group { margin: 8px 0 2px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.god-cmd { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "use level" "desc desc"; gap: 1px 8px; width: 100%; text-align: left; padding: 4px 6px !important; margin: 1px 0; background: none !important; border: 1px solid transparent !important; }
.god-cmd:hover { border-color: var(--border) !important; background: var(--panel-2) !important; }
.god-cmd code { grid-area: use; font-family: var(--mono); font-size: 12px; color: #9ecbff; overflow-wrap: anywhere; }
.god-cmd-desc { grid-area: desc; font-size: 12px; color: var(--muted); }
.god-cmd-level { grid-area: level; font-size: 10px; color: var(--warn); white-space: nowrap; }
.god-sec summary { cursor: pointer; margin: 8px 12px 2px; }

.fl-dialog { width: min(420px, calc(100vw - 16px)); top: 12vh; }
.fl-row { justify-content: space-between; padding: 3px 6px; border-bottom: 1px solid #2a2f39; }
.fl-row code { font-family: var(--mono); font-size: 13px; color: #9ecbff; }
.fl-everyday code { color: #858c99; }
.fl-form { margin-top: 10px; }
.fl-form input { flex: 1; }

/* ---- skills ---- */
.skill-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 36px; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.skill-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skill-bar { --pct: 0%; height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--accent) var(--pct), rgba(128, 128, 128, 0.25) var(--pct)); }
.skill-value { text-align: right; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.god-away { padding: 16px 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.god-away p { flex: 1 1 100%; margin: 0 0 4px; color: var(--muted); }

/* ---- touch screens ---- */

/* No double-tap zoom on the game's controls. */
#map, #dpad button, #hotbar, #panel button, #chat-bar button, #topbar button { touch-action: manipulation; }

/* On-screen arrows: a cross in the map's bottom-left corner. */
#dpad {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  grid-template-areas: ". n ." "w . e" ". s .";
  gap: 2px;
  opacity: 0.8;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#dpad button {
  padding: 0;
  font-size: 18px;
  line-height: 1;
  color: #fff;
  background: rgba(10, 12, 16, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  touch-action: none;
}
#dpad button.held { background: rgba(106, 169, 255, 0.55); border-color: rgba(255, 255, 255, 0.6); }
#dpad [data-dir="n"] { grid-area: n; }
#dpad [data-dir="w"] { grid-area: w; }
#dpad [data-dir="e"] { grid-area: e; }
#dpad [data-dir="s"] { grid-area: s; }
@media (max-width: 600px) {
  #dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 42px); left: 6px; bottom: 6px; }
}

/* Phones: the page scrolls, with the map on top, the chat right under it
   and your character below; the top bar fits the width. */
@media (max-width: 600px) {
  html, body { height: auto; min-height: 100%; }
  #topbar { gap: 6px; padding: 4px 8px; flex-wrap: nowrap; }
  #status-text, #look-toggle { display: none; }
  #topbar button, #settings summary { padding: 5px 8px; font-size: 12px; }
  .brand { font-size: 15px; }
  body.playing #play-area {
    flex: none;
    grid-template-areas: "map" "log" "side";
    grid-template-rows: auto clamp(220px, 38vh, 340px) auto;
  }
  body.playing #map-wrap { height: min(100vw, 56vh); }
  body.playing #side { overflow: visible; padding-bottom: 12px; }
  body.playing #panel { max-height: none; }
  #chat-tabs button { padding: 6px 10px; }
  #combat-tally { font-size: 11px; gap: 2px 8px; }
}

.store-locked { margin: 4px 12px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); }
.store-size { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 12px; color: var(--muted); font-size: 13px; }

/* Item pictures and details (tap an item). */
.rows li[data-item] { flex-wrap: wrap; }
.rows .info.tappable { cursor: pointer; }
.item-icon { flex: none; width: 28px; height: 28px; margin: -2px 0; image-rendering: auto; }
.item-details {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  margin: 0 0 6px 36px;
  padding: 6px 10px;
  font-size: 12px;
  border-left: 2px solid var(--accent);
  background: var(--panel-2);
  border-radius: 0 6px 6px 0;
}
.item-details .muted { color: var(--muted); }
.item-details .item-kind { font-weight: 600; }
.item-details .item-desc { flex-basis: 100%; font-style: italic; color: var(--muted); }
.rows li.open { background: var(--panel-2); }

/* ---- journal, friends, trade ---- */
.journal { list-style: none; margin: 0; padding: 6px 12px; display: grid; gap: 8px; }
.journal li { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.journal li.done { opacity: 0.7; }
.journal .q-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.journal .q-badge { font-size: 11px; font-weight: normal; padding: 1px 8px; border-radius: 999px; background: var(--accent-dim); }
.journal li.done .q-badge { background: #2e5b3f; }
.journal .q-text { margin: 4px 0 0; color: var(--muted); }
.friend-form { display: flex; gap: 6px; padding: 8px 12px; }
.friend-form input { flex: 1; min-width: 0; }
.online-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--faint); }
.online-dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.trade-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.trade-cols section { min-width: 0; }
.trade-gold { display: flex; align-items: center; gap: 8px; margin: 4px 12px; color: var(--muted); font-size: 13px; }
.trade-gold input { width: 100px; }
.trade-ready { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: #2e5b3f; color: #d8f5e2; text-transform: none; letter-spacing: 0; }
.trade-go { margin: 6px 12px; }
#output .line.k-whisper { color: #d4a6f0; }
#output[data-view="whisper"] .line:not(.k-whisper) { display: none; }
#output .line.k-whisper { cursor: pointer; }
.je-list { display: grid; gap: 6px; margin: 8px 0; }
.je-entry { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }
.je-entry code { font-size: 12px; }
.je-entry .je-acts { grid-row: span 2; display: flex; gap: 4px; align-items: center; }
.je-entry .muted { color: var(--muted); font-size: 12px; }
@media (max-width: 600px) { .trade-cols { grid-template-columns: 1fr; } }
#world-map canvas.placing { cursor: crosshair; }
#world-map [data-map="note"][aria-pressed="true"] { border-color: var(--accent); background: var(--accent-dim); }
.muted-note { color: var(--muted); font-size: 12px; }
.de-journal { margin: -2px 0 4px 18px; padding: 4px 8px; border-left: 2px solid var(--accent-dim); font-size: 12px; }
.de-journal .de-jtitle { max-width: 180px; }
.de-journal .de-jdone { white-space: nowrap; font-size: 12px; }
