:root {
  --bg: #0b0c0e;
  --surface: #141619;
  --surface-2: #1b1e22;
  --line: #24272c;
  --text: #ecebe7;
  --muted: #8b9099;
  --faint: #5d626b;
  --accent: #ffd23f; /* the one accent: departure-board yellow */

  --ok: #3ccf7a;
  --ok-bg: rgba(60, 207, 122, 0.12);
  --warn: #ff9f1c;
  --warn-bg: rgba(255, 159, 28, 0.14);
  --done: #9aa0a8;
  --done-bg: rgba(154, 160, 168, 0.12);
  --bad: #ff5a5f;
  --bad-bg: rgba(255, 90, 95, 0.14);

  /* Terminal colours: distinct hues, all >= 7:1 on --bg, kept clear of the
     status colours (green/amber/grey/red) and the yellow accent. */
  --t1: #6cb6ff; /* blue */
  --t2: #c4a2ff; /* violet */
  --t3: #ff8fbd; /* pink */
  --t4: #4fd8c8; /* teal */
  --seletar: #7ee787; /* Seletar on the Tracker: green, apart from Changi's yellow */

  --radius: 10px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------ header */
.top {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(11, 12, 14, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-weight: 650; letter-spacing: 0.01em; }
.brand-sub { color: var(--muted); font-size: 12px; letter-spacing: 0.06em; }

.tabs { display: flex; gap: 2px; background: var(--surface); border-radius: 999px; padding: 3px; }
.tab {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px;
  color: var(--muted); font-size: 14px; font-weight: 550;
}
.tab[aria-selected="true"] { background: var(--text); color: var(--bg); }

main { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 760px; margin: 0 auto; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ------------------------------------------------------------ controls */
.controls { padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 999px;
  color: var(--muted); font-size: 14px; white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.seg-date button[aria-pressed="true"] { color: var(--accent); }

.search {
  width: 100%; padding: 11px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  outline: none; font-size: 16px; /* 16px stops iOS zoom */
}
.search::placeholder { color: var(--faint); }
.search:focus { border-color: var(--faint); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .chip-saved { display: inline-flex; align-items: center; gap: 5px; }
.chips button[data-term="saved"] { --tc: var(--accent); }
.chip-saved svg { width: 13px; height: 13px; }
.chip-count { font-variant-numeric: tabular-nums; font-weight: 600; }
.chips button {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 4px 12px; font-size: 13px; color: var(--muted);
}
.chips button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.chips button[data-term="1"] { --tc: var(--t1); }
.chips button[data-term="2"] { --tc: var(--t2); }
.chips button[data-term="3"] { --tc: var(--t3); }
.chips button[data-term="4"] { --tc: var(--t4); }
.chips button[data-term]:not([data-term="all"]) { color: var(--tc); }
.chips button[data-term]:not([data-term="all"])[aria-pressed="true"] {
  border-color: var(--tc); color: var(--bg); background: var(--tc); font-weight: 600;
}

/* Wing sub-pills under T1-T3 ("All T1 · West · East"), in the terminal's colour. */
.controls > .chips-wing { margin-top: -4px; }
.chips.chips-wing button { color: var(--tc); border-color: var(--line); }
.chips.chips-wing button[aria-pressed="true"] { border-color: var(--tc); background: var(--tc); color: var(--bg); font-weight: 600; }

/* "Standby N": red, with a slow pulse (solid red under reduced motion, see the end of the file). */
.chips button.chip-standby[data-term="standby"],
.chips button.chip-standby[data-term="standby"][aria-pressed="true"] {
  display: inline-flex; align-items: center; gap: 5px;
  border-color: var(--bad); background: var(--bad); color: var(--bg); font-weight: 650;
  animation: sq-pulse-bg 1.5s ease-in-out infinite;
}
.chips button.chip-standby[data-term="standby"][aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 2px; }
@keyframes sq-pulse-bg {
  0%, 100% { background-color: #ff5a5f; box-shadow: 0 0 0 0 rgba(255, 90, 95, 0.55); }
  50% { background-color: #c9383d; box-shadow: 0 0 0 5px rgba(255, 90, 95, 0); }
}

/* Changi | Seletar on the Board (same look as the Tracker's airport buttons). */
.seg-airport button[data-airport="sin"][aria-pressed="true"] { color: var(--accent); }
.seg-airport button[data-airport="xsp"][aria-pressed="true"] { color: var(--seletar); }
.f-term.xsp, .kv dd .xsp { color: var(--seletar); }
.xsp-note { margin: -4px 0 0; color: var(--muted); font-size: 12px; }
.xsp-note::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: var(--seletar); vertical-align: 0; }
body[data-airport="xsp"] .col-head { color: var(--seletar); }

.refresh-group { display: flex; align-items: center; gap: 2px; margin-left: auto; min-width: 0; }
.updated { margin: 0; color: var(--faint); font-size: 12px; text-align: right; }

.intro { margin: 0; padding: 14px 16px 0; color: var(--muted); font-size: 14px; line-height: 1.45; text-wrap: balance; }

/* Auto-refresh: a soft ring around the icon, once. */
.refresh-btn.pulse { animation: refresh-pulse 1.2s ease-out 1; }
@keyframes refresh-pulse {
  0% { color: var(--accent); box-shadow: 0 0 0 0 rgba(255, 210, 63, 0.35); }
  60% { color: var(--accent); box-shadow: 0 0 0 8px rgba(255, 210, 63, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 210, 63, 0); }
}

.map-note.map-loading { display: flex; align-items: center; gap: 8px; color: var(--text); top: 50%; transform: translate(-50%, -50%); }
.dot-spin {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.c-cs.c-unknown { color: var(--muted); font-family: var(--sans); font-size: 18px; }

/* Refresh: a 44 px tap target around an 18 px icon. */
.refresh-btn {
  flex: none; display: grid; place-items: center;
  width: 44px; height: 44px; margin: -8px -10px -8px 0; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted);
}
.refresh-btn svg { width: 18px; height: 18px; }
.refresh-btn:hover { color: var(--text); background: var(--surface); }
.refresh-btn:disabled { cursor: progress; }
.refresh-btn.spinning { color: var(--accent); }
.refresh-btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* The same button as a Leaflet map control on the Tracker tab. */
.leaflet-bar .map-refresh {
  width: 44px; height: 44px; margin: 0; border-radius: 4px;
  background: var(--surface); color: var(--text);
}
.leaflet-bar .map-refresh:hover { background: var(--surface-2); }
.updated .stale { color: var(--warn); }

/* ------------------------------------------------------------ board */
.board { padding: 4px 0 8px; }
.empty { color: var(--muted); text-align: center; padding: 48px 16px; margin: 0; }
.empty.error { color: var(--bad); }

.more {
  display: block; width: calc(100% - 32px); margin: 4px 16px 8px; padding: 9px;
  border: 1px dashed var(--line); border-radius: var(--radius); background: transparent;
  color: var(--muted); font-size: 13px;
}

.flight { border-bottom: 1px solid var(--line); }
.flight:first-of-type { border-top: 1px solid var(--line); }
.f-row {
  width: 100%; border: 0; background: transparent; text-align: left;
  display: grid; align-items: center; column-gap: 10px;
  grid-template-columns: 3.1em auto minmax(0, 1fr) 4.4em auto;
  padding: 12px 16px; min-height: 48px;
}
.f-row:hover { background: var(--surface); }
.f-row { cursor: pointer; }
.f-row { position: relative; }

/* Live marker: a pulsing dot in the left gutter when the plane is on the map. */
.live-tag { display: none; }
.flight.live .live-tag {
  display: block; position: absolute; left: 5px; top: 24px; /* level with the first line, also on taller rows */
  width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%;
  background: var(--accent);
  animation: live-pulse 2s ease-out infinite;
}
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 210, 63, 0.55); }
  70%, 100% { box-shadow: 0 0 0 6px rgba(255, 210, 63, 0); }
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.flight.live .track-btn { background: var(--accent); color: var(--bg); }
.flight.open .f-row { background: var(--surface); }
.f-time { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 15px; color: var(--accent); }
.f-time.changed { color: var(--warn); }
.f-flight { display: flex; align-items: baseline; gap: 6px; min-width: 0; }

/* Favourite star: sits in a slightly wider right gutter (level with the first line),
   so it takes ~12 px from the row instead of a whole column. */
.f-row { padding-right: 28px; }
.fav-btn {
  position: absolute; right: 0; top: 24px; transform: translateY(-50%);
  display: grid; place-items: center;
  width: 28px; height: 40px; padding: 0;
  border: 0; border-radius: 8px; background: transparent; color: var(--faint);
}
.fav-btn svg { width: 15px; height: 15px; }
.fav-btn:hover { color: var(--text); }
.fav-btn[aria-pressed="true"] { color: var(--accent); }

.save-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: transparent; color: var(--text);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600;
}
.save-btn svg { width: 14px; height: 14px; }
.save-btn:hover { border-color: var(--faint); }
.save-btn.saved { border-color: var(--accent); color: var(--accent); }

/* Opened from a share link: a brief highlight. */
.flight.flash .f-row { animation: flash 2.6s ease-out 1; }
@keyframes flash {
  0%, 35% { background: rgba(255, 210, 63, 0.16); box-shadow: inset 3px 0 0 var(--accent); }
  100% { background: var(--surface); box-shadow: inset 3px 0 0 transparent; }
}

/* Standby view: aircraft broadcasting an emergency squawk. */
.sb-intro { margin: 0; padding: 8px 16px 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.sb-item { padding: 12px 16px 14px; border-top: 1px solid var(--line); box-shadow: inset 3px 0 0 var(--bad); }
.sb-item:last-child { border-bottom: 1px solid var(--line); }
.sb-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.sb-cs { font-family: var(--mono); font-size: 17px; font-weight: 650; }
.sb-cs.c-unknown { font-family: var(--sans); font-size: 15px; color: var(--muted); }
.sb-type { color: var(--muted); font-size: 13px; }
.sb-sq {
  margin-left: auto; padding: 1px 8px; border-radius: 999px; background: var(--bad-bg); color: var(--bad);
  font-family: var(--mono); font-size: 12px; font-weight: 650;
}
.sb-meaning { margin: 4px 0 0; color: var(--bad); font-size: 14px; font-weight: 550; }
.sb-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px 16px; margin: 10px 0 12px; }

.saved-head {
  margin: 0; padding: 14px 16px 6px; color: var(--muted);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em;
}

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 2000;
  max-width: calc(100% - 32px); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: 14px; line-height: 1.4; text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.f-fn { font-family: var(--mono); font-weight: 600; font-size: 14px; white-space: nowrap; }
.f-city { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.f-term { color: var(--muted); font-family: var(--mono); font-size: 13px; font-weight: 600; text-align: center; white-space: nowrap; }
.t1 { color: var(--t1); }
.t2 { color: var(--t2); }
.t3 { color: var(--t3); }
.t4 { color: var(--t4); }
.f-term.tbc { color: var(--faint); font-weight: 400; font-size: 11px; }

/* Terminal + gate: side by side on wider screens, stacked on phones. */
.f-where { display: flex; align-items: baseline; justify-content: center; gap: 6px; white-space: nowrap; min-width: 0; }
.f-gate { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.f-gate.changed { color: var(--warn); font-weight: 600; }
.f-note { grid-column: 2 / -1; grid-row: 2; margin-top: 3px; color: var(--warn); font-size: 12px; line-height: 1.3; }
/* Ground handler: muted, on the arrival gate line and in the detail. */
.f-gha { color: var(--muted); font-weight: 400; }
.kv dd .gha-detail { color: var(--muted); }

/* Arrival gate line ("T2 North · Gate E8"): same look as the departure gate label, under flight + city. */
.f-sub { grid-column: 2 / -1; grid-row: 2; margin-top: 3px; line-height: 1.3; }
.f-sub ~ .f-note { grid-row: 3; margin-top: 1px; }
.kv-seats { grid-column: 1 / -1; }
.kv dd .seat-note { display: block; margin-top: 2px; max-width: 48ch; line-height: 1.4; }
.kv dd .gate-was { display: block; margin-top: 2px; color: var(--warn); font-family: var(--sans); font-size: 12px; }

.f-detail.f-getting { padding-top: 12px; border-top: 1px solid var(--line); }
.f-eyebrow {
  grid-column: 1 / -1; margin: 0; color: var(--muted);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em;
}
.kv .k { display: block; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; }
.kv .v { display: block; margin-top: 2px; font-size: 14px; overflow-wrap: anywhere; }

/* Status column: the pill, with a delay tag stacked under it when 15+ min late/early. */
.f-status { justify-self: end; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.delay-tag {
  padding: 0 6px; border-radius: 999px; border: 1px solid; font-size: 11px; font-weight: 600;
  line-height: 1.5; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.delay-tag.late { color: var(--warn); border-color: rgba(255, 159, 28, 0.45); }
.delay-tag.early { color: var(--muted); border-color: var(--line); }

/* Status pill sizes to its text (never truncated); the city column gives way instead. */
.pill {
  justify-self: end;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 550;
  white-space: nowrap;
  color: var(--ok); background: var(--ok-bg);
}
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.done { color: var(--done); background: var(--done-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); }

.f-detail {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px 16px;
  margin: 0; padding: 4px 16px 16px calc(16px + 3.1em + 10px);
  background: var(--surface);
}
.f-actions {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 0 16px 16px calc(16px + 3.1em + 10px); background: var(--surface);
}
.kv { min-width: 0; }
.kv dt { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; }
.kv dd { margin: 2px 0 0; font-size: 14px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kv dd small { color: var(--muted); font-family: var(--sans); font-size: 12px; }

@media (max-width: 460px) {
  .f-row { grid-template-columns: 3em auto minmax(0, 1fr) 2.3em auto; column-gap: 8px; }
  .f-where { flex-direction: column; align-items: center; gap: 1px; line-height: 1.15; }
  .f-gate { font-size: 11px; }
  .pill { font-size: 11px; padding: 2px 6px; }
  .f-detail, .f-actions { padding-left: 16px; }
  .chips { gap: 5px; }
  .chips button { padding: 4px 10px; }
  .seg button { padding: 6px 10px; }
}

/* Tablet / desktop rows: fixed columns so terminal, status pill and star line up from
   row to row, the pill left-aligned in its own column, and one minimum row height.
   The status column spans the gate line, so a delay tag doesn't push that line down.
   Phones (portrait and landscape) keep the layout above. */
@media (min-width: 461px) and (min-height: 501px), (min-width: 461px) and (orientation: portrait) {
  .f-row {
    grid-template-columns: 3.1em 5.4em minmax(0, 1fr) 3em 7.8em;
    align-items: start; align-content: start; min-height: 66px;
  }
  .f-row > span { line-height: 21px; }
  .f-time, .f-flight, .f-city, .f-where { align-self: start; }
  .f-where { justify-content: flex-start; }
  .f-status { grid-column: 5; grid-row: 1 / span 2; justify-self: stretch; align-items: flex-start; }
  .f-status .pill { line-height: 17px; margin-top: 1px; }
  .f-status .delay-tag { line-height: 16px; }
  .f-sub, .f-note { grid-column: 2 / 5; }
  .f-row > .f-sub, .f-row > .f-note { line-height: 1.3; }
}

.track-btn {
  border: 1px solid var(--accent); background: transparent; color: var(--accent);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600;
}
.track-btn:hover { background: rgba(255, 210, 63, 0.1); }

.foot {
  margin-top: auto; padding: 20px 16px 8px;
  color: var(--faint); font-size: 12px; line-height: 1.6; text-align: center;
}

/* Credit line: last thing on the page, on both tabs (below the map on the Tracker). */
.credit {
  flex: none; margin: 0; padding: 6px 16px calc(14px + env(safe-area-inset-bottom));
  color: var(--faint); font-size: 12px; line-height: 1.6; text-align: center;
}

/* ------------------------------------------------------------ tracker */
#view-tracker { position: relative; overflow: hidden; }

.leaflet-bar .map-reset {
  display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0;
  border-radius: 4px; background: var(--surface); color: var(--text); cursor: pointer;
}
.leaflet-bar .map-reset:hover { background: var(--surface-2); }
.leaflet-bar .map-reset svg { width: 18px; height: 18px; }
@media (pointer: coarse) { .leaflet-bar .map-reset { width: 44px; height: 44px; } }

.map-hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 900;
  padding: 8px 14px; border-radius: 999px; background: rgba(11, 12, 14, 0.85); color: var(--text);
  font-size: 13px; pointer-events: none; opacity: 0; transition: opacity 0.2s ease;
}
.map-hint.show { opacity: 1; }
.map { position: absolute; inset: 0; background: #0e1013; }

/* Darken OSM tiles to match the board (the tiles themselves are standard OSM). */
.map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.4); }
.leaflet-container { font: 12px var(--sans); background: #0e1013; }
.leaflet-control-attribution { background: rgba(11, 12, 14, 0.7) !important; color: var(--faint) !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--surface) !important; color: var(--text) !important; border-color: var(--line) !important; }

.plane { width: 28px; height: 28px; display: grid; place-items: center; }
.plane svg { width: 24px; height: 24px; fill: var(--text); filter: drop-shadow(0 1px 2px rgba(0,0,0,0.8)); transition: transform 0.6s ease; }
.plane.ground svg { fill: var(--faint); }
.plane.board svg { fill: #ffffff; }
.plane.sel svg { fill: var(--accent); }
/* Possible emergency (squawk 7500/7600/7700): red plane, red glow and a label, slow pulse. */
.plane.emerg { border-radius: 50%; animation: sq-glow 1.5s ease-in-out infinite; }
.plane.emerg svg { fill: var(--bad); }
.sq-label {
  position: absolute; left: 50%; top: 31px; transform: translateX(-50%);
  padding: 2px 7px; border-radius: 4px; background: var(--bad); color: var(--bg);
  font: 700 10px/1.4 var(--sans); letter-spacing: 0.04em; white-space: nowrap; pointer-events: none;
  animation: sq-pulse-bg 1.5s ease-in-out infinite;
}
@keyframes sq-glow {
  0%, 100% { box-shadow: 0 0 6px 2px rgba(255, 90, 95, 0.45); background: rgba(255, 90, 95, 0.12); }
  50% { box-shadow: 0 0 16px 7px rgba(255, 90, 95, 0.85); background: rgba(255, 90, 95, 0.3); }
}
.c-emerg {
  margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--bad-bg); color: var(--text);
  font-size: 13px; line-height: 1.45;
}
.c-emerg strong { color: var(--bad); font-size: 12px; letter-spacing: 0.04em; }
.home-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(255, 210, 63, 0.2); }

/* Tracker header: Changi / Seletar, centred over the top of the map. */
.trk-head {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}
.trk-head button { color: var(--text); }
.trk-head button:hover { background: var(--surface-2); }
.trk-head button[data-goto="changi"] { color: var(--accent); }
.trk-head button[data-goto="seletar"] { color: var(--seletar); }

/* Seletar airport mark: a dot in its own colour (Changi's is yellow), with a label. */
.apt-mark { position: relative; width: 10px; height: 10px; }
.apt-dot {
  position: absolute; inset: 0; border-radius: 50%;
  background: var(--seletar); box-shadow: 0 0 0 4px rgba(126, 231, 135, 0.2);
}
.apt-label {
  position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
  color: var(--seletar); font: 600 11px/1 var(--sans); white-space: nowrap;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
}

/* "Near Seletar" panel: bottom left; the plane card (z 800) sits above it on phones. */
.near-panel {
  position: absolute; left: 12px; bottom: calc(28px + env(safe-area-inset-bottom)); z-index: 700;
  width: min(300px, calc(100% - 24px)); max-height: 46%; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45); font-size: 13px;
}
.near-panel summary {
  cursor: pointer; padding: 8px 12px; font-weight: 600; color: var(--seletar);
  list-style-position: inside;
}
.near-count { color: var(--muted); font-weight: 500; }
.near-list ul { list-style: none; margin: 0; padding: 0 6px; }
.near-list button {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; width: 100%;
  padding: 6px; border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left;
}
.near-list button:hover { background: var(--surface-2); }
.near-cs { font-family: var(--mono); font-weight: 650; }
.near-cs.c-unknown { font-family: var(--sans); color: var(--muted); font-weight: 500; }
.near-id { display: flex; align-items: center; gap: 6px; min-width: 0; }
.near-num { text-align: right; }
.near-tag {
  padding: 0 7px; border-radius: 999px; font-size: 11px; font-weight: 600;
  color: var(--bg); background: var(--seletar);
}
.near-type, .near-num { color: var(--muted); font-variant-numeric: tabular-nums; }
.near-empty { margin: 0; padding: 4px 12px 8px; color: var(--muted); }
.near-note { margin: 0; padding: 8px 12px 10px; border-top: 1px solid var(--line); color: var(--faint); font-size: 11.5px; line-height: 1.45; }

.map-note {
  position: absolute; top: 58px; left: 50%; transform: translateX(-50%); z-index: 500;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; color: var(--muted); white-space: nowrap;
}

.card {
  position: absolute; left: 12px; right: 12px; bottom: calc(28px + env(safe-area-inset-bottom)); z-index: 800;
  max-width: 460px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  transform: translateY(calc(100% + 60px));
  /* Closed: fully hidden (no peek on tall screens). Visibility switches after the slide-out. */
  visibility: hidden; transition: transform 0.25s ease, visibility 0s linear 0.25s;
}
.card.show { transform: none; visibility: visible; transition: transform 0.25s ease, visibility 0s; }
.card-close {
  position: absolute; top: 6px; right: 8px; width: 32px; height: 32px;
  border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1;
}
.c-head { display: flex; align-items: baseline; gap: 10px; padding-right: 30px; }
.c-cs { font-family: var(--mono); font-size: 20px; font-weight: 650; color: var(--accent); }
.c-type { color: var(--muted); font-size: 13px; }
.c-route { margin: 6px 0 0; font-size: 15px; }
.c-route small { color: var(--muted); }
.c-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 0; }
.c-stats .kv dd { font-size: 15px; }
.c-lost { color: var(--warn); font-size: 12px; margin-top: 8px; }
.c-msg { margin: 8px 0 0; color: var(--muted); }
.c-msg strong { color: var(--text); font-weight: 600; }
.c-tag {
  display: inline-block; margin-right: 4px; padding: 1px 7px; border-radius: 999px;
  background: var(--warn-bg); color: var(--warn); font-size: 11px; font-weight: 600; vertical-align: 1px;
}
.c-link {
  display: inline-block; margin-top: 12px; padding: 0; border: 0; background: none;
  color: var(--accent); font-size: 14px; font-weight: 600; text-decoration: none;
}
.c-link:hover { text-decoration: underline; }

/* ------------------------------------------------------------ wide screens (900px+)
   The board sits in a centred, wider container with departures and arrivals side by
   side; the direction toggle isn't needed. Phones never reach this breakpoint. */
@media (min-width: 900px) {
  main { max-width: 1280px; }
  body.tracking main { max-width: none; } /* the map uses the full width */
  .controls { flex-direction: row; flex-wrap: wrap; align-items: center; column-gap: 16px; }
  .controls > .row:first-child { flex: none; }
  .controls .search { flex: 1 1 260px; width: auto; }
  .controls > .row-chips, .controls > .chips-wing, .controls > .xsp-note { flex: 1 1 100%; }
  .seg[aria-label="Direction"] { display: none; }
  .cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 24px; align-items: start; padding: 0 16px; }
  .board-col { min-width: 0; }
  .col-head {
    margin: 0; padding: 12px 16px 8px; color: var(--muted);
    font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em;
  }
  .board-col .more { width: calc(100% - 32px); }
}

/* ------------------------------------------------------------ phone landscape
   Short and wide: compact header, controls on fewer lines, rows use the full width,
   and the plane card sits at the side so the map stays visible. Portrait is untouched. */
@media (orientation: landscape) and (max-height: 500px) {
  .top { padding: calc(6px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left)); }
  .brand { flex-direction: row; align-items: baseline; gap: 8px; }
  .tab { padding: 4px 12px; }
  main { max-width: none; padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
  .intro { padding-top: 8px; }
  .controls { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px 12px; padding-top: 10px; }
  .controls > .row:first-child { flex-wrap: nowrap; }
  .controls > .row-chips, .controls > .chips-wing, .controls > .xsp-note { grid-column: 1 / -1; }
  .search { padding-top: 8px; padding-bottom: 8px; }
  .card {
    left: auto; right: calc(12px + env(safe-area-inset-right, 0px)); bottom: 12px;
    width: min(380px, 55%); max-height: calc(100% - 24px); overflow: auto; margin: 0;
    padding: 10px 14px 12px;
  }
  .card .c-stats { margin-top: 8px; }
  .credit { padding-top: 4px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .card, .plane svg, .map-hint { transition: none; }
  .flight.live .live-tag { animation: none; }
  .refresh-btn.spinning svg { animation-duration: 2.4s; }
  .refresh-btn.pulse { animation: none; color: var(--accent); }
  .toast { transition: none; }
  .flight.flash .f-row { animation: none; background: rgba(255, 210, 63, 0.16); }
  .dot-spin { animation-duration: 2.4s; }
  /* Possible emergency: solid red, no pulse. */
  .chips button.chip-standby[data-term="standby"],
  .chips button.chip-standby[data-term="standby"][aria-pressed], .sq-label { animation: none; background: var(--bad); box-shadow: none; }
  .plane.emerg { animation: none; box-shadow: 0 0 12px 5px rgba(255, 90, 95, 0.75); background: rgba(255, 90, 95, 0.25); }
}
