/* ── 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;
  position: relative; /* hosts the ✕ */
}

/* universal close button (every edit-mode modal) */
.win-x {
  position: absolute;
  right: 0.15em;
  top: 50%;
  transform: translateY(-50%);
  font-family: inherit;
  font-size: 0.8em;
  line-height: 1;
  padding: 0.1em 0.35em;
  background: transparent;
  color: #0a0d12;
  border: 1px solid transparent;
  cursor: pointer;
}

.win-x:hover {
  background: #0a0d12;
  color: #e0dede;
  border-color: #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; }

/* ── STUDIO SPLASH ───────────────────────────────────────────── */
/* The very first screen: the studio card on black. It exists to
   collect the player's first gesture — that keypress/click is what
   browsers require before audio may start, so the title reveal
   comes with its music already playing. Falls away on the first
   input, or by itself after 6 quiet seconds. */

#splash-screen {
  position: absolute;
  inset: 0;
  z-index: 300; /* above the title screen and all editor chrome */
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  transition: opacity 0.6s ease;
}

#splash-screen.gone {
  opacity: 0;
  pointer-events: none;
}

#splash-art {
  max-width: 100%;
  max-height: 100%;
  image-rendering: auto;
}

/* ── 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 {
  /* follows the sidebar even after a drag-resize (px var set in
     measureCameraMargins); 15em ≈ default 14em sidebar + 1em gap */
  left: calc(var(--ed-sidebar-w, 15em) + 1em);
}

#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.
   Pinned head (MAP + TOOLS) and foot (exit) sandwich the single
   scroll region — only the middle ever scrolls, in ONE direction. */
.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.55em 0.45em 0.35em;
  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: hidden;
}

.ed-side-head, .ed-side-foot {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.12em;
}

.ed-side-scroll {
  flex: 1;
  min-height: 0; /* let the flex child actually shrink and scroll */
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  display: flex;
  flex-direction: column;
  gap: 0.12em;
}

/* collapsible sections (EDIT / EDITORS / SHOW ON MAP) */
.ed-sec-head {
  font-family: inherit;
  font-size: 0.8em;
  letter-spacing: 0.22em;
  text-align: left;
  color: var(--line);
  background: rgba(7, 7, 12, 0.97);
  border: none;
  border-bottom: 1px dashed var(--line-dim);
  margin: 0.7em 0.1em 0.2em;
  padding: 0.15em 0.1em 0.15em 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4em;
  position: sticky;
  top: 0;
  z-index: 6;
}

.ed-sec-head:hover { color: var(--text); }

.ed-sec-arrow {
  flex: none;
  color: var(--line-dim);
  transition: transform 0.15s ease;
}

.ed-sec-head.closed .ed-sec-arrow { transform: rotate(-90deg); }
.ed-sec-head.closed { border-bottom-style: solid; margin-bottom: 0.1em; }

.ed-sec-body {
  display: flex;
  flex-direction: column;
  gap: 0.12em;
}

.ed-sec-body[hidden] { display: none; }

/* drag handle: widens/narrows a docked panel; grip appears on hover */
.ed-resize-h {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 0.5em;
  cursor: ew-resize;
  pointer-events: auto;
  z-index: 20;
  touch-action: none;
}

.ed-resize-h::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 2.4em;
  border-radius: 2px;
  background: transparent;
}

.ed-resize-h:hover::after,
.ed-resize-h:active::after { background: var(--gold); }

.ed-resize-h-left { right: auto; left: 0; }

/* floating-flyout grips: right edge, bottom edge, corner */
.ed-resize-fly-r { top: 0; bottom: 0; right: 0; width: 0.5em; cursor: ew-resize; }

.ed-resize-fly-b {
  top: auto; bottom: 0; left: 0; right: 0;
  width: auto; height: 0.5em;
  cursor: ns-resize;
}

.ed-resize-fly-b::after { width: 2.4em; height: 2px; }

.ed-resize-fly-rb {
  top: auto; bottom: 0; right: 0;
  width: 1em; height: 1em;
  cursor: nwse-resize;
}

body.ed-resizing { cursor: ew-resize; user-select: none; }
body.ed-resizing * { cursor: ew-resize !important; }

.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;
}

/* compact tool grid in the pinned head: key glyph + tiny label */
.ed-tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.12em;
}

