/* ═══════════════════════════════════════════════════════════
   一个游戏的诞生 · 像素街机
   限定调色板，硬边框，无圆角，无抗锯齿。
   ═══════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'Press Start 2P';
  src: url('../assets/fonts/PressStart2P-Regular.ttf') format('truetype');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  --bg:      #0d0b1e;
  --bg-2:    #151233;
  --bg-3:    #1d1948;
  --line:    #2e2960;
  --ink:     #e8e6f0;
  --dim:     #7d78ad;
  --cyan:    #35e0d8;
  --magenta: #ff4fa3;
  --amber:   #ffc93c;
  --green:   #5cf07a;
  --red:     #ff4d5e;
  --violet:  #7a5cc4;

  --font-pixel: 'Press Start 2P', 'Courier New', monospace;
  --font-ui: 'Microsoft YaHei', 'PingFang SC', 'Hiragino Sans GB', system-ui, sans-serif;
  --font-code: 'Cascadia Mono', 'Consolas', 'SF Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  overflow: hidden;
}

body { -webkit-font-smoothing: none; }

#app {
  display: grid;
  grid-template-columns: 384px minmax(0, 1fr);
  grid-template-rows: 58px minmax(0, 1fr) 296px;
  grid-template-areas:
    "top   top"
    "rules stage"
    "code  code";
  height: 100vh;
  gap: 0;
}

.hidden { display: none !important; }

/* ── 顶栏 ───────────────────────────────────────────────── */

#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 14px;
  background: var(--bg-2);
  border-bottom: 3px solid var(--line);
}

#brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 3px;
  color: var(--cyan);
  text-shadow: 2px 2px 0 #000;
  white-space: nowrap;
}

#levels { display: flex; gap: 6px; }

.lvl-tab {
  font-family: var(--font-pixel);
  font-size: 10px;
  min-width: 34px;
  padding: 8px 6px;
  color: var(--dim);
  background: var(--bg);
  border: 2px solid var(--line);
  cursor: pointer;
}
.lvl-tab:hover:not(:disabled) { color: var(--ink); border-color: var(--dim); }
.lvl-tab:disabled { cursor: not-allowed; opacity: .45; }
.lvl-tab.active {
  color: var(--bg);
  background: var(--cyan);
  border-color: var(--cyan);
  box-shadow: 3px 3px 0 #000;
}
.lvl-tab.cleared { color: var(--green); border-color: var(--green); }
.lvl-tab.cleared.active { color: var(--bg); background: var(--green); }

#hud { display: flex; gap: 14px; margin-left: auto; align-items: center; }

.hud-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: var(--font-pixel);
  font-size: 9px;
}
.hud-item i { font-style: normal; color: var(--dim); }
.hud-item b { font-size: 12px; color: var(--amber); }
.hud-item.alert b { color: var(--red); animation: blink .5s steps(2) infinite; }

@keyframes blink { 50% { opacity: .25; } }

#controls { display: flex; gap: 6px; }

/* ── 按钮 ───────────────────────────────────────────────── */

.btn {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 8px 12px;
  color: var(--ink);
  background: var(--bg-3);
  border: 2px solid var(--line);
  border-radius: 0;
  cursor: pointer;
  box-shadow: 3px 3px 0 #000;
  transition: none;
}
.btn:hover { border-color: var(--cyan); color: var(--cyan); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 #000; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary {
  width: 100%;
  padding: 13px;
  font-size: 14px;
  color: var(--bg);
  background: var(--green);
  border-color: var(--green);
}
.btn.primary:hover { color: var(--bg); background: var(--cyan); border-color: var(--cyan); }
.btn.primary.dirty {
  color: var(--bg);
  background: var(--amber);
  border-color: var(--amber);
  animation: nudge 1.1s ease-in-out infinite;
}
@keyframes nudge { 50% { box-shadow: 0 0 0 2px #ffc93c55, 3px 3px 0 #000; } }

/* ── 面板通用 ───────────────────────────────────────────── */

.panel-head {
  padding: 10px 14px;
  background: var(--bg-2);
  border-bottom: 3px solid var(--line);
}
.panel-head.row { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--magenta);
}
.panel-head .sub { margin: 3px 0 0; font-size: 11px; color: var(--dim); }

/* ── 左栏：规则 ─────────────────────────────────────────── */

#rules-panel {
  grid-area: rules;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-2);
  border-right: 3px solid var(--line);
}

#rules-scroll { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 8px; }
.panel-foot { padding: 12px 14px; border-top: 3px solid var(--line); background: var(--bg-2); }

