/* BCP Travel — always-dark "Solari" split-flap machine.
   Tokens are repointed once here; components reference them, so the whole
   app inherits the board palette. */
:root {
  --bg: #050506;              /* outside the machine */
  --recess: #08080a;         /* dark board cavity */
  --card: #16151b;           /* flap / panel surfaces on the recess */
  --text: #efe6cd;           /* warm cream */
  --text-dim: #8f897a;
  --accent: #2bbcbc;         /* teal — links, maps, expand */
  --accent-soft: #123a3a;
  --border: #322f29;         /* warm dark hairline */
  --green: #2ec16a;
  --red: #e0584e;
  --subway: #c8201a;         /* Metro 53 red */
  --bus: #14a3a3;            /* teal */
  --rail: #ffc917;           /* NS yellow */
  --rail-text: #11101a;
  --tram: #0d9488;
  /* Mode-icon tiles (kept in colour) */
  --board: #15142a;          /* navy tile bg */
  --board-tile: #0f0e1f;
  --board-frame: #4f4636;
  --board-text: #efe6cd;
  --amber: #ffc24a;          /* warm Solari amber — logo, time flaps */
  --teal: #14a3a3;
  /* Machine housing */
  --frame: #2c2620;
  --frame-edge: #4f4636;
  --screw: #7a6a45;
  /* Split-flap rows + cards */
  --flap: #1c1b21;
  --flap-top: #2a2932;
  --flap-seam: #000000;
  --flap-seam-hi: #36353e;
  --pin: #6a6358;
  --clk-card: #0e0d12;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  overscroll-behavior-y: contain;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) 12px calc(env(safe-area-inset-bottom) + 24px);
}

/* The machine: brass chassis framing a recessed board */
.chassis {
  position: relative;
  background: var(--frame);
  border: 1px solid var(--frame-edge);
  border-radius: 22px;
  padding: 14px;
}

.board-recess {
  background: var(--recess);
  border: 1px solid #000;
  border-radius: 12px;
  padding: 14px 14px 18px;
}

/* Corner screws */
.screw {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--screw);
  box-shadow: inset 0 0 0 1px #3a3019;
}

.screw::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 8px;
  height: 1.5px;
  background: #2a2418;
  border-radius: 1px;
  transform: rotate(35deg);
}

.screw:nth-of-type(1) { top: 8px; left: 8px; }
.screw:nth-of-type(2) { top: 8px; right: 8px; }
.screw:nth-of-type(3) { bottom: 8px; left: 8px; }
.screw:nth-of-type(4) { bottom: 8px; right: 8px; }

/* Each screw's slot sits at its own angle, so they don't look stamped. */
.screw:nth-of-type(1)::after { transform: rotate(22deg); }
.screw:nth-of-type(2)::after { transform: rotate(-37deg); }
.screw:nth-of-type(3)::after { transform: rotate(71deg); }
.screw:nth-of-type(4)::after { transform: rotate(-9deg); }

/* Brand header — sits directly on the recess */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 2px;
}

/* Brand lockup: [B][C][P] Travel */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-board {
  display: flex;
  gap: 5px;
  perspective: 240px;
}

.brand .tile {
  position: relative;
  width: 26px;
  height: 34px;
  border-radius: 6px;
  background: var(--board-tile);
  color: var(--amber);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 21px;
  overflow: hidden;
}

/* Two halves of the same glyph, clipped at the seam. */
.brand .tile-half {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
}

.brand .tile-bottom { clip-path: inset(50% 0 0 0); }

.brand .tile-top {
  clip-path: inset(0 0 50% 0);
  transform-origin: 50% 50%;     /* hinge on the center seam */
  z-index: 1;
}

/* The leaving glyph's top half, peeling down over the new one (set per
   spin step in JS). */
.brand .tile-fall {
  clip-path: inset(0 0 50% 0);
  transform-origin: 50% 50%;
  z-index: 3;
  background: var(--board-tile);
  color: var(--amber);
}

.brand .tile-fall { animation: flap-peel 0.13s linear both; }

/* Flip-board fold seam */
.brand .tile::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--board);
  z-index: 2;
}

.brand-word {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.5px;
  color: var(--board-text);
}