.ed-sidebar .ed-btn.ed-tool {
  flex-direction: column;
  gap: 0.12em;
  padding: 0.2em 0.1em 0.14em;
  text-align: center;
}

.ed-tool-key {
  font-size: 1.05em;
  line-height: 1;
  color: var(--gold);
}

.ed-tool-name {
  font-size: 0.62em;
  line-height: 1;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ed-btn.active .ed-tool-key,
.ed-btn.active .ed-tool-name { color: inherit; }

.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 — natural height inside
   the sidebar's single scroll region (no nested scrollbar) */
.ed-palette {
  flex: none;
  border: 1px solid var(--line-dim);
  background: rgba(13, 13, 24, 0.6);
  margin: 0.25em 0 0.4em;
}

/* sticky titles only made sense when the palette scrolled itself */
.ed-palette .ed-panel-title { position: static; background: transparent; }

/* tool-switch focus pulse: "your brush options are HERE" */
@keyframes ed-flash-pulse {
  0% { box-shadow: 0 0 0 2px var(--gold); }
  60% { box-shadow: 0 0 0 2px rgba(232, 193, 90, 0.5); }
  100% { box-shadow: 0 0 0 2px transparent; }
}

.ed-flash { animation: ed-flash-pulse 0.9s ease-out 2; }

.ed-inspector {
  top: 0.4em;
  right: 0.5em;
  width: 17em;
  max-height: 82%;
  padding-bottom: 0.4em;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* inspector content scrolls INSIDE, so the resize handle stays put */
/* pinned inspector title row: label + ✕ close (all five types) */
.ed-insp-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4em;
  border-bottom: 1px dashed var(--line-dim);
  padding-right: 0.3em;
}

.ed-insp-head .ed-panel-title { border-bottom: none; padding: 0.25em 0.6em; }

.ed-insp-x {
  font-family: inherit;
  font-size: 0.85em;
  line-height: 1;
  padding: 0.12em 0.35em;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  cursor: pointer;
}

.ed-insp-x:hover {
  background: var(--panel-2);
  color: var(--gold);
  border-color: var(--line-dim);
}

.ed-insp-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

.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;
  /* minmax floor: tracks can shrink, so columns drop 3→2→1 as the
     sidebar narrows — never a clipped hidden column */
  grid-template-columns: repeat(auto-fill, minmax(4.5em, 1fr));
  gap: 0.25em;
  padding: 0.4em;
}

.ed-tile, .ed-rtile {
  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, .ed-rtile.active .ed-tile-name { color: var(--gold); }

.ed-tile img, .ed-tile canvas, .ed-rtile img, .ed-rtile canvas {
  image-rendering: pixelated;
  display: block;
  width: 100%;  /* previews grow with a widened sidebar */
  height: auto;
}
.ed-tile.active, .ed-rtile.active { border-color: var(--gold); outline: 1px solid var(--gold); }
.ed-tile:hover, .ed-rtile:hover { border-color: var(--line); }

/* hover mini-actions: ✎ edit (top-left), ✕ delete (top-right) */
.ed-tile, .ed-rtile { position: relative; }

.ed-tile-hbtn {
  position: absolute;
  top: 0.1em;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.35em;
  height: 1.35em;
  font-size: 0.8em;
  line-height: 1;
  font-family: inherit;
  border: 1px solid #05050a;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.08s ease;
}

.ed-tile:hover .ed-tile-hbtn,
.ed-rtile:hover .ed-tile-hbtn {
  opacity: 1;
  pointer-events: auto;
}

.ed-tile-hbtn-edit {
  left: 0.1em;
  background: var(--line);
  color: #0a0d12;
}

.ed-tile-hbtn-edit:hover { background: var(--gold); }

.ed-tile-hbtn-del {
  right: 0.1em;
  background: var(--bad);
  color: #0a0d12;
}

.ed-tile-hbtn-del:hover { background: #ff8f80; }

/* overlay tiles: dashed gold border — decoration over ground,
 * distinct from the solid-gold selection outline at a glance */
.ed-tile.ed-tile-ovl, .ed-rtile.ed-tile-ovl { border-style: dashed; border-color: var(--gold); }

/* the decor eraser entry (✕ erase overlay) — reads as destructive */
.ed-tile-eraser { border-color: var(--bad); }

.ed-tile-eraser .ed-eraser-x {
  font-size: 1.4em;
  line-height: 1.4;
  color: var(--bad);
}

.ed-tile-eraser.active {
  background: rgba(224, 108, 90, 0.12);
  outline: 1px solid var(--bad);
}

.ed-tile-eraser.active .ed-eraser-x { color: var(--text); }

.ed-tile-eraser:hover { border-color: var(--bad); }

.ed-recent-grid { grid-template-columns: repeat(auto-fill, minmax(3.4em, 1fr)); }

.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); }

