/* ── ARCANE APOTHECARY — crunchy DOS/BBS chrome over a cozy world ── */

:root {
  --bg: #07070c;
  --panel: #10101a;
  --panel-2: #161624;
  --line: #7fb2c9;
  --line-dim: #3d5a6b;
  --text: #d8e2ec;
  --dim: #71809314;
  --muted: #6a7482;
  --gold: #e8c15a;
  --good: #7dd882;
  --bad: #e06c5a;
  --amber: #e8a94a;
  --title-bg: #1c2b33;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* display overrides must never defeat the hidden attribute */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  overflow: hidden;
}

body {
  font-family: 'VT323', 'Courier New', monospace;
  color: var(--text);
  -webkit-font-smoothing: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Canvas: fixed 320×180 internal, integer-scaled, crisp pixels */
#canvas-wrap {
  position: relative;
  image-rendering: pixelated;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

/* Subtle CRT scanlines + vignette over the whole app */
#scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.14) 0px,
      rgba(0, 0, 0, 0.14) 1px,
      transparent 1px,
      transparent 3px
    ),
    radial-gradient(ellipse at center, transparent 58%, rgba(0, 0, 0, 0.38) 100%);
  z-index: 5;
}

/* UI layer floats over canvas; scale-aware font size */
#ui-root {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  font-size: calc(6px * var(--ui-scale, 3));
}

/* ── HUD: one chip family ────────────────────────────────────── */
/* Every readout and prompt shares the same translucent chip
   spec — background, border, padding, letter-spacing — so the
   corners of the screen feel like one instrument panel. */

.hud-chip {
  background: rgba(7, 7, 12, 0.82);
  border: 1px solid var(--line-dim);
  padding: 0.12em 0.6em;
  letter-spacing: 0.05em;
}

.hud-chip.readout { font-size: 0.95em; }
.hud-chip.prompt { font-size: 1em; }

/* top-left status row: clock first, coin to its right */
#hud-left {
  position: absolute;
  top: 0.6em;
  left: 0.6em;
  display: flex;
  align-items: stretch;
  gap: 0.45em;
}

#coin { color: var(--text); }

#coin .label { color: var(--muted); }

#clock { color: var(--text); }

#clock .phase { color: var(--muted); }

/* "Studying Sulfur — 23m" — appears only while a study simmers */
#study-chip {
  color: var(--amber);
  cursor: pointer;
  font-family: inherit;
  pointer-events: auto; /* #ui-root is pointer-transparent */
}

#study-chip:hover { border-color: var(--line); color: var(--gold); }

/* seated and reading: the chip breathes with the page */
#study-chip.reading {
  color: var(--gold);
  animation: study-reading 2.4s ease-in-out infinite;
}

@keyframes study-reading { 50% { opacity: 0.65; } }

/* phase glyph: a small square tinted like the sky right now */
#clock .glyph {
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  border: 1px solid rgba(216, 226, 236, 0.4);
  transform: translateY(0.06em);
  margin-right: 0.3em;
}

/* top-right: window shortcuts — POUCH [P] · SPELLBOOK [B] */
#hud-right {
  position: absolute;
  top: 0.6em;
  right: 0.6em;
  display: flex;
  align-items: stretch;
  gap: 0.45em;
}

#hud-right button {
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  letter-spacing: 0.08em;
  pointer-events: auto; /* #ui-root is pointer-transparent */
}

#hud-right button:hover {
  border-color: var(--line);
  color: var(--gold);
}

#hud-right .key { color: var(--gold); }

#prompt {
  position: absolute;
  bottom: 0.6em;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(7, 7, 12, 0.88);
  border-color: var(--line);
  color: var(--text);
  white-space: nowrap;
}

#prompt .key { color: var(--gold); }

#toasts {
  position: absolute;
  bottom: 0.6em;
  left: 0.6em;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.3em;
  z-index: 320; /* above editor chrome and panels */
}

/* edit mode: move toasts to the bottom-right (status bar owns
   the bottom-left; sidebar the left edge) and make them unmissable */
body.editing #toasts {
  left: auto;
  right: 0.6em;
  bottom: 0.5em;
}

body.editing .toast {
  font-size: 1.05em;
  border-left-width: 4px;
}

.toast {
  padding: 0.1em 0.55em;
  background: rgba(7, 7, 12, 0.88);
  border-left: 3px solid var(--gold);
  color: var(--text);
  max-width: 22em;
  animation: toast-in 0.12s steps(2) both;
}

.toast.fade { opacity: 0; transition: opacity 0.6s linear; }
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }

@keyframes toast-in {
  from { transform: translateX(-0.6em); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ── MODAL WINDOWS (old RPG shop menu look) ──────────────────── */

#modal-root {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 220; /* windows above editor chrome and the sprite editor */
}

.window {
  pointer-events: auto;
  min-width: 24em;
  max-width: 34em;
  max-height: 92%;
  background: var(--panel);
  border: 3px solid var(--line);
  outline: 2px solid #05050a;
  box-shadow:
    inset 0 0 0 2px #05050a,
    inset 0 0 0 3px var(--line-dim),
    0 0 0 1px #05050a,
    0 1em 3em rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  animation: win-in 0.1s steps(2) both;
}

@keyframes win-in {
  from { transform: scale(1.03); opacity: 0.4; }
  to { transform: none; opacity: 1; }
}

.win-title {
  background: var(--line);
  color: #0a0d12;
  text-align: center;
  padding: 0.1em 0.6em;
  font-size: 1.05em;
  letter-spacing: 0.12em;
  border-bottom: 2px solid #05050a;
}

.win-body {
  padding: 0.6em 0.9em 0.5em;
  line-height: 1.15;
  overflow: hidden auto;
}

.win-footer {
  border-top: 1px solid var(--line-dim);
  padding: 0.25em 0.9em;
  color: var(--muted);
  font-size: 0.85em;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3em 1.4em;
}

.win-footer .key { color: var(--gold); }

/* ── FULL-WINDOW EDITOR TOOLS (data / sound editors) ──────────── */
/* Editor tools want ROOM — the world behind is in edit mode and
   doesn't need babysitting. Same chunky window chrome, viewport-
   filling. Sized in % of #modal-root (which spans the window). */
.window.win-full {
  min-width: 0;
  max-width: none;
  max-height: none;
  width: 96%;
  height: 96%;
}

.window.win-full .win-body {
  flex: 1;
  min-height: 0;
}

/* Ledger / list rows */
.row {
  display: flex;
  justify-content: space-between;
  gap: 1em;
  padding: 0.05em 0.35em;
  white-space: nowrap;
}

.row.selected {
  background: var(--panel-2);
  outline: 1px solid var(--line-dim);
}

.row.selected::before { content: '► '; color: var(--gold); }
.row:not(.selected)::before { content: '  '; }

.row .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.row .num { color: var(--gold); }
.row .name { color: var(--text); }
.row .muted { color: var(--muted); }
.row .bad { color: var(--bad); }
.row .good { color: var(--good); }

.sec-head {
  color: var(--line);
  letter-spacing: 0.15em;
  margin: 0.5em 0 0.2em;
  border-bottom: 1px dashed var(--line-dim);
  padding-bottom: 0.1em;
}

.sec-head:first-child { margin-top: 0; }

.wide { white-space: normal; }

.spell-block { margin: 0.35em 0; }
.spell-block .school { color: var(--muted); }
.spell-block .note {
  color: var(--muted);
  font-size: 0.85em;
  white-space: normal;
  margin-left: 1.2em;
}
.spell-block .comp { margin-left: 1.2em; }
.spell-block .comp .prop { color: var(--amber); }

/* Discovery / observation panels */
.center { text-align: center; }
.big { font-size: 1.35em; color: var(--gold); letter-spacing: 0.1em; }
.flavor { color: var(--muted); white-space: normal; }
.gold { color: var(--gold); }
.amber { color: var(--amber); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.muted { color: var(--muted); }
.hr { border-top: 1px dashed var(--line-dim); margin: 0.45em 0; }
.indent { margin-left: 1.2em; }

/* ── TITLE SCREEN ────────────────────────────────────────────── */
/* Full-bleed title art with a keyboard-navigable menu. The art
   covers the viewport; the text wordmark only shows when the PNG
   is missing. Menu: ↑↓ select, Enter confirms (N still works). */

#title-screen {
  position: absolute;
  inset: 0;
  background: rgba(4, 5, 9, 0.9);
  pointer-events: auto;
}

#title-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;   /* fill the screen; overflow crops */
  /* top-aligned: with the art's 4:3 shape in a 16:9 frame, ALL the
     crop falls at the bottom — the top of the art never cuts off
     (the image content reads as sitting lower on screen) */
  object-position: center top;
}

#title-art.smooth { image-rendering: auto; }

/* fallback wordmark — centered, only visible without art */
#title-wordmark {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: 4.2em;
  line-height: 0.85;
  color: var(--gold);
  text-shadow:
    0.06em 0.06em 0 #5a3d10,
    0.12em 0.12em 0 #05050a;
}

.title-menu {
  position: absolute;
  bottom: 9%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.45em;
  align-items: center;
}

.title-menu button {
  font-family: inherit;
  font-size: 1.15em;
  letter-spacing: 0.08em;
  background: rgba(7, 7, 12, 0.82);
  color: var(--text);
  border: 2px solid var(--line);
  outline: 2px solid #05050a;
  padding: 0.15em 1.6em;
  min-width: 14em;
  cursor: pointer;
}

.title-menu button:hover,
.title-menu button:focus-visible,
.title-menu button.selected {
  background: var(--title-bg);
  border-color: var(--gold);
  color: var(--gold);
}

#title-copyright {
  position: absolute;
  bottom: 1.8%;
  left: 0;
  width: 100%;
  text-align: center;
  color: var(--muted);
  font-size: 0.85em;
  letter-spacing: 0.14em;
  pointer-events: none;
}

/* ── DEBUG PANEL ─────────────────────────────────────────────── */

#debug-panel {
  position: absolute;
  top: 2.4em;
  left: 0.7em;
  background: rgba(5, 8, 5, 0.9);
  border: 1px solid #4a6b4a;
  color: #9dd89d;
  font-size: 0.8em;
  padding: 0.3em 0.6em;
  pointer-events: auto;
  line-height: 1.2;
  max-width: 30em;
  white-space: pre;
  z-index: 220; /* above editor chrome */
}

/* while editing, sit right of the sidebar instead of under it */
body.editing #debug-panel {
  left: 15em;
}

