/* Look from docs/mockup (Main.dc.html = portrait kiosk, Phone.dc.html = phone).
   No inline styles in HTML (the CSP blocks them); classes only. JS may set element.style (CSSOM).
   Served no-cache; open pages reload themselves when config.json's version changes (home.js). */

/* Self-hosted variable fonts (SIL OFL 1.1, licences in /fonts), so the CSP stays font-src 'self'. */
@font-face {
  font-family: 'Inter';
  src: url('/fonts/inter-latin-wght-normal.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Space Grotesk';
  src: url('/fonts/space-grotesk-latin-wght-normal.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/jetbrains-mono-latin-wght-normal.woff2') format('woff2');
  font-weight: 100 800;
  font-display: swap;
}

:root {
  --bg: #0B1220;
  --map-bg: #0E1729;
  --panel: #121A2B;
  --border: #1E2940;
  --grid-line: #1B2742;
  --text: #E6EDF7;
  --text-soft: #C9D3E3;
  --muted: #93A1B8;
  --accent: #F5A524;
  --accent-hover: #FFC861;
  --fly: rgba(245, 165, 36, 0.35);
  --fly-text: #FFE2B0;
  --lay: rgba(245, 165, 36, 0.12);
  --route-dim: #5A6B8E;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-head: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* 1 "mockup pixel". Phone layout: real pixels (Phone.dc.html is 390 px wide). */
  --u: 1px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: calc(16 * var(--u));
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-head); font-weight: 700; margin: 0; }
a, .link-btn { color: var(--accent); }
a:hover, .link-btn:hover { color: var(--accent-hover); }
button { font: inherit; color: inherit; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* ---------- App shell (phone first) ---------- */
.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: calc(60 * var(--u));
  padding: 0 calc(20 * var(--u));
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.brand { font-size: calc(20 * var(--u)); letter-spacing: 0.5px; }
.topbar-right { display: flex; align-items: center; gap: calc(12 * var(--u)); }
.clock { font-size: calc(15 * var(--u)); color: var(--muted); }
.clock-date { display: none; font-size: calc(20 * var(--u)); color: var(--muted); }
.badge {
  font-family: var(--font-mono); font-size: calc(11 * var(--u)); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px;
}

/* ---------- Map (MapLibre + OpenFreeMap Dark) ---------- */
.map {
  position: relative;
  height: calc(300 * var(--u));
  background: var(--map-bg);
  overflow: hidden;
  flex: none;
}
body.in-flight .map { height: calc(380 * var(--u)); }
.map-canvas { position: absolute; inset: 0; }
.map-legend {
  position: absolute; left: calc(12 * var(--u)); top: calc(12 * var(--u)); z-index: 2;
  display: none; align-items: center; gap: calc(8 * var(--u));
  font-size: calc(12 * var(--u)); color: var(--text-soft);
  background: rgba(11, 18, 32, 0.85); border: 1px solid var(--border);
  border-radius: calc(10 * var(--u)); padding: calc(6 * var(--u)) calc(10 * var(--u));
}
body.in-flight .map-legend { display: flex; }
.legend-line { display: inline-block; width: calc(26 * var(--u)); height: 0; margin-left: calc(6 * var(--u)); }
.legend-line:first-child { margin-left: 0; }
.legend-live { border-top: calc(5 * var(--u)) solid var(--accent); border-radius: 3px; }
.legend-est { border-top: calc(5 * var(--u)) dashed var(--accent); opacity: 0.75; }
.legend-rest { border-top: calc(4 * var(--u)) dotted var(--route-dim); }
.map-caption {
  position: absolute; left: calc(12 * var(--u)); bottom: calc(12 * var(--u)); z-index: 2;
  font-size: calc(13 * var(--u)); color: var(--text-soft);
  background: rgba(11, 18, 32, 0.85); border: 1px solid var(--border);
  border-radius: calc(8 * var(--u)); padding: calc(6 * var(--u)) calc(10 * var(--u));
}
.map-airport {
  width: calc(14 * var(--u)); height: calc(14 * var(--u)); border-radius: 50%;
  background: var(--map-bg); border: calc(3 * var(--u)) solid var(--text);
}
.map-airport::after {
  content: attr(data-code);
  position: absolute; left: calc(16 * var(--u)); top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono); font-weight: 700; font-size: calc(16 * var(--u)); color: var(--text);
  text-shadow: 0 0 4px var(--bg), 0 0 8px var(--bg);
  white-space: nowrap; pointer-events: none;
}
.map-plane { width: calc(34 * var(--u)); height: calc(34 * var(--u)); filter: drop-shadow(0 0 6px rgba(245, 165, 36, 0.45)); }
.maplibregl-ctrl-attrib, .maplibregl-ctrl-attrib.maplibregl-compact {
  background: rgba(11, 18, 32, 0.8) !important; color: var(--muted);
}
.maplibregl-ctrl-attrib a { color: var(--muted); }
.maplibregl-ctrl-attrib-button { filter: invert(1) opacity(0.6); }

