/* SPACE LABYRINTH — 1970s phosphor CRT styling */

@font-face {
  font-family: 'VT323';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/vt323.woff2') format('woff2');
}

:root {
  --green: #2fae4f;
  --green-bright: #66ff99;
  --green-dim: #1d5c2a;
  --bg: #030a05;
  --panel: #04140a;
  --amber: #ffe14d;
  --red: #ff5544;
  --blue: #7fd4ff;
  --dock-h: 106px;   /* reserved height for the fixed mobile control dock (one compass-band tall) */
}

* { box-sizing: border-box; }

/* kill the 300ms tap delay / double-tap zoom on controls */
button { touch-action: manipulation; }

html, body {
  margin: 0; padding: 0;
  background: #000;
  color: var(--green);
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 19px;
  height: 100%;
  overscroll-behavior: none;   /* no pull-to-refresh reload mid-run */
}

#crt {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(ellipse at center, #07140b 0%, #020803 80%);
  overflow: hidden;
}

/* CRT scanlines + flicker */
.scanlines {
  pointer-events: none;
  position: fixed; inset: 0; z-index: 50;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.18) 3px
  );
  animation: flicker 4s infinite;
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: 0.85; }
  94% { opacity: 1; }
}

.hidden { display: none !important; }

.screen {
  padding: 24px;
  max-width: 1280px;
  margin: 0 auto;
}

/* ---------- title ---------- */
#screen-title { text-align: center; }
#logo {
  display: block;
  width: min(614px, 90vw);
  height: auto;
  margin: 18px auto 10px;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 16px rgba(80, 160, 255, 0.55));
}
.subtitle { color: var(--amber); letter-spacing: 3px; margin: 6px 0; }
.subtitle.small { color: var(--green); font-size: 15px; letter-spacing: 2px; }
#intro-text {
  text-align: left;
  display: inline-block;
  margin: 18px auto;
  color: var(--green);
  text-shadow: 0 0 6px rgba(47, 174, 79, 0.6);
  font-family: inherit;
  font-size: 18px;
  line-height: 1.3;
  border: 1px solid var(--green-dim);
  padding: 16px 22px;
  max-width: 640px;
}
.hint { color: var(--green-dim); margin-top: 10px; font-size: 16px; }

.big-btn {
  display: block;
  margin: 14px auto;
  background: var(--panel);
  border: 2px solid var(--green);
  color: var(--green-bright);
  font-family: inherit;
  font-size: 26px;
  padding: 10px 36px;
  cursor: pointer;
  text-shadow: 0 0 8px rgba(102, 255, 153, 0.7);
  animation: pulse 1.4s infinite;
}
.big-btn:hover { background: var(--green-dim); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(47, 174, 79, 0.4); }
  50% { box-shadow: 0 0 18px rgba(47, 174, 79, 0.9); }
}

/* ---------- character creation ---------- */
#screen-create h1, #screen-create h2 {
  color: var(--green-bright);
  text-shadow: 0 0 10px rgba(102, 255, 153, 0.6);
  letter-spacing: 2px;
}
#screen-create h2 { font-size: 20px; margin: 18px 0 6px; }
.small { color: var(--green); font-size: 15px; }
.create-box { max-width: 720px; margin: 0 auto; }
.rules-note { color: var(--green); font-size: 16px; }
.field { display: flex; gap: 10px; align-items: center; }
.field label { color: var(--amber); }
#name-input {
  background: var(--panel);
  border: 1px solid var(--green);
  color: var(--green-bright);
  font-family: inherit;
  font-size: 22px;
  padding: 4px 10px;
  flex: 1;
}
#btn-rollname, .sm-btn {
  background: var(--panel);
  border: 1px solid var(--green);
  color: var(--green);
  font-family: inherit;
  font-size: 16px;
  padding: 4px 12px;
  cursor: pointer;
}
#btn-rollname:hover, .sm-btn:hover { background: var(--green-dim); color: var(--green-bright); }