#debug-panel button {
  font-family: inherit;
  font-size: 1em;
  background: #0d1a0d;
  color: #9dd89d;
  border: 1px solid #4a6b4a;
  padding: 0 0.5em;
  margin: 0.1em 0.25em 0.1em 0;
  cursor: pointer;
}

#debug-panel button:hover { background: #1a2e1a; }

/* ── EDITOR (backtick god mode) ──────────────────────────────── */

body.editing #hud { display: none; }

#editor-root {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: calc(5px * var(--ui-scale, 3));
  z-index: 50; /* above HUD, below sprite editor / modals / tooltips */
}

/* Left sidebar: full-label tools, sections, overlays, exit */
.ed-sidebar {
  position: absolute;
  top: 0.4em;
  bottom: 0.4em;
  left: 0.4em;
  width: 14em;
  display: flex;
  flex-direction: column;
  gap: 0.12em;
  padding: 0.35em 0.35em 0.45em;
  background: rgba(7, 7, 12, 0.92);
  border: 1px solid var(--line);
  box-shadow: 0 0.4em 1.6em rgba(0, 0, 0, 0.55);
  pointer-events: auto;
  overflow-y: auto;
  scrollbar-width: thin;
}

.ed-side-title {
  color: var(--line);
  letter-spacing: 0.22em;
  font-size: 0.8em;
  margin: 0.7em 0.1em 0.2em;
  border-bottom: 1px dashed var(--line-dim);
  padding-bottom: 0.15em;
  flex: none;
}

.ed-side-title:first-child { margin-top: 0; }

.ed-sidebar .ed-btn {
  display: flex;
  align-items: center;
  gap: 0.5em;
  width: 100%;
  text-align: left;
  padding: 0.24em 0.5em;
  margin: 0;
}

.ed-sidebar .ed-map-select { width: 100%; max-width: none; }

.ed-btn-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ed-key {
  flex: none;
  font-size: 0.8em;
  color: var(--gold);
  border: 1px solid var(--line-dim);
  padding: 0 0.25em;
  background: var(--panel-2);
}

.ed-btn.active .ed-key { color: #0a0d12; border-color: #0a0d12; }

/* overlay toggles (grid / collision / …) */
.ed-layer-toggle {
  font-family: inherit;
  font-size: 1em;
  display: flex;
  align-items: center;
  gap: 0.5em;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 0.18em 0.5em;
  cursor: pointer;
}

.ed-layer-toggle::before {
  content: '○';
  color: var(--line-dim);
  flex: none;
}

.ed-layer-toggle:hover { color: var(--text); border-color: var(--line-dim); }

.ed-layer-toggle.on {
  color: var(--text);
  border-color: var(--line-dim);
  background: rgba(127, 178, 201, 0.1);
}

.ed-layer-toggle.on::before { content: '●'; color: var(--good); }

/* exit pinned to the bottom of the sidebar */
.ed-sidebar .ed-exit { margin-top: auto; }

.ed-btn {
  font-family: inherit;
  font-size: 1em;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line-dim);
  padding: 0 0.5em;
  cursor: pointer;
  flex: none;
}

.ed-btn:hover { background: var(--panel-2); color: var(--gold); }
.ed-btn.active {
  background: var(--line);
  color: #0a0d12;
  border-color: var(--line);
}
.ed-btn.ed-save { border-color: var(--good); color: var(--good); }
.ed-btn.ed-save:hover { background: #0d1a0d; }
.ed-btn.ed-exit { border-color: var(--gold); color: var(--gold); }
.ed-btn.ed-danger { border-color: var(--bad); color: var(--bad); }

/* ── hover tooltips (whole editor UI) ─────────────────────────── */

.ed-tooltip {
  position: absolute;
  z-index: 400; /* above everything, including modal windows */
  max-width: 24em;
  background: #0c0c17;
  border: 1px solid var(--line);
  box-shadow: 0 0 0 1px #05050a, 0 0.5em 1.6em rgba(0, 0, 0, 0.85);
  padding: 0.4em 0.65em;
  pointer-events: none;
  color: var(--text);
  line-height: 1.3;
}

.ed-tooltip-title {
  color: var(--gold);
  letter-spacing: 0.1em;
  margin-bottom: 0.15em;
}

.ed-tooltip-body { white-space: normal; }

.ed-panel {
  position: absolute;
  background: rgba(7, 7, 12, 0.92);
  border: 1px solid var(--line);
  pointer-events: auto;
  overflow-y: auto;
  max-height: 78%;
}

/* palette: contextual tiles/place catalog inside the sidebar */
.ed-palette {
  flex: none;
  max-height: 26em;
  overflow-y: auto;
  border: 1px solid var(--line-dim);
  background: rgba(13, 13, 24, 0.6);
  margin: 0.25em 0 0.4em;
  scrollbar-width: thin;
}

.ed-inspector {
  top: 0.4em;
  right: 0.5em;
  width: 17em;
  max-height: 82%;
  padding-bottom: 0.4em;
}

.ed-panel-hint {
  color: var(--muted);
  font-size: 0.85em;
  padding: 0.25em 0.6em 0.2em;
  white-space: normal;
  line-height: 1.25;
}

.ed-panel-title {
  color: var(--line);
  letter-spacing: 0.15em;
  padding: 0.25em 0.6em;
  border-bottom: 1px dashed var(--line-dim);
  position: sticky;
  top: 0;
  background: var(--panel);
}

.ed-tile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25em;
  padding: 0.4em;
}

