:root {
  --bg: #0a0c0f;
  --board: #12151a;
  --panel: #14181d;
  --line: #23282f;
  --ink: #ece7d9;
  --amber: #ffb84d;
  --dim: #6f7680;
  --phos: #39e07a;
  --ok: #3dbb6e;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(120% 120% at 50% 0%, #12161c 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  -webkit-tap-highlight-color: transparent;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

/* the whole thing is an app shell: it fills the screen and never scrolls
   as a page — the strip bay and timetable scroll inside themselves */
.game {
  max-width: 1280px;
  height: 100%;
  margin: 0 auto;
  padding: clamp(8px, 2vw, 20px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 10px;
  flex-wrap: wrap;
  flex: none;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--dim);
  font: inherit;
  font-size: clamp(11px, 1.4vw, 13px);
  letter-spacing: 0.18em;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

.tab:hover { border-color: var(--amber); color: var(--amber); }

.tab.active {
  color: var(--amber);
  border-color: var(--amber);
  background: rgba(255, 184, 77, 0.08);
  text-shadow: 0 0 14px rgba(255, 184, 77, 0.4);
}

.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.hdr-clock {
  color: var(--amber);
  letter-spacing: 0.14em;
  font-size: clamp(12px, 1.8vw, 18px);
  text-shadow: 0 0 16px rgba(255, 184, 77, 0.35);
  white-space: nowrap;
  flex: none;
}

#hub, #tz, #speed {
  appearance: none;
  -webkit-appearance: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--amber);
  font: inherit;
  font-size: 13px;
  padding: 10px 12px;
  min-height: 44px;
  cursor: pointer;
  letter-spacing: 0.06em;
  touch-action: manipulation;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

#hub { min-width: 0; flex: 1 1 auto; max-width: 260px; }
#speed { flex: none; min-width: 52px; text-align: center; }
#tz { flex: none; }

#hub:hover, #hub:focus, #tz:hover, #tz:focus, #speed:hover { border-color: var(--amber); outline: none; }
#hub option, #tz option { color: #22252a; background: #fff; }

/* ---------- radio ticker ---------- */

#radio {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--board);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 42px;
  font-size: clamp(11px, 1.5vw, 13px);
  color: var(--phos);
  overflow: hidden;
  white-space: nowrap;
}

.radio-tag {
  color: var(--dim);
  letter-spacing: 0.24em;
  font-size: 10px;
  flex: none;
}

#radio-text { overflow: hidden; text-overflow: ellipsis; }

#radio-text .who {
  color: var(--amber);
  font-weight: 700;
  margin-right: 6px;
}

#radio-text .who.atc { color: #7fd4e8; }

#radio-text.flash { animation: radioflash 0.5s ease-out; }

@keyframes radioflash {
  0% { opacity: 0.2; }
  100% { opacity: 1; }
}

/* ---------- layout ---------- */

.layout {
  display: flex;
  gap: 14px;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}

.mainarea {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pane {
  display: none;
  flex: 1;
  min-height: 0;
}

.pane.active { display: flex; }

/* approach radar: a square tube, sized in resize() to the largest square
   that fits whatever room is left over */
#pane-app .scope-wrap {
  width: 100%;
  height: 100%;
  margin: auto;
  position: relative;
  background: var(--board);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow:
    inset 0 0 70px rgba(0, 0, 0, 0.65),
    0 24px 70px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

#scope {
  position: absolute;
  inset: 0;
  margin: auto;
  cursor: crosshair;
  touch-action: manipulation;
}

#pane-app .scope-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.14) 0px,
      rgba(0, 0, 0, 0.14) 1px,
      transparent 1px,
      transparent 3px
    ),
    radial-gradient(90% 90% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.5) 100%);
}

/* ground radar */
#pane-ground {
  position: relative;
  background: var(--board);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

#groundc {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  touch-action: manipulation;
}

/* timetable */
#pane-time {
  background: var(--board);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* an ID beats .pane's display:none, so hiding has to be stated here too */
#pane-time { display: none; }
#pane-time.active { display: block; }

.timetable {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.tt-head {
  color: var(--amber);
  letter-spacing: 0.3em;
  font-size: 13px;
  padding: 4px 6px 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
  text-shadow: 0 0 14px rgba(255, 184, 77, 0.3);
}

.tt-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 6px;
  border-bottom: 1px solid rgba(35, 40, 47, 0.6);
  cursor: pointer;
}

.tt-row:hover { background: rgba(255, 255, 255, 0.02); }
.tt-row.sel { background: rgba(255, 184, 77, 0.07); }

.tt-time {
  color: var(--amber);
  font-size: clamp(14px, 1.8vw, 18px);
  letter-spacing: 0.06em;
  min-width: 52px;
}

.tt-mid { flex: 1; min-width: 0; }