fieldset.rule-group {
  margin: 0;
  padding: 10px 14px 14px;
  border: 0;
  border-bottom: 2px dashed var(--line);
}
fieldset.rule-group.locked { background: rgba(0, 0, 0, .28); }

.group-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--dim);
}
.group-legend .n { color: var(--amber); }
.badge {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 2px 6px;
  border: 2px solid currentColor;
}
.badge.lock { color: var(--dim); }
.badge.live { color: var(--green); }

.rule {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 10px;
  padding: 7px 0;
}
.rule + .rule { border-top: 1px solid rgba(46, 41, 96, .5); }
.rule.locked { opacity: .55; }

.rule-label { font-size: 12px; color: var(--ink); }
.rule-label .k {
  display: block;
  font-family: var(--font-code);
  font-size: 10px;
  color: var(--dim);
  margin-top: 2px;
}
.rule-hint {
  grid-column: 1 / -1;
  font-size: 11px;
  line-height: 1.5;
  color: var(--dim);
  margin: 2px 0 0;
}

.rule-ctl { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }

input[type="number"], select, input[type="text"] {
  font-family: var(--font-code);
  font-size: 12px;
  width: 74px;
  padding: 5px 6px;
  color: var(--amber);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 0;
}
select { width: auto; min-width: 96px; cursor: pointer; color: var(--cyan); }
input:focus, select:focus { outline: 0; border-color: var(--cyan); }
input:disabled, select:disabled { color: var(--dim); cursor: not-allowed; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 92px;
  height: 6px;
  background: var(--line);
  border: 2px solid var(--line);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 18px;
  background: var(--magenta);
  border: 2px solid #000;
  cursor: pointer;
}
input[type="range"]:disabled { opacity: .4; cursor: not-allowed; }

.toggle { display: flex; border: 2px solid var(--line); }
.toggle button {
  font-family: var(--font-pixel);
  font-size: 8px;
  padding: 6px 8px;
  color: var(--dim);
  background: var(--bg);
  border: 0;
  cursor: pointer;
}
.toggle button[aria-pressed="true"] { color: var(--bg); background: var(--green); }
.toggle button:disabled { cursor: not-allowed; }

.pick-btn {
  font-family: var(--font-pixel);
  font-size: 8px;
  padding: 6px 7px;
  color: var(--dim);
  background: var(--bg);
  border: 2px solid var(--line);
  cursor: pointer;
}
.pick-btn:hover { color: var(--cyan); border-color: var(--cyan); }
.pick-btn.armed { color: var(--bg); background: var(--amber); border-color: var(--amber); }

.chips { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.chip {
  font-family: var(--font-code);
  font-size: 11px;
  padding: 3px 6px;
  color: var(--cyan);
  background: var(--bg);
  border: 2px solid var(--line);
  cursor: pointer;
}
.chip:hover { border-color: var(--red); color: var(--red); }
.chip.empty { color: var(--dim); cursor: default; }
.chip.empty:hover { border-color: var(--line); color: var(--dim); }

#rules-errors {
  margin: 10px 14px;
  padding: 10px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--amber);
  background: rgba(255, 201, 60, .08);
  border: 2px solid var(--amber);
}
#rules-errors ul { margin: 0; padding-left: 18px; }
#rules-errors.fatal { color: var(--red); border-color: var(--red); background: rgba(255, 77, 94, .1); }

/* ── 右上：舞台 ─────────────────────────────────────────── */

#stage {
  grid-area: stage;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 14px;
  background:
    radial-gradient(circle at 50% 40%, #191540 0%, var(--bg) 72%);
  overflow: hidden;
}

#canvas-wrap { position: relative; line-height: 0; }

#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #08071a;
  border: 4px solid var(--line);
  box-shadow: 0 0 0 3px #000, 0 0 34px rgba(53, 224, 216, .16);
}

#scanlines, #vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#scanlines {
  background: repeating-linear-gradient(
    to bottom, rgba(0, 0, 0, .3) 0 1px, transparent 1px 3px);
  opacity: .5;
  mix-blend-mode: multiply;
}
#vignette {
  background: radial-gradient(ellipse at center, transparent 52%, rgba(0, 0, 0, .62) 100%);
}

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  background: rgba(8, 7, 26, .86);
  line-height: 1.6;
  z-index: 3;
}
#overlay h3 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 22px;
  letter-spacing: 2px;
  text-shadow: 3px 3px 0 #000;
}
#overlay.win h3 { color: var(--green); }
#overlay.lose h3 { color: var(--red); }
#overlay p { margin: 0; font-size: 13px; color: var(--dim); max-width: 420px; }
#overlay .btn { min-width: 190px; }
#overlay .stat {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--amber);
}

