:root {
  color-scheme: dark;
  --ink: #14303a;
  --paper: #f6f0df;
  --cream: #fffaf0;
  --sky: #65c9dc;
  --sea: #238ca9;
  --coral: #f26357;
  --yellow: #ffd35a;
  --mint: #73d6ac;
  --danger: #ef4056;
  --panel: rgba(16, 47, 58, .96);
  --line: rgba(255, 255, 255, .13);
  font-family: Inter, ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body { background: #0b2731; color: var(--cream); overflow: hidden; }
button { border: 0; font: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

.game-shell { height: 100dvh; display: grid; grid-template-rows: 70px minmax(0, 1fr); }
.topbar { display: flex; align-items: center; gap: 22px; padding: 9px 18px; background: #102f3a; border-bottom: 1px solid rgba(255,255,255,.12); box-shadow: 0 5px 20px rgba(0,0,0,.18); z-index: 4; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 13px; background: var(--coral); color: white; transform: rotate(-7deg); font-size: 25px; }
.brand small, .brand strong { display: block; line-height: 1.05; }
.brand small { color: #9dc3cb; font-size: 11px; text-transform: uppercase; letter-spacing: .11em; }
.brand strong { font-size: 18px; }
.game-version { align-self: flex-start; margin-left: -3px; padding: 2px 5px; border-radius: 6px; background: rgba(255,255,255,.1); color: #9dc3cb; font-size: 9px; font-weight: 850; white-space: nowrap; }
.stats { display: flex; justify-content: center; flex: 1; gap: clamp(18px, 5vw, 70px); }
.stats div { display: grid; gap: 2px; text-align: center; }
.stats span, .instrument-grid span { color: #9dc3cb; font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.stats strong { font-size: 18px; white-space: nowrap; }
#reputation { color: var(--coral); letter-spacing: 3px; font-size: 14px; }
.recording-tools { display: flex; align-items: center; gap: 7px; }
.recording-status { color: #9dc3cb; font-size: 9px; font-weight: 900; letter-spacing: .08em; white-space: nowrap; }
.recording-status.active { color: var(--coral); }
.recording-status.saved { color: var(--mint); }
.tool-button { min-height: 34px; padding: 7px 10px; border-radius: 9px; background: rgba(255,255,255,.1); color: white; font-size: 11px; font-weight: 850; }
.tool-button:disabled { opacity: .38; cursor: not-allowed; }
.danger-tool:not(:disabled) { background: rgba(239,64,86,.18); color: #ff9caa; }
.level-tool:not(:disabled) { background: rgba(255,211,90,.17); color: var(--yellow); }
.audio-tool { white-space: nowrap; }
.audio-tool[aria-pressed="true"] { background: rgba(255,255,255,.06); color: #9dc3cb; }
.icon-button { width: 42px; height: 42px; border-radius: 12px; background: rgba(255,255,255,.1); color: white; font-weight: 900; }

.play-layout { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 350px; }
.radar-wrap { min-width: 0; position: relative; overflow: hidden; background: var(--sea); }
#game-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.aircraft-canvas { position: absolute; inset: 0; z-index: 2; display: block; width: 100%; height: 100%; pointer-events: none; }
.flight-panel { overflow: auto; padding: 20px; background: var(--panel); border-left: 1px solid var(--line); }
.empty-selection { min-height: 70vh; display: grid; align-content: center; justify-items: center; text-align: center; color: #b4cdd2; }
.empty-selection[hidden] { display: none; }
.empty-selection span { font-size: 44px; animation: bob 1.4s ease-in-out infinite; }
.empty-selection strong { color: white; font-size: 19px; }
.empty-selection p { max-width: 230px; line-height: 1.5; }
.flight-heading { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 16px; }
.flight-heading > div { display: flex; align-items: center; gap: 10px; }
.aircraft-icon { display: grid; place-items: center; width: 43px; height: 43px; border-radius: 12px; background: var(--yellow); color: var(--ink); font-size: 24px; }
.flight-heading small { color: #9dc3cb; }
.flight-heading h2 { margin: 1px 0 0; font-size: 22px; }
.state-pill { padding: 6px 8px; border-radius: 20px; background: rgba(115,214,172,.15); color: var(--mint); font-size: 9px; font-weight: 900; letter-spacing: .08em; white-space: nowrap; }
.instrument-grid { display: grid; grid-template-columns: repeat(4, 1fr); background: #0a252e; border-radius: 14px; overflow: hidden; }
.instrument-grid div { display: grid; gap: 4px; padding: 12px 7px; text-align: center; border-right: 1px solid var(--line); }
.instrument-grid div:last-child { border: 0; }
.instrument-grid strong { font-size: 15px; }
.control-group { margin-top: 19px; }
.control-group h3 { margin: 0 0 8px; color: #c9dadd; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.segmented { display: grid; gap: 5px; }
.segmented.three, .heading-controls { grid-template-columns: repeat(3, 1fr); }
.segmented.five { grid-template-columns: repeat(5, 1fr); }
.segmented button { min-height: 43px; padding: 6px 4px; border-radius: 9px; background: rgba(255,255,255,.08); color: #d5e4e6; font-size: 12px; font-weight: 800; }
.segmented button:hover, .segmented button.active { background: var(--yellow); color: var(--ink); }
.control-hint, .landing-guidance { margin: 7px 0 0; color: #88aeb6; font-size: 11px; line-height: 1.4; }
.route-instructions { display: grid; grid-template-columns: 94px 1fr; align-items: center; gap: 12px; margin-top: 20px; padding: 14px; border: 1px solid rgba(255,211,90,.35); border-radius: 15px; background: rgba(255,211,90,.08); }
.route-instructions h3 { margin: 0 0 4px; color: var(--yellow); font-size: 14px; }
.route-instructions p { margin: 0; color: #c5dadd; font-size: 12px; line-height: 1.45; }
.route-gesture { position: relative; height: 58px; color: var(--yellow); }
.route-gesture span { position: absolute; left: 0; bottom: 5px; font-size: 27px; transform: rotate(18deg); }
.route-gesture i { position: absolute; inset: 6px 10px 5px 25px; border-top: 3px dashed var(--yellow); border-radius: 50%; transform: rotate(-20deg); }
.route-gesture b { position: absolute; right: 0; top: 0; font-size: 13px; }
#game-canvas.is-drawing { cursor: crosshair; }
.primary-actions { display: grid; gap: 8px; margin: 0 0 14px; }
.primary, .secondary { min-height: 48px; border-radius: 12px; padding: 10px 14px; font-weight: 900; }
.primary { background: var(--coral); color: white; box-shadow: 0 5px 0 #b83f3b; }
.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #b83f3b; }
.primary:disabled { background: #49636a; box-shadow: none; color: #91a7ac; cursor: not-allowed; }
.secondary { background: rgba(255,255,255,.09); color: white; }
.large { padding-inline: 30px; font-size: 17px; }

.alert-banner { position: absolute; top: 16px; left: 50%; translate: -50% 0; padding: 10px 18px; border: 3px solid white; border-radius: 11px; background: var(--danger); color: white; font-weight: 950; letter-spacing: .05em; box-shadow: 0 5px 18px rgba(33,20,20,.3); animation: pulse .7s infinite alternate; z-index: 3; }
.alert-banner.warning { background: #d88a19; animation: none; }
.radio-feed { position: absolute; top: 18px; left: 18px; z-index: 1; display: grid; gap: 7px; pointer-events: none; }
.radio-message { max-width: 330px; padding: 9px 12px; border-radius: 5px 13px 13px 13px; background: rgba(16,47,58,.9); color: white; box-shadow: 0 4px 14px rgba(0,0,0,.2); font-size: 13px; animation: radio-in .25s ease-out; }
.radio-message strong { color: var(--yellow); }
.tutorial { position: absolute; left: 18px; bottom: 18px; width: min(360px, calc(100% - 36px)); padding: 14px 16px; border: 2px solid var(--yellow); border-radius: 15px; background: rgba(16,47,58,.95); box-shadow: 0 8px 28px rgba(0,0,0,.28); z-index: 2; }
.tutorial > span { float: right; color: var(--yellow); font-size: 11px; font-weight: 900; }
.tutorial strong { display: block; color: var(--yellow); }
.tutorial p { margin: 5px 0; color: #d6e4e7; font-size: 13px; }
.tutorial button { padding: 0; background: none; color: #9fc5cc; text-decoration: underline; font-size: 11px; }
.replay-controls { position: absolute; right: 16px; bottom: 16px; left: 16px; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid rgba(255,255,255,.18); border-radius: 14px; background: rgba(9,36,44,.95); box-shadow: 0 8px 28px rgba(0,0,0,.3); }
.replay-controls[hidden] { display: none; }
.replay-controls button, .replay-controls select { min-height: 38px; border-radius: 9px; background: rgba(255,255,255,.12); color: white; font-weight: 850; }
.replay-controls button { padding: 7px 13px; }
.replay-controls select { padding: 5px 8px; border: 0; }
.replay-controls label { display: grid; grid-template-columns: 38px minmax(100px, 1fr) 38px; align-items: center; gap: 8px; flex: 1; font-size: 11px; text-align: center; }
.replay-controls input { width: 100%; accent-color: var(--yellow); }
.replay-analysis h2 { margin: 4px 0 18px; }
.replay-analysis h3 { margin: 20px 0 9px; color: #c9dadd; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.analysis-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.analysis-metrics div { padding: 11px; border-radius: 11px; background: rgba(255,255,255,.07); }
.analysis-metrics span, .analysis-metrics strong { display: block; }
.analysis-metrics span { color: #9dc3cb; font-size: 9px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.analysis-metrics strong { margin-top: 3px; color: var(--yellow); font-size: 19px; }
.analysis-events { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.analysis-events li { padding: 8px 9px; border-left: 3px solid #527b83; background: rgba(255,255,255,.05); color: #cbdcdf; font-size: 11px; line-height: 1.35; }
.analysis-events li.active { border-color: var(--yellow); background: rgba(255,211,90,.1); color: white; }
.analysis-events time { color: var(--yellow); font-weight: 900; }

.game-dialog { width: min(470px, calc(100% - 30px)); padding: 30px; border: 0; border-radius: 25px; background: var(--paper); color: var(--ink); text-align: center; box-shadow: 0 24px 70px rgba(0,0,0,.35); }
.game-dialog::backdrop { background: rgba(6,25,31,.72); backdrop-filter: blur(4px); }
.game-dialog h1, .game-dialog h2 { margin: 3px 0 9px; font-size: clamp(34px, 7vw, 53px); line-height: .95; }
.game-dialog h1 em { display: block; color: var(--coral); font-style: normal; }
.game-dialog p:not(.eyebrow) { color: #4d666c; line-height: 1.5; }
.game-dialog small { display: block; margin-top: 18px; color: #73868a; }
.eyebrow { margin: 0; color: #3d8291; font-weight: 900; text-transform: uppercase; letter-spacing: .14em; font-size: 11px; }
.dialog-illustration { position: relative; height: 100px; font-size: 60px; }
.dialog-illustration span { position: absolute; left: 11%; top: 5px; font-size: 40px; opacity: .7; }
.dialog-illustration b { position: relative; display: inline-block; color: var(--coral); transform: rotate(-9deg); animation: fly 2.5s ease-in-out infinite; }
.dialog-illustration i { position: absolute; right: 12%; bottom: 0; font-size: 50px; font-style: normal; }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0; }
.result-stats div { padding: 14px; border-radius: 13px; background: #e6dfcd; }
.result-stats span, .result-stats strong { display: block; }
.result-stats span { font-size: 11px; text-transform: uppercase; }
.result-stats strong { font-size: 25px; }
.pause-overlay { position: fixed; inset: 70px 0 0; z-index: 8; display: grid; place-content: center; justify-items: center; background: rgba(6,25,31,.82); text-align: center; }
.pause-overlay[hidden] { display: none; }
.pause-overlay strong { font-size: 28px; }

@keyframes bob { 50% { transform: translateY(7px); } }
@keyframes pulse { to { transform: scale(1.035); } }
@keyframes radio-in { from { opacity: 0; transform: translateY(-7px); } }
@keyframes fly { 50% { transform: translate(8px,-7px) rotate(-4deg); } }

@media (max-width: 820px) {
  body { overflow: auto; }
  .game-shell { min-height: 100dvh; height: auto; grid-template-rows: 58px minmax(0, 1fr); }
  .topbar { padding: 7px 10px; gap: 8px; }
  .brand { min-width: 0; }
  .brand-mark { width: 38px; height: 38px; }
  .brand div { display: none; }
  .stats { gap: 10px; justify-content: space-around; }
  .stats div:nth-child(3) { display: none; }
  .stats span { font-size: 8px; }
  .stats strong { font-size: 14px; }
  .recording-status, #export-recording { display: none; }
  .recording-tools { margin-left: auto; }
  .tool-button { min-height: 36px; padding-inline: 8px; font-size: 10px; }
  #stop-and-export { max-width: 82px; line-height: 1.05; }
  #test-level { max-width: 68px; line-height: 1.05; }
  .play-layout { min-height: calc(100dvh - 58px); grid-template: minmax(260px, 1fr) auto / 1fr; }
  .radar-wrap { min-height: 260px; }
  .flight-panel { min-height: 0; max-height: none; overflow: visible; padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); border: 0; border-top: 1px solid var(--line); }
  .empty-selection { min-height: 190px; }
  .flight-heading { margin-bottom: 9px; }
  .instrument-grid { display: none; }
  .control-group { margin-top: 10px; }
  .control-hint { display: none; }
  .route-instructions { grid-template-columns: 74px 1fr; margin-top: 10px; padding: 9px 11px; }
  .route-instructions p { font-size: 11px; }
  .primary-actions { grid-template-columns: 2fr 1fr; margin-bottom: 10px; }
  .primary-actions button { min-height: 44px; font-size: 12px; }
  .tutorial { bottom: 10px; left: 10px; width: min(330px, calc(100% - 20px)); padding: 10px 12px; }
  .radio-feed { top: 10px; left: 10px; }
  .radio-message { max-width: min(310px, calc(100vw - 70px)); }
  #load-recent { display: none; }
  #audio-control { min-width: 58px; }
  .replay-controls { right: 8px; bottom: 8px; left: 8px; gap: 5px; padding: 7px; }
  .replay-controls button { padding-inline: 9px; font-size: 10px; }
  .replay-controls label { grid-template-columns: 30px minmax(60px, 1fr) 30px; gap: 4px; }
  .replay-controls select { width: 55px; padding-inline: 3px; font-size: 10px; }
}

@media (max-height: 760px) {
  .flight-panel { padding: 12px 16px; }
  .flight-heading { margin-bottom: 9px; }
  .instrument-grid div { padding-block: 8px; }
  .primary-actions { grid-template-columns: 1.45fr 1fr; margin-bottom: 9px; }
  .primary-actions button { min-height: 42px; padding-inline: 8px; font-size: 12px; }
  .route-instructions { grid-template-columns: 70px 1fr; margin-top: 10px; padding: 9px 10px; }
  .route-instructions p { font-size: 11px; line-height: 1.35; }
}

@media (max-width: 430px) {
  .brand-mark { display: none; }
  .topbar { gap: 5px; }
  .stats { gap: 7px; }
  .stats div:nth-child(5) { display: none; }
  .recording-tools { gap: 4px; }
  #audio-control { padding-inline: 6px; font-size: 9px; }
  #test-level { position: absolute; top: 66px; right: 8px; z-index: 6; max-width: none; box-shadow: 0 4px 15px rgba(0,0,0,.24); }
  .alert-banner { top: 58px; max-width: calc(100% - 20px); text-align: center; }
  .segmented button { min-height: 40px; font-size: 10px; }
  .flight-heading .aircraft-icon { width: 38px; height: 38px; }
  .flight-heading h2 { font-size: 18px; }
  .control-group h3 { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}


.test-mode-badge { position: fixed; left: 50%; top: 72px; z-index: 9; transform: translateX(-50%); padding: 7px 12px; border-radius: 999px; background: #b51f2e; color: #fff; font-weight: 900; font-size: 12px; letter-spacing: .04em; box-shadow: 0 4px 16px rgba(0,0,0,.28); pointer-events: none; }
.test-mode-badge[hidden] { display: none; }
.test-dialog { width: min(520px, calc(100vw - 28px)); }
.test-warning { padding: 9px 11px; border-radius: 10px; background: #f8d9dc; color: #721621; font-weight: 800; }
.test-grid { display: grid; gap: 14px; margin: 16px 0; text-align: left; }
.test-grid label { display: grid; gap: 6px; font-weight: 800; }
.test-grid input, .test-grid select { min-height: 42px; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fffdf7; color: #173740; font: inherit; }
.test-inline { display: grid; grid-template-columns: auto minmax(70px,1fr) auto; gap: 8px; align-items: center; }
.test-inline strong { text-align: center; font-size: 22px; }
.test-inline button { min-height: 42px; min-width: 44px; }
.test-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.test-actions button { min-height: 42px; }
