/* Transit Carbon Calculator: "line diagram" design system.
   Ideas: the strip map over a train door, platform signage, and the yellow
   tactile warning strip at the platform edge (an ADA feature).
   Flat color, square-ish corners, no gradients, no soft shadows, no emoji.
   Read docs/DESIGN.md before visual changes. Every text pair below is checked
   by `npm test` (scripts/check.mjs). */

@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  src: url('../fonts/atkinson-hyperlegible-next-latin.woff') format('woff');
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: 'Overpass';
  src: url('../fonts/overpass-extrabold-latin.woff') format('woff');
  font-weight: 800;
  font-display: swap;
}

:root {
  /* Color tokens. Contrast vs the background named in the comment. */
  --ink: #12263f;        /* 13.6:1 on --paper. Text, rules, buttons, the dark panel */
  --ink-2: #0a1828;      /* hover on --ink */
  --ink-soft: #46566b;   /*  7.5:1 on --card. Hints, captions */
  --paper: #f4f2ec;      /* page: platform tile */
  --card: #ffffff;
  --rule: #6d7a8c;       /*  4.4:1 on --card. Input borders (needs 3:1) */
  --yellow: #ffc72c;     /* the line. Shapes on light; text only on --ink */
  --on-ink: #ffffff;
  --on-ink-soft: #c9d3df; /* 10.1:1 on --ink */
  --ride: #1d6b45;       /*  6.5:1 on --card. Your-ride bar */
  --car: #a3302a;        /*  7.0:1 on --card. Car bar */
  --error: #a3302a;
  --error-tint: #fbeceb;
  --link: #1a4f86;       /*  8.4:1 on --card */

  --font-body: 'Atkinson Hyperlegible Next', 'Atkinson Hyperlegible', 'Segoe UI', system-ui, sans-serif;
  --font-sign: 'Overpass', 'Highway Gothic', 'Arial Narrow', 'Segoe UI', system-ui, sans-serif;
  --radius: 4px;
  --rail: 10px;          /* thickness of the route line */

  font-family: var(--font-body);
  font-size: 112.5%;     /* 18px base, respects browser font settings */
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body { margin: 0; }
img, canvas { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); text-underline-offset: 0.18em; text-decoration-thickness: 0.08em; }
a:hover { text-decoration-thickness: 0.16em; }
sub { font-size: 0.7em; line-height: 0; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 0.5em; }
h2 { font-family: var(--font-sign); font-weight: 800; font-size: 1.5rem; letter-spacing: 0.01em; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 1em; }

/* Focus: navy ring with a yellow halo reads on light and dark backgrounds. */
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 6px var(--yellow); }
.results :focus-visible { outline-color: var(--yellow); box-shadow: 0 0 0 6px var(--ink); }
[tabindex="-1"]:focus { outline: none; box-shadow: none; }

.wrap { max-width: 44rem; margin: 0 auto; padding: 0 1.25rem; }

.skip { position: absolute; left: 1rem; top: -4rem; background: var(--yellow); color: var(--ink); padding: 0.75rem 1rem; font-weight: 700; z-index: 10; }
.skip:focus { top: 1rem; }

/* ── Masthead: a station sign ── */
.masthead { background: var(--ink); color: var(--on-ink); padding: 2.25rem 0 2rem; }
.kicker { font-family: var(--font-sign); font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.8rem; color: var(--yellow); margin-bottom: 0.9rem; }
.kicker-sep { margin: 0 0.4em; color: var(--on-ink-soft); }
.masthead h1 { font-family: var(--font-sign); font-weight: 800; font-size: clamp(2rem, 6vw, 3rem); letter-spacing: -0.01em; margin-bottom: 0.6rem; max-width: 18ch; }
.lede { color: var(--on-ink-soft); font-size: 1.05rem; max-width: 38rem; margin: 0; }

