:root {
  --bg: #0b1017;
  --panel: #121a24;
  --panel-2: #172231;
  --line: #233246;
  --text: #dbe5f0;
  --muted: #8193a8;
  --accent: #36b3ff;
  --good: #3ccf7d;
  --warn: #f2b33d;
  --bad: #ff5d5d;
  --magenta: #ff5cf0;
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0 0 0.5rem; }
.muted { color: var(--muted); font-size: 0.85rem; }
.error { color: var(--bad); }
[hidden] { display: none !important; }

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem; justify-content: center;
  padding: 0.5rem 0.9rem; border: 1px solid var(--line); border-radius: 0.5rem;
  background: var(--panel-2); color: var(--text); font: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: #1677c9; border-color: #1f8ae6; color: #fff; font-weight: 600; }
.btn.big { padding: 0.75rem 1.5rem; font-size: 1.05rem; }

/* ------------------------------------------------------------- app bar */
.appbar {
  display: flex; align-items: center; gap: 1.25rem; padding: 0.55rem 1rem;
  background: #0d141d; border-bottom: 1px solid var(--line);
}
.brand { color: var(--text); font-weight: 700; text-decoration: none; white-space: nowrap; }
.brand-mark { color: var(--accent); }
.appbar nav { margin-left: auto; display: flex; gap: 1rem; }
.appbar nav a { color: var(--muted); text-decoration: none; }
.appbar nav a:hover { color: var(--text); }
.flight-id { display: flex; flex-direction: column; line-height: 1.2; }
.flight-id span { color: var(--muted); font-size: 0.8rem; }

