:root {
  --ink: #0d0b1a; --void: #05040c; --panel: #120e22; --slot: #221c3a; --line: #4a4860;
  --text: #f4f1e8; --dim: #7c7a94; --cyan: #2ef2ff; --mag: #ff2e97; --lime: #b6ff3a; --orange: #ff7a1a;
  --accent: var(--cyan);
  --tap: 44px;
  --font: "Courier New", ui-monospace, SFMono-Regular, Consolas, monospace;
}
.app[data-hero="zip"] { --accent: var(--orange); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--void); color: var(--text); font: 700 14px/1.2 var(--font); }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
button, .button {
  font: inherit; text-transform: uppercase; letter-spacing: .04em; color: var(--dim); background: var(--slot);
  border: 2px solid var(--panel); border-top-color: var(--line); min-height: var(--tap); padding: 6px 10px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; touch-action: manipulation;
}
button:hover, button:focus-visible, .button:hover { color: var(--text); outline: none; border-color: var(--accent); }
button[aria-pressed="true"], button.active { color: var(--text); background: #3c1440; border-color: var(--mag); }
button:disabled { opacity: .4; cursor: default; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- layout: portrait / desktop ---------- */
.app {
  height: 100dvh; max-width: 1280px; margin: 0 auto; display: grid; gap: 0;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "bar bar" "stage stage" "sentence sentence" "verbs inv";
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.bar { grid-area: bar; display: flex; align-items: center; gap: 12px; padding: 6px 8px; background: var(--ink); border-bottom: 2px solid var(--panel); }
.title small { color: var(--accent); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.title h1 { margin: 0; font: 900 20px/1 system-ui, sans-serif; letter-spacing: -.04em; color: var(--mag); text-shadow: 2px 1px var(--cyan); }
.objective { flex: 1; margin: 0; color: var(--lime); font-size: 12px; font-weight: 400; min-width: 0; }
.timer { margin: 0; padding: 2px 8px; color: var(--void); background: var(--mag); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .05em; }
.timer[hidden] { display: none; }
.tools { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.tools button { font-size: 11px; padding: 4px 8px; }
.stage { grid-area: stage; position: relative; display: grid; place-items: center; overflow: hidden; background: var(--void); min-height: 140px; }
#screen { image-rendering: pixelated; touch-action: none; cursor: crosshair; display: block; }
.loading { position: absolute; color: var(--mag); margin: 0; padding: 16px; text-align: center; }
.sentence { grid-area: sentence; margin: 0; min-height: 30px; padding: 7px 10px; text-align: center; color: var(--cyan); background: #120e22; border-top: 2px solid var(--line); text-transform: uppercase; letter-spacing: .05em; }
.verbs { grid-area: verbs; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 6px; background: var(--ink); align-content: start; }
.verbs button { font-size: 12px; padding: 4px; }
.verbs button.special { color: var(--mag); }
.app[data-hero="zip"] .verbs button.special { color: var(--orange); }
.inventory { grid-area: inv; display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 4px; padding: 6px; background: #16122a; align-content: start; }
.slot { aspect-ratio: 1; width: 100%; min-height: var(--tap); padding: 4px; background: var(--slot); border: 2px solid var(--panel); border-top-color: var(--line); }
.slot img { width: 100%; height: 100%; max-width: 48px; max-height: 48px; image-rendering: pixelated; pointer-events: none; }
.slot.empty { opacity: .45; }
.slot > span { display: block; overflow: hidden; font-size: 9px; line-height: 1.1; overflow-wrap: anywhere; }
.inventory.notes { background: #10202a; }
.inventory.notes .slot:not(.empty) { border-color: #2f6f7a; border-top-color: var(--cyan); }
#btnNotes.fresh::after { content: ''; display: inline-block; width: 6px; height: 6px; margin-left: 5px; vertical-align: middle; background: var(--mag); border-radius: 50%; }
#btnSend { border-color: var(--cyan); }
.slot.selected { border-color: var(--mag); background: #3c1440; }
.choices { grid-area: 4 / 1 / 5 / 3; display: flex; flex-direction: column; gap: 4px; padding: 6px; background: var(--ink); z-index: 2; overflow-y: auto; }
.choices button { justify-content: flex-start; text-align: left; text-transform: none; color: var(--accent); font-size: 14px; }
.choices button:hover, .choices button:focus-visible { color: var(--text); }
.app.choosing .verbs, .app.choosing .inventory { visibility: hidden; }
/* Duel dialogues: stance cards in a row, icon above label; options without an icon stay small. */
.choices.duel { flex-direction: row; flex-wrap: wrap; align-items: stretch; justify-content: center; }
.choices.duel button { flex: 1 1 0; min-width: 72px; max-width: 140px; flex-direction: column; justify-content: center; align-items: center; gap: 4px; text-align: center; border: 2px solid var(--line); }
.choices.duel button img { width: 32px; height: 32px; image-rendering: pixelated; pointer-events: none; }
.choices.duel button:not(:has(img)) { flex: 0 1 auto; border-style: dashed; opacity: .8; }
.app.busy .verbs, .app.busy .inventory { opacity: .5; pointer-events: none; }
.app[data-layer="lattice"] .sentence { color: var(--mag); }

/* ---------- landscape phones: verbs left, inventory right, scene in the middle ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  :root { --tap: 40px; }
  .app {
    max-width: none;
    grid-template-columns: minmax(150px, 22vw) minmax(0, 1fr) minmax(130px, 19vw);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "bar bar bar" "verbs stage inv" "verbs sentence inv";
  }
  .bar { padding: 2px 8px; }
  .title h1 { font-size: 15px; }
  .title small { display: none; }
  .objective { font-size: 11px; }
  .tools button { min-height: 32px; }
  .verbs { grid-template-columns: 1fr 1fr; align-content: center; }
  .inventory { grid-template-columns: repeat(2, 1fr); align-content: center; }
  .sentence { min-height: 24px; padding: 3px; font-size: 12px; }
  .choices { grid-area: 2 / 2 / 4 / 3; justify-content: flex-end; background: rgba(5, 4, 12, .9); }
  .choices.duel { align-items: flex-end; align-content: flex-end; background: linear-gradient(transparent 40%, rgba(5, 4, 12, .9)); }   /* cards at the bottom, the opponent's tell visible above */
}
@media (max-width: 520px) and (orientation: portrait) {
  .bar { flex-wrap: wrap; }
  .objective { order: 3; flex-basis: 100%; }
  .app { grid-template-columns: 1fr; grid-template-areas: "bar" "stage" "sentence" "verbs" "inv"; grid-template-rows: auto minmax(0, 1fr) auto auto auto; }
  .choices { grid-area: 4 / 1 / 6 / 2; }
  .inventory { grid-template-columns: repeat(8, 1fr); }
  .slot { padding: 2px; }
}

/* ---------- dialogs ---------- */
.sheet { color: var(--text); background: var(--panel); border: 2px solid var(--mag); box-shadow: 6px 6px 0 var(--cyan); width: min(560px, 92vw); max-height: 90dvh; padding: 16px; }
.sheet::backdrop { background: rgba(2, 4, 11, .85); }
.sheet h2 { margin: 0 0 12px; color: var(--mag); text-transform: uppercase; }
.sheet h3 { margin: 16px 0 6px; font-size: 13px; color: var(--cyan); text-transform: uppercase; }
.sheet p { font-weight: 400; line-height: 1.5; }
.sheet p.epilogue { margin: 6px 0; padding-left: 10px; border-left: 2px solid var(--cyan); }
.saves { display: grid; gap: 4px; }
.save-row { display: flex; gap: 4px; align-items: center; }
.save-name { flex: 1; font-size: 12px; font-weight: 400; color: var(--text); }
.sheet textarea { width: 100%; background: var(--void); color: var(--lime); border: 1px solid var(--line); font: 12px var(--font); -webkit-user-select: text; user-select: text; }
.menu-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.menu-actions .primary { margin-left: auto; color: var(--lime); }

/* ---------- debug ---------- */
.debug { position: fixed; top: 4px; left: 4px; z-index: 50; max-width: 300px; max-height: 70dvh; overflow: auto; padding: 6px; font: 11px var(--font); background: rgba(5, 4, 12, .92); border: 1px solid var(--mag); color: var(--lime); }
.debug select { width: 100%; margin: 4px 0; font: inherit; }
.debug .flags { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
