/* Contrail — departures board, split-flap tiles and paper boarding passes. Retro B&W is the default look. */
:root {
  --bg: #f2f2f2; --card: #ffffff; --fg: #000000; --muted: #6e6e6e; --line: rgba(0,0,0,.14); --hair: rgba(0,0,0,.08);
  --flap: #222222; --flap-ink: #ffffff;
  --ok: #1fa548; --warn: #e88a00; --late: #e5372c; --air: #3d63e6; --gate: #ffcc00;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --font: var(--sans);
  --radius: 16px; --border: 1.5px solid var(--line);
  --tabbar: calc(56px + env(safe-area-inset-bottom));
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --card: #1c1c1c; --fg: #fff; --muted: #9a9a9a; --line: rgba(255,255,255,.18); --hair: rgba(255,255,255,.1);
    --flap: #3a3a3a; --ok: #32d25a; --warn: #ff9f0a; --late: #ff453a; --air: #5c85ff; }
}
html[data-theme="retro"] {
  --font: var(--mono); --line: var(--fg);
  --ok: var(--fg); --warn: var(--fg); --late: var(--fg); --air: var(--fg); --gate: var(--fg);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.35 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  padding-bottom: var(--tabbar); min-height: 100dvh; overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.caps { text-transform: uppercase; letter-spacing: .06em; }
.tiny { font-size: 10px; font-weight: 700; font-family: var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.t-ok { color: var(--ok); } .t-warn { color: var(--warn); } .t-late { color: var(--late); } .t-air { color: var(--air); } .t-muted { color: var(--muted); }

/* Page chrome */
.page { padding: calc(env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); max-width: 680px; margin: 0 auto; }
.titlebar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
.titlebar h1 { font: 800 30px/1.1 var(--font); margin: 6px 0 10px; letter-spacing: -.01em; }
html[data-theme="retro"] .titlebar h1 { font-size: 26px; text-transform: uppercase; letter-spacing: .02em; }
.navbar { position: sticky; top: 0; z-index: 500; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(env(safe-area-inset-top) + 4px) 8px 6px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border-bottom: 1px solid var(--hair); }
.navbar .title { font-weight: 700; font-family: var(--mono); text-align: center; white-space: nowrap; }
.navbar .right { justify-self: end; display: flex; gap: 4px; }
.iconbtn { border: 0; background: none; padding: 8px 10px; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; border-radius: 10px; }
.iconbtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn:active { background: var(--hair); }
.back { justify-self: start; font-family: var(--mono); font-weight: 600; }

/* Tab bar */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 900; height: var(--tabbar); padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr); background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px); border-top: 1px solid var(--hair); }
html[data-theme="retro"] #tabs { border-top: 1.5px solid var(--fg); background: var(--bg); }
#tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 10px; font-weight: 600; font-family: var(--font); }
#tabs a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs a.on { color: var(--fg); }
html[data-theme="modern"] #tabs a.on { color: var(--air); }
html[data-theme="retro"] #tabs a.on span { text-decoration: underline; text-underline-offset: 3px; }