.ed-tile {
  border: 1px solid var(--line-dim);
  padding: 0.2em 0.15em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15em;
  cursor: pointer;
  background: var(--panel-2);
  min-height: 2.6em;
}

.ed-tile-name {
  font-size: 0.72em;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ed-tile.active .ed-tile-name { color: var(--gold); }

.ed-tile img, .ed-tile canvas { image-rendering: pixelated; display: block; }
.ed-tile.active { border-color: var(--gold); outline: 1px solid var(--gold); }
.ed-tile:hover { border-color: var(--line); }

.ed-place-list { padding: 0.2em 0.4em 0.4em; }

.ed-place {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.1em 0.3em;
  cursor: pointer;
  color: var(--text);
}

.ed-place:hover { background: var(--panel-2); }
.ed-place.active { background: rgba(232, 193, 90, 0.15); outline: 1px solid var(--gold); }
.ed-place canvas { image-rendering: pixelated; }
.ed-place-icon { width: 2em; text-align: center; color: var(--amber); }

.ed-form { padding: 0.4em 0.6em; }

.ed-field {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin: 0.2em 0;
}

.ed-field label {
  width: 6.5em;
  flex: none;
  color: var(--muted);
  text-align: right;
}

.ed-field input, .ed-field select, .ed-field textarea {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 1em;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line-dim);
  padding: 0.05em 0.3em;
}

.ed-field textarea { resize: vertical; }
.ed-field input:focus, .ed-field select:focus, .ed-field textarea:focus {
  outline: none;
  border-color: var(--line);
}

.ed-readonly { color: var(--gold); overflow: hidden; text-overflow: ellipsis; }

.ed-hint {
  color: var(--muted);
  font-size: 0.85em;
  padding: 0.3em 0;
  white-space: normal;
}

.ed-inspector .ed-btn { margin: 0.3em 0.6em; }

.ed-status {
  position: absolute;
  bottom: 0.4em;
  left: 15em;
  padding: 0.1em 0.6em;
  background: rgba(7, 7, 12, 0.9);
  border: 1px solid var(--line-dim);
  color: var(--muted);
  white-space: nowrap;
  max-width: 80%;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

/* "?" marker on inspector fields that have a tooltip */
.ed-field-info {
  flex: none;
  width: 1.3em;
  height: 1.3em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-dim);
  border-radius: 50%;
  color: var(--line);
  font-size: 0.8em;
  cursor: help;
}

/* ── game-styled dropdown (replaces native select) ────────────── */

.ed-dd {
  position: relative;
  width: 100%;
}

.ed-dd:focus { outline: none; }

.ed-dd-btn {
  font-family: inherit;
  font-size: 1em;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line-dim);
  padding: 0.18em 0.5em;
  cursor: pointer;
  text-align: left;
}

.ed-dd-btn:hover {
  background: var(--panel);
  border-color: var(--line);
  color: var(--gold);
}

.ed-dd.open .ed-dd-btn {
  border-color: var(--line);
  color: var(--gold);
}

.ed-dd-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ed-dd-caret {
  flex: none;
  color: var(--gold);
  font-size: 0.85em;
  transition: transform 0.08s steps(2);
}

.ed-dd.open .ed-dd-caret { transform: rotate(180deg); }

/* the open list PORTALS to #ui-root with position:fixed — it
   escapes modal scroll zones, clamps to the viewport (JS sets
   width/max-height/left/top per open), and follows its button
   through scrolls. z-index ladder for floating UI:
   windows 220 < toasts 320 < dropdown lists 380 < tooltips 400 */
.ed-dd-list {
  position: fixed;
  z-index: 380;
  overflow-y: auto;
  pointer-events: auto; /* #ui-root is pointer-transparent */
  background: var(--panel);
  border: 2px solid var(--line);
  outline: 2px solid #05050a;
  box-shadow: 0 0.4em 1.2em rgba(0, 0, 0, 0.8);
  scrollbar-width: thin;
}