#refresh-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--board-frame);
  color: var(--amber);
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}

#refresh-btn.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Split-flap falling motion.
   flap-peel: the OLD glyph's top half is hinged at the seam and falls
   forward + down toward the viewer, revealing the new glyph behind it.
   flap-drop: a NEW glyph's top half drops in from standing upright. */
@keyframes flap-peel {
  0%   { transform: rotateX(0deg); }
  100% { transform: rotateX(-90deg); }
}

@keyframes flap-drop {
  0%   { transform: rotateX(90deg); }
  60%  { transform: rotateX(-6deg); }
  100% { transform: rotateX(0deg); }
}

/* Solid-to-transparent fade behind the iOS status bar (black-translucent),
   so the system clock stays legible over scrolled content. */
#top-fade {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(env(safe-area-inset-top) + 14px);
  background: linear-gradient(var(--bg) 55%, transparent);
  z-index: 40;
  pointer-events: none;
}

/* ---- Pull to refresh ---- */
#pull-indicator {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 4px);
  left: 50%;
  transform: translate(-50%, -60px);
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  transition: transform 0.2s, opacity 0.2s;
}

#pull-indicator.visible { transform: translate(-50%, 0); opacity: 1; }

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ---- Departure boards ---- */
/* Each board is one connected flap panel — header + departures share the
   same flap background, divided by hairlines. */
.board {
  background: var(--flap);
  border: 1px solid #000;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 14px;
}

#boards .board:last-of-type { margin-bottom: 0; }

.board-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 11px;
  background:
    linear-gradient(180deg, var(--flap-top) 0, var(--flap-top) 49.5%, #050505 50%, var(--flap) 50.5%, var(--flap) 100%);
}

.board-title {
  flex: 1;
  min-width: 0;
}

.board-title h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

/* Maps hand-off icon in a board header */
.board-maps { width: 30px; height: 30px; }
.board-maps svg { width: 19px; height: 19px; }

.board-sub {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

/* Section mode icon (metro / bus / train) — colour tile, recessed look */
.mode-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 42px;
  border-radius: 10px;
  background: var(--board);
  border: 1px solid #000;
  flex-shrink: 0;
}

.mode-tile svg { width: 40px; height: auto; display: block; }

.line-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: 9px;
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  flex-shrink: 0;
}

/* Fixed-width badges in the departure rows so headsigns line up even when
   the label varies (IC / SPR / NS). */
.departures .line-badge.small {
  width: 32px;
  min-width: 32px;
  padding: 0;
}

.line-badge.small {
  min-width: 26px;
  height: 24px;
  font-size: 13px;
  border-radius: 7px;
}

