:root {
  color-scheme: dark;
  --ink: #edf2f4;
  --muted: #9cabb4;
  --night: #10171e;
  --panel: #19232d;
  --line: #354450;
  --road: #dbe3df;
  --road-alt: #cbd6d1;
  --boss: #526a7a;
  --start: #d6e5c7;
  --stop: #f4d28d;
  --exec: #eab0a9;
  --accent: #f3b44e;
  --danger: #e8685d;
}

* { box-sizing: border-box; }

html, body { min-width: 320px; min-height: 100%; margin: 0; }

body {
  background: radial-gradient(ellipse at top, #26323d, var(--night) 68%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-shell {
  min-height: 100dvh;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 14px;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.game-stage {
  position: relative;
  width: min(100%, calc((100dvh - 20px) * 4 / 3));
  aspect-ratio: 4 / 3;
  overflow: hidden;
  flex: none;
  border: 1px solid #41515e;
  border-radius: 14px;
  background: #dce3dd;
  box-shadow: 0 22px 70px #0008;
  container-type: inline-size;
}

.stage-screen { position: absolute; inset: 0; }

.play-screen {
  display: grid;
  grid-template-rows: 9.7% 6.2% minmax(0, 1fr);
  color: #17232c;
  background: #dce3dd;
}

.hud {
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 1.8%;
  padding: 0 2.2%;
  background: #15212b;
  color: var(--ink);
}

.hud-title { display: grid; gap: 2px; min-width: 0; flex: 1; }
.hud-title strong { overflow: hidden; font-size: clamp(10px, 1.75cqw, 15px); text-overflow: ellipsis; white-space: nowrap; }
.eyebrow { margin: 0; color: #8ea0ab; font-size: clamp(7px, 1.05cqw, 9px); font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.hud-readout { min-width: 12%; display: grid; gap: 1px; text-align: right; }
.status-readout { min-width: 25%; }
.readout-label { color: #90a0aa; font-size: clamp(7px, 1cqw, 9px); font-weight: 800; letter-spacing: .12em; }
.hud-readout strong { font-size: clamp(11px, 2cqw, 17px); line-height: 1; white-space: nowrap; }
#time-readout { color: #ffd27d; font-variant-numeric: tabular-nums; }

.column-headings, .board { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); }
.column-headings { z-index: 2; background: #f4f1e9; border-bottom: 2px solid #89938f; }
.column-heading { display: flex; min-width: 0; flex-direction: column; justify-content: center; align-items: center; gap: 1px; border-left: 1px solid #c5ceca; color: #40515a; }
.column-heading:first-child { border-left: 0; }
.column-heading b { font-size: clamp(8px, 1.35cqw, 12px); line-height: 1; }
.column-heading span { overflow: hidden; max-width: 100%; color: #586971; font-size: clamp(5px, .82cqw, 8px); font-weight: 800; letter-spacing: .02em; text-overflow: clip; }
.boss-heading { background: #e4eaec; }
.start-heading { background: #e9f0e2; }
.stop-heading { background: #fff0cf; }
.executive-heading { background: #f7ded9; }

.board {
  position: relative;
  grid-template-rows: repeat(5, minmax(0, 1fr));
  overflow: hidden;
  isolation: isolate;
  background: var(--road);
}

.cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border-right: 1px solid #b4c0ba;
  border-bottom: 1px solid #b4c0ba;
  background: var(--road);
  transition: background-color .12s ease, box-shadow .12s ease;
}
.cell:nth-child(20n + 1), .cell:nth-child(20n + 2) { background: #e3e9e5; }
.cell:nth-child(20n + 2) { background: var(--start); }
.cell:nth-child(20n + 3), .cell:nth-child(20n + 5), .cell:nth-child(20n + 7) { background: var(--road-alt); }
.cell:nth-child(20n + 9) { background: var(--stop); }
.cell:nth-child(20n + 10) { background: var(--exec); border-right: 0; }
.cell:nth-child(n + 41) { border-bottom: 0; }
.cell.is-selected { box-shadow: inset 0 0 0 3px #d2912d; z-index: 1; }
.cell.is-selected::after { position: absolute; inset: 4px; border: 1px dashed #a46a13; border-radius: 8px; content: ""; pointer-events: none; }
.cell.is-obstacle { background-image: repeating-linear-gradient(135deg, #f5d48c 0 8px, #efd084 8px 16px); }

.row-label {
  position: absolute;
  top: 4px;
  left: 5px;
  color: #65756e;
  font-size: clamp(6px, .85cqw, 8px);
  font-weight: 800;
  opacity: .7;
}

.token {
  position: relative;
  z-index: 2;
  display: grid;
  width: 74%;
  max-width: 56px;
  aspect-ratio: 1;
  place-content: center;
  justify-items: center;
  border: 2px solid #ffffffc4;
  border-radius: 16px;
  box-shadow: 0 3px 8px #19232d40;
  color: white;
  font-size: clamp(7px, 1.2cqw, 11px);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  overflow: hidden;
}
.token .glyph { font-size: clamp(13px, 2.5cqw, 22px); line-height: 1; }
.boss-token { background: var(--boss); }
.laptop-token { width: 72%; background: #56616a; border-radius: 9px; }
.player-token { background: #2077a8; border-color: #e4f7ff; }
.tea-token { width: 61%; background: #b35d37; border-radius: 50% 50% 40% 40%; }
.executive-token { width: 76%; background: #a8504c; border-radius: 50%; }
.executive-token.calm { background: #4d8869; }
.executive-token.angry { background: #bf7439; }
.executive-token.imminent { background: #b54739; }
.executive-token.explosive { background: #882f36; animation: pulse .42s infinite alternate; }
.executive-token .face { font-size: clamp(15px, 3.3cqw, 27px); line-height: 1; }
.executive-token .exec-label { margin-top: 2px; font-size: clamp(6px, .8cqw, 8px); }

.moving-player {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  display: grid;
  width: 6.7%;
  aspect-ratio: 1;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 2px solid white;
  border-radius: 15px;
  background: #2077a8;
  box-shadow: 0 5px 12px #18263166;
  color: white;
  font-size: clamp(7px, 1.1cqw, 10px);
  font-weight: 950;
  pointer-events: none;
  transition: left .035s linear, top .035s linear;
}
.moving-player.is-burning { background: #ce533c; animation: shake .14s infinite alternate; }
.moving-player.is-hidden { display: none; }

.effect-banner {
  position: absolute;
  z-index: 7;
  top: 13%;
  left: 50%;
  max-width: 78%;
  padding: .65em 1.1em;
  transform: translateX(-50%);
  border: 1px solid #ffffff70;
  border-radius: 999px;
  background: #14212de8;
  color: white;
  font-size: clamp(10px, 1.55cqw, 14px);
  font-weight: 850;
  text-align: center;
  box-shadow: 0 8px 20px #0003;
}

.game-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 5%;
  background: #111821b8;
  backdrop-filter: blur(3px);
}
.overlay-card {
  width: min(78%, 420px);
  padding: 7% 5%;
  border: 1px solid #ffffff45;
  border-radius: 18px;
  background: #24313d;
  color: white;
  text-align: center;
  box-shadow: 0 16px 50px #0008;
}
.overlay-card h2 { margin: .2em 0 .6em; font-size: clamp(21px, 5cqw, 42px); letter-spacing: .08em; }
.explosion-face { margin: 0 0 3%; font-size: clamp(44px, 12cqw, 94px); line-height: 1; }
.exploded-executive { margin: -1% 0 3%; color: #ffd27d; font-size: clamp(12px, 2cqw, 17px); font-weight: 850; }
.game-overlay.game-over-only .explosion-face { display: none; }
.tap-hint { margin: 3% 0 0; color: #ffdc9c; font-size: clamp(10px, 1.6cqw, 14px); font-weight: 800; }

.cover-screen { display: grid; place-items: center; overflow: hidden; background: #16232d; color: white; cursor: pointer; }
.cover-screen::before, .cover-screen::after { position: absolute; z-index: 0; border: 1px solid #ffffff17; border-radius: 50%; content: ""; }
.cover-screen::before { width: 82%; aspect-ratio: 1; right: -21%; top: -36%; background: #f0b85616; }
.cover-screen::after { width: 58%; aspect-ratio: 1; left: -22%; bottom: -33%; background: #7bb3c814; }
.cover-art { position: absolute; inset: 0; display: grid; place-items: center; opacity: .4; }
.cover-art .art-boss { position: absolute; right: 14%; top: 20%; width: 26%; aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; background: #be554a; font-size: clamp(30px, 10cqw, 80px); }
.cover-art .art-player { position: absolute; left: 18%; bottom: 20%; width: 16%; aspect-ratio: 1; display: grid; place-items: center; border-radius: 14px; background: #2382ad; font-size: clamp(16px, 5cqw, 42px); font-weight: 900; }
.cover-art .art-path { position: absolute; left: 33%; right: 31%; bottom: 29%; height: 5px; background: repeating-linear-gradient(90deg, #f3b44e 0 10px, transparent 10px 20px); transform: rotate(-3deg); }
.cover-copy { position: relative; z-index: 1; width: 76%; text-align: center; text-shadow: 0 3px 16px #0008; }
.cover-copy .eyebrow { color: #f3c56c; font-size: clamp(8px, 1.25cqw, 11px); }
.cover-copy h1 { margin: .25em 0; font-size: clamp(27px, 8cqw, 70px); line-height: .9; letter-spacing: .06em; }
.cover-description { max-width: 40em; margin: 1.3em auto 0; color: #d0d8dc; font-size: clamp(11px, 2cqw, 16px); line-height: 1.5; }
.cover-copy .tap-hint { margin-top: 8%; animation: hint 1.2s infinite alternate; }
.comic-panels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2%; margin-top: 5%; }
.comic-panel { display: grid; min-height: 96px; align-content: center; gap: .5em; padding: 5%; border: 1px solid #ffffff42; border-radius: 10px; background: #ffffff12; }
.comic-panel .glyph { font-size: clamp(22px, 5cqw, 42px); }
.comic-panel small { color: #d3dde1; font-size: clamp(8px, 1.1cqw, 11px); line-height: 1.3; }
.success-art { width: 34%; margin: 0 auto 4%; padding: 6%; border: 2px solid #ffffff60; border-radius: 50%; background: #4e9a70; font-size: clamp(36px, 10cqw, 80px); }

.controls {
  display: grid;
  width: min(100%, 800px);
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 8px 12px;
  padding: 10px;
}
.move-controls { display: flex; gap: 6px; }
.control-button, .launch-button, .small-button {
  border: 1px solid #52616d;
  border-radius: 9px;
  background: #263440;
  color: var(--ink);
  font-weight: 850;
  cursor: pointer;
  touch-action: manipulation;
}
.control-button { width: 46px; height: 42px; font-size: 16px; }
.launch-button { min-width: 124px; height: 42px; padding: 0 16px; background: #c68229; border-color: #f3c168; color: #171f25; letter-spacing: .08em; }
.launch-button span { margin-left: 5px; opacity: .72; font-size: 10px; }
.control-hint { justify-self: end; margin: 0; color: #b5c0c8; font-size: 11px; text-align: right; }
button:hover:not(:disabled) { filter: brightness(1.12); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: default; opacity: .45; }

.debug-panel {
  width: min(100%, 800px);
  padding: 13px 15px;
  border: 1px solid #33424f;
  border-radius: 12px;
  background: #18232c;
  color: var(--ink);
  box-shadow: 0 8px 25px #0003;
}
.debug-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.debug-heading strong { display: block; margin-top: 2px; font-size: 14px; }
.debug-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.debug-grid label { display: grid; gap: 4px; min-width: 0; color: #aab8c0; font-size: 10px; font-weight: 700; }
.debug-grid input { width: 100%; min-width: 0; height: 30px; padding: 3px 7px; border: 1px solid #43535e; border-radius: 6px; background: #101820; color: white; font-size: 12px; }
.debug-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.small-button { padding: 6px 9px; font-size: 10px; }
.debug-note { margin: 8px 0 0; color: #8b9ca7; font-size: 10px; }

@keyframes pulse { to { transform: scale(1.06); filter: brightness(1.2); } }
@keyframes shake { to { transform: translate(-2px, 1px) rotate(-4deg); } }
@keyframes hint { to { opacity: .55; } }

@media (max-width: 640px) {
  .app-shell { gap: 4px; padding: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left)); }
  .game-stage { width: min(100%, calc((100dvh - 8px) * 4 / 3)); border-radius: 8px; }
  .debug-panel { padding: 10px; }
  .debug-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .controls { grid-template-columns: auto auto; justify-content: center; padding: 5px 2px; }
  .control-hint { grid-column: 1 / -1; justify-self: center; text-align: center; }
}

@media (max-height: 430px) and (orientation: landscape) {
  .app-shell { min-height: 0; display: flex; flex-direction: column; justify-content: flex-start; gap: 3px; padding: 3px; }
  .game-stage { width: min(calc((100dvh - 6px) * 4 / 3), 100vw); border-radius: 6px; }
  .controls { position: absolute; z-index: 12; right: 1%; bottom: 1%; width: auto; grid-template-columns: auto auto; gap: 4px; padding: 0; }
  .control-button { width: 34px; height: 32px; }
  .launch-button { min-width: 94px; height: 32px; padding: 0 8px; font-size: 11px; }
  .launch-button span, .control-hint { display: none; }
  .debug-panel { width: min(calc((100dvh - 6px) * 4 / 3), 100vw); }
}
