:root {
  --bg: #070d1a;
  --panel: #0c1527;
  --panel-2: #101c33;
  --panel-3: #18284a;
  --line: #1c2b46;
  --line-strong: #2a3d60;
  --text: #e9eef7;
  --muted: #9aabc4;
  --dim: #7d8fab;
  /* Ambre réservé à l'avion, au lieu sous l'avion et à l'action principale. */
  --accent: #ffb020;
  --accent-ink: #1a1000;
  --accent-soft: rgba(255, 176, 32, 0.14);
  --accent-line: rgba(255, 176, 32, 0.55);
  --sea: #8fc3e6;
  --warn: #ff9d8a;
  --radius: 14px;
  --gap: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  scrollbar-color: var(--line-strong) var(--bg);
}

::selection { background: var(--muted); color: var(--bg); }

button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; border-radius: 8px; }

[hidden] { display: none !important; }

h1, h2, p, dl, dd, ul { margin: 0; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

/* ---------- simulation banner ---------- */
.sim-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding: 4px 4px 4px 14px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 0.9375rem;
}
.btn-banner {
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: var(--accent-ink);
  color: var(--accent);
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}
.btn-banner:hover { background: #2e1d00; }
.btn-banner:focus-visible { outline-color: var(--accent-ink); }

/* ---------- header ---------- */
.top {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 12px;
  padding-bottom: 10px;
}
.brand h1 {
  font-size: 1.375rem;
  font-weight: 750;
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.route-line {
  font-size: 0.8125rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.data-note:not(:empty)::before { content: " · "; }

.modes {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 3px;
  background: var(--panel);
}
.mode {
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
}
.mode:hover { color: var(--text); }
.mode[aria-pressed="true"] { background: var(--panel-3); color: var(--text); }

.offline {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--muted);
}
.offline::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--muted);
  flex: none;
}
.offline[data-state="ready"] { color: var(--text); }
.offline[data-state="ready"]::before { background: var(--text); border-color: var(--text); }

/* ---------- status: one compact line, the rest folded ---------- */
.status {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 7px 12px 0;
}
.stat-line {
  display: flex;
  flex-wrap: wrap;
  font-size: 0.9375rem;
  font-weight: 620;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.st + .st::before { content: "·"; content: "·" / ""; margin: 0 0.45em; color: var(--dim); font-weight: 400; }
#st-age { color: var(--muted); font-weight: 500; }
#st-age.warn { color: var(--warn); font-weight: 650; }
.stat-more summary {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  font-size: 0.8125rem;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  width: fit-content;
}
.stat-more summary::-webkit-details-marker { display: none; }
.stat-more summary::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  margin-right: 2px;
}
.stat-more[open] summary::before { transform: rotate(45deg); }
.stat-more summary:hover { color: var(--text); }
.stat-more dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 14px;
  padding: 0 0 10px;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}
.stat-more dl div { display: contents; }
.stat-more dt { color: var(--muted); }

/* ---------- main ---------- */
.main { padding-top: 14px; }

.live-view { display: grid; gap: var(--gap); }
.col-map, .col-lists { display: grid; gap: var(--gap); align-content: start; min-width: 0; }

/* ---------- waiting screen ---------- */
.wait {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 28px 20px 24px;
  text-align: center;
  display: grid;
  gap: 14px;
  justify-items: center;
}
.wait h2 { font-size: 1.25rem; font-weight: 700; }
.wait-clock {
  font-size: 3.25rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.wait-text { font-size: 1.0625rem; max-width: 30ch; text-wrap: balance; }
.wait-detail { font-size: 0.9375rem; color: var(--muted); max-width: 40ch; text-wrap: pretty; }
.wait-detail:empty { display: none; }
.wait-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--panel-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #ffc04d; }

/* ---------- simulation panel (under the map) ---------- */
.sim {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 8px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
}
.sim-row { flex: 1 1 260px; display: flex; align-items: center; gap: 12px; min-width: 0; }
.sim-track { flex: 1; min-width: 0; }
.sim-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.2;
}
.sim-label output { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 32px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--line-strong); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line-strong); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--muted); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px; height: 24px; margin-top: -9px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--bg);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--bg);
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--muted); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--muted); }

.btn-icon {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  cursor: pointer;
}
.btn-icon svg { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
.btn-icon:disabled { opacity: 0.4; cursor: default; }
.btn-icon.play { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); border-color: var(--accent); }
.btn-icon.play svg { fill: var(--accent-ink); stroke: none; width: 22px; height: 22px; }
.play .i-pause, .play[aria-pressed="true"] .i-play { display: none; }
.play[aria-pressed="true"] .i-pause { display: block; }