.stat-option {
  display: block;
  padding: 4px 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.stat-option:hover { border-color: var(--green-dim); }
.stat-option b { color: var(--amber); }
.opts label { display: block; padding: 3px 0; cursor: pointer; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--green); transform: scale(1.2); margin-right: 8px; }

/* ---------- game layout ---------- */
#screen-game { max-width: 1380px; padding: 10px 18px; }

header {
  display: flex;
  align-items: center;
  gap: 18px;
  border-bottom: 2px solid var(--green-dim);
  padding-bottom: 6px;
  margin-bottom: 10px;
}
header .title {
  color: var(--green-bright);
  font-size: 28px;
  letter-spacing: 6px;
  text-shadow: 0 0 10px rgba(102, 255, 153, 0.7);
}
.hdr-right { margin-left: auto; display: flex; gap: 8px; }

#self-destruct {
  color: var(--red);
  font-size: 22px;
  animation: blinkred 0.8s infinite;
  text-shadow: 0 0 10px rgba(255, 85, 68, 0.8);
}
@keyframes blinkred { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0.25; } }

#air-timer {
  color: var(--amber);
  font-size: 16px;
  letter-spacing: 1px;
  border: 1px solid var(--green-dim);
  padding: 2px 8px;
}
#air-timer.urgent {
  color: var(--red);
  border-color: var(--red);
  animation: blinkred 0.6s infinite;
  text-shadow: 0 0 10px rgba(255, 85, 68, 0.8);
}

#pause-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
}
.pause-box {
  text-align: center;
  border: 3px double var(--green);
  background: var(--panel);
  padding: 40px 60px;
}
.pause-title {
  color: var(--green-bright);
  font-size: 48px;
  letter-spacing: 8px;
  text-shadow: 0 0 20px rgba(102, 255, 153, 0.8);
  margin-bottom: 12px;
}
.pause-box p { font-size: 18px; margin-bottom: 24px; }

/* ---------- easter egg: "RETROTRANSLATION BY ZEN SIBURJYK" (press J) ---------- */
#credit-egg {
  position: fixed;
  left: 50%;
  bottom: 46px;
  transform: translateX(-50%);
  z-index: 95;            /* over the game + pause veil, under the scanlines' sibling overlays */
  pointer-events: none;   /* purely decorative — never eats a tap */
}
.credit-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 3px double var(--green);
  background: rgba(3, 10, 5, 0.96);
  box-shadow: 0 0 26px rgba(47, 174, 79, 0.55), inset 0 0 14px rgba(47, 174, 79, 0.22);
  padding: 12px 30px;
  text-align: center;
}
.credit-deco { color: var(--green-dim); font-size: 13px; letter-spacing: 6px; }
.credit-text { color: var(--green); font-size: 15px; letter-spacing: 5px; }
.credit-name {
  color: var(--green-bright);
  font-size: 28px;
  letter-spacing: 5px;
  text-shadow: 0 0 14px rgba(102, 255, 153, 0.9);
}
#credit-egg.flash { animation: creditflash 2.6s ease-out forwards; }
@keyframes creditflash {
  0%   { opacity: 0;    transform: translateX(-50%) scale(0.92); }
  5%   { opacity: 1;    transform: translateX(-50%) scale(1); }
  9%   { opacity: 0.25; }                                          /* CRT flicker as it powers on */
  13%  { opacity: 1; }
  82%  { opacity: 1;    transform: translateX(-50%) scale(1); }
  100% { opacity: 0;    transform: translateX(-50%) scale(1); }
}

#game-grid {
  display: grid;
  grid-template-columns: 1fr 330px;
  grid-template-rows: auto 320px;
  gap: 12px;
}

#map-pane {
  position: relative;
  border: 1px solid var(--green-dim);
  background: var(--panel);
  padding: 8px;
  overflow: auto;
}
#map { display: block; margin: 0 auto; image-rendering: pixelated; }

.pane-label {
  color: var(--green-dim);
  font-size: 14px;
  letter-spacing: 2px;
  border-bottom: 1px dashed var(--green-dim);
  margin-bottom: 6px;
  padding-bottom: 2px;
}