/* Cards */
.card { background: var(--card); border: var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
html[data-theme="modern"] .card { border-color: transparent; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card h3 { margin: 0 0 10px; font: 800 12px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.section-head { display: flex; justify-content: space-between; font: 700 11px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 18px 4px 8px; }

/* Split-flap tiles */
.flap { display: inline-flex; gap: calc(var(--s, 22px) * .08); vertical-align: middle; }
.flap i { font: 700 var(--s, 22px)/1 var(--mono); font-style: normal; color: var(--flap-ink); background: var(--flap);
  width: calc(var(--s, 22px) * .74); height: calc(var(--s, 22px) * 1.28); display: inline-flex; align-items: center; justify-content: center;
  border-radius: calc(var(--s, 22px) * .12); position: relative; overflow: hidden; }
.flap i::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: max(1px, calc(var(--s, 22px) * .05)); background: rgba(0,0,0,.7); }
.flap i.flip { animation: flip .35s ease-out; }
@keyframes flip { 0% { transform: rotateX(80deg); } 100% { transform: none; } }

/* Board */
.board-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.board-head .grow { flex: 1; min-width: 0; }
.board-list { background: var(--card); border: var(--border); border-radius: var(--radius); overflow: hidden; }
html[data-theme="modern"] .board-list { border-color: transparent; }
.row { display: flex; gap: 12px; padding: 12px 14px; align-items: flex-start; border-top: 1px solid var(--hair); }
.row:first-child { border-top: 0; }
.row:active { background: var(--hair); }
.row .when { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.row .when small { font: 800 8px/1 var(--mono); color: var(--muted); }
.row .body { flex: 1; min-width: 0; }
.row .line1 { display: flex; align-items: center; gap: 6px; font: 700 12px/1.2 var(--mono); color: var(--muted); }
.row .line1 .sp { flex: 1; }
.row .city { font: 700 20px/1.2 var(--mono); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 3px 0 2px; }
.row .detail { font: 12px/1.3 var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-transform: uppercase; }
.row.past { opacity: .7; }
.live { font: 800 8px/1 var(--mono); padding: 2px 3px; border: 1px solid var(--ok); color: var(--ok); }
.remark { font: 800 11px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; padding: 4px 6px; border: 1.5px solid currentColor; }
.remark.alert { background: currentColor; }
.remark.alert span { color: var(--card); }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h2 { color: var(--fg); font: 700 20px/1.2 var(--font); margin: 12px 0 6px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1.5px solid var(--fg); background: var(--card); color: var(--fg);
  border-radius: 10px; padding: 11px 16px; font: 600 15px/1.2 var(--mono); min-height: 44px; }
.btn.primary { background: var(--fg); color: var(--bg); }
html[data-theme="modern"] .btn { border-color: transparent; background: var(--hair); font-family: var(--sans); }
html[data-theme="modern"] .btn.primary { background: var(--air); color: #fff; }
.btn.block { width: 100%; }
.btn.danger { color: var(--late); border-color: var(--late); }
html[data-theme="retro"] .btn.danger { color: var(--fg); border-color: var(--fg); }
.btn:disabled { opacity: .45; }
.btn:active:not(:disabled) { transform: scale(.98); }

/* Boarding pass */
.pass { background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; overflow: hidden; margin-bottom: 16px; }
.pass .band { display: flex; justify-content: space-between; gap: 12px; padding: 8px 16px; background: var(--fg); color: var(--bg); font: 800 11px/1.2 var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.pass .band span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pass .route { display: flex; align-items: center; justify-content: space-between; padding: 16px; gap: 8px; }
.pass .end { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pass .end.r { align-items: flex-end; text-align: right; }
.pass .end .city { font: 600 10px/1.2 var(--mono); color: var(--muted); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.pass .mid { display: flex; flex-direction: column; align-items: center; gap: 2px; font: 10px/1 var(--mono); color: var(--muted); }
.pass .mid svg { width: 22px; height: 22px; transform: rotate(90deg); fill: var(--fg); }
.fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 10px; padding: 0 16px 14px; }
.field { min-width: 0; }
.field b { display: block; font: 700 9px/1.2 var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field span { display: block; font: 600 16px/1.25 var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field s { display: block; font: 10px/1.2 var(--mono); color: var(--muted); }
.field.tap span { text-decoration: underline dotted; text-underline-offset: 3px; cursor: pointer; }
.perf { position: relative; height: 20px; }
.perf::before { content: ""; position: absolute; left: 14px; right: 14px; top: 50%; border-top: 1.2px dashed var(--muted); opacity: .7; }
.perf::after, .perf i { content: ""; position: absolute; top: 0; width: 20px; height: 20px; border-radius: 50%; background: var(--bg); }
.perf::after { right: -10px; } .perf i { left: -10px; }
html[data-theme="retro"] .perf::after, html[data-theme="retro"] .perf i { border: 1.5px solid var(--fg); }
.stub { display: flex; align-items: center; justify-content: space-between; padding: 16px; gap: 12px; }
.stamp { display: inline-block; font: 900 16px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; padding: 5px 10px; border: 2.5px solid currentColor;
  border-radius: 4px; outline: 1px solid color-mix(in srgb, currentColor 50%, transparent); outline-offset: 3px; transform: rotate(-5deg); opacity: .9; margin: 8px 4px 4px; white-space: nowrap; }
.barcode { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font: 9px/1 var(--mono); color: var(--muted); }
.barcode svg { width: 130px; height: 40px; fill: var(--fg); }

/* Timetable rows: "BOARDING ........ 19:05" */
.leader { display: flex; align-items: baseline; gap: 6px; font: 15px/1.3 var(--mono); padding: 4px 0; }
.leader .l { text-transform: uppercase; white-space: nowrap; }
.leader .dots { flex: 1; border-bottom: 2px dotted color-mix(in srgb, var(--muted) 70%, transparent); transform: translateY(-4px); min-width: 12px; }
.leader .v { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; max-width: 60%; }
.leader.done .l { font-weight: 700; }
.leader.done .l::before { content: "✓ "; color: var(--ok); }

.nowcard .big { font: 700 20px/1.2 var(--mono); text-transform: uppercase; }
.nowcard .note { font: 12px/1.35 var(--mono); margin-top: 8px; }
.stats { display: flex; gap: 18px; margin-top: 10px; flex-wrap: wrap; }
.stats div b { display: block; font: 700 9px/1.2 var(--mono); color: var(--muted); }
.stats div span { font: 700 13px/1.3 var(--mono); }
.progress { position: relative; height: 24px; margin-top: 10px; }
.progress .track, .progress .done { position: absolute; top: 50%; left: 0; height: 3px; border-radius: 2px; transform: translateY(-50%); }
.progress .track { right: 0; background: var(--hair); }
.progress .done { background: var(--air); }
.progress .plane { position: absolute; top: 50%; width: 22px; height: 22px; margin-left: -11px; transform: translateY(-50%); background: var(--card); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.progress .plane svg { width: 16px; height: 16px; fill: var(--air); transform: rotate(90deg); }
.source { font: 11px/1.4 var(--mono); color: var(--muted); padding: 0 4px 12px; }

/* Maps */
.mapbox { height: 230px; border-radius: 18px; overflow: hidden; border: 1.5px solid var(--line); margin-bottom: 16px; background: var(--card); }
.fullmap { position: fixed; inset: 0 0 var(--tabbar) 0; }
.fullmap .leaflet-container, .mapbox .leaflet-container { width: 100%; height: 100%; background: var(--bg); font-family: var(--mono); }
html[data-theme="retro"] .leaflet-tile-pane { filter: grayscale(1) contrast(1.12); }
.leaflet-tile-container img.leaflet-tile { width: 258px !important; height: 258px !important; } /* hides hairline seams at fractional zoom */
.leaflet-control-attribution { font-size: 9px !important; }
.ap-label { font: 800 11px/1 var(--mono); padding: 4px 7px; border-radius: 999px; background: rgba(0,0,0,.72); color: #fff; white-space: nowrap; transform: translate(-50%, -50%); display: inline-block; }
html[data-theme="retro"] .ap-label { background: var(--card); color: var(--fg); border: 1.5px solid var(--fg); border-radius: 2px; }
.ap-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--air); border: 2px solid var(--card); transform: translate(-50%, -50%); }
.plane-marker svg { width: 30px; height: 30px; fill: var(--air); stroke: var(--card); stroke-width: 1.2; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
html[data-theme="retro"] .plane-marker svg { fill: var(--fg); }
.plane-marker.est svg { opacity: .7; }
.chips { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar) + 10px); z-index: 600; display: flex; gap: 8px; overflow-x: auto; padding: 0 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; text-align: left; background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 8px 12px; font-family: var(--mono); }
.chip.on { background: var(--fg); color: var(--bg); }
.chip.on .t-air, .chip.on .t-ok, .chip.on .t-warn, .chip.on .t-late, .chip.on .t-muted { color: inherit; }
.chip b { display: block; font-size: 12px; } .chip span { display: block; font-size: 15px; font-weight: 600; } .chip small { display: block; font-size: 9px; font-weight: 800; }
.map-title { position: fixed; top: calc(env(safe-area-inset-top) + 10px); left: 14px; z-index: 600; background: var(--card); border: 1.5px solid var(--line); border-radius: 10px; padding: 6px 10px; font: 800 13px/1 var(--mono); letter-spacing: .1em; }

/* Logbook */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.bars div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.bars i { display: block; width: 100%; background: var(--fg); border-radius: 4px 4px 0 0; min-height: 1px; }
.bars small { font: 9px/1 var(--mono); color: var(--muted); white-space: nowrap; }
.bars em { font: 700 10px/1 var(--mono); font-style: normal; }
.rank { display: flex; gap: 10px; padding: 5px 0; font-size: 14px; }
.rank b { width: 20px; color: var(--muted); } .rank span { flex: 1; } .rank em { font-style: normal; font-weight: 700; font-variant-numeric: tabular-nums; }
select.pill { border: 1.5px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 10px; font-family: var(--mono); font-weight: 600; }

/* Forms / settings */
.group { background: var(--card); border: var(--border); border-radius: 12px; overflow: hidden; margin-bottom: 6px; }
html[data-theme="modern"] .group { border-color: transparent; }
.group > * + * { border-top: 1px solid var(--hair); }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 48px; width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.item:first-child { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .val { color: var(--muted); }
.item.danger { color: var(--late); }
.chev::after { content: "›"; font-size: 22px; color: var(--muted); line-height: 1; }
.foot { font-size: 12px; color: var(--muted); padding: 6px 14px 18px; line-height: 1.4; }
.label { font: 700 11px/1 var(--mono); color: var(--muted); letter-spacing: .1em; text-transform: uppercase; padding: 18px 14px 8px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; margin: 2px 0; width: 100%; }
.seg button { border: 0; background: none; padding: 9px 6px; font-weight: 600; font-size: 14px; }
.seg button + button { border-left: 1.5px solid var(--line); }
.seg button.on { background: var(--fg); color: var(--bg); }
input.text, textarea.text { width: 100%; border: 1.5px solid var(--line); border-radius: 10px; background: var(--card); padding: 12px; font-family: var(--mono); font-size: 16px; }
input.text:focus { outline: 2px solid var(--air); outline-offset: 1px; }
.toggle { appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--hair); position: relative; border: 1.5px solid var(--line); flex: none; transition: background .2s; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.toggle:checked { background: var(--fg); }
html[data-theme="modern"] .toggle:checked { background: var(--ok); border-color: transparent; }
.toggle:checked::after { transform: translateX(20px); }
.radio { display: flex; gap: 12px; align-items: flex-start; }
.radio .tick { width: 22px; flex: none; font-weight: 800; }
.msg { font: 13px/1.4 var(--mono); padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line); margin: 10px 0; }
.msg.err { color: var(--late); border-color: var(--late); }

/* Sheets */
.sheet-backdrop { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet { width: 100%; max-width: 680px; max-height: 92dvh; overflow-y: auto; background: var(--bg); border-radius: 16px 16px 0 0; padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); animation: up .28s cubic-bezier(.2,.9,.3,1); }
html[data-theme="retro"] .sheet { border: 1.5px solid var(--fg); border-bottom: 0; }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 6px; opacity: .5; }
.sheet .sheet-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 44px; margin-bottom: 8px; }
.sheet .sheet-bar strong { font-family: var(--mono); }
.sheet .sheet-bar button { justify-self: start; }
.menu .item { font-size: 16px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.result { display: flex; gap: 12px; align-items: center; padding: 12px 14px; }
.result .grow { flex: 1; min-width: 0; }
.result h4 { margin: 0 0 2px; font: 700 17px/1.2 var(--mono); }
.result p { margin: 0; font-size: 12px; color: var(--muted); }
.badge { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; font: 700 13px/1 var(--sans); flex: none; }
html[data-theme="retro"] .badge { background: var(--fg) !important; color: var(--bg); border-radius: 3px; font-family: var(--mono); }
.plus { font-size: 26px; font-weight: 300; }

/* Toasts */
#toasts { position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 8px); z-index: 2000; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast { pointer-events: auto; max-width: 520px; width: 100%; background: var(--card); border: 1.5px solid var(--fg); border-radius: 12px; padding: 10px 14px; font: 13px/1.35 var(--mono); box-shadow: 0 8px 24px rgba(0,0,0,.18); animation: drop .3s; }
.toast b { display: block; }
@keyframes drop { from { transform: translateY(-20px); opacity: 0; } }
.spin { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.hint { border: 1.5px dashed var(--line); border-radius: 12px; padding: 12px 14px; font-size: 13px; margin: 6px 0 14px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