.ed-dd-item {
  padding: 0.14em 0.6em;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ed-dd-item.highlighted {
  background: var(--panel-2);
  color: var(--gold);
}

.ed-dd-item.highlighted::before { content: '► '; color: var(--gold); }
.ed-dd-item:not(.highlighted)::before { content: '  '; }

.ed-dd-item.selected { color: var(--gold); }

/* dropdowns inside inspector rows shouldn't stretch full width */
.ed-inspector .ed-dd { width: auto; flex: 1; min-width: 0; }

/* ── DIALOGUE BOX (bottom-anchored, portrait + typewriter) ───── */

/* sits at the BOTTOM of the screen so it never covers the speaker */
.window.win-dialogue {
  align-self: flex-end;
  margin-bottom: 0.5em;
  width: 94%;
  max-width: 36em;
  min-width: 0;
}

.window.win-dialogue .win-title { display: none; }

.ed-dlg-body {
  display: flex;
  gap: 0.7em;
  align-items: flex-start;
}

.ed-dlg-portrait {
  flex: none;
  width: 3.4em;
  height: 3.4em;
  border: 2px solid var(--line);
  outline: 2px solid #05050a;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ed-dlg-portrait-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

/* painted (non-pixel-art) PNG portraits scale smoothly instead */
.ed-dlg-portrait-img.smooth { image-rendering: auto; }

.ed-dlg-right {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.ed-dlg-name {
  color: var(--gold);
  letter-spacing: 0.18em;
  margin-bottom: 0.1em;
  min-height: 1em;
}

/* fixed 3-line area (3 × 1.2): the box must NEVER change size
   while the typewriter runs — no growing when a line wraps */
.ed-dlg-text {
  white-space: pre-wrap;
  line-height: 1.2;
  height: 3.6em;
  overflow: hidden;
}

.ed-dlg-text.narration {
  color: var(--muted);
  font-style: italic;
}

/* out of the flow so appearing/disappearing can't resize the box */
.ed-dlg-caret {
  position: absolute;
  right: 0;
  bottom: 0.1em;
  color: var(--gold);
  animation: dlg-caret 0.7s steps(2) infinite;
}

@keyframes dlg-caret {
  50% { opacity: 0; }
}

/* ── THE SPELLBOOK (parchment pages, fading ink) ─────────────── */

/* the book's own chrome: light grey instead of steel blue, and a
   fixed body height so the window NEVER resizes between pages,
   sections, or empty states */
.win-spellbook {
  position: relative; /* anchor for the right-edge page tabs */
  min-width: 38em;    /* a proper big book */
  border-color: #6a6a78; /* dark stone grey */
  box-shadow:
    inset 0 0 0 2px #05050a,
    inset 0 0 0 3px #3a3a44,
    0 0 0 1px #05050a,
    0 1em 3em rgba(0, 0, 0, 0.75);
}

.win-spellbook .win-title { background: #8a8a98; }

.win-spellbook .win-body {
  height: 22.6em; /* fixed: 21em page + page number line */
  overflow: hidden;
}

/* SPELLS / NOTES — binder tabs protruding from the right edge */
.sb-tabs {
  position: absolute;
  top: 2.4em;
  right: -1.15em;
  display: flex;
  flex-direction: column;
  gap: 0.35em;
  z-index: 5;
}

.sb-tab {
  font-family: inherit;
  font-size: 0.85em;
  letter-spacing: 0.14em;
  writing-mode: vertical-rl;
  padding: 0.6em 0.14em;
  background: #8a6a44;           /* leather spine tone when inactive */
  color: #d8cbb0;
  border: 2px solid #5a3d26;
  border-left-color: #05050a;
  cursor: pointer;
}

.sb-tab:hover { background: #9c7a50; }

.sb-tab.active {
  background: #d8cbb0;           /* parchment: the page it belongs to */
  color: #241a12;
  border-color: #b89468;
  border-left-color: #05050a;
}

.sb-page {
  background: #d8cbb0;
  background:
    radial-gradient(ellipse at 18% 8%, rgba(120, 96, 60, 0.14), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(120, 96, 60, 0.12), transparent 50%),
    #d8cbb0;
  color: #3a2d20;
  padding: 1em 1.2em 0.8em;
  height: 21em;   /* fixed: taller content is clipped, never grows */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35em;
  box-shadow: inset 0 0 0 2px #b89468, inset 0 0 1.6em rgba(90, 61, 38, 0.25);
  text-align: center;
}

/* ink fades in: transparent + soft-edged → settled writing */
.ink {
  opacity: 0;
  animation: ink-in 0.9s ease-out forwards;
}

@keyframes ink-in {
  0% { opacity: 0; filter: blur(1.5px); transform: translateY(2px); }
  60% { opacity: 0.85; filter: blur(0.4px); }
  100% { opacity: 1; filter: blur(0); transform: none; }
}

.sb-sigil-img {
  image-rendering: pixelated;
  filter: drop-shadow(0 1px 0 rgba(58, 45, 32, 0.35));
}

.sb-sigil-blank {
  width: 4em;
  height: 4em;
  border: 2px dashed rgba(58, 45, 32, 0.4);
  margin: 0.6em 0;
}

.sb-name {
  font-size: 1.5em;
  letter-spacing: 0.28em;
  color: #241a12;
}

.sb-school {
  color: #5a4630;
  letter-spacing: 0.14em;
}

.sb-rule {
  width: 60%;
  border-top: 1px solid rgba(58, 45, 32, 0.45);
  border-bottom: 1px solid rgba(58, 45, 32, 0.2);
  height: 2px;
  margin: 0.25em 0;
}

.sb-instructions {
  font-style: italic;
  max-width: 22em;
  line-height: 1.25;
  color: #3d2a1a;
}

/* duration line: "holds for about an hour" — real time */
.sb-duration {
  margin-top: 0.2em;
  font-size: 0.85em;
  color: #5a4630;
  letter-spacing: 0.08em;
}

.sb-materials {
  width: 100%;
  max-width: 24em;
  text-align: left;
  margin-top: 0.3em;
}

.sb-materials-title {
  text-align: center;
  letter-spacing: 0.3em;
  font-size: 0.85em;
  color: #5a4630;
  margin-bottom: 0.25em;
}

.sb-material {
  display: flex;
  align-items: baseline;
  gap: 0.45em;
  padding: 0.06em 0.2em;
}

.sb-material-dot {
  flex: none;
  width: 0.7em;
  height: 0.7em;
  display: inline-block;
  border: 1px solid rgba(36, 26, 18, 0.55);
  transform: translateY(0.08em);
}

.sb-material-props {
  margin-left: auto;
  color: #5a4630;
  font-size: 0.85em;
  font-style: italic;
}

/* freshly understood: a soft gold underline that fades as you read */
.sb-material.sb-fresh {
  animation: sb-fresh-fade 4s ease-out forwards;
  border-bottom: 2px solid rgba(232, 193, 90, 0.9);
}

@keyframes sb-fresh-fade {
  0%, 55% { border-bottom-color: rgba(232, 193, 90, 0.9); }
  100% { border-bottom-color: rgba(232, 193, 90, 0); }
}

.sb-note {
  margin-top: 0.4em;
  font-size: 0.85em;
  color: #5a4630;
  max-width: 24em;
  line-height: 1.2;
}

.sb-hint {
  color: #5a4630;
  max-width: 22em;
  line-height: 1.3;
  margin-top: 0.8em;
  font-style: italic;
}

.sb-page-no {
  color: var(--muted);
  font-size: 0.8em;
  text-align: center;
  margin-top: 0.4em;
}

/* ── COMPONENT POUCH window ──────────────────────────────────── */

.pouch-row {
  display: flex;
  align-items: baseline;
  gap: 0.45em;
  padding: 0.14em 0.1em;
}

.pouch-row .qty { color: var(--gold); }

.pouch-dot {
  flex: none;
  width: 0.7em;
  height: 0.7em;
  display: inline-block;
  border: 1px solid rgba(0, 0, 0, 0.55);
  transform: translateY(0.08em);
}

.pouch-props {
  color: var(--muted);
  font-size: 0.85em;
  font-style: italic;
}

.pouch-row.selected {
  background: var(--panel-2);
  color: var(--gold);
}

.pouch-row.selected::before { content: '► '; color: var(--gold); }

/* ── SPELL HOTBAR (bottom-center sigil slots) ────────────────── */

#hotbar {
  position: absolute;
  bottom: 0.6em;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.2em;
  z-index: 10;
}

/* slots are part of the chip family: translucent, 1px line */
.hb-slot {
  position: relative;
  width: 3em;
  height: 3em;
  background: rgba(7, 7, 12, 0.82);
  border: 1px solid var(--line-dim);
  outline: 1px solid #05050a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.hb-slot:hover { background: rgba(22, 22, 36, 0.85); }

.hb-slot.active {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--gold);
  background: rgba(22, 22, 36, 0.85);
}

.hb-sigil {
  width: 2em;
  height: auto;
  image-rendering: pixelated;
}

.hb-name {
  font-family: inherit;
  font-size: 0.7em;
  color: var(--text);
  letter-spacing: 0.05em;
}

/* slot number: the same gold keycap language as [E]/[F] */
.hb-key {
  position: absolute;
  top: 0.05em;
  left: 0.25em;
  font-size: 0.75em;
  color: var(--gold);
}

/* the hotbar owns the bottom-center: when it's up, the E-prompt
   and toasts stack ABOVE it (cast prompt sits at 3.9em, E-prompt
   just above that) instead of hiding underneath */
body.has-hotbar #prompt { bottom: 5.4em; }
body.has-hotbar #toasts { bottom: 3.9em; }

/* "[F] Cast Light — Shop cat" — floats just above the hotbar */
#cast-prompt {
  position: absolute;
  bottom: 3.9em;
  left: 50%;
  transform: translateX(-50%);
  color: var(--text);
  white-space: nowrap;
  z-index: 10;
}

#cast-prompt .key { color: var(--gold); }

/* ── LIGHT COLOR PICKER ("colored as you like") ──────────────── */

#light-picker {
  position: absolute;
  bottom: 7em; /* above the stacked prompts, clear of the hotbar */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.25em;
  padding: 0.15em 0.6em;
  background: rgba(7, 7, 12, 0.88);
  border: 1px solid var(--line-dim);
  white-space: nowrap;
  z-index: 15;
  animation: toast-in 0.12s steps(2) both;
  pointer-events: auto; /* #ui-root is pointer-transparent */
}

#light-picker .lp-label,
#light-picker .lp-hint {
  color: var(--muted);
  font-size: 0.8em;
  letter-spacing: 0.1em;
}

#light-picker .lp-hint { margin-left: 0.4em; }

.lp-swatch {
  width: 1.3em;
  height: 1.3em;
  border: 1px solid rgba(216, 226, 236, 0.35);
  outline: 1px solid #05050a;
  padding: 0;
  cursor: pointer;
}

.lp-swatch:hover { transform: translateY(-1px); }

.lp-swatch.active {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--gold);
}