#monster-overlay {
  position: absolute;
  top: 36px; right: 14px;
  background: rgba(3, 10, 5, 0.95);
  border: 2px solid var(--red);
  box-shadow: 0 0 24px rgba(255, 85, 68, 0.5);
  padding: 10px 16px;
  z-index: 10;
  text-align: center;
}
#monster-name { color: var(--red); font-size: 22px; letter-spacing: 2px; animation: blinkred 1s infinite; }
#monster-art {
  color: var(--green-bright);
  text-shadow: 0 0 8px rgba(102, 255, 153, 0.8);
  font-size: 14px;
  line-height: 1.1;
  text-align: left;
  margin: 8px 0 0;
}

/* ---------- comlet panel ---------- */
#comlet {
  grid-row: 1 / 3;
  grid-column: 2;
  border: 1px solid var(--green-dim);
  background: var(--panel);
  padding: 10px;
  overflow-y: auto;
}
.char-name { color: var(--amber); font-size: 24px; letter-spacing: 2px; margin-bottom: 6px; }
.stat-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dotted rgba(47, 174, 79, 0.25);
  padding: 2px 0;
}
.stat-die { color: var(--green-bright); }
.stat-die.reduced { color: var(--red); }

.pip {
  display: inline-block;
  width: 22px; height: 14px;
  margin-left: 5px;
  border: 1px solid var(--green);
}
.pip.on { background: var(--green-bright); box-shadow: 0 0 8px rgba(102, 255, 153, 0.8); }
.pip.on.low { background: var(--red); border-color: var(--red); box-shadow: 0 0 8px rgba(255, 85, 68, 0.8); animation: blinkred 0.8s infinite; }

.badge { font-size: 15px; color: var(--green); margin: 3px 0; }
.badge.sword { color: var(--blue); text-shadow: 0 0 10px rgba(127, 212, 255, 0.8); animation: pulse 1.4s infinite; }
.badge.stim { color: var(--amber); }

