/*
 * Base tokens and page-wide layout for Please Remain Seated.
 *
 * Tokens mirror js/render/theme.js so the CSS chrome sits in the same palette as the canvas
 * and SVG marks. Type is Barlow with a real fallback stack; the only saturated colour on the
 * page is exit-sign green (for moving) and seatbelt amber (for bag work). Everything else is
 * a warm gray on paper.
 */

:root {
  --paper: #f4efe6;
  --paper-2: #ece5d6;
  --ink: #1f2a33;
  --ink-soft: rgba(31, 42, 51, 0.72);
  --ink-muted: rgba(31, 42, 51, 0.55);
  --ink-faint: rgba(31, 42, 51, 0.28);
  --rule: #c9c2b4;
  --seat-fill: #e6dfd2;
  --seat-stroke: #b8b0a0;
  --moving: #1f8a4c;
  --blocked: #4a4740;
  --bag: #e0a100;

  --font-body: "Barlow", "Helvetica Neue", Arial, sans-serif;
  --font-num: "Barlow", "Helvetica Neue", Arial, sans-serif;

  --radius-s: 4px;
  --radius-m: 8px;
  --radius-l: 14px;

  --gap-xs: 6px;
  --gap-s: 10px;
  --gap-m: 16px;
  --gap-l: 22px;
  --gap-xl: 32px;

  --page-side: clamp(16px, 4vw, 40px);
  --page-max: 1080px;

  --tap: 44px;

  /* Every native form control follows this accent. Browser blue is banned on this page. */
  accent-color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.42;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 28px var(--page-side) 60px;
}

/* Masthead */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--gap-m);
  margin-bottom: var(--gap-l);
}

.masthead .title-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
}

.masthead h1 {
  font-size: clamp(22px, 3.4vw, 30px);
  font-weight: 700;
  letter-spacing: 0.005em;
  margin: 0;
  color: var(--ink);
}

.masthead .deck {
  color: var(--ink-soft);
  font-size: clamp(13px, 1.6vw, 15px);
  margin: 0;
  max-width: 62ch;
}

/* Segmented control (mode toggle, speed) */

.segmented {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
  padding: 3px;
  gap: 2px;
  align-items: stretch;
}

.segmented .seg {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  min-height: 32px;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: 0.01em;
}

/* Round-02 NEW-m4 carry-over: the masthead mode toggle (Deplane / Board) was measured at
 * 32 px, under the 44 px tap-target spec. Bump this instance so the two mode tabs are
 * comfortable on a touch device without inflating the smaller in-flow speed pips inside
 * `#speed-group` or the tiny `.time-split .toggle-row` pips. */
.masthead .segmented .seg {
  min-height: var(--tap);
  padding: 8px 18px;
  font-size: 14px;
}

.segmented .seg:hover { color: var(--ink); }
.segmented .seg[aria-pressed="true"],
.segmented .seg.on {
  background: var(--ink);
  color: var(--paper);
}
.segmented .seg:focus-visible {
  outline: 2px solid var(--moving);
  outline-offset: 2px;
}

/* Generic inputs */

button, .btn {
  appearance: none;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  padding: 8px 16px;
  min-height: 36px;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: 0.01em;
}
button:hover, .btn:hover { border-color: var(--ink); }
button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--moving);
  outline-offset: 2px;
}

button.primary, .btn.primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
button.primary:hover, .btn.primary:hover { background: #0f1a24; }

select {
  appearance: none;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  padding: 6px 28px 6px 10px;
  min-height: 32px;
  border-radius: 6px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
                    linear-gradient(-45deg, transparent 50%, var(--ink-soft) 50%);
  background-position: right 12px top 50%, right 8px top 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
select:focus-visible { outline: 2px solid var(--moving); outline-offset: 2px; }

/* -------- Range inputs (paper palette, no browser blue anywhere) ---------- */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-height: var(--tap);
  background: transparent;
  cursor: pointer;
  accent-color: var(--ink);
}

/* WebKit / Blink track */
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--paper-2);
  border-radius: 999px;
  border: 1px solid var(--rule);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  box-shadow: 0 1px 2px rgba(31, 42, 51, 0.18);
  margin-top: -8px;
  cursor: grab;
}
input[type="range"]:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--moving);
  outline-offset: 2px;
}
input[type="range"]:active::-webkit-slider-thumb {
  background: var(--ink);
  cursor: grabbing;
}

/* Firefox */
input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--paper-2);
  border-radius: 999px;
  border: 1px solid var(--rule);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  box-shadow: 0 1px 2px rgba(31, 42, 51, 0.18);
  cursor: grab;
}
input[type="range"]:focus-visible::-moz-range-thumb {
  outline: 2px solid var(--moving);
  outline-offset: 2px;
}

/* -------- Checkbox (paper) ---------- */

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.checkbox-label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--rule);
  border-radius: 4px;
  background: var(--paper);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
  margin: 0;
  transition: background-color 0.12s ease-out, border-color 0.12s ease-out;
}
.checkbox-label input[type="checkbox"]:hover { border-color: var(--ink); }
.checkbox-label input[type="checkbox"]:checked {
  background: var(--ink);
  border-color: var(--ink);
}
.checkbox-label input[type="checkbox"]:checked::after {
  content: "";
  width: 8px;
  height: 4px;
  border-left: 2px solid var(--paper);
  border-bottom: 2px solid var(--paper);
  transform: rotate(-45deg) translate(1px, -1px);
}
.checkbox-label input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--moving);
  outline-offset: 2px;
}

input[type="text"], input[type="number"] {
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  border-radius: 6px;
  padding: 6px 10px;
  min-height: 32px;
}

label { color: var(--ink-soft); font-size: 13px; }

/* Sections */

.section {
  margin: var(--gap-xl) 0;
}

