/* Split-flap departure board — old-school Solari style. */

/* Univers — using URW "U001", a Univers-metric clone (AFPL). See u001-LICENSE.txt */
@font-face {
  font-family: "Univers";
  src: url("/u001-reg.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Univers";
  src: url("/u001-bol.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --tw: clamp(11px, 2.4vw, 24px);     /* tile width  */
  --th: calc(var(--tw) * 1.5);        /* tile height */
  --gap: clamp(3px, 0.9vw, 12px);     /* gap between columns */
  --half: 100ms;                      /* default half-flap; JS overrides per flap (see app.js) */
  /* Univers if installed; close neo-grotesque fallbacks otherwise. */
  --font: "Univers", "Univers LT Std", "UniversLTStd", "Univers LT W01",
    "Helvetica Neue", Helvetica, Arial, sans-serif;
  --amber: #f5c542;
  --green: #3ad06a;
  --red: #ff4d4d;
  --dim: #8a8a8a;
  --ink: #ece6d2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: #050505;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: clamp(10px, 3vw, 36px);
}

.board {
  width: 100%;
  max-width: 1180px;
  background: linear-gradient(180deg, #161616, #0a0a0a);
  border: 1px solid #000;
  border-radius: 12px;
  padding: clamp(12px, 2.5vw, 26px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), inset 0 1px 0 #2a2a2a;
}

/* ---- header ---- */
.board__top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: clamp(10px, 2vw, 20px);
  position: relative;
  z-index: 10; /* keep the autocomplete dropdown above the board below it */
}
.board__title {
  font-weight: 800;
  letter-spacing: 0.18em;
  font-size: clamp(15px, 3.4vw, 26px);
  color: var(--amber);
}
.board__pick {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.board__arrow {
  flex: 0 0 auto;
  color: var(--dim);
  font-weight: 700;
}
/* Each input + its clear button + its autocomplete dropdown. */
.field {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
}
.board__route {
  width: 100%;
  background: #000;
  color: var(--ink);
  border: 1px solid #333;
  border-radius: 7px;
  padding: 7px 28px 7px 10px; /* right pad leaves room for the × */
  /* 16px min: iOS Safari auto-zooms when a focused input is below 16px. */
  font-size: 16px;
  font-weight: 600;
}

/* Clear (×) button — only shown once the field has text. */
.field__clear {
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  display: none;
  background: none;
  border: none;
  padding: 4px 6px;
  color: var(--dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.field.has-value .field__clear { display: block; }
.field__clear:hover { color: var(--ink); }

/* Custom autocomplete dropdown (replaces the unreliable mobile <datalist>). */
.field__list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  background: #0d0d0d;
  border: 1px solid #333;
  border-radius: 7px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.65);
  -webkit-overflow-scrolling: touch;
}
.field__opt {
  padding: 9px 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.field__opt small { color: var(--dim); font-weight: 400; margin-left: 6px; }
.field__opt.is-active,
.field__opt:hover { background: #1f1f1f; }
.board__sound {
  flex: 0 0 auto;
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  font-size: clamp(14px, 3vw, 18px);
  line-height: 1;
  opacity: 0.85;
}
.board__sound:hover { opacity: 1; }
.board__clock {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--amber);
  font-size: clamp(13px, 2.8vw, 18px);
  letter-spacing: 0.05em;
}

/* ---- column headers + rows share one grid ---- */
/* grid-template-columns is set inline by JS to match the active layout. */
.board__cols,
.row {
  display: grid;
  column-gap: var(--gap);
}

.board__cols {
  padding: 0 4px 8px;
  border-bottom: 1px solid #262626;
  margin-bottom: 8px;
}
.col {
  font-size: clamp(9px, 1.8vw, 12px);
  letter-spacing: 0.14em;
  font-weight: 700;
  color: var(--dim);
}

/* horizontal-scroll safety net: the board is ~30 tiles wide, so on very narrow
   screens it scrolls rather than clipping; header/footer stay put. */
.board__scroll { overflow-x: auto; scrollbar-width: thin; }
.board__cols, .board__rows { min-width: max-content; }

.board__rows { display: flex; flex-direction: column; gap: 6px; }
.row { padding: 0 4px; }
.cell { display: flex; }

/* ---- split-flap tile (real two-leaf mechanism) ----
   Each tile is four stacked half-cards: a static top + bottom that show the
   resting character, and two hinged "leaves" that animate one flap per glyph:
   the top leaf folds down (revealing the new top behind it), then the bottom
   leaf falls into place. Only characters that change ever move. */
.tile {
  position: relative;
  width: var(--tw);
  height: var(--th);
  perspective: calc(var(--tw) * 6.6); /* scale with tile size so the fold meets the seam */
  color: #f4f2ea;
  font-family: var(--font);
  font-weight: 700;
  font-variant-numeric: tabular-nums; /* keep digits even-width in a proportional font */
  font-size: calc(var(--tw) * 0.9); /* fill more of the tile so letters sit closer */
}
.tile__card {
  position: absolute;
  left: 0;
  width: 100%;
  height: 50%;
  overflow: hidden;
  display: flex;
  justify-content: center;
  background: #181818;
  backface-visibility: hidden;
}
.tile__card > b {
  height: var(--th);
  display: flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  line-height: 1;
}
.tile__top, .tile__fold-top {
  top: 0;
  align-items: flex-start;
  border-radius: 3px 3px 0 0;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.4); /* centre seam */
}
.tile__bottom, .tile__fold-bottom {
  bottom: 0;
  align-items: flex-end;
  border-radius: 0 0 3px 3px;
}
/* The leaves overlap the centre seam by a hair so the static half behind them
   never shows a 1px hairline as the fold crosses the midline (a common tearing
   tell on mobile). */
.tile__fold-top { z-index: 2; transform-origin: center bottom; height: calc(50% + 0.5px); }
.tile__fold-bottom { z-index: 2; transform-origin: center top; transform: rotateX(90deg); height: calc(50% + 0.5px); }
/* Promote ONLY the leaf that's actively flipping. Toggling will-change with the
   .go class means a tile gets its own compositor layer for the duration of a
   flap and releases it after — so we don't permanently promote hundreds of
   tiles (which would blow up GPU memory on a phone). */
.tile__fold-top.go { animation: foldTop var(--half) ease-in forwards; will-change: transform; }
.tile__fold-bottom.go { animation: foldBottom var(--half) ease-out forwards; animation-delay: var(--half); will-change: transform; }
@keyframes foldTop {
  to { transform: rotateX(-90deg); }
}
@keyframes foldBottom {
  from { transform: rotateX(90deg); }
  to { transform: rotateX(0deg); }
}

/* The "leaf catches shadow as it turns" shading used to ride on filter:
   brightness inside the fold keyframes. Animating `filter` forces a per-frame
   repaint that the compositor can't keep in sync with the `transform` layer —
   on mobile that desync is exactly what tears at the seam. We get the same look
   from a black overlay whose OPACITY animates instead, which the compositor
   handles on the same cheap path as the transform. */
.tile__fold-top::after,
.tile__fold-bottom::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
}
.tile__fold-top.go::after { animation: shadeIn var(--half) ease-in forwards; }
.tile__fold-bottom.go::after { animation: shadeOut var(--half) ease-out forwards; animation-delay: var(--half); }
@keyframes shadeIn { to { opacity: 0.28; } }  /* ≈ brightness(0.72) */
@keyframes shadeOut { from { opacity: 0.28; } to { opacity: 0; } }

/* The ":" is painted on permanently — not a flap at all. It uses the same
   line-height metric as the flap glyphs so it sits at the same height. */
.tile--sep .tile__card { display: none; }
.tile--sep::after {
  content: ":";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* rows are white by default; colour only signals a problem. Empty rows are NOT
   dimmed: the flaps must visibly roll to/from blank, and an instant colour
   change would hide that animation. A cleared slot just reads as blank tiles. */
.row.s-delayed   .tile { color: var(--amber); }
.row.s-cancelled .tile { color: var(--red); }

.board__empty {
  text-align: center;
  padding: clamp(30px, 7vw, 70px) 10px;
  color: var(--dim);
  font-size: clamp(13px, 2.6vw, 17px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ---- mobile: stacked two-line departure blocks ----
   On phones the six-column line is too wide, forcing tiny tiles and sideways
   scroll. Instead reflow each row into a block: a top line (DEP + DESTINATION
   flaps) over a second line of smaller flaps (arr · jrny · plat · expected).
   Desktop (≥600px) is untouched — everything below lives in the media query.
   The plain-text .row__sub is unused on mobile now; hidden everywhere. */
.row__sub { display: none; }

@media (max-width: 600px) {
  /* Top line: DEP + the 14-tile destination (~19 tiles) fit one line on a
     ~320–430px phone. Smaller than desktop, but legible and never wraps. */
  :root { --tw: clamp(11px, 4.3vw, 18px); }

  .board__cols { display: none; } /* column header doesn't fit the block layout */

  /* stop sideways scrolling; let blocks flow down the page */
  .board__scroll { overflow-x: visible; }
  .board__rows { min-width: 0; gap: 16px; }

  /* Two-line block via flex with a forced wrap: DEP + DESTINATION on line 1,
     the smaller ARR/JRNY/PLAT/EXPECTED flaps on line 2. (Overrides the
     stylesheet's display:grid; the inline grid-template-columns is then inert.) */
  .row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    column-gap: var(--gap);
    row-gap: 6px;
  }
  .cell--dep, .cell--dest { order: 0; }
  .row::before { /* zero-height full-width item → breaks the line after dest */
    content: "";
    order: 1;
    flex-basis: 100%;
    height: 0;
  }

  /* Second-line flaps are smaller (tile metrics all derive from --tw, so a
     local override shrinks height and glyph size together). The tile run stays
     a horizontal row; the tiny title is floated above it via position. */
  .cell--arr, .cell--jrny, .cell--plat, .cell--expected {
    order: 2;
    --tw: clamp(8px, 3.1vw, 13px);
    position: relative;
    margin-top: 12px; /* reserve room for the title above */
  }
  .cell--arr::before, .cell--jrny::before,
  .cell--plat::before, .cell--expected::before {
    content: attr(data-label);
    position: absolute;
    bottom: 100%; /* directly above the flaps */
    left: 0;
    margin-bottom: 2px;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.12em;
    white-space: nowrap;
    color: var(--dim);
  }
  .row.is-empty .cell::before { content: ""; } /* no titles on blank filler rows */
}

/* ---- footer ---- */
.board__bottom {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: clamp(10px, 2vw, 18px);
  padding-top: 10px;
  border-top: 1px solid #262626;
  font-size: clamp(10px, 2vw, 13px);
  color: var(--dim);
}