.speeds { flex: 1 0 auto; display: grid; grid-template-columns: repeat(3, minmax(56px, 1fr)); gap: 6px; }
.speed {
  min-height: 40px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.speed:hover { color: var(--text); }
.speed[aria-pressed="true"] { color: var(--text); border-color: var(--muted); background: var(--panel-3); }

/* ---------- map ---------- */
.mapwrap {
  position: relative;
  aspect-ratio: 1 / 1;
  max-height: 62vh;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #081122;
}
#map { display: block; width: 100%; height: 100%; }
.zoom {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: grid;
  justify-items: center;
  gap: 4px;
}
.zoom .btn-icon { background: rgba(12, 21, 39, 0.88); }
.zoom-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 6px;
}

/* ---------- under the plane ---------- */
.live-view h2 {
  font-size: 0.875rem;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 6px;
}
.h-note { font-weight: 450; }
.h-note::before { content: "· "; }

.under {
  border-top: 2px solid var(--accent);
  padding-top: 10px;
  min-width: 0;
}
.u-sea {
  margin-bottom: 4px;
  color: var(--sea);
  font-size: 0.9375rem;
  font-weight: 600;
}
.u-name {
  font-size: clamp(1.75rem, 7.5vw, 2.5rem);
  font-weight: 760;
  line-height: 1.05;
  letter-spacing: -0.02em;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.u-kind { margin-top: 6px; color: var(--muted); font-size: 0.9375rem; }
.under-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--accent);
  font-size: 1.125rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.under-meta:empty { display: none; }
.under-meta .needle { width: 30px; height: 30px; }
.under-text { margin-top: 10px; font-size: 1.0625rem; line-height: 1.55; max-width: 65ch; text-wrap: pretty; }
.under-text:empty { display: none; }
.is-empty { color: var(--muted); }
.src-note { margin-top: 6px; font-size: 0.8125rem; color: var(--dim); }

/* ---------- needle (relative bearing) ---------- */
.needle { width: 28px; height: 28px; flex: none; overflow: visible; }
.needle circle { fill: none; stroke: var(--line-strong); stroke-width: 1.5; }
.needle .hand { fill: var(--accent); }
.needle .nose { fill: var(--muted); }
/* Dans les listes : aiguilles atténuées, l'ambre reste au lieu sous l'avion. */
.places .needle .hand { fill: var(--muted); }
.places .needle .nose { fill: var(--dim); }

/* ---------- lists ---------- */
.col-lists .list-block { padding-top: 4px; }
.places { list-style: none; padding: 0; border-top: 1px solid var(--line); }
.places li { border-bottom: 1px solid var(--line); }
.places li.open { background: var(--panel); }
.row {
  width: 100%;
  min-height: 56px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.row:hover .r-name { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--muted); }
.r-main { min-width: 0; }
.r-name { display: block; font-weight: 650; font-size: 1.0625rem; line-height: 1.25; }
.r-sub { display: block; font-size: 0.8125rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-dist { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.r-km { display: block; font-weight: 650; }
.r-side { display: block; font-size: 0.8125rem; color: var(--muted); }
.detail { padding: 0 4px 14px 44px; font-size: 0.9375rem; line-height: 1.55; max-width: 65ch; }

.empty { color: var(--muted); font-size: 0.9375rem; padding: 12px 0; }
.fatal { border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 14px; color: var(--warn); }

.foot { margin-top: 28px; font-size: 0.8125rem; color: var(--muted); }

/* ---------- wide screens ---------- */
@media (min-width: 900px) {
  .app { max-width: 1180px; padding-left: 24px; padding-right: 24px; }
  .top { grid-template-columns: auto 1fr auto; }
  .offline { grid-column: auto; grid-row: 1; grid-column-start: 2; justify-self: end; }
  .live-view {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "map under" "map lists";
    column-gap: 28px;
    row-gap: 20px;
    align-items: start;
  }
  .under { grid-area: under; }
  .col-lists { grid-area: lists; }
  /* La colonne carte reste dans la hauteur visible, panneau de simulation compris. */
  .col-map {
    grid-area: map;
    position: sticky;
    top: 12px;
    gap: 12px;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }
  .mapwrap { max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); }
  .is-sim .mapwrap { max-height: calc(100vh - 24px - 12px - 64px); max-height: calc(100dvh - 24px - 12px - 64px); }
  .sim { flex-wrap: nowrap; }
  .speeds { flex: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

.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; }