/* ---------- Flight details ---------- */
.details {
  padding: calc(20 * var(--u));
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: calc(16 * var(--u));
  flex: none;
}
.details > p { margin: 0; }

.details-next { display: flex; flex-direction: column; gap: calc(16 * var(--u)); }
.countdown-block { display: flex; flex-direction: column; gap: calc(4 * var(--u)); }
.eyebrow { font-size: calc(14 * var(--u)); font-weight: 600; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; }
.countdown { font-size: calc(44 * var(--u)); font-weight: 700; color: var(--accent); line-height: 1.1; }
.next-summary { font-size: calc(16 * var(--u)); color: var(--text-soft); }

.trip-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.trip-list li {
  display: grid; grid-template-columns: calc(74 * var(--u)) calc(84 * var(--u)) minmax(0, 1fr);
  gap: calc(8 * var(--u)); align-items: baseline;
  padding: calc(9 * var(--u)) calc(12 * var(--u));
  background: var(--panel); border-radius: calc(8 * var(--u));
  font-size: calc(14 * var(--u));
}
.trip-day { color: var(--muted); }
.trip-flight { font-family: var(--font-mono); font-weight: 700; }
.trip-rest { display: flex; justify-content: space-between; gap: 8px; }
.trip-route { font-family: var(--font-mono); }
.trip-time { color: var(--text-soft); }
.trip-list li.is-past { opacity: 0.45; }