.timeline { display: flex; gap: 0.25rem; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.timeline li {
  padding: 0.2rem 0.5rem; border-radius: 999px; font-size: 0.75rem; color: var(--muted);
  border: 1px solid var(--line);
}
.timeline li.done { color: var(--good); border-color: #1d5a39; }
.timeline li.current { color: #fff; background: #1677c9; border-color: #1f8ae6; }

.score-box { display: flex; align-items: baseline; gap: 0.4rem; padding: 0.2rem 0.75rem; border-radius: 0.5rem; background: var(--panel-2); }
.score-label { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; }
.score-value { font-size: 1.4rem; font-weight: 700; }
.score-steps { color: var(--muted); font-size: 0.75rem; }
.score-box[data-level="good"] .score-value { color: var(--good); }
.score-box[data-level="fair"] .score-value { color: var(--warn); }
.score-box[data-level="poor"] .score-value { color: var(--bad); }

/* ------------------------------------------------------------- landing */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.hero h1 { font-size: clamp(1.6rem, 3vw, 2.3rem); }
.hero p { max-width: 60rem; line-height: 1.6; color: #b7c5d6; }
.pilot-name { display: flex; align-items: center; gap: 0.75rem; margin: 1rem 0 1.5rem; }
input, select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 0.4rem;
  padding: 0.45rem 0.6rem; font: inherit;
}
.scenario-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.scenario-card {
  display: flex; flex-direction: column; gap: 0.6rem; padding: 1.2rem; border-radius: 0.9rem;
  background: linear-gradient(160deg, #18324f, var(--panel) 55%); border: 1px solid var(--line);
}
.scenario-card.tod-dusk { background: linear-gradient(160deg, #5a3326, var(--panel) 55%); }
.scenario-card.tod-night { background: linear-gradient(160deg, #0d1530, var(--panel) 55%); }
.scenario-card header { display: flex; gap: 0.4rem; }
.tag { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 0.15rem 0.5rem; border-radius: 999px; background: #ffffff14; }
.scenario-card .route { font-weight: 600; }
.scenario-card .route span { color: var(--muted); font-weight: 400; }
.scenario-card p { margin: 0; line-height: 1.5; color: #b7c5d6; }
.scenario-card dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin: 0.25rem 0 0.5rem; }
.scenario-card dt { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; }
.scenario-card dd { margin: 0; font-weight: 600; }
.scenario-card .btn { margin-top: auto; }
.disclaimer { color: var(--muted); font-size: 0.8rem; margin-top: 2rem; }

/* ------------------------------------------------------------- simulator */
.sim-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.sim {
  flex: 1; min-height: 0; display: grid; gap: 0.5rem; padding: 0.5rem;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "window side" "radio side";
}
.window { grid-area: window; position: relative; border-radius: 0.6rem; overflow: hidden; background: #000; min-height: 220px; }
.window canvas { width: 100%; height: 100%; display: block; }
.hud {
  position: absolute; left: 50%; bottom: 3%; transform: translateX(-50%); display: flex; gap: 0.5rem;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}
.hud div { background: #000c; border: 1px solid #2c3b4f; border-radius: 0.35rem; padding: 0.2rem 0.55rem; min-width: 5.5rem; text-align: center; }
.hud span { display: block; color: var(--muted); font-size: 0.65rem; }
.hud b { color: #3dff9a; font-size: 1.15rem; }
.hud small { color: var(--muted); margin-left: 0.2rem; }
.phase-label {
  position: absolute; top: 4%; left: 50%; transform: translateX(-50%); padding: 0.25rem 0.8rem;
  background: #000a; border-radius: 999px; font-size: 0.85rem; letter-spacing: 0.05em; text-transform: uppercase;
}
.speed { position: absolute; top: 4%; right: 4.5%; font-size: 0.75rem; color: var(--muted); background: #000a; padding: 0.25rem 0.5rem; border-radius: 0.4rem; }
.speed select { padding: 0.1rem 0.3rem; margin-left: 0.3rem; }

.side { grid-area: side; display: flex; flex-direction: column; gap: 0.5rem; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 0.6rem; padding: 0.6rem; }
.panel header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.4rem; flex-wrap: wrap; }
.panel h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0; }
.map-panel { flex: 1.25; display: flex; flex-direction: column; min-height: 0; }
.map-panel canvas { flex: 1; width: 100%; min-height: 0; border-radius: 0.4rem; background: #07182a; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 0.4rem; overflow: hidden; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 0.2rem 0.55rem; font: inherit; font-size: 0.75rem; cursor: pointer; }
.seg button.selected { background: #1677c9; color: #fff; }
.route-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.table-wrap { overflow: auto; min-height: 0; }
.route-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; font-family: ui-monospace, monospace; }
.route-table th { text-align: left; color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--panel); }
.route-table td, .route-table th { padding: 0.25rem 0.4rem; border-bottom: 1px solid #1a2636; }
.route-table tr.passed td { color: #5d6c7e; }
.route-table tr.active td { color: var(--magenta); font-weight: 700; }

.radio {
  grid-area: radio; display: grid; gap: 0.75rem; padding: 0.75rem; border-radius: 0.6rem;
  background: var(--panel); border: 1px solid var(--line);
  grid-template-columns: 170px minmax(0, 1fr) 200px;
  grid-template-areas: "com atc ptt" "result result result";
  max-height: 46vh; overflow: auto;
}
.com { grid-area: com; font-family: ui-monospace, monospace; background: #050a0f; border-radius: 0.5rem; padding: 0.6rem; border: 1px solid #1d2a3a; }
.com-label { font-size: 0.7rem; color: var(--muted); display: flex; gap: 0.35rem; align-items: center; }
.lamp { padding: 0 0.3rem; border-radius: 0.2rem; background: #1a2430; color: #445; font-size: 0.65rem; }
.lamp.on { background: var(--good); color: #021; }
.lamp.tx.on { background: var(--bad); color: #200; }
.com-freq { font-size: 1.8rem; color: #ffb547; letter-spacing: 0.04em; }
.com-unit { font-size: 0.8rem; color: #cfe1f3; min-height: 1.2em; }
.atc { grid-area: atc; display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.status { font-weight: 600; padding: 0.45rem 0.7rem; border-radius: 0.4rem; background: var(--panel-2); border-left: 4px solid var(--line); }
.status[data-kind="rx"] { border-color: var(--good); }
.status[data-kind="tx-ready"] { border-color: var(--accent); }
.status[data-kind="tx"] { border-color: var(--bad); }
.status[data-kind="busy"], .status[data-kind="flying"] { border-color: var(--warn); }
.status[data-kind="good"] { border-color: var(--good); color: var(--good); }
.status[data-kind="warn"] { border-color: var(--warn); color: var(--warn); }
.status[data-kind="error"] { border-color: var(--bad); color: var(--bad); }
.atc-text { margin: 0; font-size: 1.05rem; line-height: 1.5; font-family: ui-monospace, monospace; }
.atc-text.hidden-text { color: var(--muted); font-family: inherit; font-size: 0.85rem; font-style: italic; }
.atc-controls { display: flex; gap: 1rem; align-items: center; }
.toggle { display: inline-flex; gap: 0.4rem; align-items: center; color: var(--muted); font-size: 0.85rem; }

.ptt-wrap { grid-area: ptt; display: flex; flex-direction: column; gap: 0.4rem; }
.ptt {
  flex: 1; min-height: 96px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem;
  border-radius: 0.8rem; border: 2px solid #2a3c52; background: radial-gradient(circle at 50% 30%, #23364d, #142130);
  color: var(--text); font: inherit; font-weight: 700; letter-spacing: 0.05em; cursor: pointer; user-select: none;
  touch-action: none; -webkit-user-select: none;
}
.ptt small { font-weight: 400; color: var(--muted); letter-spacing: 0; }
.ptt-icon { font-size: 1.6rem; }
.ptt:not(:disabled):hover { border-color: var(--accent); }
.ptt.active { background: radial-gradient(circle at 50% 30%, #b62b2b, #5c1414); border-color: var(--bad); box-shadow: 0 0 24px #ff5d5d66; }
.ptt:disabled { opacity: 0.4; cursor: not-allowed; }
.level { height: 6px; background: #0a121b; border-radius: 3px; overflow: hidden; }
.level div { height: 100%; width: 0; background: linear-gradient(90deg, var(--good), var(--warn), var(--bad)); transition: width 60ms linear; }

.result { grid-area: result; border-top: 1px solid var(--line); padding-top: 0.6rem; }
.result-head { display: flex; align-items: center; gap: 0.9rem; }
.result-score {
  width: 3.4rem; height: 3.4rem; border-radius: 50%; display: grid; place-items: center; font-size: 1.3rem; font-weight: 800;
  border: 3px solid var(--bad); color: var(--bad);
}
.result[data-passed="true"] .result-score { border-color: var(--good); color: var(--good); }
.result-verdict { font-weight: 700; }
.result-actions { margin-left: auto; display: flex; gap: 0.5rem; }
.elements { list-style: none; padding: 0; margin: 0.6rem 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.35rem; }
.elements li { display: flex; gap: 0.45rem; align-items: baseline; padding: 0.3rem 0.5rem; border-radius: 0.35rem; background: var(--panel-2); font-size: 0.85rem; }
.elements .icon { font-weight: 800; }
.elements .label { color: var(--muted); }
.elements .value { margin-left: auto; font-family: ui-monospace, monospace; text-align: right; }
.elements li.correct .icon { color: var(--good); }
.elements li.missing .icon { color: var(--warn); }
.elements li.incorrect .icon, .elements li.incorrect .value { color: var(--bad); }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.compare p { margin: 0.2rem 0 0; font-family: ui-monospace, monospace; }
.feedback { margin: 0.5rem 0 0; padding-left: 1.2rem; color: #c9d6e3; font-size: 0.9rem; }

.overlay { position: fixed; inset: 0; background: #000b; display: grid; place-items: center; z-index: 10; padding: 1rem; }
.dialog { max-width: 640px; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 0.9rem; padding: 1.5rem; max-height: 90vh; overflow: auto; }
.dialog.center { text-align: center; }
.dialog h3 { margin-top: 1rem; font-size: 1rem; }
.brief-list { line-height: 1.7; padding-left: 1.2rem; }
.finish-score { font-size: 4rem; font-weight: 800; color: var(--accent); }

/* ------------------------------------------------------------- summary */
.summary-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.big-score { display: flex; flex-direction: column; align-items: center; padding: 0.8rem 1.4rem; border-radius: 0.9rem; border: 2px solid; }
.big-score span { font-size: 3rem; font-weight: 800; line-height: 1; }
.big-score small { letter-spacing: 0.1em; font-weight: 700; }
.big-score.pass { border-color: var(--good); color: var(--good); }
.big-score.fail { border-color: var(--bad); color: var(--bad); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem; margin: 1.25rem 0; }
.stats div { background: var(--panel); border: 1px solid var(--line); border-radius: 0.6rem; padding: 0.8rem; display: flex; flex-direction: column; }
.stats b { font-size: 1.6rem; }
.stats span { color: var(--muted); font-size: 0.85rem; }
.issues ul { margin: 0; padding-left: 1.2rem; line-height: 1.7; }
.issues { margin-bottom: 1rem; }
.debrief { display: flex; flex-direction: column; gap: 0.4rem; }
.debrief-row { background: var(--panel); border: 1px solid var(--line); border-radius: 0.6rem; border-left: 4px solid var(--line); }
.debrief-row.status-passed { border-left-color: var(--good); }
.debrief-row.status-failed { border-left-color: var(--bad); }
.debrief-row.status-skipped, .debrief-row.status-not-attempted { border-left-color: var(--warn); }
.debrief-row summary {
  display: grid; grid-template-columns: 2rem 6.5rem 12rem minmax(0, 1fr) 3rem 7rem; gap: 0.6rem; align-items: center;
  padding: 0.55rem 0.8rem; cursor: pointer; list-style: none;
}
.debrief-row summary::-webkit-details-marker { display: none; }
.debrief-row .n { color: var(--muted); }
.debrief-row .unit small { color: var(--muted); }
.debrief-row .atc-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #b7c5d6; font-family: ui-monospace, monospace; font-size: 0.85rem; }
.debrief-row .state { text-transform: capitalize; color: var(--muted); font-size: 0.85rem; }
.badge { display: inline-block; min-width: 2.4rem; text-align: center; padding: 0.15rem 0.4rem; border-radius: 0.35rem; background: var(--panel-2); font-weight: 700; }
.status-passed .badge, .badge.pass { color: var(--good); }
.status-failed .badge, .badge.fail { color: var(--bad); }
.debrief-body { padding: 0 0.9rem 0.9rem; }
.debrief-body .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.debrief-body h4 { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; margin-top: 0.8rem; }
.debrief-body p { margin: 0.2rem 0 0.4rem; font-family: ui-monospace, monospace; }
.debrief-body audio { height: 32px; width: 100%; max-width: 320px; }
.attempt { border-top: 1px dashed var(--line); padding-top: 0.5rem; margin-top: 0.5rem; }
.attempt:not(.final) { opacity: 0.7; }
.attempt-head { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.transcript { color: #e9f1fa; }
.actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; flex-wrap: wrap; }
table.history { width: 100%; border-collapse: collapse; }
table.history th, table.history td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--line); }
table.history th { color: var(--muted); font-weight: 500; }

@media (max-width: 980px) {
  .sim-page { height: auto; overflow: auto; }
  .sim { grid-template-columns: 1fr; grid-template-rows: 50vh auto auto; grid-template-areas: "window" "radio" "side"; }
  .side { height: 80vh; }
  .radio { grid-template-columns: 1fr; grid-template-areas: "com" "atc" "ptt" "result"; max-height: none; }
  .timeline { display: none; }
  .debrief-row summary { grid-template-columns: 2rem 1fr 3rem; }
  .debrief-row .phase, .debrief-row .atc-line, .debrief-row .state { display: none; }
  .debrief-body .cols, .compare { grid-template-columns: 1fr; }
}

@media print {
  :root { color-scheme: light; color: #000; background: #fff; }
  .appbar, .actions { display: none; }
  .panel, .debrief-row, .stats div { background: #fff; border-color: #bbb; }
  .debrief-row summary, .debrief-body p, .transcript, .elements li { color: #000; background: #fff; }
  audio { display: none; }
}