/* The tactile warning strip: yellow with rows of raised domes. */
.tactile {
  height: 18px;
  background-color: var(--yellow);
  background-image: radial-gradient(circle, rgba(18, 38, 63, 0.38) 2.6px, transparent 3.2px);
  background-size: 12px 12px;
  background-position: 6px 3px;
  border-bottom: 3px solid var(--ink);
}

main { padding: 2rem 0 3rem; }

/* ── Panels ── */
.panel { background: var(--card); border: 2px solid var(--ink); border-top-width: 6px; border-radius: var(--radius); padding: 1.5rem 1.25rem; margin-bottom: 1.75rem; }
@media (min-width: 40rem) { .panel { padding: 2rem 2rem 1.75rem; } }

/* ── Form ── */
.field { margin: 0 0 1.4rem; padding: 0; border: 0; min-width: 0; }
label, legend { display: block; font-weight: 700; margin-bottom: 0.25rem; padding: 0; }
legend { font-size: 1.05rem; margin-bottom: 0.6rem; }
.optional { font-weight: 400; color: var(--ink-soft); }
.hint { color: var(--ink-soft); font-size: 0.92rem; margin: 0 0 0.45rem; }
.row { display: grid; gap: 0 1.25rem; }
@media (min-width: 34rem) { .row { grid-template-columns: 1fr 1fr; } }
fieldset.car { border-top: 2px solid var(--ink); padding-top: 1.2rem; margin-top: 0.4rem; }
fieldset.car > legend { float: left; width: 100%; margin-bottom: 0.3rem; }
fieldset.car > legend + * { clear: both; }

input[type=text], select, textarea {
  width: 100%; min-height: 3rem; padding: 0.6rem 0.75rem;
  background: var(--card); border: 2px solid var(--rule); border-radius: var(--radius);
}
input[type=text]:hover, select:hover { border-color: var(--ink); }
textarea { min-height: 10rem; font-size: 0.95rem; }
[aria-invalid="true"] { border-color: var(--error) !important; border-width: 3px !important; }

.with-unit { display: flex; align-items: stretch; }
.with-unit input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.unit { display: flex; align-items: center; padding: 0 0.8rem; background: var(--paper); border: 2px solid var(--rule); border-left: 0; border-radius: 0 var(--radius) var(--radius) 0; color: var(--ink-soft); font-weight: 700; white-space: nowrap; }
.unit-before .unit { order: -1; border-left: 2px solid var(--rule); border-right: 0; border-radius: var(--radius) 0 0 var(--radius); }
.unit-before input { border-radius: 0 var(--radius) var(--radius) 0; }

/* Mode choices: big targets, checked state shown by border, bar, and dot. */
.choices { display: grid; gap: 0.6rem; }
@media (min-width: 34rem) { .choices { grid-template-columns: 1fr 1fr; } }
.choice { position: relative; display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.8rem 0.9rem; min-height: 3.4rem; border: 2px solid var(--rule); border-radius: var(--radius); background: var(--card); cursor: pointer; font-weight: 400; margin: 0; }
.choice:hover { border-color: var(--ink); }
.choice input { appearance: none; -webkit-appearance: none; flex: none; width: 1.35rem; height: 1.35rem; margin: 0.1rem 0 0; border: 3px solid var(--ink); border-radius: 50%; background: var(--card); }
.choice input:checked { background: radial-gradient(circle, var(--ink) 45%, var(--card) 50%); }
.choice:has(input:checked) { border-color: var(--ink); box-shadow: inset 6px 0 0 var(--yellow); }
.choice-text { display: block; font-weight: 700; line-height: 1.3; }
.choice-hint { display: block; font-weight: 400; color: var(--ink-soft); font-size: 0.88rem; line-height: 1.35; margin-top: 0.15rem; }

