/* ═══════════════════════════════════════════════════════════
   ATC Tower module — a dark, high-contrast tower display. Three themes
   (green phosphor / amber / clean modern) are just sets of --atc-* variables
   switched by data-theme on #module-atc; the canvas reads the same variables,
   so CSS is the single source of truth for colour. Isolated to #module-atc and
   the .atc-modal-* sheets appended to <body>.
   ═══════════════════════════════════════════════════════════ */
#module-atc,
.atc-modal-backdrop {
  --atc-bg: #000; --atc-panel: #06140a; --atc-line: #12421f;
  --atc-text: #7dffa0; --atc-dim: #3f9d58; --atc-accent: #b8ffc9;
  --atc-blip: #9dffb5; --atc-ground: #3f9d58; --atc-mil: #ffd24a;
  --atc-emerg: #ff4d4d; --atc-sweep: #37ff6b; --atc-rwy: #b8ffc9;
  --atc-font: 'Share Tech Mono', 'Courier New', monospace;
}
#module-atc[data-theme="amber"], .atc-modal-backdrop[data-theme="amber"] {
  --atc-bg: #000; --atc-panel: #160d00; --atc-line: #4a3000;
  --atc-text: #ffb000; --atc-dim: #a06c00; --atc-accent: #ffd36b;
  --atc-blip: #ffc233; --atc-ground: #a06c00; --atc-mil: #4de1ff;
  --atc-emerg: #ff3b3b; --atc-sweep: #ffa200; --atc-rwy: #ffd36b;
}
#module-atc[data-theme="modern"], .atc-modal-backdrop[data-theme="modern"] {
  --atc-bg: #000; --atc-panel: #0d141d; --atc-line: #26364d;
  --atc-text: #e6eef9; --atc-dim: #7f93ad; --atc-accent: #5fd0ff;
  --atc-blip: #5fd0ff; --atc-ground: #5d718a; --atc-mil: #ffb347;
  --atc-emerg: #ff5470; --atc-sweep: #5fd0ff; --atc-rwy: #ffffff;
}

/* While this screen is showing, the whole page goes black and edge-to-edge
   (the other modules sit in a padded 600px column on a light page). */
