/* TWR.SYS — CRT phosphor UI */
:root {
  --bg: #010603;
  --panel: #020d06;
  --fg: #33ff66;
  --fg-hi: #b6ffc9;
  --fg-dim: #1d9a41;
  --fg-faint: #0b3d1a;
  --line: #0f5a26;
  --dep: #ffb000;
  --arr: #33ff66;
  --warn: #ffb000;
  --red: #ff3b3b;
  --cyan: #59fff0;
  --glow: 0 0 5px rgba(51, 255, 102, 0.55);
  --font: 'VT323', 'Courier New', ui-monospace, monospace;
  color-scheme: dark;
}
html[data-phosphor='p3'] {
  --fg: #ffb000;
  --fg-hi: #ffe2a3;
  --fg-dim: #b97f00;
  --fg-faint: #3f2b00;
  --line: #5c3f00;
  --arr: #ffb000;
  --dep: #fff1c4;
  --warn: #ffd76a;
  --cyan: #ffe7a0;
  --glow: 0 0 5px rgba(255, 176, 0, 0.55);
  --bg: #060300;
  --panel: #0d0802;
}
html[data-phosphor='p4'] {
  --fg: #d9e6f2;
  --fg-hi: #ffffff;
  --fg-dim: #8597a8;
  --fg-faint: #26303a;
  --line: #3a4652;
  --arr: #9fd6ff;
  --dep: #ffd27a;
  --warn: #ffd27a;
  --cyan: #9fd6ff;
  --glow: 0 0 5px rgba(217, 230, 242, 0.45);
  --bg: #04070a;
  --panel: #080d12;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body {
  color: var(--fg);
  font-family: var(--font);
  font-size: 20px;
  line-height: 1.2;
  text-shadow: var(--glow);
  -webkit-font-smoothing: none;
}
a { color: var(--fg-hi); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--fg); color: var(--bg); text-shadow: none; }
[hidden] { display: none !important; }

