: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; }
.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; }
.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; }
.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 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(3, 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-top: 22px; }
.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; 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; }

.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(2) { display: none; }
  .stats span { font-size: 8px; }
  .stats strong { font-size: 14px; }
  .play-layout { min-height: calc(100dvh - 58px); grid-template: minmax(52dvh, 1fr) auto / 1fr; }
  .radar-wrap { min-height: 52dvh; }
  .flight-panel { min-height: 220px; max-height: 42dvh; 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-top: 12px; }
  .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)); }
}

@media (max-width: 430px) {
  .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; }
}