/* ── SPRITE PIXEL EDITOR ─────────────────────────────────────── */

.ed-sprite-root {
  position: absolute;
  inset: 2%;
  background: rgba(7, 7, 12, 0.96);
  border: 3px solid var(--line);
  outline: 2px solid #05050a;
  box-shadow: inset 0 0 0 2px #05050a, inset 0 0 0 3px var(--line-dim),
    0 1em 3em rgba(0, 0, 0, 0.8);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  font-size: calc(5px * var(--ui-scale, 3));
  z-index: 100; /* above editor chrome, below modal windows */
}

.ed-sprite-title {
  background: var(--line);
  color: #0a0d12;
  padding: 0.15em 0.8em;
  letter-spacing: 0.15em;
  flex: none;
}

.ed-sprite-close {
  position: absolute;
  top: 0.15em;
  right: 0.3em;
}

.ed-sprite-save {
  position: absolute;
  top: 0.15em;
  right: 4.5em;
  border-color: var(--good);
  color: var(--good);
}

.ed-preview {
  display: flex;
  align-items: center;
  gap: 0.6em;
}

/* ── PNG sheet import window ── */
.ed-sheet-root {
  position: absolute;
  inset: 2%;
  background: rgba(7, 7, 12, 0.96);
  border: 3px solid var(--line);
  outline: 2px solid #05050a;
  box-shadow: inset 0 0 0 2px #05050a, inset 0 0 0 3px var(--line-dim),
    0 1em 3em rgba(0, 0, 0, 0.8);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  font-size: calc(5px * var(--ui-scale, 3));
  z-index: 110; /* above the sprite editor that opened it */
}