#compass { text-align: center; margin: 4px 0 8px; }
#compass-mid { display: flex; justify-content: center; gap: 44px; margin: 2px 0; }
.dir {
  background: var(--panel);
  border: 2px solid var(--green);
  color: var(--green-bright);
  font-family: inherit;
  font-size: 17px;
  width: 74px;
  padding: 4px 0;
  cursor: pointer;
  line-height: 1.1;
}
.dir:hover:not(:disabled) { background: var(--green-dim); }
.dir:disabled { border-color: #11331a; color: #11331a; cursor: default; }
.dir.unexplored:not(:disabled) { border-style: dashed; }
.dir.locked:not(:disabled) { border-color: var(--red); color: var(--red); }

/* compass arrows live in CSS, so each button holds just its letter — that lets the
   dock flatten the cross (no stacked arrow-over-letter) on phones. */
#go-N::before { content: "\25B2"; display: block; }
#go-S::after  { content: "\25BC"; display: block; }
#go-W::before { content: "\25C4\00A0"; }
#go-E::after  { content: "\00A0\25BA"; }

.act-btn {
  display: block;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--green);
  color: var(--green);
  font-family: inherit;
  font-size: 16px;
  text-align: left;
  padding: 5px 10px;
  margin: 4px 0;
  cursor: pointer;
}
.act-btn:hover:not(:disabled) { background: var(--green-dim); color: var(--green-bright); }
.act-btn:disabled { border-color: #11331a; color: #11331a; cursor: default; }

.inv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 0;
  font-size: 16px;
}
.inv-empty { color: var(--green-dim); font-size: 15px; }
.use-btn {
  background: var(--panel);
  border: 1px solid var(--amber);
  color: var(--amber);
  font-family: inherit;
  font-size: 13px;
  padding: 1px 8px;
  cursor: pointer;
}
.use-btn:hover:not(:disabled) { background: #332b00; }
.use-btn:disabled { border-color: #333; color: #333; cursor: default; }

.mline { font-size: 15px; color: var(--green); }
.mline.dead { color: var(--green-dim); text-decoration: line-through; }

/* ---------- terminal ---------- */
#terminal {
  grid-column: 1;
  border: 1px solid var(--green-dim);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  padding: 8px;
  min-height: 0;
}
#log {
  flex: 1;
  overflow-y: auto;
  font-size: 18px;
  line-height: 1.25;
  text-shadow: 0 0 6px rgba(47, 174, 79, 0.5);
}
.line { margin: 1px 0; white-space: pre-wrap; }
.line.roll { color: #9adfae; }
.line.warn { color: var(--amber); }
.line.alert { color: var(--red); text-shadow: 0 0 8px rgba(255, 85, 68, 0.6); }
.line.good { color: var(--green-bright); }
.line.item { color: var(--blue); }
.line.score { color: var(--amber); font-size: 15px; }
.line.move { color: var(--green-dim); }
.line.echo { color: #d8ffe2; }
.line.sword { color: var(--blue); text-shadow: 0 0 10px rgba(127, 212, 255, 0.8); }
.line.flavor { color: #79c98e; font-style: italic; }

#choices { border-bottom: 1px dashed var(--green-dim); padding-bottom: 6px; margin-bottom: 4px; }
#choices:empty { display: none; }
.prompt { color: var(--amber); margin-bottom: 4px; }
.choice-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid var(--green);
  color: var(--green-bright);
  font-family: inherit;
  font-size: 17px;
  padding: 4px 10px;
  margin: 3px 0;
  cursor: pointer;
}
.choice-btn:hover:not(:disabled) { background: var(--green-dim); }
.choice-btn:disabled { border-color: #11331a; color: #11331a; cursor: default; }

/* ---------- game over ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.over-box {
  text-align: center;
  border: 3px double var(--green);
  background: var(--panel);
  padding: 40px 60px;
  max-width: 640px;
}
#over-title { font-size: 54px; letter-spacing: 8px; margin: 0 0 16px; }
#over-title.win { color: var(--green-bright); text-shadow: 0 0 20px rgba(102, 255, 153, 0.9); }
#over-title.lose { color: var(--red); text-shadow: 0 0 20px rgba(255, 85, 68, 0.9); }
#over-reason { font-size: 20px; }
.score-final { color: var(--amber); font-size: 24px; }

/* ---------- leaderboard ---------- */
#initials-entry { margin: 18px 0; }
.new-high {
  color: var(--amber);
  font-size: 22px;
  letter-spacing: 2px;
  text-shadow: 0 0 12px rgba(255, 191, 0, 0.7);
  animation: pulse 1.4s infinite;
}
#initials-input {
  background: var(--panel);
  border: 2px solid var(--amber);
  color: var(--amber);
  font-family: inherit;
  font-size: 48px;
  letter-spacing: 18px;
  text-align: center;
  text-indent: 18px; /* compensate trailing letter-spacing for visual centering */
  width: 200px;
  padding: 6px 0;
  text-transform: uppercase;
}
.board-title {
  color: var(--green-bright);
  letter-spacing: 3px;
  margin: 18px 0 10px;
}
#leaderboard { margin: 10px 0 6px; }
#board-table {
  margin: 0 auto;
  border-collapse: collapse;
  font-size: 22px;
  min-width: 360px;
}
#board-table th { padding: 1px 14px; font-size: 13px; color: var(--green-dim); letter-spacing: 2px; border-bottom: 1px solid var(--green-dim); text-align: left; }
#board-table th.board-score, #board-table th.board-mode { text-align: center; }
#board-table td { padding: 3px 14px; text-align: left; }
#board-table .rank { color: var(--green-dim); text-align: right; }
#board-table .initials { color: var(--green-bright); letter-spacing: 4px; }
#board-table .board-score { color: var(--amber); text-align: right; font-variant-numeric: tabular-nums; }
#board-table .won { color: var(--green-bright); text-align: center; }
#board-table .board-mode { font-size: 14px; letter-spacing: 1px; text-align: center; }
#board-table .mode-iron  { color: var(--red);          font-weight: bold; }
#board-table .mode-timer { color: var(--amber); }
#board-table .mode-opt   { color: var(--green); }
#board-table .mode-std   { color: var(--green-dim); }
#board-table .mode-—     { color: var(--green-dim); }
#board-table tr.me td {
  color: var(--bg);
  background: var(--amber);
  text-shadow: none;
  animation: blink 0.8s steps(1) infinite;
}
@keyframes blink {
  50% { background: var(--green-bright); }
}