.field-error { color: var(--error); font-weight: 700; margin: 0.4rem 0 0; }
.field-error::before { content: "Error: "; }
.error-summary { border: 3px solid var(--error); background: var(--error-tint); border-radius: var(--radius); padding: 1rem 1.1rem 0.4rem; margin-bottom: 1.4rem; }
.error-summary ul { margin: 0 0 0.6rem; padding-left: 1.2rem; }
.error-summary a { color: var(--error); font-weight: 700; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 3rem; padding: 0.6rem 1.1rem; border: 2px solid var(--ink); border-radius: var(--radius); background: var(--card); color: var(--ink); font-weight: 700; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--paper); }
.btn-primary { width: 100%; background: var(--ink); color: var(--on-ink); font-family: var(--font-sign); font-weight: 800; font-size: 1.15rem; letter-spacing: 0.02em; min-height: 3.5rem; margin-top: 0.4rem; }
.btn-primary:hover { background: var(--ink-2); text-decoration: underline; text-underline-offset: 0.2em; }
.btn-quiet { border-color: var(--rule); color: var(--ink-soft); }

/* ── Results: the line diagram ── */
.results { background: var(--ink); color: var(--on-ink); border-radius: var(--radius); padding: 1.5rem 1.25rem 1.25rem; margin-bottom: 1.75rem; }
@media (min-width: 40rem) { .results { padding: 2rem 2rem 1.5rem; } }
.results-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.25rem 1rem; }
.results h2 { color: var(--yellow); text-transform: uppercase; letter-spacing: 0.06em; font-size: 1.05rem; margin-bottom: 0.6rem; }
.agency-line { color: var(--on-ink-soft); font-size: 0.92rem; margin: 0 0 0.6rem; }
.headline { font-size: clamp(1.25rem, 3.4vw, 1.6rem); font-weight: 700; line-height: 1.3; margin-bottom: 1.6rem; max-width: 34ch; }

.line { list-style: none; margin: 0 0 1.25rem; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); position: relative; }
.line::before { content: ""; position: absolute; left: 12.5%; right: 12.5%; top: calc(1.5rem + 11px); height: var(--rail); background: var(--yellow); border-radius: 0; transform-origin: left center; }
.stop { display: grid; grid-template-rows: 1.5rem 32px auto; justify-items: center; text-align: center; gap: 0.5rem; position: relative; }
.stop-when { font-family: var(--font-sign); font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.8rem; color: var(--on-ink-soft); align-self: end; }
.stop-dot { width: 32px; height: 32px; border-radius: 50%; background: var(--on-ink); border: 6px solid var(--yellow); position: relative; z-index: 1; }
.stop-end .stop-dot { width: 32px; height: 32px; background: var(--yellow); border: 6px solid var(--on-ink); box-shadow: 0 0 0 4px var(--yellow); }
.stop-value { font-family: var(--font-sign); font-weight: 800; font-size: clamp(1.05rem, 3vw, 1.45rem); line-height: 1.15; }
.stop-value small { display: block; font-family: var(--font-body); font-weight: 400; font-size: 0.78rem; color: var(--on-ink-soft); letter-spacing: 0; }
.stop-end .stop-when { color: var(--yellow); }

/* Narrow screens: the strip map turns vertical, like a station column. */
@media (max-width: 33.99rem) {
  .line { grid-template-columns: 1fr; gap: 1.1rem; padding-left: 0.25rem; }
  .line::before { left: calc(0.25rem + 11px); right: auto; top: 16px; bottom: 16px; width: var(--rail); height: auto; transform-origin: center top; }
  .stop { grid-template-columns: 32px 1fr; grid-template-rows: auto auto; justify-items: start; text-align: left; column-gap: 1rem; row-gap: 0; align-items: center; }
  .stop-dot { grid-row: 1 / span 2; grid-column: 1; }
  .stop-when { grid-column: 2; align-self: end; }
  .stop-value { grid-column: 2; }
}