.ed-sheet-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.ed-sheet-left {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0.5em;
  gap: 0.4em;
}

.ed-sheet-pathrow {
  display: flex;
  gap: 0.4em;
  flex: none;
}

.ed-sheet-root input, .ed-sheet-root select {
  background: #0d0f14;
  border: 1px solid var(--line-dim);
  color: var(--ink-bright, #cfd6e4);
  font: inherit;
  padding: 0.15em 0.4em;
}

.ed-sheet-root input:focus, .ed-sheet-root select:focus {
  outline: 1px solid var(--line);
}

.ed-sheet-cfgrow {
  display: flex;
  gap: 0.8em;
  flex: none;
}

.ed-sheet-cfg {
  display: flex;
  align-items: center;
  gap: 0.3em;
  white-space: nowrap;
}

.ed-sheet-num { width: 3.5em; }

.ed-sheet-view {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line-dim);
  background: #14161c;
  padding: 0.4em;
}

.ed-sheet-canvas {
  image-rendering: pixelated;
  cursor: crosshair;
  display: block;
}

.ed-sheet-right {
  width: 20em;
  flex: none;
  border-left: 1px solid var(--line-dim);
  padding: 0.6em;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

.ed-sheet-pathrow input[type='text'], .ed-sheet-pathrow input:not([type]) {
  flex: 1;
  min-width: 0;
}

.ed-sheet-add {
  border-color: var(--good);
  color: var(--good);
}

.ed-sheet-repoint {
  border-color: #e8b44a;
  color: #e8b44a;
}


.ed-preview-canvas {
  image-rendering: pixelated;
  border: 1px solid var(--line-dim);
}

.ed-sprite-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.ed-sprite-left {
  width: 16em;
  flex: none;
  border-right: 1px solid var(--line-dim);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.ed-tabs {
  display: flex;
  flex-wrap: wrap;
  flex: none;
  border-bottom: 1px solid var(--line-dim);
}

.ed-tab {
  font-family: inherit;
  font-size: 0.9em;
  background: transparent;
  color: var(--muted);
  border: none;
  border-right: 1px solid var(--line-dim);
  padding: 0.15em 0.6em;
  cursor: pointer;
}

.ed-tab.active {
  color: var(--gold);
  background: var(--panel-2);
  box-shadow: inset 0 -2px 0 var(--gold);
}

.ed-sprite-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.3em;
}

.ed-sprite-list .ed-place canvas {
  width: 2.4em;
  height: auto;
}

.ed-sprite-left > .ed-btn { margin: 0.3em; flex: none; }

.ed-sprite-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-width: 0;
  padding: 0.5em;
}

/* scrollable canvas viewport: centers the canvas when it fits,
   scrolls (wheel / middle-drag / arrow keys) when it doesn't —
   the zoom bar and frame strip stay on screen regardless */
.ed-pix-viewport {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  width: 100%;
}

.ed-pix-wrap {
  border: 1px solid var(--line);
  line-height: 0;
  margin: auto; /* centering that still allows full scroll */
  flex: none;
}

.ed-pix-canvas {
  image-rendering: pixelated;
  cursor: crosshair;
  display: block;
}

.flex-none { flex: none; }

.ed-frames {
  display: flex;
  align-items: center;
  gap: 0.3em;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 100%;
}

.ed-frame {
  background: var(--panel-2);
  border: 1px solid var(--line-dim);
  padding: 0.2em;
  cursor: pointer;
  line-height: 0;
}

.ed-frame.active { border-color: var(--gold); outline: 1px solid var(--gold); }
.ed-frame canvas { width: 2.5em; height: auto; image-rendering: pixelated; }

.ed-sprite-right {
  width: 15em;
  flex: none;
  border-left: 1px solid var(--line-dim);
  overflow-y: auto;
  padding-bottom: 0.5em;
}

.ed-sprite-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2em;
  padding: 0.4em;
}

/* text-labeled tool buttons (PEN / ERASE / FILL / LINE / RECT / PICK…) */
.ed-sprite-tools .ed-btn {
  min-width: 0;
  padding: 0.15em 0.4em;
  font-size: 0.85em;
  letter-spacing: 0.05em;
}

/* zoom bar above the pixel canvas */
.ed-zoom-bar {
  display: flex;
  align-items: center;
  gap: 0.3em;
}

