/* =========================================================================
   Flight Board
   The e-ink panel's layout and hierarchy, drawn for a colour screen. Nothing
   scrolls: every dimension derives from a root font size taken from the
   viewport, so the board is bound by whichever dimension runs out first.
   Tuned for a 5.5" 960x480 panel.
   ========================================================================= */

:root {
  /* Sized up from the first build to fill the panel: at 960x480 this lands on
     ~17.8px, against 13.9px before. min() of the two axes is what keeps a
     scrollbar impossible rather than merely unlikely. */
  font-size: clamp(11px, min(2.25vw, 3.7vh), 30px);

  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* --- paper: the default, a warm off-white like the panel in daylight --- */
[data-theme='paper'] {
  --paper: #eae6dc;
  --card: #faf8f3;
  --ink: #14151a;
  --ink-2: #55565f;
  --ink-3: #8d8e97;
  --rule: #cec8ba;
  --rule-soft: #e2ddd1;
  --banner: #17181d;
  --banner-ink: #f5f2eb;
  --banner-ink-2: #a3a199;
  --accent: #bd6a15;
  --warn: #a93c28;
  --shadow: rgba(20, 21, 26, 0.16);
  --photo-filter: saturate(0.93) contrast(1.02);
  --map-route: #6f6a5e;
  --map-marker-stroke: rgba(255, 255, 255, 0.9);
}

/* --- night: the same board for a screen left on in a dark room --- */
[data-theme='night'] {
  --paper: #0c0d10;
  --card: #15171c;
  --ink: #e9e7e1;
  --ink-2: #9b9ba3;
  --ink-3: #696a73;
  --rule: #2b2e36;
  --rule-soft: #21242b;
  --banner: #05060a;
  --banner-ink: #e9e7e1;
  --banner-ink-2: #85858e;
  --accent: #d9903f;
  --warn: #c9604a;
  --shadow: rgba(0, 0, 0, 0.5);
  --photo-filter: saturate(0.8) brightness(0.72) contrast(1.05);
  --map-route: #7d8590;
  --map-marker-stroke: rgba(0, 0, 0, 0.75);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;              /* the board never scrolls */
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.board {
  position: relative;
  width: 100%;
  height: 100dvh;
  background: linear-gradient(180deg, var(--card) 0%, var(--paper) 100%);
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  /* Each flight may recolour its own accent from the airline's brand; the
     default is the board's amber. */
  --flight-accent: var(--accent);
}
.view[hidden] { display: none; }

/* =========================== banner ===================================== */

.banner {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.45rem 1.1rem;
  background: var(--banner);
  color: var(--banner-ink);
  flex: none;
}
.banner-slim { padding: 0.4rem 1.1rem; }

.banner-icon { display: flex; align-items: center; }
.banner-icon svg { width: 2.4rem; height: 2.4rem; }
.climb-icon { color: var(--banner-ink-2); }
.climb-icon[data-state='climbing'],
.climb-icon[data-state='descending'] { color: var(--flight-accent); }

.callsign {
  margin: 0;
  font-family: var(--mono);
  font-size: 3.2rem;
  font-weight: 600;
  letter-spacing: 0.015em;
  line-height: 1.04;
  white-space: nowrap;
}

.tracking {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.55rem;
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.banner-right {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  white-space: nowrap;
}

.compass {
  font-family: var(--mono);
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  color: var(--banner-ink-2);
}

.distance {
  font-family: var(--mono);
  font-size: 2.2rem;
  font-weight: 500;
}

.state {
  font-family: var(--mono);
  font-size: 0.92rem;
  letter-spacing: 0.16em;
  color: var(--banner-ink-2);
  display: inline-flex;
  align-items: center;
  gap: 0.36rem;
}
.state::before {
  content: '';
  width: 0.5rem; height: 0.5rem;
  border-radius: 50%;
  background: var(--flight-accent);
}
.state[data-stale='true'] { color: var(--warn); }
.state[data-stale='true']::before { background: var(--warn); }
.state:empty { display: none; }

/* =========================== ticket ===================================== */

.ticket-body {
  flex: 1;
  display: flex;
  min-height: 0;
  padding: 0.85rem 1.1rem 0.7rem;
  gap: 1rem;
}

.ticket-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  /* Lets the data values size themselves against the column they live in. */
  container-type: inline-size;
}

.route {
  display: grid;
  grid-template-columns: auto minmax(2rem, 1fr) auto;
  align-items: center;
  gap: 1rem;
}

.airport-code {
  font-family: var(--mono);
  font-size: 5.2rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.01em;
}

.route-line {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  width: 100%;
}

.airline {
  font-size: 1.12rem;
  font-weight: 500;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.airline[hidden] { display: none; }

/* The airline's symbol sitting beside its name. The symbol is decoration on
   top of the name, never a replacement, because roughly half of the traffic
   over the UK has no mark in the set at all. */
.airline-lockup {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  max-width: 100%;
}
.airline-mark {
  height: 2.2rem;
  width: auto;
  max-width: 3.6rem;
  flex: none;
  object-fit: contain;
  display: block;
}
.airline-mark[hidden] { display: none; }
/* Several marks are near-black navy, which disappears on the night board.
   Lifting brightness keeps the brand colour rather than flattening it to a
   white silhouette. */
[data-theme='night'] .airline-mark { filter: brightness(1.55) saturate(1.12); }

.route-rule { position: relative; width: 100%; height: 0.85rem; }
.route-rule::before {
  content: '';
  position: absolute;
  left: 0; right: 0.95rem; top: 50%;
  height: 2px;
  transform: translateY(-50%);
  background: repeating-linear-gradient(
    90deg, var(--ink-3) 0 0.5rem, transparent 0.5rem 0.95rem);
}
.route-rule::after {
  content: '';
  position: absolute;
  right: 0; top: 50%;
  transform: translateY(-50%);
  border-left: 0.85rem solid var(--flight-accent);
  border-top: 0.42rem solid transparent;
  border-bottom: 0.42rem solid transparent;
}

.airport-names {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.3rem;
  font-size: 1.12rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.airport-names span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.airport-names span:last-child { text-align: right; }

.rule {
  width: 100%;
  height: 0;
  margin: 0.55rem 0;
  border: 0;
  border-top: 2px solid var(--rule);
}

.stats { display: flex; gap: 1.4rem; }
.stat { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.stat-key {
  font-size: 1.02rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--ink-3);
}
.stat-value {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--mono);
  /* The firmware meets this exact problem and answers it with a scale
     fallback: try the big size, drop a step when the string will not fit
     whole, never truncate a number. cqw is the CSS equivalent - the value
     shrinks with the column, so the widest realistic pair ("36,000 ft" beside
     "1204 kmh") still fits rather than colliding. */
  font-size: clamp(1.5rem, 8.5cqw, 3.4rem);
  font-weight: 500;
  line-height: 1.04;
  white-space: nowrap;
}

.bearing-arrow {
  width: 1.7rem; height: 1.7rem;
  flex: none;
  color: var(--flight-accent);
  transform-origin: 50% 50%;
}
.bearing-arrow[hidden] { display: none; }

.ticket-footer {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  font-size: 1.2rem;
  color: var(--ink-2);
}
.clock { font-family: var(--mono); letter-spacing: 0.05em; }

/* --- the art column ------------------------------------------------------
 * The photo bleeds off the right, top and bottom edges and dissolves into the
 * page on its left, so it reads as part of the card rather than a picture
 * pasted into a box. Negative margins cancel the body padding to reach the
 * panel edge.
 */
.ticket-art {
  position: relative;
  width: 36%;
  max-width: 20rem;
  flex: none;
  margin: -0.85rem -1.1rem -0.7rem 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.aircraft-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  filter: var(--photo-filter);
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, rgba(0,0,0,0.4) 20%, #000 55%);
  mask-image: linear-gradient(90deg, transparent 0%, rgba(0,0,0,0.4) 20%, #000 55%);
}
.aircraft-photo[hidden] { display: none; }

/* A scrim only under the caption, and only when a photo is behind it. */
.ticket-art::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 42%;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.45));
  opacity: 0;
  pointer-events: none;
}
.ticket-art[data-photo='true']::after { opacity: 1; }
.ticket-art[data-photo='true'] { justify-content: flex-end; align-items: flex-end; }

.silhouette-wrap { display: block; width: 100%; padding: 0 0.6rem; }
.silhouette-wrap[hidden] { display: none; }
.silhouette { display: block; width: 100%; height: auto; color: var(--ink); }

.art-caption {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0 0.6rem;
}
.ticket-art[data-photo='true'] .art-caption {
  align-items: flex-end;
  padding: 0 1.05rem 0.6rem 0;
}

.aircraft-type {
  font-family: var(--mono);
  font-size: 1.7rem;
  font-weight: 500;
  letter-spacing: 0.09em;
}
.ticket-art[data-photo='true'] .aircraft-type {
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

/* Required by CC-BY. Deliberately quiet, but present. */
.photo-credit {
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.62);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.photo-credit:empty { display: none; }

/* =========================== nearby list ================================ */

.rows {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
}

/* The rows are <li> wrappers around <button> click targets, so the flex sizing
   has to be on the wrapper - otherwise the buttons keep their natural height
   and the list bunches at the top of the screen. */
.rows > li {
  flex: 1;
  min-height: 0;
  display: flex;
}
.rows > li + li { border-top: 2px dashed var(--rule); }

.row {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.35rem 1.1rem;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}
.row:hover, .row:focus-visible {
  background: color-mix(in srgb, var(--flight-accent) 9%, transparent);
  outline: none;
}
.row:active { background: color-mix(in srgb, var(--flight-accent) 16%, transparent); }

.row-main {
  display: grid;
  grid-template-columns: minmax(0, 11.6rem) minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 0.9rem;
  font-family: var(--mono);
  font-size: 2.4rem;
  font-weight: 500;
}
.row-main .row-route { color: var(--ink-2); font-size: 2.15rem; }
.row-main .row-distance { text-align: right; white-space: nowrap; }
.row-main span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.row-detail {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.18rem;
  letter-spacing: 0.04em;
  color: var(--ink-2);
}
.row-detail .climb-icon { width: 1.4rem; height: 1.4rem; flex: none; color: var(--accent); }
.row-detail .climb-icon[data-state='level'] { color: var(--ink-3); }

.list-footer {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.4rem 5.2rem 0.55rem 1.1rem;
  border-top: 2px solid var(--rule);
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--ink-3);
  flex: none;
}
.footer-hint {
  font-family: var(--sans);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-size: 0.82rem;
  opacity: 0.75;
}

/* =========================== map ======================================== */

.back-btn {
  flex: none;
  width: 2.5rem; height: 2.5rem;
  padding: 0.35rem;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--banner-ink);
  cursor: pointer;
}
.back-btn svg { width: 100%; height: 100%; display: block; }
.back-btn:hover, .back-btn:focus-visible { background: rgba(255, 255, 255, 0.22); outline: none; }