@media (prefers-reduced-motion: no-preference) {
  .results.is-new .line::before { animation: draw 700ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  @keyframes draw { from { transform: scaleX(0); } to { transform: scaleX(1); } }
  @media (max-width: 33.99rem) { @keyframes draw { from { transform: scaleY(0); } to { transform: scaleY(1); } } }
}

.years { display: grid; gap: 0.4rem; border-top: 1px solid rgba(255, 255, 255, 0.35); padding-top: 1rem; }
.years label { color: var(--on-ink); font-weight: 700; margin: 0; }
.years output { font-family: var(--font-sign); font-weight: 800; color: var(--yellow); font-size: 1.2em; }
input[type=range] { width: 100%; height: 2.75rem; margin: 0; background: transparent; accent-color: var(--yellow); cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 8px; background: var(--on-ink-soft); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; margin-top: -10px; border-radius: 50%; background: var(--yellow); border: 4px solid var(--on-ink); }
input[type=range]::-moz-range-track { height: 8px; background: var(--on-ink-soft); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--yellow); border: 4px solid var(--on-ink); }
input[type=range] { -webkit-appearance: none; appearance: none; }

/* ── Details ── */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; margin: 0 0 1rem; }
.stat { border-top: 4px solid var(--ink); padding-top: 0.5rem; }
.stat dt { font-size: 0.9rem; color: var(--ink-soft); font-weight: 700; }
.stat dd { margin: 0.1rem 0 0; font-family: var(--font-sign); font-weight: 800; font-size: clamp(1.3rem, 4vw, 1.75rem); line-height: 1.15; }
.equiv { color: var(--ink-soft); }

.compare { margin: 1.5rem 0; padding: 1rem 0 0; border-top: 2px solid var(--ink); }
.compare figcaption { font-weight: 700; margin-bottom: 0.8rem; }
.bar-row { display: grid; grid-template-columns: 9.5rem 1fr auto; align-items: center; gap: 0.75rem; margin-bottom: 0.7rem; }
.bar-name { font-weight: 700; font-size: 0.95rem; }
.bar-track { height: 1.1rem; background: var(--paper); border: 1px solid var(--rule); }
.bar { display: block; height: 100%; width: 0; }
.bar-ride { background: var(--ride); }
.bar-car { background: repeating-linear-gradient(135deg, var(--car) 0 8px, #7d241f 8px 12px); }
.bar-value { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 6.5rem; text-align: right; }
@media (max-width: 33.99rem) {
  .bar-row { grid-template-columns: 1fr auto; row-gap: 0.25rem; }
  .bar-track { grid-column: 1 / -1; grid-row: 2; }
}

.share { border-top: 2px solid var(--ink); padding-top: 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.status:empty { padding: 0; margin: 0; border: 0; } /* stays in the a11y tree so role=status announces */
.status { margin: 0.8rem 0 0; padding: 0.7rem 0.9rem; border-left: 6px solid var(--yellow); background: var(--paper); }
.fallback { margin-top: 0.8rem; }

/* ── Method ── */
.method ol.steps { padding-left: 1.3rem; }
.method li { margin-bottom: 0.35rem; }
.table-wrap { overflow-x: auto; margin: 1rem 0 1.25rem; }
.factors { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
.factors caption { text-align: left; font-weight: 700; margin-bottom: 0.4rem; }
.factors th, .factors td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.factors thead th { border-bottom: 2px solid var(--ink); }
.factors td.num { font-variant-numeric: tabular-nums; }
.checked { color: var(--ink-soft); font-size: 0.92rem; margin: 0; }

/* ── Footer ── */
.footer { border-top: 6px solid var(--ink); background: var(--card); padding: 1.5rem 0 2rem; font-size: 0.95rem; color: var(--ink-soft); }
.footer p { margin: 0 0 0.6rem; }

[hidden] { display: none !important; }

/* Windows High Contrast: restore native radios and keep the checked tile visible. */
@media (forced-colors: active) {
  .choice input { appearance: auto; -webkit-appearance: radio; background: none; border: 0; }
  .choice:has(input:checked) { border-width: 4px; border-color: Highlight; }
  .stop-dot, .line::before, .bar, .tactile { forced-color-adjust: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  .masthead, .tactile, .share, .skip { display: none; }
  .results { background: none; color: var(--ink); border: 2px solid var(--ink); }
  .results h2, .stop-when, .stop-end .stop-when { color: var(--ink); }
}