/* place-catalog previews: capped height, natural width; tiny node
   icons get their 2× boost inline (JS) */
.ed-palette .ed-place canvas {
  max-height: 3.2em;
  width: auto;
}

.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 [hidden] { display: none !important; }

.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;
}

/* ── kept sheets: chips (import window) + palette picker ── */
.ed-sheet-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3em;
  align-items: center;
  flex: none;
}

.ed-sheet-chiplabel {
  color: var(--muted);
  font-size: 0.85em;
  letter-spacing: 0.1em;
}

.ed-sheet-chip {
  display: flex;
  align-items: center;
  gap: 0.3em;
  background: var(--panel-2);
  border: 1px solid var(--line-dim);
  color: var(--text);
  font: inherit;
  padding: 0.08em 0.4em;
  cursor: pointer;
}

.ed-sheet-chip:hover { border-color: var(--line); }
.ed-sheet-chip.active { border-color: var(--gold); color: var(--gold); }

.ed-sheet-chip-x {
  color: var(--muted);
  padding: 0 0.1em;
}

.ed-sheet-chip-x:hover { color: #e07a7a; }

.ed-sheet-keep {
  border-color: var(--gold);
  color: var(--gold);
}

/* ── pack browser (import window) ── */
.ed-sheet-browsebtn {
  border-color: var(--line);
  color: var(--ink-bright, #cfd6e4);
}

.ed-sheet-browse {
  flex: 0 1 auto;
  max-height: 46%;
  min-height: 8em;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line-dim);
  background: #14161c;
}

.ed-sheet-bcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15em;
  padding: 0.25em 0.4em;
  border-bottom: 1px solid var(--line-dim);
  flex: none;
}

.ed-sheet-bcrumb-part {
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  padding: 0.05em 0.3em;
  cursor: pointer;
}

.ed-sheet-bcrumb-part:hover { color: var(--gold); }

.ed-sheet-bcrumb-sep { color: var(--muted); }

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

.ed-sheet-bdirs {
  width: 11em;
  flex: none;
  overflow-y: auto;
  border-right: 1px solid var(--line-dim);
  padding: 0.25em 0.2em;
  scrollbar-width: thin;
}

.ed-sheet-bdir {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  padding: 0.12em 0.35em;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ed-sheet-bdir:hover { background: var(--panel-2); color: var(--gold); }

.ed-sheet-bthumbs {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.4em, 1fr));
  gap: 0.25em;
  padding: 0.3em;
  align-content: start;
  scrollbar-width: thin;
}

.ed-sheet-bthumb {
  border: 1px solid var(--line-dim);
  background: #0d0f14;
  padding: 0.2em 0.1em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.2em;
}

.ed-sheet-bthumb:hover { border-color: var(--gold); }

.ed-sheet-bthumb-miss { opacity: 0.35; }

.ed-sheet-bthumbc { image-rendering: auto; display: block; }

.ed-sheet-bmore {
  grid-column: 1 / -1;
  border: 1px dashed var(--line-dim);
  background: transparent;
  color: var(--muted);
  font: inherit;
  padding: 0.3em;
  cursor: pointer;
}

.ed-sheet-bmore:hover { color: var(--gold); border-color: var(--gold); }

/* the sidebar keeps only an opener; the picker lives in this
   near-fullscreen flyout (child of #ui-root), resizable via its
   right/bottom/corner grips */
.ed-sheet-flyout {
  position: fixed;
  z-index: 45; /* above the canvas, below #editor-root (50) — the
                  sidebar's tooltips (inside editor-root) stay on top */
  background: rgba(7, 7, 12, 0.97);
  border: 1px solid var(--line);
  box-shadow: 0 0.4em 1.6em rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  padding: 0.3em 0 0.4em;
  display: flex;
  flex-direction: column;
  /* no overflow:hidden — the sheet dropdown may overhang the box;
     the pickwrap scrolls itself (min-height:0 + overflow:auto) */
}