.map-callsign { font-size: 2.1rem; }
.map-mark { height: 1.55rem; margin-left: 0.35rem; filter: brightness(1.55) saturate(1.12); }
.map-route {
  font-family: var(--mono);
  font-size: 1.5rem;
  letter-spacing: 0.06em;
  color: var(--banner-ink);
}

.map-canvas { flex: 1; min-height: 0; background: var(--paper); }

.map-footer {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.4rem 5.2rem 0.5rem 1.1rem;
  border-top: 2px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.98rem;
  color: var(--ink-2);
  flex: none;
}
.map-progress { color: var(--ink-3); white-space: nowrap; }

.leaflet-container {
  background: var(--paper);
  font-family: var(--sans);
  font-size: 0.75rem;
}
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--card) 78%, transparent);
  color: var(--ink-3);
  font-size: 0.62rem;
}
.leaflet-control-attribution a { color: var(--ink-2); }
.leaflet-bar a {
  background: var(--card);
  color: var(--ink);
  border-bottom-color: var(--rule);
}
.leaflet-bar a:hover { background: var(--rule-soft); }

.plane-marker svg { width: 100%; height: 100%; display: block; overflow: visible; }
.airport-marker { position: relative; }
.airport-dot {
  position: absolute;
  left: -0.36rem; top: -0.36rem;
  width: 0.72rem; height: 0.72rem;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 0.2rem var(--card);
}
.airport-code-label {
  position: absolute;
  left: 0.65rem; top: -0.8rem;
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  padding: 0.05rem 0.3rem;
  border-radius: 0.2rem;
  white-space: nowrap;
}

