:root {
  --text: #f4f6fb;
  --muted: #a9b7d3;
  --ok: #7be08f;
  --late: #ffa53d;
  --cancel: #ff5a5a;
  --dep: #ffcf3f;          /* départs : jaune sur bleu */
  --dep-bg: rgba(9, 27, 66, 0.88);
  --arr: #6ee7c0;          /* arrivées : vert d'eau sur vert sombre */
  --arr-bg: rgba(6, 46, 40, 0.88);
  --sky-top: #6fa8dc;
  --sky-bottom: #f3dcae;
  --land-filter: none;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh; color: var(--text); background: #0c1830;
  display: flex; justify-content: center; align-items: flex-start;
  padding: clamp(12px, 4vh, 48px) 12px 30vh; overflow-x: hidden;
}
button { font: inherit; }

/* ---------- fond : ciel selon l'heure + paysage ---------- */
#sky { position: fixed; inset: 0; z-index: -3; background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom)); transition: background 2s; }
#stars {
  position: absolute; inset: 0; opacity: 0; transition: opacity 2s;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff, transparent), radial-gradient(1px 1px at 27% 8%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 44% 22%, #fff, transparent), radial-gradient(1px 1px at 61% 12%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 78% 25%, #fff, transparent), radial-gradient(1px 1px at 88% 6%, #fff, transparent),
    radial-gradient(1px 1px at 6% 34%, #fff, transparent), radial-gradient(1px 1px at 35% 38%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 70% 40%, #fff, transparent), radial-gradient(1px 1px at 95% 36%, #fff, transparent);
}
body.night #stars { opacity: 0.9; }
#landscape { position: fixed; left: 0; right: 0; bottom: 0; height: 100vh; z-index: -2; filter: var(--land-filter); transition: filter 2s; }
#landscape svg { width: 100%; height: 100%; display: block; }
#landscape .lights, #landscape .lamps { transition: opacity 2s; }
body:not(.night) #landscape .lamps { opacity: 0.25; }
body.night #landscape .lights { opacity: 1; filter: drop-shadow(0 0 6px #ffcf6a); }
body.photo #landscape { background: center / cover no-repeat var(--photo); }
body.photo #sky { display: none; }

/* ---------- tableau : deux ambiances ---------- */
.board {
  --accent: var(--dep); --bg: var(--dep-bg);
  width: min(980px, 100%); background: var(--bg);
  border: 1px solid rgba(255, 255, 255, 0.12); border-top: 6px solid var(--accent);
  border-radius: 14px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  overflow: hidden; transition: background .4s, border-color .4s;
}
.board.mode-arrivals { --accent: var(--arr); --bg: var(--arr-bg); }
.board-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 18px 24px 12px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
h1 { margin: 2px 0 0; font-size: clamp(22px, 4vw, 34px); font-weight: 650; letter-spacing: -0.01em; }
.clock { font-variant-numeric: tabular-nums; color: var(--accent); font-size: clamp(28px, 5vw, 44px); font-weight: 600; line-height: 1; }
.clock span { font-size: 0.55em; opacity: 0.8; }

/* sélecteur Départs / Arrivées */
.switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 4px 24px 14px; }
.switch button {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px; border-radius: 10px; cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.14); background: rgba(255, 255, 255, 0.04);
  color: var(--muted); font-size: 18px; font-weight: 700; letter-spacing: 0.02em;
  transition: background .2s, color .2s, border-color .2s;
}
.switch svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.switch .sw-dep[aria-selected="true"] { background: var(--dep); border-color: var(--dep); color: #0b1d45; }
.switch .sw-arr[aria-selected="true"] { background: var(--arr); border-color: var(--arr); color: #06302a; }
.switch button:hover[aria-selected="false"] { color: var(--text); border-color: rgba(255, 255, 255, 0.3); }
.switch button:focus-visible, .period button:focus-visible, .row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 24px; background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-top: 1px solid rgba(255, 255, 255, 0.08); border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.banner p { margin: 0; color: var(--accent); font-weight: 650; font-size: 14px; }
.period { display: flex; background: rgba(0, 0, 0, 0.25); border-radius: 8px; padding: 3px; }
.period button { border: 0; background: none; color: var(--muted); padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; }
.period button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.14); color: var(--text); }