html:has(#module-atc:not([style*="none"])),
body:has(#module-atc:not([style*="none"])) { background: #000; }
.app-container:has(#module-atc:not([style*="none"])) { max-width: none; padding: 0; background: #000; }

#module-atc {
  background: var(--atc-bg);
  color: var(--atc-text);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  font-family: var(--atc-font);
  border-radius: 0;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}
/* header: faint panel tint + a thin theme-coloured rule, square corners, so it reads as a
   separate bar over the black scope without a white band */
#module-atc .mod-header { --mod-header-accent: var(--atc-text); background: var(--atc-panel); border: 0; border-bottom: 1px solid var(--atc-text); border-radius: 0; margin: 0; }
#module-atc .mod-header-title { color: var(--atc-text); font-family: var(--atc-font); letter-spacing: 0.12em; text-transform: uppercase; }
#module-atc .mod-header-status { color: var(--atc-dim); font-family: var(--atc-font); }
#module-atc .mod-header-status.atc-bad { color: var(--atc-emerg); }

.atc-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; flex-wrap: wrap;
}
.atc-airport-btn {
  display: flex; align-items: baseline; gap: 8px; min-height: 44px; padding: 0 14px;
  background: var(--atc-panel); color: var(--atc-text); border: 1px solid var(--atc-line);
  border-radius: 10px; font-family: var(--atc-font); font-size: 15px; cursor: pointer;
  max-width: 100%; min-width: 0;
}
.atc-airport-btn b { font-size: 18px; letter-spacing: 0.08em; }
.atc-airport-btn span { color: var(--atc-dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.atc-chips { display: flex; gap: 6px; margin-left: auto; }
.atc-chip {
  min-width: 44px; min-height: 44px; padding: 0 10px; background: transparent;
  color: var(--atc-dim); border: 1px solid var(--atc-line); border-radius: 10px;
  font-family: var(--atc-font); font-size: 14px; cursor: pointer;
}
.atc-chip.on { color: var(--atc-bg); background: var(--atc-text); border-color: var(--atc-text); }

.atc-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.atc-scope-wrap { position: relative; flex: 1; min-height: 0; }
.atc-scope-wrap canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
.atc-side {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 8px 12px; border-top: 1px solid var(--atc-line);
}
.atc-summary { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.atc-tog {
  min-height: 44px; padding: 0 12px; background: transparent; color: var(--atc-dim);
  border: 1px solid var(--atc-line); border-radius: 10px; font-family: var(--atc-font);
  font-size: 13px; cursor: pointer; opacity: 0.55;
}
.atc-tog b { color: var(--atc-dim); font-size: 16px; margin-right: 5px; }
.atc-tog.on { opacity: 1; color: var(--atc-text); border-color: var(--atc-text); }
.atc-tog.on b { color: var(--atc-text); }
.atc-tog.mil.on { border-color: var(--atc-mil); } .atc-tog.mil.on b, .atc-tog.mil.on { color: var(--atc-mil); }
.atc-tog.emerg.on { border-color: var(--atc-emerg); } .atc-tog.emerg.on b, .atc-tog.emerg.on { color: var(--atc-emerg); }
.atc-btn {
  min-height: 44px; padding: 0 16px; background: var(--atc-panel); color: var(--atc-text);
  border: 1px solid var(--atc-line); border-radius: 10px; font-family: var(--atc-font);
  font-size: 14px; cursor: pointer;
}
.atc-btn.primary { background: var(--atc-text); color: var(--atc-bg); border-color: var(--atc-text); }

@media (orientation: landscape) and (min-width: 700px) {
  .atc-main { flex-direction: row; }
  .atc-side {
    width: 300px; flex-direction: column; align-items: stretch; justify-content: flex-start;
    border-top: 0; border-left: 1px solid var(--atc-line); overflow-y: auto;
  }
}

/* loud failure banner over the scope */
.atc-banner {
  position: absolute; top: 8px; left: 8px; right: 8px; z-index: 3; text-align: left;
  padding: 10px 12px; background: rgba(40, 0, 0, 0.92); color: #ffb4b4;
  border: 1px solid var(--atc-emerg); border-radius: 10px; font-family: var(--atc-font);
  font-size: 13px; line-height: 1.35; cursor: pointer;
}
.atc-banner[hidden] { display: none; }
.atc-banner b { color: #fff; }

/* selected-aircraft card */
.atc-card {
  position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 2; max-width: 420px;
  padding: 12px 14px; background: color-mix(in srgb, var(--atc-panel) 94%, transparent);
  border: 1px solid var(--atc-line); border-radius: 12px; font-size: 13px;
  max-height: 64%; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.atc-card[hidden] { display: none; }
.atc-card-top { display: flex; align-items: flex-start; gap: 10px; }
.atc-card-title { font-size: 20px; letter-spacing: 0.06em; color: var(--atc-accent); }
.atc-card-sub { color: var(--atc-dim); font-size: 12px; margin-top: 2px; }
.atc-card-close {
  margin-left: auto; width: 44px; height: 44px; margin-top: -8px; margin-right: -8px;
  background: transparent; border: 0; color: var(--atc-dim); font-size: 26px; cursor: pointer;
}
.atc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 12px; margin-top: 10px; }
.atc-grid div span { display: block; color: var(--atc-dim); font-size: 10px; letter-spacing: 0.1em; }
.atc-grid div b { font-size: 16px; font-weight: 600; }
.atc-tag { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; margin-left: 6px; color: var(--atc-bg); }
.atc-tag.mil { background: var(--atc-mil); }
.atc-tag.emerg { background: var(--atc-emerg); color: #fff; }

.atc-route { margin-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.atc-route b { font-size: 18px; letter-spacing: 0.06em; color: var(--atc-text); }
.atc-route span, .atc-opline { color: var(--atc-dim); font-size: 12px; }
.atc-opline { margin-top: 6px; }
.atc-photo { margin: 10px 0 0; }
.atc-photo img { display: block; width: 100%; max-height: 150px; object-fit: cover; border-radius: 8px; background: var(--atc-bg); }
.atc-photo figcaption { margin-top: 4px; font-size: 11px; }
.atc-photo a { color: var(--atc-dim); text-decoration: underline; }

.atc-side-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.atc-sqk { display: inline-block; text-align: center; padding: 2px 0; border-radius: 6px; color: #fff !important; background: var(--atc-emerg); font-size: 14px !important; }
.atc-sqk.radio { background: var(--atc-mil); color: var(--atc-bg) !important; }

/* modals (appended to <body>) */
.atc-modal-backdrop {
  position: fixed; inset: 0; z-index: 2000; background: rgba(0, 0, 0, 0.78);
  display: flex; align-items: flex-start; justify-content: center; /* top-anchored so the keyboard never covers it */
  font-family: var(--atc-font);
}
.atc-modal-sheet {
  width: 100%; max-width: 560px; max-height: calc(100% - 24px); margin-top: 12px; display: flex; flex-direction: column;
  background: var(--atc-bg); color: var(--atc-text); border: 1px solid var(--atc-line);
  border-radius: 16px; padding: 14px 16px;
  box-sizing: border-box;
}
.atc-modal-head { display: flex; align-items: center; margin-bottom: 10px; }
.atc-modal-head h2 { margin: 0; font-size: 18px; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 400; }
.atc-modal-close { margin-left: auto; width: 44px; height: 44px; background: transparent; border: 0; color: var(--atc-dim); font-size: 28px; cursor: pointer; }
.atc-modal-body { overflow-y: auto; flex: 1; min-height: 0; }
.atc-input {
  width: 100%; box-sizing: border-box; min-height: 48px; padding: 0 14px; font-size: 18px;
  background: var(--atc-panel); color: var(--atc-text); border: 1px solid var(--atc-line);
  border-radius: 10px; font-family: var(--atc-font); text-transform: uppercase; margin-bottom: 8px;
}
.atc-list { display: flex; flex-direction: column; }
.atc-row {
  display: flex; align-items: baseline; gap: 10px; min-height: 48px; padding: 8px 6px; width: 100%;
  background: transparent; color: var(--atc-text); border: 0; border-bottom: 1px solid var(--atc-line);
  text-align: left; font-family: var(--atc-font); cursor: pointer; font-size: 14px;
}
.atc-row b { width: 52px; flex: none; font-size: 16px; color: var(--atc-accent); }
.atc-row span { color: var(--atc-dim); font-size: 12px; }
.atc-note { color: var(--atc-dim); font-size: 12px; padding: 6px 2px; line-height: 1.4; }
.atc-note.bad { color: #ffb4b4; }
.atc-credits a { color: var(--atc-text); }
.atc-opt { display: flex; align-items: center; gap: 8px; margin: 8px 0 14px; flex-wrap: wrap; }
.atc-opt > label { flex: 1 1 100%; color: var(--atc-dim); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; }

/* diagnostics */
.atc-diag-item { border: 1px solid var(--atc-line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; font-size: 12px; }
.atc-diag-item .h { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.atc-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--atc-dim); flex: none; }
.atc-dot.ok { background: #3ddc84; } .atc-dot.fail { background: var(--atc-emerg); } .atc-dot.loading { background: #ffd24a; }
.atc-diag-item .m { color: var(--atc-dim); margin-top: 4px; word-break: break-all; }
.atc-diag-item .m.bad { color: #ffb4b4; }
.atc-diag-item pre { margin: 6px 0 0; white-space: pre-wrap; word-break: break-all; color: var(--atc-dim); font-size: 11px; max-height: 90px; overflow: auto; }

@media (prefers-reduced-motion: reduce) { .atc-card, .atc-banner { transition: none; } }