/* the sheet canvas area eats all the flyout's height */
.ed-sheet-flyout .ed-sheet-pickwrap {
  flex: 1;
  min-height: 0;
  margin: 0 0.4em;
  max-height: none;
}

.ed-sheet-flyout .ed-sheet-gridrow,
.ed-sheet-flyout .ed-sheet-nameform,
.ed-sheet-flyout .ed-sheet-pickrow { flex: none; }

.ed-sheet-flyout .ed-panel-hint { flex: none; }

.ed-sheet-picker .ed-sheet-open {
  margin: 0.3em 0.4em 0.35em;
  text-align: center;
}

/* grouped sheet dropdown inside the flyout: folder headers with
   thumbnail strips + pickable rows */
/* button.ed-sheet-dd-btn (0,2,1) must beat the pickrow's generic
   `.ed-sheet-pickrow .ed-btn` flex:none (0,2,0) — otherwise the
   closed dropdown shrink-wraps to the current sheet's label */
.ed-sheet-pickrow button.ed-sheet-dd-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4em;
}

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

.ed-sheet-dd-list {
  position: absolute; /* inside the flyout — stacking stays put */
  z-index: 30;
  background: #0c0c17;
  border: 1px solid var(--line);
  box-shadow: 0 0.5em 1.6em rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
}

/* filter box pinned at the dropdown's top; items scroll beneath */
.ed-sheet-dd-filter {
  flex: none;
  padding: 0.3em 0.4em;
  border-bottom: 1px dashed var(--line-dim);
}

.ed-sheet-dd-filter input {
  width: 100%;
  background: #0d0f14;
  border: 1px solid var(--line-dim);
  color: var(--text);
  font: inherit;
  padding: 0.1em 0.35em;
}

.ed-sheet-dd-filter input:focus {
  outline: none;
  border-color: var(--gold);
}

.ed-sheet-dd-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

.ed-sheet-dd-group {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5em;
  background: #0c0c17;
  border-bottom: 1px dashed var(--line-dim);
  padding: 0.22em 0.5em;
  cursor: pointer;
  color: var(--line);
  letter-spacing: 0.12em;
  font-size: 0.78em;
}

.ed-sheet-dd-group:hover { color: var(--text); }
.ed-sheet-dd-groupcaret { flex: none; color: var(--line-dim); }

.ed-sheet-dd-item {
  display: flex;
  justify-content: space-between;
  gap: 0.5em;
  padding: 0.14em 0.6em;
  cursor: pointer;
  color: var(--text);
}

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

.ed-sheet-dd-item.selected { outline: 1px solid var(--gold); color: var(--gold); }