.cols, .row { display: grid; grid-template-columns: 92px 112px 1fr 150px; gap: 12px; align-items: center; padding: 0 24px; }
.cols { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; padding-top: 10px; padding-bottom: 6px; }

.rows { list-style: none; margin: 0; padding: 0; }
.board.long .rows { max-height: 62vh; overflow-y: auto; scrollbar-color: rgba(255,255,255,.25) transparent; }
.row { min-height: 64px; padding-top: 8px; padding-bottom: 8px; border-top: 1px solid rgba(255, 255, 255, 0.08); cursor: pointer; position: relative; }
.row:nth-child(odd) { background: rgba(255, 255, 255, 0.025); }
.row:hover { background: rgba(255, 255, 255, 0.07); }
.row.selected { background: color-mix(in srgb, var(--accent) 16%, transparent); box-shadow: inset 4px 0 0 var(--accent); }
.time { color: var(--accent); font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.time.struck { color: var(--muted); text-decoration: line-through; font-size: 20px; }
.train { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); }
.train b { color: var(--text); font-size: 15px; font-weight: 600; }
.badge { display: inline-block; width: fit-content; margin-top: 3px; padding: 1px 7px; border-radius: 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; background: #2b4a8a; color: #fff; }
.mode-arrivals .badge { background: #1d6b58; }
.badge.car { background: #7a4fb5 !important; }
.dest { min-width: 0; }
.dest b { display: block; font-size: 20px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dest b .dir { color: var(--muted); font-weight: 500; font-size: 0.7em; margin-right: 6px; }
.via { display: block; color: var(--muted); font-size: 13px; overflow: hidden; white-space: nowrap; mask-image: linear-gradient(to right, #000 90%, transparent); }
.via span { display: inline-block; }
.via.scroll span { animation: defile 26s linear infinite; }
@keyframes defile { 0%, 8% { transform: translateX(0); } 100% { transform: translateX(-50%); } }
.info { text-align: right; font-weight: 650; font-size: 15px; }
.info .new { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.info.ontime { color: var(--ok); }
.info.late { color: var(--late); }
.info.canceled { color: var(--cancel); }
.row.canceled .dest b { text-decoration: line-through; opacity: 0.7; }
.map-hint { position: absolute; right: 8px; top: 8px; width: 16px; height: 16px; opacity: 0; transition: opacity .2s; stroke: var(--muted); fill: none; stroke-width: 2; }
.row:hover .map-hint, .row.selected .map-hint { opacity: 1; }

.day {
  position: sticky; top: 0; z-index: 1; padding: 8px 24px; background: color-mix(in srgb, var(--accent) 22%, #0b1730);
  color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
}
.empty { padding: 28px 24px; color: var(--muted); }
.more { display: block; width: 100%; padding: 12px; border: 0; border-top: 1px solid rgba(255,255,255,.08); background: none; color: var(--accent); font-weight: 650; cursor: pointer; }
.more:hover { background: rgba(255,255,255,.05); }
.board-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; padding: 12px 24px; border-top: 1px solid rgba(255, 255, 255, 0.08); color: var(--muted); font-size: 12px; }
#rt-status::before { content: "●"; margin-right: 6px; color: var(--muted); }
#rt-status.live::before { color: var(--ok); }
#rt-status.down::before { color: var(--cancel); }

/* ---------- panneau carte ---------- */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); z-index: 50;
  display: flex; flex-direction: column; background: #0d1a33; color: var(--text);
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.5); border-left: 6px solid var(--panel-accent, var(--dep));
  animation: slidein .25s ease-out;
}
.panel[hidden] { display: none; }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } }
.panel-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px 18px 10px; }
.panel-head h2 { margin: 2px 0 4px; font-size: 22px; }
.p-status { margin: 0; font-size: 14px; font-weight: 600; }
.p-status.ontime { color: var(--ok); } .p-status.late { color: var(--late); } .p-status.canceled { color: var(--cancel); }
.p-status small { display: block; color: var(--muted); font-weight: 500; margin-top: 2px; }
.close { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.06); color: var(--text); font-size: 24px; line-height: 1; cursor: pointer; }
.close:hover { background: rgba(255,255,255,.14); }
.map { flex: none; height: 46vh; min-height: 260px; background: #1b2a44; }
.estimate { margin: 0; padding: 8px 18px; font-size: 12px; color: var(--muted); background: rgba(255,255,255,.04); }
.stops { list-style: none; margin: 0; padding: 8px 0 24px; overflow-y: auto; flex: 1; }
.stops li { display: grid; grid-template-columns: 18px 1fr auto; gap: 10px; align-items: center; padding: 6px 18px; font-size: 14px; position: relative; }
.stops li::before { content: ""; position: absolute; left: 26px; top: 0; bottom: 0; width: 2px; background: #3a4a68; }
.stops li:first-child::before { top: 50%; } .stops li:last-child::before { bottom: 50%; }
.stops .dot { position: relative; z-index: 1; width: 12px; height: 12px; border-radius: 50%; background: #0d1a33; border: 2px solid #8796b5; justify-self: center; }
.stops li.passed { color: var(--muted); }
.stops li.passed .dot { background: #8796b5; }
.stops li.here .dot { width: 16px; height: 16px; border-color: var(--panel-accent, var(--dep)); background: var(--panel-accent, var(--dep)); }
.stops li.here { font-weight: 700; }
.stops li.skipped span:nth-child(2) { text-decoration: line-through; color: var(--cancel); }
.stops .t { text-align: right; font-variant-numeric: tabular-nums; }
.stops .t s { color: var(--muted); margin-right: 6px; font-size: 12px; }
.stops .t.late { color: var(--late); }
.stops li.current { background: rgba(255,255,255,.06); }

.train-marker { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--panel-accent, #ffcf3f); border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(255, 207, 63, .3), 0 4px 10px rgba(0,0,0,.4); }
.train-marker svg { width: 18px; height: 18px; fill: #0b1d45; }
.train-marker.moving { animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 207, 63, .55), 0 4px 10px rgba(0,0,0,.4); } 100% { box-shadow: 0 0 0 16px rgba(255, 207, 63, 0), 0 4px 10px rgba(0,0,0,.4); } }
.stop-label { background: rgba(13, 26, 51, .85); color: #fff; border: 0; border-radius: 4px; box-shadow: none; font-size: 11px; padding: 2px 6px; }
.stop-label::before { display: none; }

@media (max-width: 640px) {
  .board-head { padding: 14px 16px 10px; }
  .switch { padding: 4px 16px 12px; }
  .switch button { font-size: 16px; padding: 10px; }
  .banner { padding: 8px 16px; }
  .cols { display: none; }
  .row { grid-template-columns: 64px 1fr auto; grid-template-areas: "time dest info" "time train info"; gap: 2px 10px; padding: 10px 16px; }
  .time { grid-area: time; font-size: 22px; }
  .train { grid-area: train; flex-direction: row; gap: 8px; align-items: center; }
  .badge { margin-top: 0; }
  .dest { grid-area: dest; }
  .dest b { font-size: 17px; }
  .via { display: none; }
  .info { grid-area: info; font-size: 13px; }
  .info .new { font-size: 18px; }
  .day { padding: 8px 16px; }
  .panel { top: auto; height: 88vh; width: 100vw; border-left: 0; border-top: 6px solid var(--panel-accent, var(--dep)); border-radius: 16px 16px 0 0; animation-name: slideup; }
  @keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
  .map { height: 38vh; }
}
@media (prefers-reduced-motion: reduce) { .via.scroll span, .train-marker.moving, .panel { animation: none; } }

/* Roissy : familles de trains */
.badge.tgv { background: #8a1538 !important; }
.badge.ouigo { background: #e5007d !important; }
.badge.ic { background: #2a6fb5 !important; }