.details-flying { display: flex; flex-direction: column; gap: calc(20 * var(--u)); }
.flight-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.flight-title { display: flex; flex-direction: column; gap: calc(6 * var(--u)); }
.flight-code-row { display: flex; align-items: center; gap: calc(12 * var(--u)); }
.flight-code { font-size: calc(36 * var(--u)); font-weight: 700; }
.pill {
  font-size: calc(13 * var(--u)); font-weight: 600; color: var(--bg); background: var(--accent);
  padding: calc(4 * var(--u)) calc(10 * var(--u)); border-radius: 999px;
}
.flight-route { font-size: calc(17 * var(--u)); color: var(--text-soft); }
.fly-status { display: flex; flex-direction: column; align-items: flex-end; gap: calc(6 * var(--u)); }
.data-badge {
  font-family: var(--font-mono); font-size: calc(13 * var(--u)); font-weight: 700; letter-spacing: 1px;
  color: var(--text-soft); border: 1px dashed #3A4A6B; border-radius: 999px;
  padding: calc(4 * var(--u)) calc(10 * var(--u));
}
.data-badge.is-live { color: var(--bg); background: var(--accent); border: 1px solid var(--accent); }
.offline-note { font-size: calc(13 * var(--u)); color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.offline-note::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #E5484D; }
.tile-sub { font-size: calc(12 * var(--u)); color: var(--muted); }
.tile-value.is-live { color: var(--accent); }
.fly-next { margin: 0; font-size: calc(14 * var(--u)); color: var(--text-soft); }
.progress-block { display: flex; flex-direction: column; gap: calc(10 * var(--u)); }
.progress-ends { display: flex; justify-content: space-between; gap: 8px; font-size: calc(16 * var(--u)); }
.pt { color: var(--muted); font-size: 0.75em; }
.progress { height: calc(14 * var(--u)); background: var(--grid-line); border-radius: calc(7 * var(--u)); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: calc(7 * var(--u)); }
.progress-labels { display: flex; justify-content: space-between; font-size: calc(14 * var(--u)); color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: calc(12 * var(--u)); }
.tile {
  background: var(--panel); border-radius: calc(14 * var(--u));
  padding: calc(14 * var(--u)) calc(16 * var(--u));
  display: flex; flex-direction: column; gap: calc(4 * var(--u));
}
.tile-label { font-size: calc(13 * var(--u)); color: var(--muted); }
.tile-value { font-size: calc(22 * var(--u)); font-weight: 700; }
.tile-accent { color: var(--accent); font-family: var(--font-body); font-size: calc(18 * var(--u)); font-weight: 600; }

.notice h2 { font-size: calc(20 * var(--u)); margin-bottom: 8px; }
.notice p { margin: 0; }

/* ---------- Calendar ---------- */
.calendar {
  padding: calc(16 * var(--u)) calc(20 * var(--u)) calc(24 * var(--u));
  display: flex; flex-direction: column; gap: calc(10 * var(--u));
}
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cal-title-row { display: flex; align-items: center; gap: calc(6 * var(--u)); }
.cal-title { font-size: calc(20 * var(--u)); min-width: 9.5em; text-align: center; }
.icon-btn {
  min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--muted);
  font-size: calc(28 * var(--u)); line-height: 1; cursor: pointer; border-radius: 10px;
}
.icon-btn:hover, .icon-btn:focus-visible { color: var(--text); background: var(--panel); }
.legend { display: none; gap: calc(20 * var(--u)); font-size: calc(16 * var(--u)); color: var(--muted); }
.legend-item { display: flex; align-items: center; gap: calc(8 * var(--u)); }
.swatch { width: calc(14 * var(--u)); height: calc(14 * var(--u)); border-radius: 4px; }
.swatch-fly { background: var(--fly); }
.swatch-lay { background: var(--lay); }

.cal-weekdays, .cal-grid {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: calc(4 * var(--u));
}
.cal-weekdays { font-size: calc(12 * var(--u)); color: var(--muted); text-align: center; }
.cal-grid { grid-auto-rows: calc(46 * var(--u)); }

.day {
  border: 0; border-radius: calc(8 * var(--u)); padding: 0;
  background: var(--panel); color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-width: 0; min-height: 0; overflow: hidden;
}
button.day { cursor: pointer; }
button.day:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.day-num { font-size: calc(14 * var(--u)); font-weight: 600; }
.day.home .day-num { color: var(--muted); font-weight: 400; }
.day.fly { background: var(--fly); }
.day.lay { background: var(--lay); }
.day-label { font-family: var(--font-mono); font-size: calc(9 * var(--u)); color: var(--fly-text); white-space: nowrap; }
.day.lay .day-label { color: var(--text-soft); }
.day-label-long { display: none; }
.day.today .day-num {
  font-weight: 700; color: var(--bg); background: var(--text); border-radius: 999px; padding: 0 calc(7 * var(--u));
}
.day.blank { background: transparent; }

.cal-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  font-size: calc(13 * var(--u)); color: var(--muted);
}
.sync { display: flex; align-items: center; gap: 12px; }
/* Touch-first: real px minimums (not scaled by --u) so it stays easy to tap on the kiosk; no
   hover-only behaviour; :active gives feedback on touch. */