.ed-sheet-dd-itemlbl {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ed-sheet-dd-pinnedmark { color: var(--gold); flex: none; }

/* stale-server notice pinned to the list bottom (404 on the
   sheet index): never silently swallow a missing endpoint */
.ed-sheet-dd-stale {
  position: sticky;
  bottom: 0;
  background: #0c0c17;
  border-top: 1px dashed var(--bad);
  color: var(--bad);
  font-size: 0.8em;
  padding: 0.3em 0.6em;
}

/* pin/unpin toggle beside the dropdown */
.ed-sheet-pin { flex: none; }
.ed-sheet-pin.pinned { color: var(--gold); border-color: var(--gold); }

/* inline grid editor (auto sheets) */
.ed-sheet-gridrow {
  display: flex;
  gap: 0.5em;
  align-items: center;
  padding: 0.25em 0.4em 0.2em;
}

.ed-sheet-gridrow[hidden] { display: none; }

.ed-sheet-gridfield {
  display: flex;
  align-items: center;
  gap: 0.25em;
  color: var(--muted);
  font-size: 0.8em;
}

.ed-sheet-gridfield input {
  width: 3.2em;
  background: #0d0f14;
  border: 1px solid var(--line-dim);
  color: var(--text);
  font: inherit;
  padding: 0.05em 0.25em;
}

.ed-sheet-picker { flex: none; }

.ed-sheet-pickrow {
  display: flex;
  gap: 0.25em;
  align-items: center;
  padding: 0.3em 0.4em 0.25em;
}

.ed-sheet-pickrow select {
  flex: 1;
  min-width: 0;
  background: #0d0f14;
  border: 1px solid var(--line-dim);
  color: var(--text);
  font: inherit;
  padding: 0.08em 0.25em;
}

.ed-sheet-pickrow .ed-btn { padding: 0.08em 0.4em; margin: 0; flex: none; }

.ed-sheet-zoomlbl {
  font-size: 0.85em;
  min-width: 2.8em;
  text-align: center;
}

.ed-sheet-pickwrap {
  border: 1px solid var(--line-dim);
  background: #14161c;
  overflow: auto;
  max-height: 20em;
  margin: 0 0.4em;
}

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

.ed-sheet-nameform {
  display: flex;
  gap: 0.3em;
  padding: 0.3em 0.4em;
  flex-wrap: wrap;
  align-items: center;
}

/* live preview of the dragged selection + its consequence caption */
.ed-sheet-formpreview {
  image-rendering: pixelated;
  border: 1px solid var(--line-dim);
  background: #14161c;
  max-width: 100%;
  max-height: 6em;
  flex: 1 1 100%;
  object-fit: contain;
  align-self: center;
}

.ed-sheet-formcaption {
  flex: 1 1 100%;
  color: var(--gold);
  font-size: 0.8em;
  letter-spacing: 0.06em;
  min-height: 1.1em;
  text-align: center;
}

/* tile-only option toggles (◇ overlay / solid) */
.ed-sheet-optrow {
  display: flex;
  gap: 1em;
  flex: 1 1 100%;
  align-items: center;
}

.ed-sheet-opt {
  display: flex;
  align-items: center;
  gap: 0.3em;
  color: var(--muted);
  font-size: 0.82em;
  cursor: pointer;
  letter-spacing: 0.06em;
}

.ed-sheet-opt input { cursor: pointer; }

.ed-sheet-opt:has(input:checked) { color: var(--gold); }

/* the kind buttons: rows of consequences */
.ed-sheet-btnrow {
  display: flex;
  gap: 0.3em;
  flex: 1 1 100%;
}

.ed-sheet-btnrow .ed-btn { flex: 1; text-align: center; }

.ed-sheet-form-obj { border-color: var(--amber); }

.ed-sheet-btnrow .ed-btn[hidden] { display: none; }

/* ── in-flyout collision editor ─────────────────────────────── */
.ed-sheet-collider {
  border-top: 1px dashed var(--line-dim);
  padding: 0.35em 0.4em 0.2em;
  display: flex;
  flex-direction: column;
  gap: 0.3em;
}

.ed-sheet-collider[hidden] { display: none; }

.ed-sheet-collider-title {
  color: var(--gold);
  letter-spacing: 0.12em;
  font-size: 0.9em;
  text-align: center;
}

.ed-sheet-collider-canvas {
  image-rendering: pixelated;
  align-self: center;
  cursor: crosshair;
  border: 1px solid var(--line-dim);
  background: #14161c;
  max-width: 100%;
  touch-action: none;
}

.ed-sheet-collider-readout {
  color: var(--muted);
  font-size: 0.82em;
  text-align: center;
  min-height: 1.1em;
}

.ed-sheet-collider-chips {
  display: flex;
  gap: 0.3em;
  justify-content: center;
}

.ed-sheet-collider-chips .ed-btn { padding: 0.08em 0.5em; font-size: 0.85em; }

/* SAVE demands a drawn box — visually and functionally off until then */
.ed-sheet-collider .ed-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.ed-sheet-collider-all { justify-content: center; }

/* sprite-editor host: a section among sections, not a modal chrome */
.ed-sheet-collider.compact {
  border-top: none;
  border: 1px solid var(--line-dim);
  padding: 0.25em 0.3em;
  margin-top: 0.3em;
}

.ed-sheet-collider.compact .ed-sheet-collider-sync,
.ed-sheet-collider .ed-sheet-collider-sync { margin-top: 0.2em; }


.ed-sheet-nameform[hidden] { display: none; }

.ed-sheet-nameform input {
  flex: 1;
  min-width: 0;
  background: #0d0f14;
  border: 1px solid var(--line-dim);
  color: var(--text);
  font: inherit;
  padding: 0.1em 0.3em;
}

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


.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;
}