.tt-cs { font-weight: 700; font-size: clamp(13px, 1.6vw, 16px); letter-spacing: 0.06em; }
.tt-type { color: #7fd4e8; font-size: 12px; margin-left: 8px; }
.tt-place { color: #d8c98a; font-size: 11px; letter-spacing: 0.06em; margin-top: 2px; }
.tt-airline { color: var(--dim); font-size: 10px; margin-top: 1px; }

/* ---------- sidebar ---------- */

.sidebar {
  width: 300px;
  flex: none;
  background: var(--board);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
}

.sect-head {
  color: var(--amber);
  letter-spacing: 0.22em;
  font-size: 11px;
  padding: 10px 6px 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
  text-shadow: 0 0 12px rgba(255, 184, 77, 0.3);
}

.empty { color: #3a414c; padding: 6px 8px 10px; }

.fcard {
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: auto auto;
  gap: 4px 10px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  margin-bottom: 4px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.fcard:hover { border-color: var(--line); }
.fcard.sel { border-color: var(--amber); background: rgba(255, 184, 77, 0.06); }

.alogo {
  grid-row: 1 / 3;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.06em;
  flex: none;
}

.alogo.img { background: #fff; padding: 4px; }
.alogo.img img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }

.tt-logo { width: 36px; height: 36px; font-size: 12px; grid-row: auto; }

.fmain { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.fcs { font-weight: 700; font-size: 15px; letter-spacing: 0.06em; }
.ftype { color: #7fd4e8; font-size: 12px; }

.fchips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  font-size: 10px;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.chip.act { background: rgba(255, 184, 77, 0.16); color: var(--amber); border: 1px solid rgba(255, 184, 77, 0.4); }
.chip.ok { background: rgba(61, 187, 110, 0.14); color: var(--ok); border: 1px solid rgba(61, 187, 110, 0.4); }

/* ---------- controls ---------- */

.controls {
  display: none;
  gap: 8px;
  flex-wrap: wrap;
  flex: none;
}

body.tab-app .controls { display: flex; }

.controls button {
  background: #1a1f26;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  letter-spacing: 0.06em;
  touch-action: manipulation;
}

.controls button:hover { border-color: var(--amber); color: var(--amber); }

.controls button[aria-pressed="true"] {
  border-color: var(--amber);
  color: var(--amber);
  background: rgba(255, 184, 77, 0.07);
}

/* ---------- phones & small tablets (portrait) ---------- */

@media (max-width: 820px) {
  .game { padding: 8px; gap: 8px; }

  /* tabs get their own scrollable row, the panel controls get the next */
  .tabs { flex: 1 1 100%; }
  .tab { padding: 9px 12px; letter-spacing: 0.1em; font-size: 12px; }

  .top-right { width: 100%; gap: 6px; }
  #hub { max-width: none; }
  #hub, #tz, #speed { font-size: 12px; padding: 9px 10px; min-height: 40px; }
  #tz { max-width: 104px; }
  .hdr-clock { font-size: 12px; letter-spacing: 0.06em; margin-left: auto; }

  .layout { flex-direction: column; gap: 8px; }

  /* the radar keeps the top half, the strip bay lives below and scrolls */
  .mainarea { flex: 1 1 auto; }
  .sidebar {
    width: 100%;
    flex: 0 1 auto;
    height: 32dvh;
    min-height: 116px;
  }

  /* one tidy scrolling row instead of two wrapped ones */
  .controls {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .controls::-webkit-scrollbar { display: none; }
  .controls button {
    flex: none;
    padding: 9px 12px;
    min-height: 42px;
    font-size: 12px;
    white-space: nowrap;
  }

  #radio { padding: 8px 10px; min-height: 38px; }

  .timetable { grid-template-columns: 1fr; gap: 10px; }
  .tt-row { gap: 8px; padding: 8px 4px; }
  .tt-time { min-width: 44px; }

  .fcard { grid-template-columns: 38px 1fr; padding: 7px 6px; }
  .alogo { width: 38px; height: 38px; font-size: 12px; }
}

/* ---------- landscape phones: wide but very short ---------- */

@media (max-height: 520px) and (orientation: landscape) {
  .game { padding: 6px; gap: 6px; }
  .layout { flex-direction: row; gap: 8px; }
  .mainarea { flex: 1 1 auto; }
  .sidebar { width: 240px; height: auto; flex: none; }
  .tabs { flex: 0 1 auto; }
  .tab { padding: 7px 10px; min-height: 36px; font-size: 11px; }
  #hub, #tz, #speed { min-height: 36px; padding: 7px 10px; font-size: 12px; }
  .top-right { width: auto; }
  .controls button { min-height: 36px; padding: 7px 10px; }
  #radio { min-height: 32px; padding: 5px 10px; }
}