/* Sentence-case section headings above the compare and time-split blocks. Sized larger than
 * their sub-line and never in all-caps micro-type (m3 in the round-01 pass carried over into
 * round-02 as the "seven letterspaced micro-labels" complaint). */
.section-heading {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 2px;
  letter-spacing: 0.005em;
}
.section-sub {
  margin: 0;
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.45;
}

/* Finish card (winner + margin + settings + copy-link, drawn directly under lane B). Meant to
 * sit inside the viewport at the moment the race ends: race.js scrolls the second cabin card
 * and this card into view together on finish (NEW-B1). */

.finish-card {
  margin-top: var(--gap-s);
  background: var(--paper-2);
  border: 1px solid var(--ink);
  border-radius: var(--radius-l);
  padding: 14px 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 18px;
  align-items: center;
  box-shadow: 0 1px 0 rgba(31, 42, 51, 0.06);
}
.finish-card .headline {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
  grid-column: 1 / -1;
}
.finish-card .headline .winner-name { color: var(--moving); }
.finish-card .why {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.45;
  grid-column: 1;
}
.finish-card .facts {
  font-size: 12px;
  color: var(--ink-muted);
  line-height: 1.5;
  grid-column: 1;
}
.finish-card .actions {
  grid-column: 2;
  grid-row: 2 / 4;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  min-width: 160px;
}
.finish-card .actions button {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 13px;
}
.finish-card .pb {
  font-size: 12px;
  color: var(--ink-muted);
  text-align: right;
}
.finish-card .pb.new { color: var(--moving); font-weight: 600; }

@media (max-width: 620px) {
  .finish-card { grid-template-columns: 1fr; padding: 12px 14px; }
  .finish-card .actions { grid-column: 1; grid-row: auto; min-width: 0; flex-direction: row; }
  .finish-card .actions button { flex: 1 1 auto; }
  .finish-card .pb { text-align: left; }
}

/* Footer */

.footer {
  margin-top: 60px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  color: var(--ink-muted);
  font-size: 12px;
  display: flex;
  gap: var(--gap-m);
  flex-wrap: wrap;
  justify-content: space-between;
}
.footer a { color: var(--ink-muted); text-decoration: underline; text-underline-offset: 3px; }
.footer a:hover { color: var(--ink); }

/* Utility */

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

.mono-num { font-variant-numeric: tabular-nums; }

/* Muted label utility used by controls that need a soft label next to a form control.
 * Replaces one inline `style="color:var(--ink-muted);"` so index.html can ship with a
 * strict Content-Security-Policy that does not allow inline styles. */
.muted-label { color: var(--ink-muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* -------- Phone tap targets (N6-m6) ---------------------------------------
 *
 * WCAG 2.5.5 Level AAA and the round-06 critic ask for a 44 CSS-px hit area on every
 * interactive control at phone width. The base rules leave several controls narrower
 * (segmented pips at 32 px, the chime checkbox at 16 px, the finish-card action buttons
 * at 40 px, selects at 32 px), so bump them here in one place instead of hunting them
 * across five files.
 *
 * The info-anchor (`.info-btn`) already carries a 44 px `::after` hit area on coarse
 * pointers via sidebar.css. Phones report `pointer:coarse` in every mainstream browser,
 * so those buttons are covered without touching their visible circle size; a documented
 * exception in the e2e test skips their 22 px bounding box.
 *
 * Fine-pointer devices at 400 px viewport are the awkward middle: a laptop with a tiny
 * window. The exception list covers them too.
 */
@media (max-width: 899px) {
  /* Every segmented pip (mode toggles, speed group, time-split Last/Average, rankings
   * mode toggle) gets a 44 px minimum. Base rule was 32 px; the masthead override was
   * already 44 but this catches every remaining group in one line. */
  .segmented .seg {
    min-height: var(--tap);
    min-width: var(--tap);
  }

  /* The Last/Average pips were shrunk to 4x10 padding + 12 px font; give them the tap
   * spec while keeping the visual language (small font, tight padding around the label). */
  .time-split .toggle-row .segmented .seg {
    padding: 6px 12px;
    min-height: var(--tap);
    min-width: var(--tap);
  }

  /* Every native <select> jumps to 44 px on phone. Aircraft / bins / seed-count and the
   * rankings preset select all inherit from here. */
  select {
    min-height: var(--tap);
    padding: 10px 30px 10px 12px;
  }

  /* Every plain <button> (Cancel, New plane, more-knobs summary label pips) gets a 44 px
   * min. The button base rule sits at 36 px. Anything more specific (info-btn) still wins
   * because of its own explicit width/height. */
  button {
    min-height: var(--tap);
  }

  /* Heat toggle: the base rule uses padding, no min-height. */
  .heat-toggle {
    min-height: var(--tap);
    min-width: var(--tap);
  }

  /* Chime checkbox: the tap target is the <label>, which triggers the input from anywhere
   * inside it. Keep the visible 16 px checkbox and grow the label to 44 px on phone. The
   * input itself is a documented exception in the e2e test (its bounding box stays 16 px). */
  .checkbox-label {
    min-height: var(--tap);
    padding: 6px 4px;
    display: inline-flex;
    align-items: center;
  }

  /* Finish-card action buttons: base was 40 px, spec is 44. */
  .finish-card .actions button {
    min-height: var(--tap);
  }

  /* Text inputs (the seed field): base is 32 px, sidebar overrides to 36 px. */
  input[type="text"], input[type="number"] {
    min-height: var(--tap);
  }
  .page-side .seed-row-side input[type="text"] {
    min-height: var(--tap);
  }

  /* Race-controls seed-row text input (the top-level control): base at 40 px, spec 44. */
  .race-controls .seed-row input[type="text"] {
    min-height: var(--tap);
  }
}
