/* Pixel UI: square panels, hard shadows, bevelled buttons, one night palette shared with the game art. */
:root {
  --bg: #0b0a1a;
  --void: #05040c;
  --panel: #14112b;
  --panel-2: #1a1636;
  --panel-3: #221d42;
  --line: #433d72;
  --line-hi: #6b6b9c;
  --text: #e8e6f0;
  --muted: #a3a7c2;
  --faint: #6b6b9c;
  --green: #8fd48a;
  --green-2: #4fa36a;
  --green-3: #2f6b4f;
  --amber: #f2c46d;
  --amber-3: #8a5a3a;
  --red: #e07a7a;
  --red-3: #7e2a3e;
  --cyan: #7fd6e0;
  --violet: #8a7ad6;
  --violet-3: #3d3378;
  --font: 'VT323', ui-monospace, monospace; /* Pixelify Sans drew Z like 2, which made ZIBO read as 2IB0 */
  --display: 'Silkscreen', 'VT323', ui-monospace, monospace;
  --shadow: 6px 6px 0 var(--void);
  --bevel: inset -3px -3px 0 rgba(0, 0, 0, 0.3), inset 3px 3px 0 rgba(255, 255, 255, 0.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { font-size: 20px; font-synthesis: none; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 1.05rem/1.4 var(--font); overflow-x: hidden; }
button { font: inherit; color: inherit; }
img, canvas { image-rendering: pixelated; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
::selection { background: var(--green); color: var(--void); }

/* pixel stars behind every screen */
.starfield { position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(#e8e6f0, #e8e6f0), linear-gradient(#7fd6e0, #7fd6e0), linear-gradient(#e8e6f0, #e8e6f0),
    linear-gradient(#a3a7c2, #a3a7c2), linear-gradient(#e8e6f0, #e8e6f0), linear-gradient(#6b6b9c, #6b6b9c);
  background-size: 2px 2px;
  background-repeat: no-repeat;
  background-position: 12% 18%, 78% 12%, 33% 72%, 88% 64%, 55% 38%, 6% 88%;
  opacity: 0.7; }
.starfield::after { content: ''; position: absolute; inset: 0;
  background-image: linear-gradient(#e8e6f0, #e8e6f0), linear-gradient(#e8e6f0, #e8e6f0), linear-gradient(#7fd6e0, #7fd6e0), linear-gradient(#a3a7c2, #a3a7c2);
  background-size: 2px 2px; background-repeat: no-repeat;
  background-position: 65% 22%, 22% 45%, 92% 33%, 44% 90%;
  animation: twinkle 3s steps(2) infinite; }
@keyframes twinkle { 50% { opacity: 0.2; } }

/* ---------- buttons ---------- */
.btn { border: 3px solid var(--void); border-radius: 0; padding: 9px 18px; font-family: var(--font); font-weight: 600; font-size: 1.05rem; letter-spacing: 0.02em;
  cursor: pointer; white-space: nowrap; color: var(--void); background: var(--green); box-shadow: var(--bevel), 0 4px 0 var(--void); transition: filter 0.1s; }
.btn:hover:not(:disabled) { filter: brightness(1.1); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: var(--bevel), 0 1px 0 var(--void); }
/* disabled: clearly off (flat, dashed, muted) but still readable */
.btn:disabled { cursor: not-allowed; background: var(--panel-2); color: var(--faint); text-shadow: none; box-shadow: none; border-style: dashed; border-color: var(--line); filter: none; }
.btn-primary { background: var(--green); }
.btn-secondary { background: var(--violet); color: #fff; text-shadow: 2px 2px 0 var(--violet-3); }
.btn-ghost { background: var(--panel-3); color: var(--text); box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.35), inset 3px 3px 0 rgba(255, 255, 255, 0.08), 0 4px 0 var(--void); }
.btn-lg { padding: 13px 28px; font-size: 1.2rem; }
.btn-sm { padding: 4px 10px; font-size: 0.9rem; }
.btn-block { width: 100%; }
.btn-teach { font-size: 1.15rem; padding: 6px 22px; }
.icon-btn { width: 42px; height: 42px; border: 3px solid var(--void); background: var(--panel-3); display: grid; place-items: center; cursor: pointer; color: var(--text);
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.35), inset 3px 3px 0 rgba(255, 255, 255, 0.08), 0 3px 0 var(--void); }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--void); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn[aria-pressed="false"] { color: var(--faint); }
.audio-controls { display: flex; align-items: center; gap: 8px; }
/* pixel-style volume slider */
.vol { -webkit-appearance: none; appearance: none; width: 74px; height: 12px; background: var(--void); border: 2px solid var(--line); margin: 0; cursor: pointer; }
.vol::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 18px; background: var(--cyan); border: 2px solid var(--void); box-shadow: 0 2px 0 var(--void); }
.vol::-moz-range-thumb { width: 10px; height: 16px; border-radius: 0; background: var(--cyan); border: 2px solid var(--void); }
.vol::-moz-range-progress { background: var(--violet-3); height: 8px; }
.vol:disabled { opacity: 0.4; cursor: default; }
.icon-btn[aria-pressed="true"] { color: var(--void); background: var(--cyan); }
.glass { background: var(--panel); border: 3px solid var(--line); box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.05), var(--shadow); }

/* ---------- title ---------- */
.screen { min-height: 100vh; }
.title-screen { display: grid; place-items: center; padding: 32px 16px; text-align: center; }
.title-inner { max-width: 760px; display: flex; flex-direction: column; align-items: center; }
.title-zib { width: 160px; height: 200px; animation: hover 1s steps(2) infinite; filter: drop-shadow(0 0 24px rgba(143, 212, 138, 0.25)); }
@keyframes hover { 50% { transform: translateY(-5px); } }
.eyebrow { font-family: var(--display); text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.8rem; color: var(--amber); margin: 10px 0 6px; }
.logo { font-family: var(--display); font-weight: 700; font-size: clamp(2.4rem, 8vw, 5.2rem); line-height: 1; margin: 0; color: var(--green); text-transform: uppercase;
  text-shadow: 0 5px 0 var(--green-3), 0 10px 0 var(--void); letter-spacing: 0.02em; }
.logo em { font-style: normal; font-size: 0.45em; color: var(--amber); text-shadow: 0 3px 0 var(--amber-3), 0 6px 0 var(--void); vertical-align: middle; }
.tagline { color: var(--muted); font-size: 1.2rem; margin: 26px 0 30px; max-width: 580px; text-wrap: balance; }
.title-actions { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.title-actions.small { margin-top: 18px; }
.privacy { margin-top: 34px; color: var(--faint); font-size: 0.95rem; display: flex; align-items: center; gap: 10px; }
.lock { width: 8px; height: 8px; background: var(--green); box-shadow: 0 0 0 2px var(--green-3); animation: blink 1.4s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

/* ---------- game layout ---------- */
.topbar { display: flex; align-items: center; gap: 14px; padding: 8px 16px; max-width: 1880px; margin: 0 auto; }
.brand { font-family: var(--display); font-size: 0.95rem; display: flex; align-items: center; gap: 10px; color: var(--green); text-transform: uppercase; }
.brand-dot { width: 10px; height: 10px; background: var(--green); box-shadow: 0 0 0 2px var(--green-3); }
.chapter-label { flex: 1; text-align: center; color: var(--muted); font-size: 1.05rem; }
.chapter-label b { color: var(--text); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.lang { font-size: 0.9rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 3px solid var(--line); background: var(--panel); white-space: nowrap; }
.lang b { color: var(--text); font-family: var(--display); font-size: 0.85rem; }
.lang-bar { position: relative; width: 54px; height: 8px; background: repeating-linear-gradient(90deg, var(--red-3) 0 3px, transparent 3px 5px); border: 2px solid var(--void); }
.lang-bar i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--green); transition: width 0.4s steps(6); }
.lang.bump { animation: lang-bump 0.5s steps(3); }
@keyframes lang-bump { 40% { border-color: var(--green); transform: translateY(-2px); } }
.net { font-size: 0.9rem; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px; border: 3px solid var(--line); background: var(--panel); }
.net i { width: 8px; height: 8px; background: var(--faint); }
.net.online i { background: var(--green); }
.net.offline i { background: var(--amber); }

/* ---------- game layout: ONE grid, two columns ----------
   Main column: mission strip, scene, narrator/command bar, panels. All share the same left and right edges.
   Right column: fixed width, teaching controls then dictionary and accuracy. */
:root { --gap: 12px; --pad: 12px; --stage-h: clamp(200px, calc(100vh - 480px), 640px); }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--gap) 16px; padding: 0 16px 16px; max-width: 1880px; margin: 0 auto; align-items: start; }
.main-col { min-width: 0; display: flex; flex-direction: column; gap: var(--gap); }
/* The frame is full width (so its edges line up); the scene inside keeps its 240:110 pixel ratio and a capped height. */
.stage-frame { border: 3px solid var(--line); background: #0b0a1a; display: flex; justify-content: center; }
.stage { position: relative; width: min(100%, calc(var(--stage-h) * 240 / 110)); aspect-ratio: 240 / 110; background: #0b0a1a; overflow: hidden; }
.scene-wrap { position: absolute; inset: 0; }
#scene { width: 100% !important; height: 100% !important; display: block; image-rendering: pixelated; }
.scene-wrap::after { content: ''; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px), radial-gradient(ellipse at center, transparent 60%, rgba(5, 4, 12, 0.45) 100%); }

/* mission: a slim one-line strip above the scene */
.mission-strip { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px var(--pad); background: var(--panel); border: 3px solid var(--line); font-size: 0.95rem; }
.mission-title { font-family: var(--display); text-transform: uppercase; font-size: 0.75rem; color: var(--amber); letter-spacing: 0.08em; flex: none; }
.obj-count { flex: none; color: var(--muted); font-size: 0.85rem; }
.ship-status { display: flex; flex-wrap: nowrap; gap: 4px; flex: none; }
.ship-progress { font-size: 0.85rem; color: var(--muted); white-space: nowrap; flex: none; }
.ship-progress b { color: var(--green); }
.repaired-list { margin: 0 0 12px; color: var(--muted); }
.repaired-list b { color: var(--green); }
.part { font-size: 0.68rem; padding: 0 4px; background: var(--red-3); color: #ffd0d0; border: 2px solid var(--void); line-height: 1.5; }
.part.half { background: var(--amber-3); color: #ffe7b0; }
.part.ok { background: var(--green-3); color: #d6f2a2; }
.objectives { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; }
/* one line: only the current objective (or the last one once all are done) */
.objectives li { display: none; }
.objectives li.active, .objectives:not(:has(li.active)) li:last-child { display: flex; }
.objectives li > span:last-child { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.objectives li { gap: 8px; align-items: center; color: var(--muted); line-height: 1.3; }
.objectives .check { flex: none; width: 16px; height: 16px; border: 3px solid var(--faint); background: var(--panel-2); display: grid; place-items: center; color: var(--void); }
.objectives .check svg { width: 10px; height: 10px; }
.objectives li.active { color: var(--text); }
.objectives li.active .check { border-color: var(--amber); animation: blink 1s steps(2) infinite; }
.objectives li.done { color: var(--faint); text-decoration: line-through; text-decoration-thickness: 2px; }
.objectives li.done .check { background: var(--green); border-color: var(--green-3); animation: none; }

/* speech bubble */
.bubble { position: absolute; transform: translate(-50%, calc(-100% - 12px)); background: var(--text); color: var(--void); font-family: var(--font); font-weight: 600;
  font-size: clamp(0.95rem, 1.6vw, 1.2rem); padding: 4px 12px; border: 3px solid var(--void); box-shadow: 0 3px 0 rgba(5, 4, 12, 0.6); white-space: nowrap; pointer-events: none; min-width: 44px; text-align: center; z-index: 3; }
.bubble::before { content: ''; position: absolute; left: calc(50% - 6px); bottom: -9px; width: 12px; height: 6px; background: var(--text); border: 3px solid var(--void); border-top: 0; }
.bubble::after { content: ''; position: absolute; left: calc(50% - 3px); bottom: -14px; width: 6px; height: 5px; background: var(--void); }
.bubble.pop { animation: pop 0.2s steps(3); }
@keyframes pop { from { transform: translate(-50%, calc(-100% - 4px)) scale(0.7); } }

/* toast */
.toast { position: absolute; top: 12px; right: 12px; max-width: min(360px, 46%); padding: 8px 12px 8px 14px; background: rgba(20, 17, 43, 0.95); border: 3px solid var(--line); border-left: 6px solid var(--cyan);
  box-shadow: 4px 4px 0 var(--void); font-size: 0.95rem; opacity: 0; transform: translateY(-6px); transition: opacity 0.15s steps(2), transform 0.15s steps(2); pointer-events: none; z-index: 4; }
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-left-color: var(--green); }
.toast.warn { border-left-color: var(--amber); }
.toast.error { border-left-color: var(--red); }

/* chapter title card */
.chapter-card { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 8px; z-index: 5;
  background: repeating-conic-gradient(rgba(5, 4, 12, 0.9) 0 25%, rgba(5, 4, 12, 0.72) 0 50%) 0 0 / 4px 4px; }
.chapter-card span { font-family: var(--display); text-transform: uppercase; letter-spacing: 0.2em; color: var(--amber); font-size: 1rem; }
.chapter-card strong { font-family: var(--display); font-size: clamp(1.8rem, 5.5vw, 3.8rem); line-height: 1.1; color: var(--green); text-shadow: 0 4px 0 var(--green-3), 0 8px 0 var(--void); text-transform: uppercase; }
.chapter-card em { font-style: normal; color: var(--text); font-size: clamp(0.95rem, 1.8vw, 1.25rem); margin-top: 10px; padding: 0 16px; }
.chapter-card.play { animation: card 2.2s steps(12) forwards; }
@keyframes card { 0% { opacity: 0; } 12%, 82% { opacity: 1; } 100% { opacity: 0; } }

/* narration: a slim bar directly under the scene */
.dialog { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 6px 8px 6px var(--pad); background: var(--panel); border: 3px solid var(--line); cursor: pointer; animation: slideup 0.2s steps(3); }
@keyframes slideup { from { transform: translateY(6px); opacity: 0; } }
.dialog-who { flex: none; font-family: var(--display); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; padding: 2px 8px; background: var(--amber); color: var(--void); border: 2px solid var(--void); }
.dialog.is-zib .dialog-who { background: var(--green); }
.dialog-text { flex: 1; min-width: 0; margin: 0; font-size: 1.05rem; line-height: 1.35; }
.dialog.is-zib .dialog-text { color: var(--green); font-size: 1.2rem; letter-spacing: 0.04em; }
.dialog-next { flex: none; border: 3px solid var(--void); background: var(--panel-3); padding: 3px 10px; font-family: var(--font); cursor: pointer; color: var(--text); box-shadow: 0 3px 0 var(--void); }
.dialog-next span { display: inline-block; animation: blink 0.8s steps(2) infinite; color: var(--amber); }

/* command bar */
.main-col:has(.dialog:not([hidden])) :is(.command-bar, .quick) { display: none; } /* narration takes the command bar's place */
.command-bar { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 4px 6px 4px var(--pad); background: var(--panel); border: 3px solid var(--line); }
.command-icon { width: 10px; height: 18px; background: var(--green); flex: none; animation: blink 1s steps(2) infinite; }
.command-bar input { flex: 1; min-width: 0; background: transparent; border: none; color: var(--text); font: 600 1.1rem var(--font); padding: 4px 0; }
.command-bar input::placeholder { color: var(--faint); }
.command-bar input:focus { outline: none; }
.command-bar:focus-within { border-color: var(--green); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: calc(var(--gap) * -0.5); }
.chip { border: 2px solid var(--void); background: var(--panel-3); padding: 1px 8px; font-size: 0.9rem; cursor: pointer; color: var(--text); box-shadow: 0 2px 0 var(--void); }
.chip:hover { background: var(--line); }
.chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--void); }
.chip.verb { background: var(--violet-3); color: #d8d0ff; }
.quick-label { font-size: 0.9rem; color: var(--faint); margin-right: 2px; }

/* console */
/* the right column fits the space under the top bar (58px) and the page's bottom padding, so it never stretches the page */
.console { display: flex; flex-direction: column; gap: var(--gap); position: sticky; top: 12px; max-height: calc(100vh - 74px); overflow: auto; min-width: 0; }
.console-head .segmented { flex: 1; }
.teach-box { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; background: var(--panel); border: 3px solid var(--line); }
.side-panels { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.ask-row { display: flex; gap: 8px; }
.ask-row #test { flex: 1; padding: 5px 14px; }
.teach-row input { padding: 6px 10px; }
.console .pill { font-size: 0.8rem; padding: 1px 6px; }
.console .segmented button { padding: 3px; }
.console .swatch { width: 22px; height: 22px; }
.console-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.console h2 { font-family: var(--display); font-size: 0.8rem; margin: 0; text-transform: uppercase; color: var(--amber); }
.pill { font-size: 0.85rem; padding: 2px 8px; border: 3px solid var(--line); color: var(--muted); background: var(--panel-2); }
.pill.ready { color: var(--green); border-color: var(--green-3); }
.pill.loading { color: var(--amber); border-color: var(--amber-3); }
.pill.error { color: var(--red); border-color: var(--red-3); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.segmented button { border: 3px solid var(--void); background: var(--panel-2); padding: 6px; color: var(--muted); cursor: pointer; font-family: var(--font); box-shadow: 0 3px 0 var(--void); }
.segmented button[aria-selected="true"] { background: var(--line); color: var(--text); transform: translateY(2px); box-shadow: 0 1px 0 var(--void), inset 0 3px 0 rgba(255, 255, 255, 0.08); }
.viewport { position: relative; aspect-ratio: 4 / 3; height: auto; width: min(100%, 240px); overflow: hidden; background: #000; border: 3px solid var(--line); margin: 0 auto; flex: none; display: flex; justify-content: center; contain: size; } /* sized by its own width + 4:3, never by the canvas's internal pixels */
.teach-box, .side-panels, .console > * { min-width: 0; }
#video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; image-rendering: auto; }
#draw { height: 100%; width: auto; aspect-ratio: 1; background: #fff; touch-action: none; cursor: crosshair; display: block; image-rendering: auto; user-select: none; -webkit-user-select: none; }
.draw-actions { display: flex; gap: 8px; }
.draw-actions .btn:disabled { opacity: 0.45; cursor: default; }
.finder { position: absolute; top: 8px; bottom: 8px; left: 50%; transform: translateX(-50%); aspect-ratio: 1; pointer-events: none; } /* frames the square CLIP sees */
.finder i { position: absolute; width: 20px; height: 20px; border: 4px solid var(--green); }
.finder i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.finder i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.finder i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.finder i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.finder b { position: absolute; left: 0; right: 0; height: 4px; top: 0; background: var(--green); box-shadow: 0 0 0 2px rgba(143, 212, 138, 0.3); opacity: 0; }
.viewport.scanning .finder b { opacity: 1; animation: scan 0.8s steps(10) infinite alternate; }
.viewport.scanning .finder i { border-color: var(--amber); }
@keyframes scan { to { top: calc(100% - 4px); } }
.draw-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.swatches { display: flex; gap: 8px; }
.swatch { width: 26px; height: 26px; border: 3px solid var(--void); cursor: pointer; padding: 0; box-shadow: 0 3px 0 var(--void); }
.swatch[aria-checked="true"] { outline: 3px solid var(--amber); outline-offset: 2px; }
.teach-row { display: flex; gap: 8px; }
.teach-row input { flex: 1; min-width: 0; background: var(--void); border: 3px solid var(--line); color: var(--text); padding: 9px 12px; font: 600 1.1rem var(--font); }
.teach-row input:focus { outline: none; border-color: var(--green); }

.card { background: var(--panel-2); border: 3px solid var(--line); padding: 6px var(--pad) var(--pad); }
.card h3 { font-family: var(--display); font-size: 0.85rem; margin: 0 0 8px; min-height: 24px; align-items: center !important; display: flex; justify-content: space-between; align-items: baseline; text-transform: uppercase; color: var(--amber); }
.count { font-family: var(--font); font-size: 0.9rem; color: var(--muted); text-transform: none; }
.dictionary { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.dictionary.big { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.dictionary.big .word-card { width: 120px; }
.empty { color: var(--faint); margin: 0; grid-column: 1 / -1; }
.word-card { position: relative; background: var(--panel); border: 3px solid var(--void); box-shadow: 0 0 0 2px var(--line); padding: 5px; text-align: center; animation: pop-in 0.2s steps(3); }
@keyframes pop-in { from { transform: scale(0.8); } }
.word-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #fff; image-rendering: pixelated; }
.word-card .w { display: block; margin-top: 4px; font-weight: 600; }
.word-card .n { position: absolute; top: 8px; left: 8px; background: var(--green); color: var(--void); font-size: 0.75rem; padding: 0 5px; border: 2px solid var(--void); }
.word-card .x { position: absolute; top: 7px; right: 7px; width: 22px; height: 22px; border: 2px solid var(--void); background: var(--red); color: var(--void); display: grid; place-items: center; cursor: pointer; opacity: 0; padding: 0; }
.word-card .x svg { width: 10px; height: 10px; }
.word-card:hover .x, .word-card .x:focus-visible { opacity: 1; }
@media (hover: none) { .word-card .x { opacity: 1; } }

.mind-compare { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.mind figure { margin: 0; text-align: center; font-size: 0.85rem; color: var(--muted); }
.mind figure img { width: 100%; max-width: 84px; aspect-ratio: 1; object-fit: cover; display: block; margin: 0 auto 4px; background: #fff; border: 3px solid var(--void); image-rendering: pixelated; }
.mind .arrow { color: var(--amber); font-size: 1.4rem; }
.verdict { font-size: 1.25rem; font-weight: 600; margin: 10px 0 8px; }
.verdict.ok { color: var(--green); }
.verdict.unsure { color: var(--red); }
.ranks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ranks li { display: grid; grid-template-columns: 64px 1fr 44px; align-items: center; gap: 8px; font-size: 0.95rem; }
.meter { position: relative; height: 12px; background: var(--void); border: 2px solid var(--line); }
.meter span { position: absolute; inset: 0 auto 0 0; background: repeating-linear-gradient(90deg, var(--green) 0 6px, transparent 6px 8px); }
.meter.below span { background: repeating-linear-gradient(90deg, var(--faint) 0 6px, transparent 6px 8px); }
.meter i { position: absolute; top: -5px; bottom: -5px; width: 3px; background: var(--amber); }
.brain-map { display: block; width: 100%; height: 130px; background: var(--void); border: 3px solid var(--line); image-rendering: auto; }
.map-legend, .map-near { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 0.95rem; }
.map-near:empty, .map-legend:empty { display: none; }
.map-near { color: var(--muted); }
.map-near b { color: var(--text); font-weight: 600; }
.key { display: inline-flex; align-items: center; gap: 5px; }
.key i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--void); display: inline-block; }
.key i.test { background: #fff; border-color: var(--amber); }
.accuracy .acc-head { display: flex; align-items: baseline; gap: 10px; }
.accuracy .acc-big { font-family: var(--display); font-size: 1.6rem; color: var(--text); }
.accuracy .acc-sub { color: var(--muted); }
.acc-chart { position: relative; margin-top: 8px; }
.acc-chart svg { display: block; width: 100%; height: auto; background: var(--void); border: 3px solid var(--line); }
.acc-chart svg text { font: 13px var(--font); fill: var(--muted); }
.acc-tip { position: absolute; pointer-events: none; transform: translate(var(--ax, -50%), calc(-100% - 10px)); background: var(--panel-3); border: 2px solid var(--line-hi); padding: 2px 8px; font-size: 0.9rem; white-space: nowrap; color: var(--text); }
.acc-tests { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 6px; margin-top: 10px; }
.acc-test { position: relative; margin: 0; background: var(--panel); border: 3px solid var(--void); padding: 3px; text-align: center; font-size: 0.8rem; line-height: 1.1; }
.acc-test img { width: 100%; aspect-ratio: 1; display: block; background: #fff; }
.acc-test.ok { box-shadow: 0 0 0 2px var(--green-2); }
.acc-test.bad { box-shadow: 0 0 0 2px var(--red-3); }
.acc-test .mark { display: block; margin-top: 2px; color: var(--muted); }
.acc-test.ok .mark b { color: var(--green); }
.acc-test.bad .mark b { color: var(--red); }
.acc-test .x { position: absolute; top: 4px; right: 4px; width: 18px; height: 18px; padding: 0; border: 2px solid var(--void); background: var(--red); color: var(--void); display: grid; place-items: center; cursor: pointer; opacity: 0; }
.acc-test .x svg { width: 8px; height: 8px; }
.acc-test:hover .x, .acc-test .x:focus-visible { opacity: 1; }
@media (hover: none) { .acc-test .x { opacity: 1; } }
.mind-actions { margin-top: 10px; }

/* ---------- panels under the stage ---------- */
.panels { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--gap); align-items: stretch; min-width: 0; } /* Brain Map and Mind: equal width AND equal height */
.panels > .fix { grid-column: 1 / -1; }
.panel { background: var(--panel-2); border: 3px solid var(--line); min-width: 0; }
.panel > summary { list-style: none; display: flex; align-items: center; gap: 8px; min-height: 24px; padding: 6px var(--pad); cursor: pointer; user-select: none; }
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before { content: ''; width: 0; height: 0; border-style: solid; border-width: 5px 0 5px 7px; border-color: transparent transparent transparent var(--amber); transition: transform 0.15s steps(2); flex: none; }
.panel[open] > summary::before { transform: rotate(90deg); }
.panel > summary:hover h3 { color: var(--text); }
.panel > summary h3 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0; font-family: var(--display); font-size: 0.85rem; text-transform: uppercase; color: var(--amber); }
.panel > :not(summary) { margin: 0 var(--pad) var(--pad); }
.panel-help { font-size: 0.9rem; color: var(--muted); background: var(--panel); border: 2px dashed var(--line); padding: 8px 10px; }
.panel-empty { color: var(--faint); margin: 0; }
.help-btn { flex: none; width: 24px; height: 24px; padding: 0; border: 2px solid var(--void); background: var(--panel-3); color: var(--text); font: 0.7rem var(--display); cursor: pointer; box-shadow: 0 2px 0 var(--void); }
.help-btn[aria-expanded="true"] { background: var(--amber); color: var(--void); }
.map-body[hidden] { display: none; }
.panel .map-legend, .panel .map-near { font-size: 0.85rem; gap: 2px 10px; margin-top: 6px; }
.map-keys { display: contents; }
.map-keys:empty { display: none; }
/* compact accuracy meter (right column): the number beside a small chart */
.panel-acc .accuracy:has(.acc-head) { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; align-items: center; }
.panel-acc .acc-head { display: contents; }
.panel-acc .acc-big { grid-column: 1; grid-row: 1; font-size: 1.4rem; }
.panel-acc .acc-chart { grid-column: 2; grid-row: 1; margin: 0; }
/* compact: just the number and the chart; the sentence stays for screen readers, details are behind "?" and the toggle */
.panel-acc .acc-sub { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.panel-acc .acc-tests-wrap { grid-column: 1 / -1; margin: 0; }
.acc-tests-wrap > summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; line-height: 1.2; }
.acc-tests-wrap > summary:hover { color: var(--text); }
.panel-acc .acc-tests { grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); }
/* compact dictionary (right column): small thumbnails with labels */
.console .dictionary { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; max-height: 66px; overflow: auto; } /* one row; scrolls when ZIBO knows more */
.console .word-card { padding: 2px; border: 2px solid var(--void); box-shadow: 0 0 0 1px var(--line); }
.console .word-card img { width: 40px; margin: 0 auto; }
.console .word-card .w { margin-top: 1px; font-size: 0.8rem; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.console .word-card .n { top: 5px; left: 5px; font-size: 0.65rem; padding: 0 3px; border-width: 1px; }
.console .word-card .x { top: 4px; right: 4px; width: 18px; height: 18px; }
.console .word-card .x svg { width: 8px; height: 8px; }
.fix { border-color: var(--amber); }
.fix .fix-intro { margin: 0 0 10px; color: var(--muted); }
.fix .fix-intro b { color: var(--text); }
.fix-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fix-col { background: var(--panel); border: 3px solid var(--void); padding: 8px; min-width: 0; }
.fix-col h4 { margin: 0 0 6px; font-family: var(--display); font-size: 0.7rem; text-transform: uppercase; color: var(--muted); }
.fix-col img { width: 56px; aspect-ratio: 1; display: block; background: #fff; border: 2px solid var(--void); margin-bottom: 6px; }
.fix-col .verdict { font-size: 1.05rem; margin: 0 0 6px; }
.fix-col .ranks { gap: 6px; }
.fix-col .ranks li { grid-template-columns: minmax(0, 46px) 1fr 32px; gap: 4px; font-size: 0.85rem; }
.fix-col .ranks li > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.fix-col.pending { display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 0.95rem; }
.fix-result { margin: 10px 0 0; font-weight: 600; }
.fix-result.ok { color: var(--green); }
.fix-result.not { color: var(--amber); }
.fix-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.small { font-size: 0.9rem; }
.hint { margin: 10px 0 0; }

/* ---------- ending ---------- */
.ending-screen { padding: 52px 20px 64px; }
.ending-inner { max-width: 1000px; margin: 0 auto; text-align: center; }
.ending-inner h2 { font-family: var(--display); font-size: 1.1rem; text-transform: uppercase; color: var(--amber); margin: 48px 0 18px; }
.ending-inner .tagline { margin: 22px auto 0; }
.logo.small { font-size: clamp(2rem, 6.5vw, 4rem); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 32px; }
.stat { padding: 16px 10px; background: var(--panel); border: 3px solid var(--line); box-shadow: 4px 4px 0 var(--void); }
.stat b { display: block; font-family: var(--display); font-size: 2.2rem; color: var(--green); line-height: 1.1; }
.stat span { color: var(--muted); }
.lessons { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; text-align: left; }
.lesson { display: flex; gap: 14px; align-items: flex-start; }
.lessons .lesson { background: var(--panel); border: 3px solid var(--line); padding: 14px; box-shadow: 4px 4px 0 var(--void); }
.lesson-icon { flex: none; width: 52px; height: 52px; display: grid; place-items: center; font-family: var(--display); font-size: 1.1rem; color: var(--void); background: var(--amber); border: 3px solid var(--void); box-shadow: var(--bevel); }
.lesson-icon svg { width: 26px; height: 26px; }
.lesson h3 { font-family: var(--display); font-size: 0.95rem; text-transform: uppercase; margin: 0 0 6px; color: var(--green); }
.lesson p { margin: 0; color: var(--muted); }
.lesson .eyebrow { margin: 0 0 4px; font-size: 0.65rem; }
.ending-screen .title-actions { margin-top: 44px; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: repeating-conic-gradient(rgba(5, 4, 12, 0.88) 0 25%, rgba(5, 4, 12, 0.7) 0 50%) 0 0 / 4px 4px; animation: fade 0.15s steps(2); }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 3px solid var(--line-hi); box-shadow: inset 0 0 0 3px var(--panel-2), 10px 10px 0 var(--void); padding: 24px; animation: rise-in 0.2s steps(3); }
.modal.wide { width: min(840px, 100%); }
@keyframes rise-in { from { transform: translateY(10px); } }
.modal h2 { font-family: var(--display); font-size: 1.3rem; text-transform: uppercase; color: var(--green); margin: 0 0 16px; }
.modal p { color: var(--muted); }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; margin-top: 24px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.step { background: var(--panel-2); border: 3px solid var(--line); padding: 14px; }
.step .lesson-icon { margin-bottom: 12px; }
.step h3 { font-family: var(--display); font-size: 0.9rem; text-transform: uppercase; color: var(--green); margin: 0 0 6px; }
.step p { margin: 0; font-size: 0.95rem; }
.chapter-list { display: grid; gap: 10px; }
.chapter-btn { display: flex; align-items: center; gap: 14px; text-align: left; width: 100%; padding: 10px 12px; border: 3px solid var(--void); background: var(--panel-2); cursor: pointer; box-shadow: 0 0 0 2px var(--line), 0 5px 0 var(--void); }
.chapter-btn:hover:not(:disabled) { background: var(--panel-3); box-shadow: 0 0 0 2px var(--green-2), 0 5px 0 var(--void); }
.chapter-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.chapter-btn .num { width: 38px; height: 38px; display: grid; place-items: center; font-family: var(--display); background: var(--green); color: var(--void); border: 3px solid var(--void); flex: none; }
.chapter-btn b { display: block; font-weight: 600; font-size: 1.05rem; }
.chapter-btn small { color: var(--muted); font-size: 0.9rem; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  :root { --stage-h: 9999px; } /* full width scene */
  .console { position: static; max-height: none; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
}
@media (max-width: 720px) {
  body { font-size: 1rem; }
  .topbar { padding: 8px 12px; gap: 10px; }
  .brand, .net, .lang-bar { display: none; }
  .vol { width: 44px; }
  /* phones: the top bar must fit 375px (word count + 4 sound buttons + slider) */
  .topbar-right, .audio-controls { gap: 6px; }
  .topbar .icon-btn { width: 34px; height: 34px; }
  .chapter-label { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.95rem; }
  #lang-unit { display: none; }
  .layout { padding: 0 12px 16px; }
  .console { display: flex; }
  .panels { grid-template-columns: minmax(0, 1fr); }
  .mission-strip { flex-wrap: wrap; row-gap: 4px; padding: 6px var(--pad); }
  .mission-strip .objectives { flex-basis: 100%; order: 5; }
  .toast { top: auto; bottom: 10px; right: 10px; max-width: calc(100% - 20px); }
  .stats { grid-template-columns: 1fr 1fr; }
  .lessons, .steps { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
