:root {
  color-scheme: dark;
  font-family: "Courier New", Consolas, monospace;
  color: #e6e3d8;
  background: #111513;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --acid: #c4dc86;
  --muted: #929890;
  --panel: rgba(15, 20, 18, .84);
  --line: rgba(226, 231, 214, .16);
}

* { box-sizing: border-box; }
html, body, #game-shell { width: 100%; height: 100%; min-height: 420px; margin: 0; overflow: hidden; }
body { background: #111513; }
button, a { font: inherit; }
button { color: inherit; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }

.topbar {
  position: absolute; z-index: 2; top: 0; left: 0; right: 0; min-height: 84px;
  padding: 19px 28px; display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(180deg, rgba(9, 13, 12, .86), transparent);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--acid);
  color: var(--acid); font: 800 17px Impact, "Arial Narrow", sans-serif; letter-spacing: -.04em;
  transform: skew(-5deg);
}
.brand strong, .brand small, .identity-copy strong, .identity-copy small { display: block; }
.brand strong { font: 800 20px Impact, "Arial Narrow", sans-serif; letter-spacing: .11em; }
.brand small { margin-top: 2px; color: #a4aaa1; font-size: 9px; letter-spacing: .15em; }
.identity { display: flex; align-items: center; gap: 10px; min-width: 180px; justify-content: flex-end; }
.identity-status { color: var(--acid); font-size: 9px; letter-spacing: .1em; }
.identity-status.offline { color: #b19a74; }
.identity img { width: 34px; height: 34px; object-fit: cover; border: 1px solid var(--acid); border-radius: 50%; }
.identity-copy strong { font-size: 11px; font-weight: 600; }
.identity-copy small { color: var(--muted); font-size: 9px; margin-top: 3px; }
.sign-in { color: var(--acid); font-size: 10px; text-decoration: underline; }

.mission-panel, .status-panel, .radio {
  position: absolute; z-index: 1; background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.mission-panel { top: 112px; left: 28px; width: min(360px, calc(100vw - 56px)); padding: 17px 20px 15px; border-left: 2px solid var(--acid); }
.eyebrow { margin: 0; color: var(--acid); font-size: 9px; letter-spacing: .19em; }
.mission-panel h1 { margin: 8px 0 12px; font: 600 25px/1.08 Impact, "Arial Narrow", sans-serif; letter-spacing: .015em; }
.location { display: flex; gap: 8px; align-items: center; margin: 0; color: #a4aaa1; font-size: 9px; letter-spacing: .08em; }
.location #mission-clock { margin-left: auto; color: #e6e3d8; }
.live-dot, .radio-wave { width: 6px; height: 6px; border-radius: 50%; background: var(--acid); box-shadow: 0 0 9px var(--acid); }
.status-panel { top: 112px; right: 28px; width: 190px; padding: 15px 16px; }
.health-row, .status-meta { display: flex; align-items: center; justify-content: space-between; }
.health-row { color: #a4aaa1; font-size: 9px; letter-spacing: .08em; }
.health-row strong { color: #ece9df; font-weight: 500; }
.health-track { height: 3px; margin: 9px 0 13px; background: #454b45; }
.health-track span { display: block; height: 100%; width: 100%; background: var(--acid); transition: width .18s, background .18s; }
.status-meta { color: var(--muted); font-size: 9px; }
.status-meta strong { color: #eeeae0; font: 600 18px Impact, "Arial Narrow", sans-serif; }
.status-meta small { font: 9px "Courier New", monospace; }

.radio { left: 28px; bottom: 75px; width: min(390px, calc(100vw - 56px)); padding: 12px 15px 13px; }
.radio-label { display: flex; align-items: center; gap: 8px; color: var(--acid); font-size: 9px; letter-spacing: .14em; }
.radio-wave { animation: pulse 1.3s infinite; }
.radio p { margin: 8px 0 0; color: #d6d2c7; font-size: 11px; line-height: 1.5; }
.radio.signal-lost { border-color: rgba(214, 151, 103, .72); }
.radio.signal-lost .radio-label { color: #e2a774; }
.radio.signal-lost .radio-wave { background: #e2a774; box-shadow: 0 0 9px #e2a774; animation-duration: .35s; }
.controls-hint { position: absolute; left: 28px; bottom: 23px; z-index: 1; display: flex; gap: 15px; color: #c1c5ba; font-size: 8px; letter-spacing: .03em; }
kbd { display: inline-block; min-width: 16px; margin-right: 2px; padding: 3px 4px; border: 1px solid rgba(226,231,214,.35); color: #f0eee6; text-align: center; font: inherit; }
.board-button {
  position: absolute; z-index: 6; right: 28px; bottom: 24px; padding: 10px 13px;
  color: var(--acid); background: rgba(15,20,18,.86); border: 1px solid rgba(196,220,134,.45);
  font-size: 9px; letter-spacing: .12em; cursor: pointer;
}
.board-button[hidden] { display: none; }
.board-button:hover, .screen-card button:hover { background: #d2e99a; color: #151a14; }
.prompt {
  position: absolute; z-index: 2; left: 50%; top: 67%; transform: translate(-50%, -50%);
  padding: 11px 15px; color: #f0eee6; background: rgba(12,16,14,.9); border: 1px solid rgba(196,220,134,.6);
  font-size: 10px; letter-spacing: .04em; box-shadow: 0 4px 25px #0008;
}
.prompt kbd { margin-right: 6px; border-color: var(--acid); color: var(--acid); }
.toast { position: absolute; z-index: 4; top: 88px; left: 50%; transform: translateX(-50%); padding: 9px 13px; color: #f0eee6; background: #1e2520; border: 1px solid var(--line); font-size: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.visible { opacity: 1; }
.screen { position: absolute; z-index: 5; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(7,10,9,.76); backdrop-filter: blur(5px); }
.screen[hidden] { display: none; }
.screen-card { position: relative; width: min(560px, 100%); max-height: min(90vh, 760px); overflow: auto; padding: 34px; background: #171d19; border: 1px solid rgba(196,220,134,.43); box-shadow: 0 20px 90px #0008; }
.screen-card h2 { margin: 9px 0; font: 700 42px/1 Impact, "Arial Narrow", sans-serif; letter-spacing: .04em; }
.screen-card > p:not(.eyebrow):not(.final-score) { max-width: 370px; color: #b7bcb1; font-size: 11px; line-height: 1.7; }
.screen-card button:not(.close-button) { margin-top: 17px; padding: 12px 15px; color: #151a14; background: var(--acid); border: 0; font-size: 10px; letter-spacing: .12em; cursor: pointer; }
#menu-screen {
  background:
    linear-gradient(0deg, rgba(8, 11, 10, .93), rgba(8, 11, 10, .1) 62%),
    linear-gradient(90deg, rgba(8, 11, 10, .72), transparent 70%),
    url("../assets/menu-bg.jpg") center / cover,
    #111513;
  backdrop-filter: none;
  place-items: end start;
  padding: clamp(20px, 5vw, 64px);
}
.menu-card {
  width: min(640px, 100%);
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
  overflow: visible;
}
.menu-card h2 { max-width: 700px; color: #eeeae0; font-size: clamp(48px, 9vw, 90px); text-shadow: 0 4px 24px #000; }
.menu-card > p:not(.eyebrow) { margin-bottom: 3px; max-width: 460px; color: #d6d2c7; text-shadow: 0 2px 10px #000; }
.menu-card .eyebrow { text-shadow: 0 2px 10px #000; }
.menu-card #start-button { align-self: flex-start; padding: 15px 28px; font-size: 12px; }
.nav-hint { margin: 16px 0 0; color: var(--muted); font-size: 8px; letter-spacing: .12em; }
.screen-card button:focus-visible, .board-button:focus-visible, .pause-button:focus-visible {
  outline: 2px solid #f0eee6; outline-offset: 3px; background: #d2e99a; color: #151a14;
}
.pause-button {
  position: absolute; z-index: 6; right: 28px; bottom: 66px; padding: 10px 13px;
  color: var(--acid); background: rgba(15,20,18,.86); border: 1px solid rgba(196,220,134,.45);
  font-size: 9px; letter-spacing: .12em; cursor: pointer;
}
.pause-button[hidden] { display: none; }
.pause-button kbd { margin-left: 4px; font-size: 8px; color: inherit; }
.pause-button:hover { background: #d2e99a; color: #151a14; }
.sound-button {
  position: absolute; z-index: 30; right: 28px; bottom: 108px; padding: 10px 13px;
  color: var(--acid); background: rgba(15,20,18,.86); border: 1px solid rgba(196,220,134,.45);
  font-size: 9px; letter-spacing: .12em; cursor: pointer;
}
.sound-button:hover, .sound-button:focus-visible { background: #d2e99a; color: #151a14; outline: none; }
.sound-button[aria-pressed="true"] { color: #b7bcb1; }
.pause-card { width: min(460px, 100%); }
.countdown {
  position: absolute; z-index: 7; inset: 0; display: grid; place-content: center; justify-items: center;
  background: rgba(7,10,9,.55); pointer-events: none;
}
.countdown[hidden] { display: none; }
.countdown span { color: var(--acid); font: 700 clamp(96px, 20vw, 180px)/1 Impact, "Arial Narrow", sans-serif; text-shadow: 0 6px 30px #000; }
.countdown small { color: #e6e3d8; font-size: 11px; letter-spacing: .3em; }
.selection-card { width: min(980px, 100%); }
.selection-card > p:not(.eyebrow) { max-width: 640px; }
.mission-list { display: grid; gap: 9px; }
.chapter-group { margin-top: 20px; }
.chapter-group h3 { margin: 0 0 8px; color: var(--acid); font: 600 15px Impact, "Arial Narrow", sans-serif; letter-spacing: .08em; }
.chapter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mission-card { min-width: 0; padding: 13px; background: rgba(8,12,10,.56); border: 1px solid var(--line); }
.mission-card[data-state="available"] { border-color: rgba(196,220,134,.7); }
.mission-card[data-state="completed"] { border-color: rgba(196,220,134,.42); }
.mission-card h4 { margin: 4px 0 7px; color: #eeeae0; font: 600 15px Impact, "Arial Narrow", sans-serif; letter-spacing: .03em; }
.mission-card p { margin: 5px 0; color: #b7bcb1; font-size: 9px; line-height: 1.5; }
.mission-card .mission-number, .mission-card .mission-state { color: var(--acid); font-size: 8px; letter-spacing: .12em; }
.mission-card .mission-state { min-height: 12px; }
.mission-card[data-state="locked"] .mission-state, .mission-card[data-state="unlocked"] .mission-state { color: #d49b82; }
.mission-card button { width: 100%; margin-top: 9px !important; padding: 8px 10px !important; }
.mission-card button:disabled { color: #929890 !important; background: #303832 !important; border: 1px solid var(--line) !important; cursor: not-allowed; }
.special-operations { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.special-operations > .eyebrow { margin-bottom: 9px; }
.special-operations .mission-card { max-width: 470px; }
.briefing-card { width: min(700px, 100%); }
.briefing-details { display: grid; gap: 8px; margin: 21px 0 5px; }
.briefing-details > div { padding: 12px; background: rgba(8,12,10,.48); border: 1px solid var(--line); }
.briefing-details dt { color: var(--muted); font-size: 8px; letter-spacing: .12em; }
.briefing-details dd { margin: 6px 0 0; color: #eeeae0; font-size: 11px; line-height: 1.5; }
.screen-card .secondary-action { color: #e6e3d8; background: #303832; border: 1px solid var(--line); }
.screen-card .secondary-action:hover { color: #151a14; background: #d2e99a; }
.debrief-card > p:not(.eyebrow) { margin-bottom: 20px; }
.debrief-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 22px 0 0; }
.debrief-stats > div { min-width: 0; padding: 12px; background: rgba(8,12,10,.48); border: 1px solid var(--line); }
.debrief-stats dt { color: var(--muted); font-size: 8px; letter-spacing: .12em; }
.debrief-stats dd { overflow-wrap: anywhere; margin: 7px 0 0; color: #eeeae0; font-size: 12px; }
.debrief-stats > div:nth-child(2) dd { color: var(--acid); font: 600 22px Impact, "Arial Narrow", sans-serif; }
.debrief-stats .grade-stat { grid-column: span 2; }
.debrief-stats .grade-stat dd { color: var(--acid); font: 700 30px Impact, "Arial Narrow", sans-serif; }
.score-submit-status { margin: 13px 0 0; color: #b7bcb1; font-size: 9px; line-height: 1.5; }
.score-submit-status[data-status="success"] { color: var(--acid); }
.score-submit-status[data-status="failed"], .score-submit-status[data-status="unavailable"] { color: #d49b82; }
.debrief-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.screen-card .debrief-actions button { margin-top: 17px; }
.screen-card .debrief-actions .secondary-action { color: #e6e3d8; background: #303832; border: 1px solid var(--line); }
.screen-card .debrief-actions .secondary-action:hover { color: #151a14; background: #d2e99a; }
.leaderboard-card { max-height: min(80vh, 640px); overflow: auto; }
.leaderboard-card h2 { margin-bottom: 4px; }
.close-button { position: absolute; top: 12px; right: 15px; background: none; border: 0; color: #aeb4a9; font-size: 25px; cursor: pointer; }
.board-note { margin: 10px 0 18px; color: #aeb4a9; font-size: 10px; }
#leaderboard-list { margin: 0; padding: 0; list-style: none; }
#leaderboard-list li { display: flex; justify-content: space-between; padding: 11px 8px; border-top: 1px solid var(--line); font-size: 11px; }
#leaderboard-list li.self { color: var(--acid); }
#leaderboard-list .rank { color: #8e958b; margin-right: 10px; }
#leaderboard-list .record-score { font-weight: 600; }

@keyframes pulse { 50% { opacity: .35; } }
@media (max-width: 700px) {
  .topbar { padding: 14px; min-height: 72px; }
  .brand strong { font-size: 17px; }
  .brand-mark { width: 36px; height: 36px; }
  .identity { min-width: 0; gap: 6px; }
  .identity-status { display: none; }
  .identity img { width: 28px; height: 28px; }
  .mission-panel { top: 88px; left: 14px; padding: 12px 14px; width: min(310px, calc(100vw - 28px)); }
  .mission-panel h1 { font-size: 21px; }
  .status-panel { top: 197px; left: 14px; right: auto; width: 154px; padding: 10px 12px; }
  .radio { left: 14px; bottom: 82px; width: min(340px, calc(100vw - 28px)); }
  .controls-hint { left: 14px; bottom: 16px; gap: 7px; font-size: 7px; }
  .controls-hint span:nth-child(2), .controls-hint span:nth-child(4) { display: none; }
  .board-button { right: 14px; bottom: 14px; }
  .screen-card { padding: 24px 20px; }
  .screen-card h2 { font-size: 36px; }
  .menu-card { min-height: 0; padding: 0; }
  .menu-card h2 { font-size: clamp(40px, 13vw, 58px); }
  .chapter-grid { grid-template-columns: 1fr; }
}

html, body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
#game { touch-action: none; }
.touch-controls { display: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.touch-controls[hidden] { display: none !important; }

body.touch-mode .touch-controls {
  display: block; position: absolute; z-index: 3; inset: 0; pointer-events: none; touch-action: none;
}
.touch-stick {
  position: absolute; left: max(22px, env(safe-area-inset-left)); bottom: max(26px, env(safe-area-inset-bottom));
  width: 128px; height: 128px; border-radius: 50%; pointer-events: auto; touch-action: none;
  background: rgba(15,20,18,.5); border: 1px solid rgba(196,220,134,.45);
}
.touch-knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: rgba(196,220,134,.6); border: 1px solid var(--acid); pointer-events: none;
}
.touch-actions {
  position: absolute; right: max(22px, env(safe-area-inset-right)); bottom: max(26px, env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(2, 72px); gap: 12px; pointer-events: auto; touch-action: none;
}
.touch-actions button {
  width: 72px; height: 72px; border-radius: 50%; display: grid; place-content: center; padding: 0;
  color: var(--acid); background: rgba(15,20,18,.62); border: 1px solid rgba(196,220,134,.55);
  font: 800 17px Impact, "Arial Narrow", sans-serif; letter-spacing: .06em; touch-action: none;
}
.touch-actions button small { display: block; margin-top: 2px; font: 8px "Courier New", monospace; color: #c1c5ba; }
.touch-actions button[data-touch-key="KeyE"] { grid-column: 1 / 3; justify-self: end; width: 88px; height: 88px; }
.touch-actions button.active { background: var(--acid); color: #151a14; }
.touch-actions button.active small { color: #151a14; }

body.touch-mode .controls-hint { display: none; }
body.touch-mode .screen { padding: 8px 12px; }
body.touch-mode .screen-card { max-height: calc(100% - 4px); }
body.touch-mode .nav-hint { display: none; }
body.touch-mode .pause-button { top: 76px; right: 14px; bottom: auto; padding: 12px 14px; }
body.touch-mode .pause-button kbd { display: none; }
body.touch-mode .board-button { top: 124px; right: 14px; bottom: auto; padding: 12px 14px; }
body.touch-mode .sound-button { top: 172px; right: 14px; bottom: auto; padding: 12px 14px; }
body.touch-mode .screen-card button:not(.close-button), body.touch-mode .close-button { min-height: 44px; }
body.touch-mode .radio { left: 168px; right: 190px; bottom: 16px; width: auto; max-width: 420px; }
body.touch-mode .prompt { top: 58%; }

@media (max-width: 700px) {
  body.touch-mode .radio { left: 14px; right: 14px; bottom: 176px; width: auto; max-width: none; }
}
@media (max-width: 700px) and (min-height: 521px) {
  body.touch-mode .pause-button { top: 205px; right: 14px; }
  body.touch-mode .board-button { top: 253px; right: 14px; }
  body.touch-mode .sound-button { top: 301px; right: 14px; }
}
@media (max-height: 520px) {
  html, body, #game-shell { min-height: 0; }
  .topbar { min-height: 56px; padding: 8px 14px; }
  .brand small, .identity-copy small { display: none; }
  .mission-panel { top: 58px !important; padding: 8px 12px !important; }
  .mission-panel h1 { font-size: 17px !important; }
  .status-panel { top: 126px !important; padding: 7px 10px !important; }
  body.touch-mode .pause-button { top: 10px; right: 150px; padding: 10px 12px; }
  body.touch-mode .board-button { top: 10px; right: 240px; padding: 10px 12px; }
  body.touch-mode .sound-button { top: 10px; right: 345px; padding: 10px 12px; }
  body.touch-mode .touch-stick { width: 112px; height: 112px; bottom: 16px; }
  body.touch-mode .touch-actions { bottom: 16px; grid-template-columns: repeat(2, 60px); gap: 8px; }
  body.touch-mode .touch-actions button { width: 60px; height: 60px; }
  body.touch-mode .touch-actions button[data-touch-key="KeyE"] { width: 76px; height: 76px; }
  body.touch-mode .radio { left: 150px; right: 170px; bottom: 10px; }
  .screen { padding: 8px; }
  .screen-card { padding: 18px 20px; max-height: 94vh; }
  .screen-card h2 { font-size: 30px; }
}