/* =========================== status screens ============================= */

.view-status { align-items: center; justify-content: center; text-align: center; padding: 2rem; }
.status-title {
  margin: 0;
  font-family: var(--mono);
  font-size: 4.8rem;
  font-weight: 500;
  letter-spacing: 0.11em;
}
.status-rule { max-width: 22rem; margin: 1.4rem auto; }
.status-line { margin: 0; font-size: 1.42rem; color: var(--ink-2); }
.status-sub { margin: 0.65rem 0 0; font-size: 1.05rem; color: var(--ink-3); }

/* =========================== chrome ===================================== */

.gear, .sound-chip {
  position: fixed;
  border: 0;
  cursor: pointer;
  font: inherit;
  color: var(--ink-3);
  background: transparent;
  transition: opacity 0.18s ease, color 0.18s ease;
  z-index: 500;
}

.gear {
  right: 0.45rem; bottom: 0.35rem;
  width: 2.2rem; height: 2.2rem;
  padding: 0.32rem;
  opacity: 0.3;
  border-radius: 50%;
}
.gear svg { width: 100%; height: 100%; display: block; }
.gear:hover, .gear:focus-visible { opacity: 1; color: var(--ink); outline: none; }

.sound-chip {
  right: 2.9rem; bottom: 0.35rem;
  width: 2.2rem; height: 2.2rem;
  padding: 0;
  border-radius: 50%;
  font-size: 1.15rem;
  line-height: 1;
  opacity: 0.4;
  animation: sound-hint 2.8s ease-in-out infinite;
}
.sound-chip:hover, .sound-chip:focus-visible { opacity: 1; color: var(--ink); outline: none; }
.sound-chip[hidden] { display: none; }