.mode-subway { background: var(--subway); }
.mode-bus { background: var(--bus); }
.mode-rail, .mode-regional_rail, .mode-regional_fast_rail, .mode-highspeed_rail,
.mode-long_distance, .mode-night_rail { background: var(--rail); color: var(--rail-text); }
.mode-tram { background: var(--tram); }
.mode-ferry { background: #0ea5e9; }
.mode-coach { background: #7c3aed; }
.mode-walk { background: transparent; color: var(--text-dim); font-weight: 600; }

ul.departures {
  list-style: none;
  margin: 0;
  padding: 0;
}

ul.departures:empty::after {
  content: attr(data-empty);
  display: block;
  padding: 10px 0;
  color: var(--text-dim);
  font-size: 14px;
}

/* Each departure is a split-flap strip: hinge pins (background dots), a fold
   seam across the middle, and the content riding on top. */
/* The flap fold (two-tone + a 1px crease) lives in the background, so opaque
   parts (badges, tiles, clock cards) hide it and text rides on top — no
   strike-through. Hinge pins are the two dots at the ends. */
ul.departures li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 9px 11px;
  border-top: 1px solid #000;
  font-size: 15px;
  perspective: 240px;
  background:
    linear-gradient(180deg, var(--flap-top) 0, var(--flap-top) 49.5%, #050505 50%, var(--flap) 50.5%, var(--flap) 100%);
}

.dep-headsign {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dep-time {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

/* Delay column: reserved per board, only as wide as the current view needs
   (width set in JS; absent entirely when nothing is delayed). */
.dep-delay {
  color: var(--red);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 700;
  width: var(--delay-w, 0px);
  text-align: right;
  overflow: hidden;
  flex-shrink: 0;
}

/* Platform: compact number chip (full "spoor N" kept as tooltip/aria). */
.dep-track {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 0;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.board-expand {
  width: 100%;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.board-expand .expand-arrow {
  transition: transform 0.2s;
  display: inline-block;
}

.board-expand[aria-expanded="true"] .expand-arrow {
  transform: rotate(180deg);
}

/* Countdown: plain, readable amber text in a fixed column so every "x min"
   lines up (the live dot sits inside, never changing the column width). */
.dep-countdown {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex: 0 0 64px;
  white-space: nowrap;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  color: var(--amber);
}

/* Clock time as little amber split-flaps: each digit is a flap with a seam
   across the glyph; the colon is a plain separator. */
.clock-flap {
  display: inline-flex;
  align-items: stretch;
  gap: 2px;
  perspective: 220px;
}

.clock-flap .cell {
  position: relative;
  width: 10px;
  height: 22px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--clk-card);
}

.clock-flap .sep {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 4px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--amber);
}

.clock-flap .cf {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--amber);
  backface-visibility: hidden;
}

.clock-flap .cf-bottom { clip-path: inset(50% 0 0 0); }

.clock-flap .cf-top {
  clip-path: inset(0 0 50% 0);
  transform-origin: 50% 50%;
  z-index: 1;
}

.clock-flap .cf-fall {
  clip-path: inset(0 0 50% 0);
  transform-origin: 50% 50%;
  z-index: 3;
  background: var(--clk-card);
  color: var(--amber);
}

/* Fold seam across the digit */
.clock-flap .cell::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: #000;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06);
  z-index: 2;
}

.clock-flap .cf-fall { animation: flap-peel 0.42s cubic-bezier(0.4, 0.15, 0.3, 1) both; }
.clock-flap .cf-top.drop { animation: flap-drop 0.42s cubic-bezier(0.3, 0.7, 0.45, 1) both; }

.rt-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  margin-right: 3px;
  animation: pulse 2s ease-in-out infinite;
  vertical-align: 1px;
}

@keyframes pulse { 50% { opacity: 0.35; } }

#boards-updated {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  margin: 2px 0 4px;
}

.board.error ul.departures::after {
  content: attr(data-error);
  color: var(--red);
}

/* ---- Search ---- */
#search { margin: 18px 0 6px; }

.search-wrap { position: relative; }

#dest-input {
  width: 100%;
  min-height: 70px;
  padding: 8px 44px 8px 12px;
  font-size: 17px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--card);
  color: var(--text);
  outline: none;
}

#dest-input:focus { border-color: var(--accent); }

/* Split-flap placeholder: a two-row board filling the input width */
#ghost {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  pointer-events: none;
  overflow: hidden;
}

#ghost.hidden { display: none; }

/* Shared split-flap character row (placeholder board + results title). */
.flaprow {
  display: inline-flex;
  gap: 1px;
}

.flaprow .fcell {
  position: relative;
  width: 11px;
  height: 20px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--clk-card);
}

.flaprow .cf {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12px;
  color: var(--amber);
  backface-visibility: hidden;
}

.flaprow .cf-bottom { clip-path: inset(50% 0 0 0); }

.flaprow .cf-top {
  clip-path: inset(0 0 50% 0);
  transform-origin: 50% 50%;
  z-index: 1;
}

.flaprow .cf-fall {
  clip-path: inset(0 0 50% 0);
  transform-origin: 50% 50%;
  z-index: 3;
  background: var(--clk-card);
  color: var(--amber);
  animation: flap-peel 0.09s linear both;
}

.flaprow .fcell::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: #000;
  z-index: 2;
}

/* Results title as a bigger, wrapping flap board */
.flaprow-title {
  flex-wrap: wrap;
  gap: 2px;
}

.flaprow-title .fcell { width: 15px; height: 24px; border-radius: 3px; }
.flaprow-title .cf { font-size: 15px; }

/* Two-row board: cells stretch to fill the container width; the font
   scales with it (size isn't critical here). */