#pick-hint {
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  font-family: var(--font-pixel);
  font-size: 9px;
  padding: 8px 12px;
  color: var(--bg);
  background: var(--amber);
  border: 2px solid #000;
  box-shadow: 3px 3px 0 #000;
  animation: blink .9s steps(2) infinite;
}

/* ── 下方：代码 ─────────────────────────────────────────── */

#code-panel {
  grid-area: code;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #08071a;
  border-top: 3px solid var(--line);
}

#code-meta { display: flex; align-items: center; gap: 12px; }
#code-file {
  font-family: var(--font-code);
  font-size: 11px;
  color: var(--dim);
}
#diff-stat { font-family: var(--font-pixel); font-size: 9px; color: var(--dim); }
#diff-stat .add { color: var(--green); }
#diff-stat .del { color: var(--red); }
#code-panel.broken .panel-head { border-bottom-color: var(--red); }
#code-panel.broken .panel-head h2 { color: var(--red); }

#code-scroll { flex: 1; overflow: auto; min-height: 0; position: relative; }

#code {
  margin: 0;
  padding: 8px 0 24px;
  font-family: var(--font-code);
  font-size: 12.5px;
  line-height: 1.55;
  tab-size: 4;
  counter-reset: ln;
}

.ln {
  display: grid;
  grid-template-columns: 52px 52px 18px 1fr;
  white-space: pre;
}
.ln .gut {
  text-align: right;
  padding-right: 8px;
  color: #3a3568;
  user-select: none;
  font-size: 11px;
}
.ln .mark { text-align: center; user-select: none; font-weight: 700; }
.ln .txt { padding-right: 20px; }

.ln-add { background: rgba(92, 240, 122, .13); }
.ln-add .mark { color: var(--green); }
.ln-del { background: rgba(255, 77, 94, .13); }
.ln-del .mark { color: var(--red); }
.ln-del .txt { color: var(--dim); text-decoration: line-through; opacity: .8; }

.ln.pulse { animation: pulse 1.5s ease-out 1; }
@keyframes pulse {
  0%   { background: rgba(255, 201, 60, .5); }
  100% { background: transparent; }
}
.ln-add.pulse { animation: pulse-add 1.5s ease-out 1; }
@keyframes pulse-add {
  0%   { background: rgba(255, 201, 60, .55); }
  100% { background: rgba(92, 240, 122, .13); }
}
.ln-del.pulse { animation: pulse-del 1.5s ease-out 1; }
@keyframes pulse-del {
  0%   { background: rgba(255, 201, 60, .55); }
  100% { background: rgba(255, 77, 94, .13); }
}

/* Python 语法着色 */
.tk-kw  { color: var(--magenta); }
.tk-bi  { color: var(--violet); }
.tk-str { color: var(--amber); }
.tk-num { color: var(--cyan); }
.tk-com { color: #4e4880; font-style: italic; }
.tk-fn  { color: var(--green); }
.tk-const { color: #6fd3ff; }
.tk-op  { color: var(--dim); }
.tk-err { background: rgba(255, 77, 94, .3); box-shadow: inset 3px 0 0 var(--red); }

/* ── 滚动条 ─────────────────────────────────────────────── */

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line); border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--dim); }
::-webkit-scrollbar-corner { background: var(--bg); }

/* ── 窄屏 ───────────────────────────────────────────────── */

@media (max-width: 1080px) {
  #app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 58px minmax(240px, 1fr) auto auto;
    grid-template-areas: "top" "stage" "rules" "code";
    height: auto;
    min-height: 100vh;
  }
  html, body { overflow: auto; }
  #rules-panel { border-right: 0; border-top: 3px solid var(--line); }
  #rules-scroll { max-height: 340px; }
  #code-panel { height: 320px; }
  #hud { display: none; }
}

/* 原创配乐与章节幕间 */
.music-volume { display: flex; align-items: center; gap: 5px; font-size: 10px; color: var(--dim); }
.music-volume input[type="range"] { width: 52px; }
#controls { flex-shrink: 0; }
#topbar { gap: 12px; }
#hud { gap: 9px; }
#controls .btn { padding: 8px; white-space: nowrap; letter-spacing: 0; }
.btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 4px; }