.sync-btn {
  min-height: 48px; min-width: 120px; padding: 0 20px;
  border: 1px solid var(--accent); border-radius: 999px; background: transparent;
  color: var(--accent); font-weight: 600; font-size: max(15px, calc(16 * var(--u)));
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.sync-btn:active { background: rgba(245, 165, 36, 0.2); }
.sync-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sync-btn:disabled { color: var(--muted); border-color: var(--border); background: transparent; cursor: default; }
button { touch-action: manipulation; }
.link-btn { border: 0; background: none; padding: 0; min-height: 44px; cursor: pointer; font-size: inherit; text-decoration: underline; }
.link-btn:disabled { color: var(--muted); cursor: default; text-decoration: none; }

.foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 0 calc(20 * var(--u)) calc(16 * var(--u)) ;
  padding-bottom: max(calc(16 * var(--u)), env(safe-area-inset-bottom));
  font-size: calc(13 * var(--u));
}
.foot a { min-height: 44px; display: inline-flex; align-items: center; }

/* ---------- Day dialog ---------- */
.day-dialog {
  width: min(92vw, 560px); border: 1px solid var(--border); border-radius: 16px;
  background: var(--panel); color: var(--text); padding: 20px;
}
.day-dialog::backdrop { background: rgba(5, 9, 17, 0.7); }
.day-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.day-dialog-head h2 { font-size: 22px; }
.day-legs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.day-legs li { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.leg-top { display: flex; justify-content: space-between; gap: 12px; font-family: var(--font-mono); font-size: 18px; font-weight: 700; }
.leg-cities { color: var(--text-soft); font-size: 14px; }
.leg-times { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 15px; }
.leg-times dt { color: var(--muted); }
.leg-times dd { margin: 0; font-family: var(--font-mono); }
.leg-source { font-size: 12px; color: var(--muted); }

.error-panel { max-width: 560px; margin: 24px auto; padding: 20px; background: var(--panel); border-radius: 16px; }
.btn { min-height: 48px; padding: 0 24px; border: 0; border-radius: 999px; background: var(--accent); color: var(--bg); font-weight: 700; cursor: pointer; }

/* ---------- Portrait kiosk (Surface Pro 7) and other tall, wide screens: Main.dc.html ----------
   Sizes are the mockup's 1080×1920 pixels scaled to the viewport. Header, details and calendar keep
   their size (the calendar at least the mockup's ~560 px); the map takes whatever height is left.
   No page scroll. */
@media (orientation: portrait) and (min-width: 700px) {
  :root { --u: min(calc(100vw / 1080), calc(100vh / 1920)); }
  .app { max-width: none; height: 100dvh; min-height: 0; overflow: hidden; }
  .topbar { height: calc(96 * var(--u)); padding: 0 calc(48 * var(--u)); }
  .brand { font-size: calc(34 * var(--u)); }
  .topbar-right { gap: calc(24 * var(--u)); }
  .clock { font-size: calc(30 * var(--u)); color: var(--text); }
  .clock-date { display: inline; }
  .badge { font-size: calc(16 * var(--u)); padding: calc(4 * var(--u)) calc(12 * var(--u)); }

  .map, body.in-flight .map { height: auto; flex: 1 1 0; min-height: calc(240 * var(--u)); }
  .map-legend { left: calc(32 * var(--u)); top: calc(28 * var(--u)); font-size: calc(18 * var(--u)); gap: calc(12 * var(--u)); padding: calc(14 * var(--u)) calc(20 * var(--u)); border-radius: calc(12 * var(--u)); }
  .legend-line { width: calc(36 * var(--u)); }
  .map-caption { left: calc(32 * var(--u)); bottom: calc(24 * var(--u)); font-size: calc(18 * var(--u)); padding: calc(10 * var(--u)) calc(16 * var(--u)); border-radius: calc(10 * var(--u)); }
  .map-airport { width: calc(24 * var(--u)); height: calc(24 * var(--u)); border-width: calc(4 * var(--u)); }
  .map-airport::after { left: calc(30 * var(--u)); font-size: calc(30 * var(--u)); }
  .map-plane { width: calc(56 * var(--u)); height: calc(56 * var(--u)); }

  .details { padding: calc(36 * var(--u)) calc(48 * var(--u)); gap: calc(28 * var(--u)); }
  .details > p { font-size: calc(22 * var(--u)); }
  .eyebrow { font-size: calc(20 * var(--u)); }
  .countdown { font-size: calc(88 * var(--u)); }
  .next-summary { font-size: calc(26 * var(--u)); }
  .trip-list { gap: calc(4 * var(--u)); }
  .trip-list li { grid-template-columns: calc(120 * var(--u)) calc(150 * var(--u)) minmax(0, 1fr); font-size: calc(22 * var(--u)); padding: calc(10 * var(--u)) calc(18 * var(--u)); }
  .flight-code { font-size: calc(56 * var(--u)); }
  .pill { font-size: calc(18 * var(--u)); padding: calc(6 * var(--u)) calc(12 * var(--u)); }
  .flight-route { font-size: calc(26 * var(--u)); }
  .data-badge { font-size: calc(18 * var(--u)); padding: calc(6 * var(--u)) calc(14 * var(--u)); }
  .offline-note { font-size: calc(17 * var(--u)); }
  .tile-sub { font-size: calc(15 * var(--u)); }
  .fly-next { font-size: calc(22 * var(--u)); }
  .progress-ends { font-size: calc(24 * var(--u)); }
  .progress-labels { font-size: calc(20 * var(--u)); }
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: calc(16 * var(--u)); }
  .tile { padding: calc(18 * var(--u)) calc(20 * var(--u)); }
  .tile-label { font-size: calc(16 * var(--u)); }
  .tile-value { font-size: calc(32 * var(--u)); }
  .tile-accent { font-size: calc(22 * var(--u)); }

  body.in-flight .calendar { height: calc(534 * var(--u)); }
  .calendar { flex: none; height: calc(580 * var(--u)); padding: calc(28 * var(--u)) calc(48 * var(--u)) calc(20 * var(--u)); gap: calc(14 * var(--u)); }
  .cal-title { font-size: calc(30 * var(--u)); }
  .icon-btn { font-size: calc(40 * var(--u)); }
  .legend { display: flex; }
  .cal-weekdays { font-size: calc(15 * var(--u)); gap: calc(6 * var(--u)); }
  .cal-grid { gap: calc(6 * var(--u)); flex: 1; min-height: 0; grid-auto-rows: minmax(0, 1fr); }
  .day { align-items: flex-start; justify-content: flex-start; padding: calc(8 * var(--u)) calc(10 * var(--u)); gap: calc(4 * var(--u)); border-radius: calc(10 * var(--u)); }
  .day-num { font-size: calc(18 * var(--u)); }
  .day.today .day-num { padding: 0 calc(9 * var(--u)); }
  .day-label { font-size: calc(13 * var(--u)); line-height: 1.3; white-space: normal; text-align: left; }
  .day-label-short { display: none; }
  .day-label-long { display: inline; }
  .cal-foot { font-size: calc(18 * var(--u)); }
  .sync-btn { font-size: max(15px, calc(20 * var(--u))); }

  .foot { padding: 0 calc(48 * var(--u)) calc(14 * var(--u)); font-size: calc(15 * var(--u)); }
  .foot a { min-height: 0; }
}

/* Touch test mode (?touchtest=1, js/touchtest.js) */
.touchtest {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  background: rgba(11, 18, 32, 0.92);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}
.touchtest-info {
  position: absolute;
  top: 16px;
  left: 16px;
  margin: 0;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 8px;
  color: #fff;
  font: 16px/1.5 'JetBrains Mono', monospace;
  white-space: pre;
  pointer-events: none;
}
.touchtest-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: #5AA9FF;
  pointer-events: none;
}
.touchtest-down {
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  background: #F5A524;
}
.touchtest-up,
.touchtest-cancel {
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  background: transparent;
  border: 3px solid #F5A524;
}
.touchtest-cancel { border-color: #FF5C5C; }