@keyframes sound-hint {
  0%, 100% { opacity: 0.28; }
  50%      { opacity: 0.75; }
}
@media (prefers-reduced-motion: reduce) {
  .sound-chip { animation: none; opacity: 0.5; }
}

/* =========================== settings =================================== */

.settings-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.8rem;
  background: color-mix(in srgb, var(--paper) 70%, transparent);
  backdrop-filter: blur(6px);
  z-index: 1000;
}
.settings-backdrop[hidden] { display: none; }

.settings-panel {
  width: min(52rem, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 0.8em 1em 0.85em;
  border: 2px solid var(--rule);
  border-radius: 0.55rem;
  background: var(--card);
  box-shadow: 0 1rem 3rem var(--shadow);
  /* Everything inside this panel is sized in `em`, not `rem`, so this single
     declaration governs the whole form. Sizing the children in rem was the
     bug: rem is root-relative, so shrinking the panel changed nothing and the
     Save button kept falling off a 480px screen. */
  font-size: 0.58rem;
}
.settings-panel h2 {
  margin: 0 0 0.5em;
  font-family: var(--mono);
  font-size: 1.7em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.settings-panel fieldset {
  margin: 0 0 0.6em;
  padding: 0.5em 0.8em 0.6em;
  border: 2px solid var(--rule-soft);
  border-radius: 0.35em;
}
.settings-panel legend {
  padding: 0 0.35em;
  font-size: 1em;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.settings-panel label {
  display: flex;
  flex-direction: column;
  gap: 0.25em;
  margin-bottom: 0.45em;
  font-size: 1.15em;
  color: var(--ink-2);
}
.settings-panel label:last-child { margin-bottom: 0; }
.settings-panel .pair,
.settings-panel .triple,
.settings-panel .quad { display: grid; gap: 0.9em; }
.settings-panel .pair { grid-template-columns: 1fr 1fr; }
.settings-panel .triple { grid-template-columns: 1.3fr 1fr 1fr; }
.settings-panel .quad { grid-template-columns: repeat(4, 1fr); }
.settings-panel .in-row { align-self: end; margin-bottom: 0.05em; }
.settings-panel label.check {
  flex-direction: row;
  align-items: center;
  gap: 0.45em;
  align-self: end;
  margin-bottom: 0.5em;
}

.settings-panel input[type='text'],
.settings-panel input[type='number'],
.settings-panel select {
  width: 100%;
  padding: 0.35em 0.5em;
  border: 2px solid var(--rule);
  border-radius: 0.28em;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 1.05em;
}
.settings-panel input:focus-visible,
.settings-panel select:focus-visible { outline: none; border-color: var(--accent); }
.settings-panel input[type='checkbox'] {
  width: 1.2em; height: 1.2em; accent-color: var(--accent); flex: none;
}

.hint {
  margin: 0.35em 0 0;
  font-size: 1em;
  line-height: 1.45;
  color: var(--ink-3);
}
.hint[hidden], .hint:empty { display: none; }

.settings-actions { display: flex; align-items: center; gap: 0.55em; margin-top: 0.7em; }
.settings-actions .spacer { flex: 1; }

.settings-panel button {
  padding: 0.5em 1.1em;
  border-radius: 0.3em;
  font: inherit;
  font-size: 1.05em;
  font-weight: 500;
  cursor: pointer;
}
.settings-panel .primary {
  border: 2px solid var(--banner);
  background: var(--banner);
  color: var(--banner-ink);
}
.settings-panel .ghost {
  border: 2px solid var(--rule);
  background: transparent;
  color: var(--ink-2);
}
.settings-panel .ghost:hover { border-color: var(--ink-3); color: var(--ink); }

.credit-list {
  max-height: 44vh;
  overflow-y: auto;
  margin-top: 0.5em;
  padding-top: 0.4em;
  border-top: 2px solid var(--rule-soft);
  font-size: 1em;
  line-height: 1.55;
  color: var(--ink-3);
  columns: 2;
}
.credit-list div { padding: 0.05em 0; break-inside: avoid; }
.credit-list b { color: var(--ink-2); font-weight: 500; }

/* A short flash when a new aircraft takes the ticket, so the change is
   noticeable across a room even with the sound muted. */
@keyframes ticket-arrive { from { opacity: 0.25; } to { opacity: 1; } }
.view-ticket[data-arrived='true'] { animation: ticket-arrive 0.45s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .view-ticket[data-arrived='true'] { animation: none; }
}

/* Portrait or very narrow: stack the art under the text rather than squeezing
   the airport codes into nothing. */
@media (max-aspect-ratio: 4/5) {
  .ticket-body { flex-direction: column; }
  .ticket-art {
    width: auto;
    max-width: none;
    height: 34%;
    margin: 0 -1.1rem -0.7rem;
    flex: none;
  }
  .aircraft-photo {
    -webkit-mask-image: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.4) 18%, #000 45%);
    mask-image: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.4) 18%, #000 45%);
  }
  .silhouette-wrap { max-width: 60%; margin: 0 auto; }
}