#chapter-dialog {
  --speaker: var(--cyan);
  padding: 0;
  width: min(880px, calc(100vw - 40px));
  max-width: none;
  max-height: calc(100dvh - 32px);
  overflow: auto;
  color: var(--ink);
  background: #100e23;
  border: 2px solid #51435f;
  box-shadow: 0 0 0 5px #090815, 12px 12px 0 #05040c, 0 0 100px #0009;
  font-family: var(--font-ui);
}
#chapter-dialog::backdrop { background: rgba(5, 5, 15, .88); backdrop-filter: blur(5px); }
#chapter-dialog[data-speaker="grasshopper"] { --speaker: var(--amber); }
.story-shell { position: relative; overflow: hidden; }
.story-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 28px 34px 0; }
#story-chapter { font-family: var(--font-code); font-size: 11px; letter-spacing: 3px; color: #a99d88; }
.story-heading h1 { font-size: clamp(22px, 3vw, 32px); font-weight: 600; letter-spacing: 4px; margin: 10px 0 12px; color: #efe4ce; }
.story-heading p { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 11px; color: #9d94b5; letter-spacing: 2px; }
.story-dash { width: 20px; height: 2px; background: #b19a60; }
.story-options { display: flex; gap: 10px; }
.story-options .btn { padding: 7px 10px; color: #b2a5bf; border-color: #3d334c; background: transparent; font-size: 11px; box-shadow: none; }
.story-options .btn:hover { color: var(--amber); border-color: var(--amber); }
.story-scene { position: relative; display: flex; justify-content: center; align-items: flex-end; gap: 35px; height: clamp(190px, 34vh, 300px); padding: 14px 36px 22px; margin-top: 10px; }
.story-scene::before { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at 22% 82%, #1b57532b, transparent 40%), radial-gradient(ellipse at 50% 82%, #79602e26, transparent 40%), radial-gradient(ellipse at 80% 82%, #8a443626, transparent 40%); }
.story-stars { position: absolute; top: 12%; left: 10%; right: 10%; text-align: center; color: #76665a; font-family: var(--font-code); font-size: 17px; letter-spacing: 7px; }
.story-horizon { position: absolute; bottom: 0; left: 0; right: 0; height: 75px; border-top: 1px solid #62507140; background-image: linear-gradient(#51426438 1px, transparent 1px), linear-gradient(90deg, #51426438 1px, transparent 1px); background-size: 32px 18px; transform: perspective(160px) rotateX(25deg); transform-origin: bottom; mask-image: linear-gradient(transparent, #000); }
.portrait { position: relative; z-index: 1; margin: 0; width: 230px; height: 100%; display: flex; align-items: center; flex-direction: column; justify-content: flex-end; }
.portrait img { display: block; width: 100%; height: calc(100% - 28px); object-fit: contain; image-rendering: pixelated; opacity: .45; filter: saturate(.6) brightness(.75); transform: translateY(4px); transition: filter .2s, opacity .2s, transform .2s; }
#chapter-dialog[data-speaker="robot"] .portrait-robot img,
#chapter-dialog[data-speaker="grasshopper"] .portrait-grasshopper img,
#chapter-dialog[data-speaker="ant"] .portrait-ant img { opacity: 1; filter: none; transform: translateY(0); }
.portrait figcaption { display: flex; align-items: center; gap: 8px; height: 28px; font-size: 13px; color: #ddd3c1; }
.portrait figcaption > span { font-family: var(--font-code); font-size: 10px; color: #83788f; }
.portrait figcaption small { font-size: 10px; color: #8a8096; }
.story-conversation { position: relative; z-index: 2; margin: 0 28px; padding: 20px 24px 18px; background: #1a152e; border: 1px solid #514264; border-left: 3px solid var(--speaker); box-shadow: 5px 5px 0 #090715; }
.story-voice { display: flex; align-items: center; gap: 12px; }
#story-speaker { color: var(--speaker); font-size: 15px; letter-spacing: 2px; }
#story-role { color: #9e90ac; font-size: 11px; }
#story-count { margin-left: auto; font-family: var(--font-code); font-size: 11px; color: #a89ab6; letter-spacing: 2px; }
#story-text { margin: 15px 0 12px; min-height: 64px; font-size: 16px; line-height: 1.9; letter-spacing: .7px; color: #ebe3d7; }
.story-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.story-key-hint { margin-right: auto; font-family: var(--font-code); font-size: 10px; color: #9a8ca8; }
#story-prev { background: transparent; border-color: #50425f; color: #b6a8c2; font-size: 11px; padding: 8px 12px; box-shadow: none; }
#story-next { background: #e3c47d; border-color: #e3c47d; color: #221b30; min-width: 142px; padding: 10px 14px; font-size: 12px; }
#story-next:hover { background: #f5dfab; border-color: #f5dfab; }
.story-progress-track { position: absolute; bottom: -1px; left: 0; right: 0; height: 2px; background: #3b2c47; }
#story-progress { height: 100%; background: var(--speaker); transition: width .18s; }
.story-footer { display: flex; align-items: center; gap: 14px; padding: 21px 30px; color: #9d8dab; font-size: 10px; }
.chapter-path { display: flex; gap: 9px; }
.chapter-dot { display: block; width: 5px; height: 5px; background: #4c3f59; }
.chapter-dot.past { background: #927b51; }
.chapter-dot.current { background: #e3c47d; box-shadow: 0 0 0 2px #5b4933; }
.story-credit { margin-left: auto; color: #8a7f99; }

@media (min-width: 1081px) and (max-width: 1380px) {
  #hud { display: none; }
  #controls { margin-left: auto; }
}
@media (max-width: 720px) {
  #topbar { flex-wrap: wrap; height: auto; padding: 10px; gap: 10px; }
  #app { grid-template-rows: auto minmax(240px, 1fr) auto auto; }
  #brand { font-size: 12px; letter-spacing: 1px; }
  #levels { margin-left: auto; }
  #controls { width: 100%; justify-content: space-between; gap: 4px; }
  #controls .btn { font-size: 10px; padding: 7px 5px; }
  .music-volume { display: none; }
  #chapter-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
  .story-header { padding: 20px 18px 0; }
  .story-heading h1 { font-size: 22px; letter-spacing: 2px; }
  #story-chapter { font-size: 9px; letter-spacing: 2px; }
  .story-options { flex-direction: column; gap: 8px; }
  .story-scene { padding: 12px 15px 16px; gap: 0; height: clamp(170px, 30vh, 250px); }
  .portrait { width: 32%; }
  .portrait figcaption small { display: none; }
  .story-conversation { margin: 0 12px; padding: 16px; }
  #story-text { font-size: 14px; min-height: 88px; margin-top: 12px; }
  #story-role { font-size: 10px; }
  .story-key-hint { display: none; }
  .story-actions { justify-content: space-between; }
  #story-next { min-width: 130px; }
  .story-footer { padding: 18px 16px; flex-wrap: wrap; gap: 10px; }
  .story-credit { width: 100%; margin-left: 0; font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) {
  .portrait img, #story-progress { transition: none; }
}

#chapter-dialog[data-speaker="ant"] { --speaker: #ed8b7a; }

/* 十五章导航、规则折叠与运行时提示 */
#app { grid-template-rows: auto minmax(0, 1fr) 220px; }
#topbar { flex-wrap: wrap; padding: 10px 14px; gap: 10px 18px; }
#levels { order: 4; flex-basis: 100%; overflow-x: auto; padding-bottom: 3px; margin: 0; gap: 8px; }
#controls { margin-left: auto; }
.lvl-tab { flex: 0 0 36px; }
.rule-section { border-bottom: 1px solid var(--line); }
.rule-section > summary { padding: 15px 12px; font-size: 12px; color: var(--ink); cursor: pointer; }
.rule-section[open] > summary { color: var(--cyan); background: var(--bg-3); }
.rule-section .rule-group { margin: 0; }
#stage { padding-top: 30px; padding-bottom: 34px; }
#mechanic-hud { position: absolute; top: 10px; left: 14px; right: 14px; text-align: center; font-size: 11px; color: var(--amber); z-index: 4; pointer-events: none; }
#play-help { position: absolute; bottom: 10px; left: 12px; right: 12px; display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; color: var(--dim); font-size: 10px; z-index: 4; pointer-events: none; }
#level-help { color: var(--cyan); }
.chapter-path { gap: 6px; flex-shrink: 0; }
@media (max-width:1080px) {
  #app { grid-template-rows: auto minmax(360px, 55vh) auto auto; }
  #stage { min-height: 360px; }
}
@media (max-width:720px) {
  #topbar { padding: 10px; gap: 8px; }
  #controls { order: 2; margin-left: 0; }
  #levels { order: 3; gap: 5px; }
  .lvl-tab { flex-basis: 29px; min-width: 29px; font-size: 9px; padding: 7px 3px; }
  #mechanic-hud { font-size: 10px; line-height: 1.6; }
  #stage { padding-top: 50px; }
}
#map-legend { pointer-events: auto; color: var(--dim); }
#map-legend summary { cursor: pointer; color: var(--amber); }
#map-legend p { position: absolute; bottom: 20px; left: 0; right: 0; padding: 14px; background: #151233f5; border: 1px solid var(--line); color: var(--ink); text-align: left; line-height: 1.8; font-size: 11px; }