/* ---------- mobile-only chrome ----------
   These (control dock, status drawer, map controls) are styled here but hidden by
   default; the phone layouts (portrait frame + landscape columns) flip them on. */
#dock, #map-tools { display: none; }

/* GEAR & QUARRY drawer toggle — caret + live counts live in CSS so the JS only
   toggles the open class (see main.js / ui.js). */
#comlet-toggle {
  display: none;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--green-dim);
  color: var(--green);
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 1px;
  text-align: left;
  padding: 8px 10px;
  margin: 6px 0 2px;
  cursor: pointer;
}
#comlet-toggle::before { content: "\25B8\00A0"; }                     /* ▸ collapsed */
#comlet.extra-open #comlet-toggle::before { content: "\25BE\00A0"; }  /* ▾ open */
#comlet-count { color: var(--green-dim); letter-spacing: 0; }
@keyframes drawerIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
#comlet.extra-open #comlet-extra { animation: drawerIn 0.18s ease; }

/* tap-to-expand minimap button + fullscreen pannable map overlay (both orientations) */
#map-expand {
  display: none;
  position: absolute;
  top: 6px; right: 6px;
  z-index: 6;
  background: rgba(4, 20, 10, 0.85);
  border: 1px solid var(--green);
  color: var(--green-bright);
  font-family: inherit;
  font-size: 16px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
}
#map-pane.map-expanded {
  position: fixed;
  inset: 0;
  max-height: none;
  z-index: 80;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  text-align: left;          /* left-anchored so the scroll can reach the left edge */
  padding: 0;
  border: none;
  background: rgba(2, 8, 3, 0.98);
}
#map-pane.map-expanded #map { max-width: none; max-height: none; margin: 0; }
#map-pane.map-expanded #map-expand { display: none; }
#map-pane.map-expanded #map-tools {
  display: flex;
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  left: calc(env(safe-area-inset-left) + 8px);
  right: calc(env(safe-area-inset-right) + 8px);
  z-index: 85;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
#map-tools button {
  background: rgba(4, 20, 10, 0.95);
  border: 1px solid var(--green);
  color: var(--green-bright);
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 1px;
  padding: 9px 13px;
  cursor: pointer;
}

/* narrow screens */
@media (max-width: 1000px) {
  #game-grid { grid-template-columns: 1fr; grid-template-rows: auto auto 300px; }
  #comlet { grid-row: 2; grid-column: 1; }
  #terminal { grid-row: 3; }
}

/* phones in PORTRAIT — fixed app-frame: glanceable map + status, scrolling log, and
   a thumb-pinned control dock (movement/actions, or the pending choice). Landscape
   gets its own column layout further down. */