.flaprow-display {
  display: flex;
  width: 100%;
  gap: 2px;
  container-type: inline-size;
}

.flaprow-display .fcell {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
  height: 30px;
  border-radius: 2px;
}

.flaprow-display .cf { font-size: clamp(13px, 5.4cqw, 22px); }

/* Quick-pick destinations */
#quick { margin-top: 12px; }

#quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

#clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

#suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  list-style: none;
  margin: 0;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.14);
  max-height: 320px;
  overflow-y: auto;
}

#suggestions li {
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}

#suggestions li:active, #suggestions li.active { background: var(--accent-soft); }

.sug-icon { font-size: 17px; width: 22px; text-align: center; flex-shrink: 0; }

.sug-text { overflow: hidden; }

.sug-name {
  font-size: 15.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sug-area { font-size: 12.5px; color: var(--text-dim); }

/* ---- Recents ---- */
#recents { margin-top: 12px; }

.recents-label {
  margin: 0 0 6px 4px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

#recent-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Flip-board chips: amber mono on a flap face with a centre crease. */
.chip {
  position: relative;
  overflow: hidden;
  border: 1px solid #000;
  border-radius: 4px;
  padding: 5px 9px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12.5px;
  color: var(--amber);
  cursor: pointer;
  max-width: 100%;
  white-space: nowrap;
  text-overflow: ellipsis;
  background:
    linear-gradient(180deg, var(--flap-top) 0, var(--flap-top) 49.5%, #050505 50%, var(--flap) 50.5%, var(--flap) 100%);
}

.chip:active { filter: brightness(1.3); }

/* ---- Route results ---- */
#routes { margin-top: 20px; }

#routes-title {
  margin: 0 0 12px 2px;
  line-height: 0;
}

.route-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.route-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.route-card-head .icon { font-size: 18px; }

.route-card-head .mode-tile {
  width: 36px;
  height: 32px;
  border-radius: 8px;
}

.route-card-head .mode-tile svg { width: 30px; }

.route-card-head h3 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  flex: 1;
}

.route-note {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

.itinerary {
  border-top: 1px solid var(--border);
}

.itin-summary {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 10px 0;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.itin-times {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.itin-range { font-weight: 700; font-size: 15.5px; }

.itin-meta { color: var(--text-dim); font-size: 13px; flex: 1; }

.itin-duration { font-weight: 700; font-size: 15px; }

.itin-legs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 7px;
  font-size: 13px;
  color: var(--text-dim);
}

.leg-sep { opacity: 0.55; font-size: 11px; }

.leg-walk { white-space: nowrap; }

.itin-chevron {
  margin-left: auto;
  color: var(--accent);
  transition: transform 0.2s;
}

.itinerary.open .itin-chevron { transform: rotate(180deg); }

/* ---- Expanded step-by-step detail ---- */
.itin-detail { display: none; padding: 4px 0 12px; }

.itinerary.open .itin-detail { display: block; }

.leg-detail {
  position: relative;
  padding: 6px 0 6px 14px;
  border-left: 2px solid var(--border);
  margin-left: 4px;
}

.leg-detail-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.leg-dir { font-size: 13.5px; font-weight: 600; }

.leg-stop {
  display: flex;
  gap: 8px;
  font-size: 13.5px;
  padding: 1px 0;
}

.leg-stop-time {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 38px;
}

.leg-stop-name { color: var(--text); }

.leg-ride {
  font-size: 12px;
  color: var(--text-dim);
  padding: 2px 0 2px 46px;
}

.leg-walk-detail {
  font-size: 13px;
  color: var(--text-dim);
  padding: 6px 0 6px 4px;
}

/* Maps hand-off icon in the route-card header */
.maps-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  color: var(--accent);
  text-decoration: none;
}

.maps-link svg { width: 20px; height: 20px; display: block; }

.maps-link:active { opacity: 0.6; }

.route-card .status {
  padding: 10px 0 4px;
  font-size: 14px;
  color: var(--text-dim);
}

.route-card .status.error { color: var(--red); }

.skeleton {
  height: 18px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--border) 25%, var(--accent-soft) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  margin: 10px 0;
}

@keyframes shimmer { to { background-position: -200% 0; } }
