@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;500;600;700&family=JetBrains+Mono:wght@500;600&display=swap');

:root {
  color-scheme: dark;
  --bg: #071318;
  --bg-deep: #040b0e;
  --panel: rgba(14, 31, 37, 0.92);
  --panel-soft: rgba(19, 40, 47, 0.78);
  --line: rgba(139, 191, 187, 0.18);
  --line-strong: rgba(139, 191, 187, 0.36);
  --text: #f3f1e9;
  --muted: #93a8a9;
  --cyan: #72d7c9;
  --cyan-deep: #1f8f87;
  --amber: #f0a66b;
  --red: #ff725f;
  --green: #83d7a2;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.3);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--bg-deep); }

body {
  color: var(--text);
  font-family: "IBM Plex Sans Thai", system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button, select, input { font: inherit; }
button { color: inherit; }
button, select { touch-action: manipulation; }

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(18px + var(--safe-top)) calc(22px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(22px + var(--safe-left));
  background:
    radial-gradient(circle at 12% 0%, rgba(62, 147, 138, 0.14), transparent 29%),
    radial-gradient(circle at 92% 8%, rgba(240, 166, 107, 0.08), transparent 25%),
    linear-gradient(150deg, #08171c 0%, #061115 45%, #050d10 100%);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 14px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand-lockup { display: flex; align-items: center; gap: 13px; min-width: 245px; }
.brand-mark {
  width: 46px; height: 46px; display: grid; place-items: center;
  border: 1px solid var(--line-strong); border-radius: 13px;
  color: var(--cyan); font: 600 15px/1 "JetBrains Mono", monospace;
  background: linear-gradient(145deg, rgba(114,215,201,.12), rgba(114,215,201,.02));
  box-shadow: inset 0 0 24px rgba(114,215,201,.05);
}
.eyebrow { margin: 0 0 3px; color: var(--cyan); font: 600 10px/1.2 "JetBrains Mono", monospace; letter-spacing: .14em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 21px; line-height: 1; letter-spacing: -.02em; }
h1 span { color: var(--muted); font: 500 10px/1 "JetBrains Mono", monospace; margin-left: 6px; letter-spacing: .04em; }
h2 { margin-bottom: 0; font-size: 19px; line-height: 1.25; letter-spacing: -.02em; }

.session-strip { display: flex; align-items: center; gap: 12px; }
.field { display: grid; gap: 5px; }
.field span, .clock-block span { color: var(--muted); font: 600 9px/1 "JetBrains Mono", monospace; letter-spacing: .12em; }
select {
  height: 42px; min-width: 150px; padding: 0 34px 0 12px;
  border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: #10232a;
}
.compact-field select { min-width: 215px; }
.clock-block { min-width: 110px; padding: 7px 12px; border-left: 1px solid var(--line); }
.clock-block strong { display: block; margin-top: 4px; color: var(--amber); font: 600 17px/1 "JetBrains Mono", monospace; letter-spacing: .05em; }
.connection-pill { height: 38px; display: flex; align-items: center; gap: 7px; padding: 0 12px; border: 1px solid rgba(131,215,162,.25); border-radius: 999px; background: rgba(131,215,162,.07); color: var(--green); font: 600 9px/1 "JetBrains Mono", monospace; letter-spacing: .08em; }
.connection-pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 12px currentColor; }

.workspace-tabs { display: flex; gap: 5px; border-bottom: 1px solid var(--line); }
.tab-button {
  position: relative; min-height: 43px; padding: 0 21px 11px; border: 0; background: transparent; color: var(--muted);
  display: flex; align-items: center; gap: 9px; cursor: pointer; font-weight: 600;
}
.tab-button::after { content: ""; position: absolute; bottom: -1px; left: 15px; right: 15px; height: 2px; border-radius: 2px; background: transparent; }
.tab-button.active { color: var(--text); }
.tab-button.active::after { background: var(--amber); box-shadow: 0 0 16px rgba(240,166,107,.55); }
.tab-index { color: var(--cyan); font: 600 9px/1 "JetBrains Mono", monospace; }

main { min-height: 0; }
.workspace { display: none; height: 100%; }
.workspace.active { display: grid; }
.workspace[data-workspace="pilot"] { grid-template-columns: minmax(0, 1.55fr) minmax(350px, .65fr); gap: 14px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(145deg, rgba(17,37,43,.95), rgba(10,24,29,.94)); box-shadow: var(--shadow); overflow: hidden; }
.panel-heading { min-height: 68px; padding: 15px 17px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-bottom: 1px solid var(--line); }

.radar-panel { min-height: 560px; display: grid; grid-template-rows: auto 1fr; }
.radar-tools { display: flex; align-items: center; gap: 9px; color: var(--cyan); font: 600 10px/1 "JetBrains Mono", monospace; }
.icon-button { min-width: 42px; min-height: 42px; border: 1px solid var(--line); border-radius: 10px; background: rgba(114,215,201,.06); cursor: pointer; font-size: 18px; }
.icon-button:active { transform: translateY(1px); background: rgba(114,215,201,.14); }
.radar-stage { position: relative; min-height: 0; background: #061216; overflow: hidden; }
#radarCanvas, #towerCanvas { display: block; width: 100%; height: 100%; touch-action: none; }
.radar-readout { position: absolute; left: 15px; bottom: 14px; display: flex; align-items: baseline; gap: 9px; padding: 9px 11px; background: rgba(4,11,14,.78); border: 1px solid var(--line); border-radius: 9px; backdrop-filter: blur(8px); }
.radar-readout span { color: var(--amber); font: 600 13px/1 "JetBrains Mono", monospace; }
.radar-readout small { color: var(--muted); font: 500 9px/1 "JetBrains Mono", monospace; }

.action-panel { display: flex; flex-direction: column; min-height: 560px; }
.selected-flight { min-height: 112px; padding: 16px 18px; background: linear-gradient(105deg, rgba(114,215,201,.12), rgba(240,166,107,.04)); border-bottom: 1px solid var(--line); }
.selected-flight .flight-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.selected-flight h3 { margin: 0; font: 600 27px/1 "JetBrains Mono", monospace; letter-spacing: -.04em; }
.selected-flight .phase { padding: 5px 8px; border-radius: 999px; background: rgba(114,215,201,.1); color: var(--cyan); font: 600 9px/1 "JetBrains Mono", monospace; }
.flight-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 13px; }
.flight-metrics span { display: block; color: var(--muted); font: 600 8px/1 "JetBrains Mono", monospace; letter-spacing: .1em; }
.flight-metrics b { display: block; margin-top: 4px; font: 600 15px/1 "JetBrains Mono", monospace; }
.quick-header { padding: 14px 17px 11px; display: flex; justify-content: space-between; align-items: flex-start; }
.shortcut-hint { color: var(--muted); font-size: 11px; }
.action-groups { padding: 0 14px 14px; display: grid; gap: 13px; overflow: auto; }
.action-group-title { margin: 0 0 6px; color: var(--muted); font: 600 9px/1 "JetBrains Mono", monospace; letter-spacing: .12em; }
.action-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.action-button { min-height: 58px; padding: 8px 5px; border: 1px solid var(--line); border-radius: 11px; background: rgba(114,215,201,.045); display: grid; place-items: center; align-content: center; gap: 4px; cursor: pointer; }
.action-button:hover, .action-button:active { border-color: var(--cyan-deep); background: rgba(114,215,201,.12); }
.action-button .action-icon { color: var(--cyan); font: 600 15px/1 "JetBrains Mono", monospace; }
.action-button span:last-child { font-size: 11px; font-weight: 600; }
.action-button.danger .action-icon { color: var(--red); }
.command-log { margin-top: auto; min-height: 59px; padding: 11px 17px; border-top: 1px solid var(--line); background: rgba(4,11,14,.25); }
.command-log span { color: var(--muted); font: 600 8px/1 "JetBrains Mono", monospace; letter-spacing: .12em; }
.command-log p { margin: 5px 0 0; color: var(--green); font-size: 12px; }

.instructor-grid { height: 100%; display: grid; grid-template-columns: 1.1fr .9fr; grid-template-rows: auto 1fr; gap: 14px; }
.session-control, .traffic-board, .scenario-panel, .timeline-panel { min-height: 0; }
.transport-row { display: flex; align-items: end; gap: 9px; padding: 15px 17px; }
.primary-control, .secondary-control { min-height: 42px; padding: 0 15px; border-radius: 10px; cursor: pointer; font-weight: 600; }
.primary-control { border: 1px solid var(--amber); background: var(--amber); color: #24140b; }
.secondary-control { border: 1px solid var(--line); background: rgba(114,215,201,.06); }
.status-chip { padding: 6px 9px; border-radius: 999px; font: 600 9px/1 "JetBrains Mono", monospace; }
.status-chip.running { color: var(--green); background: rgba(131,215,162,.1); border: 1px solid rgba(131,215,162,.25); }
.status-chip.paused { color: var(--amber); background: rgba(240,166,107,.1); border-color: rgba(240,166,107,.25); }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); }
.metric-grid div { padding: 13px 15px; border-right: 1px solid var(--line); }
.metric-grid div:last-child { border-right: 0; }
.metric-grid span { color: var(--muted); font-size: 10px; }
.metric-grid strong { display: block; margin-top: 5px; font: 600 19px/1 "JetBrains Mono", monospace; }
.traffic-board { grid-row: span 2; display: grid; grid-template-rows: auto 1fr; }
.traffic-table-wrap { overflow: auto; }
.traffic-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.traffic-table th { position: sticky; top: 0; padding: 10px 12px; text-align: left; color: var(--muted); background: #10232a; font: 600 8px/1 "JetBrains Mono", monospace; letter-spacing: .08em; }
.traffic-table td { padding: 12px; border-top: 1px solid var(--line); }
.traffic-table tr { cursor: pointer; }
.traffic-table tr:hover { background: rgba(114,215,201,.05); }
.traffic-table td:first-child { color: var(--cyan); font: 600 12px/1 "JetBrains Mono", monospace; }
.scenario-panel { padding-bottom: 14px; }
.scenario-buttons { padding: 13px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.scenario-buttons button { min-height: 69px; padding: 10px; display: grid; grid-template-columns: 40px 1fr; grid-template-rows: 1fr 1fr; align-items: center; text-align: left; border: 1px solid var(--line); border-radius: 11px; background: rgba(240,166,107,.04); cursor: pointer; }
.scenario-buttons button > span { grid-row: 1 / 3; width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid rgba(240,166,107,.28); border-radius: 9px; color: var(--amber); font: 600 9px/1 "JetBrains Mono", monospace; }
.scenario-buttons b { font-size: 11px; }
.scenario-buttons small { color: var(--muted); font-size: 9px; }
.timeline-panel { display: grid; grid-template-rows: auto 1fr; }
.timeline-panel ol { margin: 0; padding: 12px 17px 15px 44px; overflow: auto; list-style: none; counter-reset: timeline; }
.timeline-panel li { position: relative; padding: 0 0 12px 0; color: var(--muted); font-size: 11px; }
.timeline-panel li::before { content: ""; position: absolute; left: -19px; top: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 8px rgba(114,215,201,.5); }
.timeline-panel li::after { content: ""; position: absolute; left: -17px; top: 12px; bottom: 0; width: 1px; background: var(--line); }
.timeline-panel li:last-child::after { display: none; }
.timeline-panel time { margin-right: 8px; color: var(--amber); font: 600 9px/1 "JetBrains Mono", monospace; }

.tower-workspace { min-height: 600px; }
.tower-panel { height: 100%; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.tower-stage { position: relative; min-height: 480px; overflow: hidden; background: #a4c9d3; cursor: grab; }
.tower-stage.dragging { cursor: grabbing; }
.tower-hud { position: absolute; inset: 14px 16px auto; display: grid; grid-template-columns: 1fr auto 1fr; gap: 15px; pointer-events: none; }
.view-bearing, .weather-readout, .fov-readout { padding: 9px 11px; border: 1px solid rgba(255,255,255,.22); border-radius: 10px; background: rgba(4,11,14,.64); backdrop-filter: blur(9px); }
.view-bearing { justify-self: start; }
.weather-readout { text-align: center; min-width: 210px; }
.fov-readout { justify-self: end; text-align: right; }
.tower-hud span, .tower-hud small { display: block; color: #bcd0d1; font: 600 8px/1.5 "JetBrains Mono", monospace; letter-spacing: .1em; }
.tower-hud strong, .tower-hud b { font: 600 15px/1.4 "JetBrains Mono", monospace; }
.weather-readout b { color: var(--amber); }
.drag-hint { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); padding: 7px 12px; border-radius: 999px; background: rgba(4,11,14,.62); color: rgba(255,255,255,.82); font-size: 10px; pointer-events: none; transition: opacity .25s; }
.drag-hint.hidden { opacity: 0; }
.tower-controls { min-height: 83px; padding: 11px 14px; display: flex; align-items: center; justify-content: center; gap: 8px; border-top: 1px solid var(--line); }
.view-control { min-width: 100px; min-height: 56px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 11px; background: rgba(114,215,201,.05); cursor: pointer; font-size: 18px; }
.view-control span { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; }
.view-control.featured { border-color: rgba(114,215,201,.35); color: var(--cyan); }
.view-control.amber { border-color: rgba(240,166,107,.35); color: var(--amber); }
.zoom-control { min-width: 155px; display: grid; gap: 5px; margin-left: 10px; }
.zoom-control span { color: var(--muted); font: 600 8px/1 "JetBrains Mono", monospace; }
.zoom-control input { accent-color: var(--amber); }

.app-footer { min-height: 20px; display: flex; justify-content: space-between; color: #61787a; font: 600 8px/1 "JetBrains Mono", monospace; letter-spacing: .1em; }

.action-sheet { position: fixed; inset: 0; z-index: 20; display: none; align-items: end; justify-content: center; }
.action-sheet.open { display: flex; }
.sheet-backdrop { position: absolute; inset: 0; border: 0; background: rgba(0,0,0,.62); backdrop-filter: blur(3px); }
.sheet-card { position: relative; z-index: 1; width: min(580px, 100%); padding: 8px 18px calc(18px + var(--safe-bottom)); border: 1px solid var(--line-strong); border-bottom: 0; border-radius: 22px 22px 0 0; background: #10232a; box-shadow: 0 -24px 70px rgba(0,0,0,.42); }
.sheet-handle { width: 42px; height: 4px; margin: 0 auto 10px; border-radius: 99px; background: var(--line-strong); }
.sheet-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.preset-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.preset-button { min-height: 55px; border: 1px solid var(--line); border-radius: 11px; background: rgba(114,215,201,.05); cursor: pointer; font: 600 13px/1 "JetBrains Mono", monospace; }
.preset-button.selected { color: #071318; border-color: var(--cyan); background: var(--cyan); }
.execute-button { width: 100%; min-height: 50px; margin-top: 13px; border: 0; border-radius: 11px; background: var(--amber); color: #27170c; font-weight: 700; cursor: pointer; }
.execute-button:disabled { opacity: .35; cursor: not-allowed; }

@media (max-width: 980px) {
  .app-shell { padding-left: calc(13px + var(--safe-left)); padding-right: calc(13px + var(--safe-right)); }
  .workspace[data-workspace="pilot"] { grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); }
  .radar-panel, .action-panel { min-height: 520px; }
  .compact-field select { min-width: 180px; }
  .scenario-buttons { grid-template-columns: 1fr; }
}

@media (orientation: landscape) and (max-width: 1200px) {
  .tower-workspace { height: calc(100dvh - 190px); min-height: 0; }
  .tower-stage { min-height: 0; }
  .tower-controls { min-height: 74px; padding-block: 8px; }
  .view-control { min-height: 52px; }
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; }
  .session-strip { flex-wrap: wrap; justify-content: flex-end; }
  .connection-pill { display: none; }
  .workspace[data-workspace="pilot"] { grid-template-columns: 1fr; height: auto; }
  .radar-panel { min-height: 470px; }
  .action-panel { min-height: 540px; }
  .instructor-grid { grid-template-columns: 1fr; grid-template-rows: auto; }
  .traffic-board { grid-row: auto; min-height: 360px; }
  .tower-stage { min-height: 500px; }
}

@media (orientation: portrait) and (max-width: 820px) {
  .app-shell { display: block; }
  .topbar { display: grid; gap: 13px; }
  .session-strip { justify-content: flex-start; margin-bottom: 12px; }
  .workspace-tabs { margin-bottom: 14px; overflow-x: auto; }
  .tab-button { white-space: nowrap; }
  .workspace { min-height: calc(100dvh - 220px); }
  .app-footer { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