@media (max-width: 700px) and (orientation: portrait) {
  html, body { font-size: 18px; }
  .screen { padding: 12px; }
  /* phone game screen: fixed app-frame — header, content column, pinned dock.
     padding-bottom reserves room for the position:fixed #dock; the side/top
     padding honours notch + home-indicator safe areas (viewport-fit=cover). */
  #screen-game {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    padding: calc(8px + env(safe-area-inset-top))
             calc(10px + env(safe-area-inset-right))
             calc(var(--dock-h) + env(safe-area-inset-bottom))
             calc(10px + env(safe-area-inset-left));
  }

  header { gap: 8px; flex-wrap: wrap; padding-bottom: 5px; margin-bottom: 8px; flex: 0 0 auto; }
  header .title { font-size: 17px; letter-spacing: 2px; }
  .hdr-right { gap: 5px; }
  #btn-pause, #btn-theme, #btn-mute, #btn-exit { font-size: 14px; padding: 7px 9px; }

  /* stack inside the frame: map (glance) -> compact status -> log (fills, scrolls).
     movement/actions/choices live in the fixed #dock below, not here. */
  #game-grid { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; gap: 8px; }
  /* resting minimap: short, and the WHOLE map scaled to fit (no truncation) — it's a
     glance now; tap it (or the corner button) to open the legible fullscreen view. */
  #map-pane {
    flex: 0 0 auto;
    max-height: 18vh;
    overflow: hidden;
    position: relative;
    text-align: center;
    padding: 4px;
  }
  #map-pane > .pane-label { display: none; }   /* the long station title isn't worth the height on a phone */
  #map { max-width: 100%; max-height: 16vh; width: auto; height: auto; margin: 0 auto; }
  #map-expand { display: block; }
  #comlet { flex: 0 0 auto; max-height: 34vh; }
  #terminal { flex: 1 1 auto; min-height: 0; }
  /* compact the status panel: its section labels head controls that moved to
     the dock, so drop them; tighten the rest. */
  #comlet > .pane-label { display: none; }
  #comlet .char-name { font-size: 16px; margin-bottom: 4px; }
  #comlet .stat-row { padding: 1px 0; }

  /* roomier touch targets */
  .dir { width: 64px; font-size: 20px; padding: 11px 0; }
  #compass-mid { gap: 64px; }
  .act-btn, .choice-btn { font-size: 18px; padding: 11px 12px; }
  .use-btn { font-size: 15px; padding: 6px 12px; }
  #btn-rollname, .sm-btn { font-size: 16px; padding: 8px 14px; }
  .big-btn { font-size: 22px; padding: 13px 28px; }
  #name-input { font-size: 20px; padding: 8px 10px; }
  .stat-option { padding: 8px; }
  .opts label { padding: 8px 0; }
  input[type="checkbox"], input[type="radio"] { transform: scale(1.4); margin-right: 12px; }

  #logo { width: 92vw; margin: 10px auto 6px; }
  #intro-text { font-size: 16px; padding: 12px 14px; }

  /* game-over overlay */
  .over-box { padding: 28px 22px; }
  #over-title { font-size: 38px; letter-spacing: 4px; }
  #over-reason { font-size: 18px; }

  /* leaderboard on phones */
  .new-high { font-size: 18px; }
  #initials-input { font-size: 38px; letter-spacing: 12px; text-indent: 12px; width: 160px; }
  #board-table { font-size: 18px; min-width: 0; width: 100%; }
  #board-table td { padding: 3px 6px; }

  /* ---- fixed control dock: compass + actions in one short band, or the pending choice ---- */
  #dock {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    display: flex;
    flex-flow: row wrap;
    align-items: center;
    justify-content: center;
    gap: 6px 10px;
    max-height: 52vh;
    overflow-y: auto;
    background: linear-gradient(to bottom, rgba(4, 20, 10, 0.97), var(--panel));
    border-top: 2px solid var(--green-dim);
    box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.55);
    padding: 6px calc(10px + env(safe-area-inset-right))
             calc(6px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
  }
  /* compass on the left, actions filling the right — a band ~one compass tall,
     instead of actions stacked ON TOP of the compass (that doubled the height). */
  #dock #compass { order: 1; flex: 0 0 auto; margin: 0; }
  #dock .dir { width: 50px; font-size: 16px; padding: 4px 0; line-height: 1.0; }
  /* drop the stacked arrows here — the cross layout already reads as N/W/E/S, and
     single-line keys halve the compass height (the dock's main space hog). */
  #dock #go-N::before, #dock #go-S::after,
  #dock #go-W::before, #dock #go-E::after { content: none; }
  #dock #compass-mid { gap: 38px; margin: 1px 0; }
  #dock #actions {
    order: 2;
    flex: 1 1 0;
    min-width: 140px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin: 0;
  }
  #dock .act-btn { width: 100%; text-align: center; font-size: 14px; padding: 7px 10px; margin: 0; }
  /* a pending choice owns the whole dock width (movement is disabled during a choice) */
  #dock #choices { order: 3; flex: 1 1 100%; border: none; margin: 0; padding: 0; }
  #dock .prompt { text-align: center; }
  #dock:has(#choices:not(:empty)) #actions,
  #dock:has(#choices:not(:empty)) #compass { display: none; }

  /* collapsible GEAR & QUARRY drawer (styling is global; just enable it here) */
  #comlet-toggle { display: block; }
  #comlet:not(.extra-open) #comlet-extra { display: none; }

  /* combat: show the monster as a top banner, not pinned over the shrunk map */
  #monster-overlay {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 56px);
    left: 50%; right: auto;
    transform: translateX(-50%);
    max-width: 92vw;
    z-index: 55;
  }
  #monster-name { font-size: 18px; }
  #monster-art { font-size: 11px; }
}

