:root {
  color-scheme: light dark;
  --bg: #fbfbf8;
  --fg: #1d1d1b;
  --muted: #4b4b46;
  --rule: #c9c9c2;
  --accent: #0a4f8c;
  --focus: #0a4f8c;
  --cell-on: #0a4f8c;
  --cell-on-mark: #ffffff;
  --cell-off-border: #6d6d66;
  --blocked: #a31526;
  --shot-off: #8a8a82;
  --code-bg: #efefe9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614;
    --fg: #ecebe5;
    --muted: #b5b4ac;
    --rule: #3a3a36;
    --accent: #7fb8ea;
    --focus: #7fb8ea;
    --cell-on: #7fb8ea;
    --cell-on-mark: #161614;
    --cell-off-border: #8f8e86;
    --blocked: #ff8f8f;
    --shot-off: #77766f;
    --code-bg: #22221f;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1rem/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

main, footer {
  max-width: 62rem;
  margin: 0 auto;
  padding-inline: 1.25rem;
}

main { padding-block: 1rem 3rem; }

footer {
  border-top: 1px solid var(--rule);
  padding-block: 1.5rem;
  color: var(--muted);
  font-size: .9rem;
}

section { margin-block: 3rem; }

h1 { font-size: clamp(1.8rem, 4.5vw, 2.7rem); line-height: 1.15; margin: .25rem 0 1rem; }
h2 { font-size: clamp(1.35rem, 3vw, 1.8rem); line-height: 1.2; margin: 0 0 .75rem; }
h3 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
h4 { font-size: 1rem; margin: 1rem 0 .4rem; }

p, li, dd { max-width: 70ch; }

a { color: var(--accent); }

code, pre {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: .92em;
}

code { background: var(--code-bg); padding: .05em .3em; border-radius: 3px; }

pre {
  background: var(--code-bg);
  padding: .75rem 1rem;
  overflow-x: auto;
  border-radius: 4px;
  max-width: 100%;
}

pre code { background: none; padding: 0; }

.kicker {
  margin: 0;
  color: var(--muted);
  font-size: .85rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.scope, .note, .status, .axis { color: var(--muted); font-size: .95rem; }
.label, .fixed { font-weight: 600; }

.gate-message {
  border-left: 3px solid var(--blocked);
  padding-left: .75rem;
}

.skip-link {
  position: absolute;
  left: .75rem;
  top: -3rem;
  z-index: 10;
  padding: .5rem .75rem;
  background: var(--bg);
  color: var(--fg);
}

.skip-link:focus { top: .75rem; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Grid cells: lit (read), grey outline (not read). The symbol and the sr-only text carry the state too. */
.grid-figure { margin: 1.25rem 0; }
.grid-figure figcaption { font-weight: 600; margin-bottom: .25rem; }

.cells {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(1.9rem, 1fr));
  gap: .35rem;
}

.cells.dense {
  grid-template-columns: repeat(auto-fill, minmax(1.15rem, 1fr));
  gap: .2rem;
  font-size: .7rem;
}

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--cell-off-border);
  border-radius: 4px;
  color: var(--cell-off-border);
  font-weight: 700;
  line-height: 1;
}

.cell.on,
.cell.read {
  background: var(--cell-on);
  border-color: var(--cell-on);
  color: var(--cell-on-mark);
}

/* Replays: two columns on wide screens, one column in narrow containers. */
.pair-wrap { container-type: inline-size; }

.pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.5rem;
  margin-top: 1rem;
}

/* The global section rule sets margin-block: 3rem. Replay columns are sections too, so reset it here. */
.side { min-width: 0; margin-block: 0; }

@container (max-width: 40rem) {
  .pair { grid-template-columns: minmax(0, 1fr); }
}

.meta {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: .15rem .75rem;
  margin: 0 0 .5rem;
  font-size: .95rem;
}

.meta dt { font-weight: 600; }
.meta dd { margin: 0; overflow-wrap: anywhere; }