/* CRT overlay */
.crt { min-height: 100vh; display: flex; flex-direction: column; position: relative; }
.crt::before {
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: 1000;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 2px, rgba(0, 0, 0, 0.22) 3px);
}
.crt::after {
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: 1001;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 60%, rgba(0, 0, 0, 0.55) 100%);
  animation: flicker 6s infinite steps(1);
}
@keyframes flicker { 0%, 100% { opacity: 1; } 47% { opacity: 0.94; } 48% { opacity: 1; } 83% { opacity: 0.97; } }
@media (prefers-reduced-motion: reduce) { .crt::after { animation: none; } }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 6px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.logo { font-size: 30px; color: var(--fg-hi); letter-spacing: 2px; }
.logo span { color: var(--fg-dim); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { padding: 0 8px; color: var(--fg); }
.nav a.active, .nav a:hover { background: var(--fg); color: var(--bg); text-shadow: none; text-decoration: none; }
.whoami { color: var(--fg-dim); display: flex; gap: 10px; align-items: center; }
.whoami b { color: var(--fg-hi); font-weight: normal; }
.announcement { background: var(--warn); color: #000; text-shadow: none; padding: 2px 16px; text-align: center; }

.view { flex: 1; padding: 18px 16px 40px; max-width: 1180px; width: 100%; margin: 0 auto; }
.view.full { max-width: none; padding: 0; }

/* generic */
h1, h2, h3 { font-weight: normal; margin: 0 0 10px; color: var(--fg-hi); letter-spacing: 1px; }
h1 { font-size: 40px; }
h2 { font-size: 30px; border-bottom: 1px dashed var(--line); padding-bottom: 4px; margin-top: 26px; }
h3 { font-size: 24px; margin-top: 16px; }
p { margin: 6px 0 12px; }
.dim { color: var(--fg-dim); }
.hi { color: var(--fg-hi); }
.warn { color: var(--warn); }
.red { color: var(--red); }
.blink { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cursor::after { content: '█'; animation: blink 1s steps(1) infinite; margin-left: 2px; }
pre.ascii { margin: 0; line-height: 1.05; font-size: 15px; color: var(--fg-hi); overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; }

.box { border: 1px solid var(--line); background: var(--panel); padding: 12px 14px; margin: 12px 0; position: relative; }
.box > .box-title { position: absolute; top: -12px; left: 10px; background: var(--bg); padding: 0 6px; color: var(--fg-dim); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

.btn {
  font-family: var(--font); font-size: 20px; color: var(--fg); background: transparent;
  border: 1px solid var(--fg-dim); padding: 3px 12px; cursor: pointer; text-shadow: var(--glow);
}
.btn:hover:not(:disabled), .btn:focus-visible { background: var(--fg); color: var(--bg); text-shadow: none; outline: none; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.big { font-size: 26px; padding: 6px 22px; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.danger:hover:not(:disabled) { background: var(--red); color: #000; }
.btn.small { font-size: 17px; padding: 0 8px; }
.btn.on { background: var(--fg-faint); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

input, textarea, select {
  font-family: var(--font); font-size: 20px; color: var(--fg-hi); background: #000;
  border: 1px solid var(--line); padding: 4px 8px; width: 100%; text-shadow: var(--glow);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--fg); }
label { display: block; margin: 10px 0 4px; color: var(--fg-dim); }
.form { max-width: 460px; }
.msg { margin: 10px 0; padding: 4px 8px; border-left: 3px solid var(--fg); }
.msg.err { border-color: var(--red); color: var(--red); }
.msg.ok { border-color: var(--fg); }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 3px 8px; border-bottom: 1px dotted var(--fg-faint); white-space: nowrap; }
.tbl th { color: var(--fg-dim); font-weight: normal; border-bottom: 1px solid var(--line); }
.tbl tr:hover td { background: rgba(255, 255, 255, 0.03); }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl-wrap { overflow-x: auto; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 8px 0 14px; }
.tabs .btn.active { background: var(--fg); color: var(--bg); text-shadow: none; }

.kbd { border: 1px solid var(--fg-dim); padding: 0 5px; color: var(--fg-hi); }
.bar { white-space: pre; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 70px; }
.spark div { flex: 1; background: var(--fg-dim); min-height: 2px; box-shadow: var(--glow); }

/* home */
.boot { color: var(--fg-dim); min-height: 150px; white-space: pre-wrap; font-size: 18px; }
.motd { border-left: 3px solid var(--fg); padding-left: 10px; }
.stats-line { display: flex; gap: 26px; flex-wrap: wrap; }
.stats-line b { color: var(--fg-hi); font-weight: normal; font-size: 30px; display: block; }

/* difficulty cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin: 16px 0; }
.card { border: 1px solid var(--line); padding: 12px; cursor: pointer; background: var(--panel); text-align: left; font: inherit; color: inherit; text-shadow: inherit; }
.card:hover, .card.sel, .card:focus-visible { border-color: var(--fg); background: var(--fg-faint); outline: none; }
.card .tag { color: var(--fg-dim); font-size: 16px; }
.card h3 { margin: 4px 0; }
.card.panic h3 { color: var(--red); }

/* manual */
.manual dt { color: var(--fg-hi); margin-top: 8px; }
.manual dd { margin: 0 0 4px 20px; color: var(--fg); }
.nato { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 14px; }
.toc a { margin-right: 14px; }

/* ===================== GAME ===================== */
.game {
  display: grid;
  grid-template-rows: auto 1fr minmax(190px, 30vh);
  height: calc(100vh - 46px);
  min-height: 600px;
  font-size: 18px;
}
.g-top {
  display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center;
  padding: 4px 10px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.g-top .cell { color: var(--fg-dim); white-space: nowrap; }
.g-top .cell b { color: var(--fg-hi); font-weight: normal; }
.g-top .metar { color: var(--fg); flex: 1; min-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: help; }
.g-top .ctrl { display: flex; gap: 4px; }
.strikes .x { color: var(--red); }
.g-main { display: grid; grid-template-columns: 1fr minmax(300px, 380px); min-height: 0; }
.g-radar { position: relative; min-height: 0; overflow: hidden; border-right: 1px solid var(--line); background: #000; }
.g-radar canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.g-side { display: flex; flex-direction: column; min-height: 0; }
.panel { border-bottom: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.ptitle { padding: 1px 8px; color: var(--bg); background: var(--fg-dim); text-shadow: none; display: flex; justify-content: space-between; gap: 8px; }
.ptitle .st-clear { color: var(--bg); }
.ptitle .st-occ { background: var(--red); color: #000; padding: 0 6px; animation: blink 0.8s steps(1) infinite; }
.ground-wrap { position: relative; aspect-ratio: 2.1 / 0.95; width: 100%; background: #000; }
.ground-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.strips { flex: 1; overflow-y: auto; padding: 4px 6px; }
.bay-title { color: var(--fg-dim); margin: 6px 0 2px; font-size: 16px; letter-spacing: 1px; }
.strip {
  display: grid; grid-template-columns: 6px 1fr auto; gap: 0 8px; margin: 3px 0;
  border: 1px solid var(--line); background: #000; cursor: pointer; font-size: 17px; line-height: 1.1;
}
.strip .rail { background: var(--arr); box-shadow: var(--glow); }
.strip.dep .rail { background: var(--dep); }
.strip .main { padding: 2px 0; }
.strip .cs { color: var(--fg-hi); font-size: 20px; }
.strip.dep .cs { color: var(--dep); }
.strip .meta { color: var(--fg-dim); }
.strip .right { text-align: right; padding: 2px 6px 2px 0; }
.strip .flags { color: var(--fg-hi); }
.strip.sel { border-color: var(--fg-hi); background: var(--fg-faint); }
.strip.calling .cs::after { content: ' ◄CALL'; color: var(--warn); animation: blink 0.9s steps(1) infinite; font-size: 16px; }
.strip.emerg { border-color: var(--red); }
.strip.emerg .cs { color: var(--red); }
.strip.handed { opacity: 0.4; }
.strip.stca { border-color: var(--red); animation: blink 0.6s steps(1) infinite; }
.g-bottom { display: grid; grid-template-columns: 1fr minmax(340px, 520px); min-height: 0; border-top: 1px solid var(--line); }
.comms { border-right: 1px solid var(--line); }
.log { flex: 1; overflow-y: auto; padding: 4px 8px; font-size: 18px; }
.log .ln { margin: 1px 0; cursor: pointer; }
.log .ln .ts { color: var(--fg-dim); opacity: 0.6; margin-right: 6px; }
.log .ln.atc { color: var(--cyan); }
.log .ln.pilot { color: var(--fg); }
.log .ln.mayday { color: var(--red); }
.log .ln.system { color: var(--warn); }
.log .ln .who { color: var(--fg-hi); }
.log .ln.atc .who { color: var(--cyan); }
.cmds { flex: 1; overflow-y: auto; padding: 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 5px; align-content: start; }
.cmd {
  font-family: var(--font); font-size: 18px; text-align: left; color: var(--fg); background: #000;
  border: 1px solid var(--line); padding: 4px 8px; cursor: pointer; text-shadow: var(--glow);
}
.cmd .k { color: var(--bg); background: var(--fg-dim); padding: 0 5px; margin-right: 6px; text-shadow: none; }
.cmd:hover:not(:disabled) { border-color: var(--fg-hi); background: var(--fg-faint); }
.cmd.hot { border-color: var(--fg); color: var(--fg-hi); }
.cmd.hot .k { background: var(--fg); }
.cmd.danger { color: var(--red); border-color: #5a1515; }
.cmd.danger .k { background: var(--red); }
.cmd.neg { color: var(--warn); border-color: var(--warn); grid-column: 1 / -1; }
.cmd.neg .k { background: var(--warn); }
.cmd:disabled { opacity: 0.3; cursor: default; }
.cmd-info { grid-column: 1 / -1; color: var(--fg-dim); padding: 6px; }
.toasts { position: absolute; top: 8px; right: 10px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; pointer-events: none; z-index: 5; }
.toast { background: rgba(0, 0, 0, 0.8); border: 1px solid var(--fg-dim); padding: 1px 8px; animation: toast 4.5s forwards; font-size: 18px; }
.toast.penalty { color: var(--warn); border-color: var(--warn); }
.toast.strike { color: #000; background: var(--red); border-color: var(--red); text-shadow: none; font-size: 22px; }
.toast.bonus { color: var(--cyan); border-color: var(--cyan); }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 6% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
.hintbox { position: absolute; left: 10px; bottom: 10px; right: 10px; max-width: 640px; background: rgba(0, 0, 0, 0.85); border: 1px dashed var(--cyan); color: var(--cyan); padding: 4px 10px; z-index: 4; cursor: pointer; }
.spdmenu { position: absolute; z-index: 7; background: rgba(0, 0, 0, 0.92); border: 1px solid var(--cyan); display: flex; flex-direction: column; min-width: 120px; max-height: calc(100% - 12px); overflow-y: auto; }
.spdmenu-t { color: var(--cyan); padding: 1px 8px; border-bottom: 1px solid var(--cyan); }
.spdmenu button { font-family: var(--font); font-size: 18px; text-align: left; color: var(--fg); background: transparent; border: 0; padding: 1px 8px; cursor: pointer; }
.spdmenu button:hover { background: var(--fg-faint); color: var(--fg-hi); }
.spdmenu button.cur { color: var(--cyan); }
.spdmenu button.cur::after { content: ' ◄'; }
.radar-info { position: absolute; left: 10px; top: 8px; color: var(--fg-dim); font-size: 16px; pointer-events: none; z-index: 3; line-height: 1.15; }
.flash-red { animation: flashred 0.7s 2; }
@keyframes flashred { 0%, 100% { box-shadow: inset 0 0 0 0 transparent; } 50% { box-shadow: inset 0 0 80px 10px rgba(255, 0, 0, 0.55); } }
.paused-banner { position: absolute; top: 40%; left: 0; right: 0; text-align: center; font-size: 46px; color: var(--fg-hi); z-index: 6; pointer-events: none; }

.overlay { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.88); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.overlay .dialog { border: 1px solid var(--fg); background: var(--bg); padding: 16px 22px; max-width: 760px; width: 100%; max-height: 100%; overflow-y: auto; }
.report pre { margin: 0; white-space: pre-wrap; font-family: var(--font); font-size: 20px; }

@media (max-width: 900px) {
  .game { height: auto; grid-template-rows: auto auto auto; }
  .g-main { grid-template-columns: 1fr; }
  .g-radar { height: 62vh; border-right: 0; }
  .g-bottom { grid-template-columns: 1fr; }
  .comms .log { max-height: 30vh; }
  .strips { max-height: 40vh; }
  .cmds { grid-template-columns: 1fr; }
  body { font-size: 18px; }
}
