.board-panel {
  width: min(100%, 60rem);
  padding: clamp(0.5rem, 2.5vw, 1.5rem);
  border: 1px solid var(--housing-edge);
  border-radius: var(--radius);
  background: var(--housing);
  box-shadow: 0 1.5rem 3rem rgb(0 0 0 / 0.45), inset 0 1px 0 rgb(255 255 255 / 0.04);
}

.board-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-block-end: clamp(0.6rem, 2vw, 1rem);
  color: var(--amber);
  font: 700 clamp(0.8rem, 2.6vw, 1.05rem)/1.2 var(--font-board);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.board-header :is(h1, h2) { margin: 0; font: inherit; }
.clock { font-variant-numeric: tabular-nums; letter-spacing: 0.08em; }

/* The table is the content. It is what shows without scripts, and what a
   screen reader reads once the board has replaced it on screen. It is hidden
   through .timetable because a table never shrinks below its content's width. */
.departures {
  width: 100%;
  border-collapse: collapse;
  font: 600 clamp(0.8rem, 2.8vw, 1rem)/1.4 var(--font-board);
  text-transform: uppercase;
}
.departures th {
  padding: 0 0.5rem 0.4rem 0;
  color: var(--ink-dim);
  font-size: 0.75em;
  letter-spacing: 0.12em;
  text-align: start;
}
.departures td {
  padding: 0.4rem 0.5rem 0.4rem 0;
  border-block-start: 1px solid var(--housing-edge);
}
.departures td:last-child { color: var(--amber); }

.board { container-type: inline-size; }
.board:empty { display: none; }

/* Sizes are in flaps, and every flap's size follows from the board's width.
   A row is 28 flaps with one blank flap between fields. Only a board too
   narrow for that to stay legible wraps each row onto two lines, 19 across. */
.board-row {
  --flaps: 19;
  --gap-ratio: 0.1;
  --cell-w: calc(100cqi / (var(--flaps) + (var(--flaps) - 1) * var(--gap-ratio)));
  --cell-gap: calc(var(--cell-w) * var(--gap-ratio));
  --cell-h: calc(var(--cell-w) * 1.46);

  display: flex;
  flex-wrap: wrap;
  column-gap: calc(var(--cell-w) + 2 * var(--cell-gap));
  row-gap: var(--cell-gap);
}
.board-row + .board-row { margin-block-start: calc(var(--cell-h) * 0.4); }

.field { display: flex; gap: var(--cell-gap); }
.field:is([data-field="destination"], [data-field="name"]) { flex-basis: 100%; }
.field[data-field="status"] { margin-inline-start: auto; color: var(--amber); }

/* 300px of board gives flaps of about 10px, the smallest that read well. */
@container (min-width: 18.75rem) {
  .board-row { --flaps: 28; flex-wrap: nowrap; }
  .field:is([data-field="destination"], [data-field="name"]) { flex-basis: auto; }
}

.cell {
  position: relative;
  flex: none;
  inline-size: var(--cell-w);
  block-size: var(--cell-h);
  perspective: calc(var(--cell-h) * 5);
  font: 700 calc(var(--cell-h) * 0.72) / var(--cell-h) var(--font-board);
  text-align: center;
  contain: layout style;
}

/* Two halves at rest and two leaves that turn: the upper leaf falls away to
   show the new character's top, then the lower leaf swings down over the old
   character's bottom. */
.half, .leaf {
  position: absolute;
  inset-inline: 0;
  block-size: 50%;
  overflow: hidden;
  background: var(--flap);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.half.upper, .leaf.upper {
  inset-block-start: 0;
  border-radius: 0.14em 0.14em 0 0;
  background: var(--flap-top);
  transform-origin: 50% 100%;
}
.half.lower, .leaf.lower {
  inset-block-end: 0;
  border-radius: 0 0 0.14em 0.14em;
  transform-origin: 50% 0;
}
.leaf { z-index: 1; }

.glyph {
  position: absolute;
  inset-inline: 0;
  block-size: var(--cell-h);
}
.upper .glyph { inset-block-start: 0; }
.lower .glyph { inset-block-end: 0; }

.cell::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  inset-block-start: calc(50% - 0.5px);
  block-size: 1px;
  background: var(--hinge);
  z-index: 2;
}

/* Two identically named sets of keyframes, alternated per turn, restart the
   animation without forcing a reflow. --turn-half is set from the timing the
   board is planned with. */
@media (prefers-reduced-motion: no-preference) {
  .board { --turn-half: 40ms; }
  .cell[data-turn="a"] .leaf.upper { animation: fall-a var(--turn-half) ease-in both; }
  .cell[data-turn="b"] .leaf.upper { animation: fall-b var(--turn-half) ease-in both; }
  .cell[data-turn="a"] .leaf.lower { animation: land-a var(--turn-half) ease-out var(--turn-half) both; }
  .cell[data-turn="b"] .leaf.lower { animation: land-b var(--turn-half) ease-out var(--turn-half) both; }

  .board[data-state="settled"] .board-row[data-final] .field[data-field="status"] .cell {
    animation: boarding 1.8s ease-in-out infinite;
  }
}

@keyframes fall-a { from { transform: rotateX(0deg); } to { transform: rotateX(-90deg); } }
@keyframes fall-b { from { transform: rotateX(0deg); } to { transform: rotateX(-90deg); } }
@keyframes land-a { from { transform: rotateX(90deg); } to { transform: rotateX(0deg); } }
@keyframes land-b { from { transform: rotateX(90deg); } to { transform: rotateX(0deg); } }
@keyframes boarding { 50% { opacity: var(--pulse-low); } }

.notice { display: grid; justify-items: start; gap: 1.25rem; max-width: 34rem; }
.notice-text { margin: 0; font-size: 1.15rem; }