/* phones in LANDSCAPE — short & wide: three columns (glance map | control rail | log)
   instead of a tall stack with a bottom dock that would eat the scarce height. The
   dock-relocation JS is gated to portrait, so movement/actions stay in the rail. */
@media (orientation: landscape) and (max-height: 500px) {
  html, body { font-size: 17px; }
  .screen { padding: 8px; }
  #screen-game {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    padding: calc(4px + env(safe-area-inset-top))
             calc(8px + env(safe-area-inset-right))
             calc(6px + env(safe-area-inset-bottom))
             calc(8px + env(safe-area-inset-left));
  }
  header { gap: 8px; flex-wrap: wrap; padding-bottom: 3px; margin-bottom: 5px; flex: 0 0 auto; }
  header .title { font-size: 15px; letter-spacing: 2px; }
  .hdr-right { gap: 5px; }
  #btn-pause, #btn-theme, #btn-mute, #btn-exit { font-size: 13px; padding: 5px 8px; }
  #air-timer { font-size: 13px; padding: 2px 6px; }

  #game-grid {
    display: flex;
    flex-direction: row;
    flex: 1 1 auto;
    min-height: 0;
    gap: 8px;
  }

  /* col 1: glance minimap (tap to expand) */
  #map-pane {
    order: 1;
    flex: 0 0 22%;
    max-width: 220px;
    max-height: none;
    overflow: hidden;
    position: relative;
    text-align: center;
    padding: 4px;
  }
  #map-pane > .pane-label { display: none; }
  #map { max-width: 100%; max-height: 100%; width: auto; height: auto; margin: 0 auto; }
  #map-expand { display: block; }

  /* col 2: control rail — compact status, flat compass, actions, GEAR drawer */
  #comlet {
    order: 2;
    flex: 0 0 31%;
    max-width: 260px;
    grid-row: auto; grid-column: auto;
    max-height: none;
    overflow-y: auto;
    padding: 6px 8px;
  }
  #comlet > .pane-label { font-size: 12px; }
  #comlet .char-name { font-size: 15px; margin-bottom: 3px; }
  #comlet .stat-row { padding: 1px 0; }
  #go-N::before, #go-S::after, #go-W::before, #go-E::after { content: none; }  /* flat compass */
  #compass { margin: 6px 0; }
  .dir { width: 54px; font-size: 16px; padding: 6px 0; }
  #compass-mid { gap: 42px; }
  .act-btn { font-size: 14px; padding: 7px 9px; margin: 3px 0; }
  #comlet-toggle { display: block; }
  #comlet:not(.extra-open) #comlet-extra { display: none; }

  /* col 3: the log */
  #terminal {
    order: 3;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    grid-row: auto; grid-column: auto;
  }
  #log { font-size: 16px; }
  .choice-btn { font-size: 15px; padding: 7px 10px; }

  /* combat banner, centred up top so the map + choices stay usable */
  #monster-overlay {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 4px);
    left: 50%; right: auto;
    transform: translateX(-50%);
    max-width: 64vw;
    z-index: 55;
    padding: 6px 12px;
  }
  #monster-name { font-size: 15px; }
  #monster-art { font-size: 9px; }
}