.ed-zoom-btn { padding: 0.1em 0.55em; }

.ed-zoom-label {
  color: var(--muted);
  font-size: 0.85em;
  min-width: 2.4em;
  text-align: center;
}

.ed-swatch-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.3em;
  padding: 0.4em;
}

.ed-swatch {
  height: 2em;
  border: 1px solid var(--line-dim);
  cursor: pointer;
}

/* the "no pixel" pseudo-swatch — paints transparency */
.ed-swatch-transparent {
  background: repeating-conic-gradient(#9c9cb0 0% 25%, #707086 0% 50%) 0 0 / 0.9em 0.9em;
}

/* checkerboard behind every sprite thumbnail/preview so
   transparent areas read as transparent everywhere */
.ed-frame canvas,
.ed-preview-canvas,
.ed-sprite-list .ed-place canvas {
  background: repeating-conic-gradient(#9c9cb0 0% 25%, #707086 0% 50%) 0 0 / 6px 6px;
}

.ed-swatch.active { border-color: var(--gold); outline: 1px solid var(--gold); }
.ed-swatch-add {
  background: var(--panel-2);
  color: var(--gold);
  font-family: inherit;
}

.ed-sprite-right .ed-field { padding: 0 0.4em; }
.ed-sprite-right .ed-danger { margin: 0.4em; }
.ed-sprite-right .ed-hint { padding: 0.2em 0.5em; }

/* ── DATA EDITOR ─────────────────────────────────────────────── */

.ed-data-layout {
  display: flex;
  gap: 0.8em;
  margin-top: 0.4em;
  text-align: left;
}

.ed-data-list {
  width: 14em;
  flex: none;
  border-right: 1px dashed var(--line-dim);
  padding-right: 0.5em;
}

.ed-data-form {
  flex: 1;
  min-width: 0;
  padding-bottom: 0.4em;
}

.ed-data-form .ed-field label { width: 7.5em; }

.ed-data-actions {
  display: flex;
  gap: 0.3em;
  margin: 0.3em 0;
}

/* dialogue tab: speaker + text + row buttons per line */
.ed-dlg-line { align-items: flex-start; }
.ed-dlg-line .ed-dd { flex: none; width: 10em; margin-top: 0.1em; }
.ed-dlg-line textarea { min-height: 2.4em; }
.ed-dlg-line-btns { display: flex; flex: none; gap: 0.2em; margin-top: 0.05em; }
.ed-dlg-line-btns .ed-btn { padding: 0 0.45em; }

/* dialogue tab: speaker registry rows */
.ed-dlg-speaker .ed-readonly { flex: none; width: 5.5em; }
.ed-dlg-speaker .ed-dlg-name { flex: 1; min-width: 5em; }
.ed-dlg-speaker .ed-dd { flex: none; width: 8.5em; }

.ed-field.ed-check { justify-content: flex-start; }
.ed-field.ed-check label { width: auto; text-align: left; }

/* ── sprite editor color grids (game colors + master palette) ── */

.ed-panel-sub {
  color: var(--muted);
  font-size: 0.8em;
  padding: 0.2em 0.6em 0;
  line-height: 1.2;
}

.ed-color-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.2em;
  padding: 0.35em;
}

.ed-color-mini {
  height: 1.6em;
  border: 1px solid rgba(5, 5, 10, 0.8);
  cursor: pointer;
  padding: 0;
}

.ed-color-mini:hover {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
  z-index: 1;
}

/* ── audio editor ────────────────────────────────────────────── */

.ed-step {
  border: 1px solid var(--line-dim);
  background: rgba(22, 22, 36, 0.5);
  margin: 0.3em 0;
}

.ed-step-head {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.15em 0.5em;
  border-bottom: 1px dashed var(--line-dim);
  color: var(--muted);
}

.ed-step-num {
  color: var(--gold);
  min-width: 1.2em;
}

.ed-step-del {
  margin-left: auto;
  color: var(--bad);
  border-color: var(--bad);
}

.ed-step-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.1em 0.8em;
  padding: 0.25em 0.5em;
}

.ed-step-grid .ed-field label { width: 4.5em; }

.ed-music-controls {
  align-items: center;
  margin-top: 0.4em;
}

.ed-music-controls .ed-dd { width: 8em; flex: none; }

.ed-music-num { width: 8em; flex: none; }

.ed-music-grid-wrap {
  overflow-x: auto;
  margin-top: 0.4em;
  padding-bottom: 0.3em;
}

.ed-music-grid {
  display: grid;
  gap: 0.15em;
  min-width: 32em;
}

.ed-music-corner { }

.ed-music-head {
  color: var(--muted);
  font-size: 0.75em;
  text-align: center;
  align-self: end;
}

.ed-music-head.beat { color: var(--line); }

.ed-music-label {
  color: var(--muted);
  font-size: 0.85em;
  display: flex;
  align-items: center;
}

.ed-music-cell {
  height: 1.5em;
  border: 1px solid var(--line-dim);
  background: var(--panel-2);
  cursor: pointer;
  padding: 0;
}

.ed-music-cell.beat { border-color: var(--line); }

.ed-music-cell.on {
  background: var(--gold);
  border-color: #f2e8b0;
  box-shadow: inset 0 0 0 1px #5a3d10;
}