.replay-button {
  font: inherit;
  margin: .25rem 0 .5rem;
  padding: .35rem .9rem;
  border: 2px solid var(--accent);
  border-radius: 4px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.replay-button:hover { background: var(--accent); color: var(--bg); }

/* Press feedback differs from hover: the button fills with the text colour. */
.replay-button:active { background: var(--fg); border-color: var(--fg); color: var(--bg); }

.steps {
  list-style: none;
  margin: .5rem 0 0;
  padding: 0 0 0 .75rem;
  border-left: 2px solid var(--rule);
}

.steps li { padding: .2rem 0; font-size: .95rem; }
.steps li.write, .steps li.final { font-weight: 600; }
.steps li.blocked { position: relative; color: var(--blocked); font-weight: 600; }
.steps li .note { margin-left: .4rem; }

.replay .cells { margin: .5rem 0; }
.pending { visibility: hidden; }

/* Video shot strip: widths follow the shot durations (flex-grow is set by app.js). */
.strip {
  list-style: none;
  display: flex;
  gap: 1px;
  height: 2.6rem;
  margin: .5rem 0 .25rem;
  padding: 0;
}

.shot { flex: 1 1 0; min-width: 2px; background: var(--shot-off); }
.shot.read { background: var(--cell-on); }

.axis {
  display: flex;
  justify-content: space-between;
  margin: 0 0 1rem;
}

/* GIS field units: names only. */
.fields {
  list-style: none;
  margin: .25rem 0 .5rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: .4rem;
}

.fields li {
  padding: .3rem .5rem;
  border: 2px solid var(--cell-on);
  border-radius: 4px;
  font-size: .9rem;
  overflow-wrap: anywhere;
}

/* Tables. On narrow containers each row becomes a card with the column name before each value. */
.table-wrap {
  container-type: inline-size;
  overflow-x: auto;
  margin: .75rem 0 1rem;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: .92rem;
}

/* Wide enough that columns do not collapse; the wrapper scrolls instead (it is keyboard-focusable). */
.table-wrap > table { min-inline-size: 36rem; }

details summary {
  cursor: pointer;
  font-weight: 600;
  padding-block: .25rem;
}

caption {
  text-align: left;
  font-weight: 600;
  padding-bottom: .4rem;
}

th, td {
  text-align: left;
  vertical-align: top;
  padding: .4rem .5rem;
  border-bottom: 1px solid var(--rule);
}

thead th { border-bottom: 2px solid var(--rule); }
tfoot th, tfoot td { font-weight: 600; }

@container (max-width: 40rem) {
  .responsive thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .responsive,
  .responsive tbody,
  .responsive tfoot,
  .responsive tr { display: block; }

  .responsive tr {
    border-bottom: 2px solid var(--rule);
    padding: .5rem 0;
  }

  .responsive th,
  .responsive td {
    display: block;
    border: 0;
    padding: .15rem .25rem;
  }

  .responsive {
    min-inline-size: 0;
  }

  .responsive caption {
    display: block;
    width: 100%;
  }

  .responsive td::before {
    content: attr(data-label) ": ";
    font-weight: 600;
  }
}

/* Dates and model names stay on one line in the ledger on wide screens. */
.ledger td[data-label="Date"],
.ledger td[data-label="Model"] {
  white-space: nowrap;
}

/* Reduced motion: no playback and no flashing; the final state is shown with a note. */
.motion-note { display: none; }

@media (prefers-reduced-motion: reduce) {
  .motion-note { display: block; }
  .replay-button { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  /* The frame fades in and out with opacity only, at most twice in 2.4 seconds. app.js adds
   * .revealed when the step appears, so the flash plays where it can be seen. */
  .steps li.blocked.revealed::after {
    content: "";
    position: absolute;
    inset: -3px;
    border: 2px solid var(--blocked);
    border-radius: 4px;
    opacity: 0;
    pointer-events: none;
    animation: flash 1.2s ease-in-out 2;
  }

  @keyframes flash {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
  }
}
