/* Ticket Tapper Fares (fares.apswood.uk): foundation
   A modern reading of the Network SouthEast livery (navy body, blue / white / red flash)
   set on the Andrew Wood CV "Midsummer" & "Polar night" palettes: warm cream or deep slate ground,
   high-contrast cards, a shared teal accent (#1f5f7a / #7fb8d1), a Rail Alphabet-style grotesque
   for headings and an amber dot-matrix departure board. */

/* Schibsted Grotesk (SIL OFL 1.1): an open neo-grotesque standing in for Kinneir Calvert's
   Rail Alphabet. It shares the horizontal terminals, spurred G, straight-legged R, angled t
   and flagged 1. One variable file covers weights 400 to 900. */
@font-face {
  font-family: "Schibsted Grotesk";
  src: url("../fonts/SchibstedGrotesk-wght.woff2") format("woff2-variations"),
       url("../fonts/SchibstedGrotesk-wght.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  /* Midsummer (Andrew Wood CV light design system) */
  --ground: #f6f1e7;
  --surface: #ffffff;
  --paper: #f5f2eb;
  --raised: #ece4d3;
  --active: #e3d8c2;
  --border: #e4dccb;
  --rule: #efe8da;
  --control: #8c8474;
  --text: #26292b;
  --ink: #26292b;
  --muted: #4b5256;
  --faint: #5a6066;
  --accent: #1f5f7a;
  --accent-hover: #174a60;
  --accent-ink: #ffffff;
  --accent-wash: #edf3f5;
  --focus: #9a3b00;

  /* Network SouthEast livery */
  --navy: #0b132b;
  --navy-2: #131d3a;
  --navy-3: #1a2547;
  --navy-ink: #c9cfdb;
  --navy-muted: #9aa4b8;
  --navy-focus: #ffb070;
  --sidebar-border: transparent;
  --nse-blue: #0a3fb8;
  --nse-red: #d4251f;
  --livery: linear-gradient(to bottom, var(--nse-blue) 0 42%, #fff 42% 58%, var(--nse-red) 58% 100%);
  --gradient-rule: linear-gradient(90deg, var(--accent) 0%, var(--nse-blue) 58%, var(--nse-red) 75%, var(--focus) 100%);

  /* Departure board */
  --board-bg: #101214;
  --board-ink: #ffb000;
  --board-sub: #c8c2b4;
  --board-pos: #7fd6a0;
  --board-neg: #ff9b8f;
  --board-warn: #ffc56b;

  /* Signals */
  --positive: #1f6b45;
  --negative: #b3261e;
  --warning: #8a3a00;
  --pill-positive-bg: #e2efe4;
  --pill-positive-ink: #14432b;
  --pill-negative-bg: #fbe5e1;
  --pill-negative-ink: #7f1d17;
  --pill-warning-bg: #fbecd3;
  --pill-warning-ink: #6e2e00;
  --pill-neutral-bg: #ece4d3;
  --pill-neutral-ink: #3a3f42;

  /* Component surface tokens (theme-aware) */
  --notice-warn-bg: #fbf3e4;
  --notice-warn-border: #ecd3a8;
  --notice-warn-ink: var(--pill-warning-ink);
  --notice-pos-bg: #eef6ef;
  --notice-pos-border: #cfe3d3;
  --notice-pos-ink: var(--pill-positive-ink);
  --notice-btn-bg: var(--surface);
  --notice-btn-border: #93c9a6;
  --cor-track: #d9cfbb;
  --cor-stop-stroke: #9c927e;
  --cor-end-stroke: var(--navy);
  --seg-active-bg: var(--navy);
  --seg-active-ink: #ffffff;
  --crs-bg: var(--navy);
  --crs-border: transparent;
  --fav-active: #b57400;
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%234b5256' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");

  /* Charts (read by charts.js and app.js at render time) */
  --chart-1: #1f5f7a;
  --chart-2: #7a7366;
  --chart-3: #a69d8a;
  --chart-muted: #c2b8a5;
  --chart-mark: #26292b;
  --chart-span: 0.07;
  --grid: #ebe4d6;
  --axis-ink: #4b5256;

  /* Type */
  --font-head: "Schibsted Grotesk", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font: Seravek, "Gill Sans Nova", Ubuntu, Calibri, "Segoe UI", Candara, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --fs-title: clamp(1.85rem, 1.35rem + 1.6vw, 2.6rem);
  --fs-lede: clamp(1.02rem, 0.95rem + 0.3vw, 1.18rem);
  --fs-section: 1.1rem;
  --fs-kpi: clamp(2rem, 1.6rem + 1.4vw, 2.75rem);
  --fs-body: 0.97rem;
  --fs-table: 0.92rem;
  --fs-small: 0.8rem;

  /* Space and shape */
  --sidebar-width: 244px;
  --pad: clamp(16px, 3vw, 40px);
  --gap: 16px;
  --card-pad: clamp(16px, 1.6vw, 24px);
  --radius-card: 10px;
  --radius-panel: 14px;
  --radius-control: 8px;
  --radius-tag: 4px;
  --radius-pill: 999px;
  --control-height: 40px;
  --row-height: 48px;
  --nav-row: 40px;
  --canvas-max: 1320px;

  --shadow-card: 0 1px 2px rgba(11, 19, 43, 0.04);
  --shadow-lift: 0 12px 24px -4px rgba(28, 25, 23, 0.12), 0 6px 12px -2px rgba(28, 25, 23, 0.08), 0 2px 4px rgba(28, 25, 23, 0.04);
  --shadow-board: 0 2px 8px rgba(11, 19, 43, 0.16);

  /* Motion: soft deceleration, never abrupt */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-drawer: cubic-bezier(0.2, 0.7, 0.2, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --t-quick: 160ms;
  --t-ui: 280ms;
  --t-calm: 560ms;
  --t-slow: 900ms;
}

/* Night Service (dark mode aligned with apswood.uk "Polar night" and pantheon.apswood.uk) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #12181d;
    --surface: #182027;
    --paper: #141b21;
    --raised: #202a33;
    --active: #283540;
    --border: #27333d;
    --rule: #202b34;
    --control: #60717f;
    --text: #e9e6df;
    --ink: #e9e6df;
    --muted: #aab3ba;
    --faint: #87939c;
    --accent: #7fb8d1;
    --accent-hover: #97cae0;
    --accent-ink: #0f1519;
    --accent-wash: rgba(127, 184, 209, 0.14);
    --focus: #ffb070;

    --navy: #091024;
    --navy-2: #111b36;
    --navy-3: #1a274a;
    --sidebar-border: #1e2c52;

    --positive: #7fd6a0;
    --negative: #ff9b8f;
    --warning: #f6d58f;
    --pill-positive-bg: #12301f;
    --pill-positive-ink: #b4efc8;
    --pill-negative-bg: #3a1a1b;
    --pill-negative-ink: #ffc9c4;
    --pill-warning-bg: #38290d;
    --pill-warning-ink: #f6d58f;
    --pill-neutral-bg: #232d35;
    --pill-neutral-ink: #d4dce2;

    --notice-warn-bg: #2a200e;
    --notice-warn-border: #5f471d;
    --notice-warn-ink: #f6d58f;
    --notice-pos-bg: #12281c;
    --notice-pos-border: #245338;
    --notice-pos-ink: #b4efc8;
    --notice-btn-bg: #1a3727;
    --notice-btn-border: #3a7c56;
    --cor-track: #33414d;
    --cor-stop-stroke: #6d7c88;
    --cor-end-stroke: #e9e6df;
    --seg-active-bg: var(--accent);
    --seg-active-ink: var(--accent-ink);
    --crs-bg: #1a274a;
    --crs-border: rgba(255, 255, 255, 0.18);
    --fav-active: #ffb000;
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%23aab3ba' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");

    --chart-1: #7fb8d1;
    --chart-2: #8b98a3;
    --chart-3: #5b6873;
    --chart-muted: #3c4852;
    --chart-mark: #e9e6df;
    --chart-span: 0.12;
    --grid: #25313b;
    --axis-ink: #aab3ba;

    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.32);
    --shadow-lift: 0 12px 24px -4px rgba(0, 0, 0, 0.45), 0 6px 12px -2px rgba(0, 0, 0, 0.32);
    --shadow-board: 0 4px 14px rgba(0, 0, 0, 0.48);
  }
}

:root[data-theme="dark"] {
  --ground: #12181d;
  --surface: #182027;
  --paper: #141b21;
  --raised: #202a33;
  --active: #283540;
  --border: #27333d;
  --rule: #202b34;
  --control: #60717f;
  --text: #e9e6df;
  --ink: #e9e6df;
  --muted: #aab3ba;
  --faint: #87939c;
  --accent: #7fb8d1;
  --accent-hover: #97cae0;
  --accent-ink: #0f1519;
  --accent-wash: rgba(127, 184, 209, 0.14);
  --focus: #ffb070;

  --navy: #091024;
  --navy-2: #111b36;
  --navy-3: #1a274a;
  --sidebar-border: #1e2c52;

  --positive: #7fd6a0;
  --negative: #ff9b8f;
  --warning: #f6d58f;
  --pill-positive-bg: #12301f;
  --pill-positive-ink: #b4efc8;
  --pill-negative-bg: #3a1a1b;
  --pill-negative-ink: #ffc9c4;
  --pill-warning-bg: #38290d;
  --pill-warning-ink: #f6d58f;
  --pill-neutral-bg: #232d35;
  --pill-neutral-ink: #d4dce2;

  --notice-warn-bg: #2a200e;
  --notice-warn-border: #5f471d;
  --notice-warn-ink: #f6d58f;
  --notice-pos-bg: #12281c;
  --notice-pos-border: #245338;
  --notice-pos-ink: #b4efc8;
  --notice-btn-bg: #1a3727;
  --notice-btn-border: #3a7c56;
  --cor-track: #33414d;
  --cor-stop-stroke: #6d7c88;
  --cor-end-stroke: #e9e6df;
  --seg-active-bg: var(--accent);
  --seg-active-ink: var(--accent-ink);
  --crs-bg: #1a274a;
  --crs-border: rgba(255, 255, 255, 0.18);
  --fav-active: #ffb000;
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%23aab3ba' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");

  --chart-1: #7fb8d1;
  --chart-2: #8b98a3;
  --chart-3: #5b6873;
  --chart-muted: #3c4852;
  --chart-mark: #e9e6df;
  --chart-span: 0.12;
  --grid: #25313b;
  --axis-ink: #aab3ba;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.32);
  --shadow-lift: 0 12px 24px -4px rgba(0, 0, 0, 0.45), 0 6px 12px -2px rgba(0, 0, 0, 0.32);
  --shadow-board: 0 4px 14px rgba(0, 0, 0, 0.48);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 400 var(--fs-body)/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p, figure, ul, ol, dl, dd { margin: 0; }
h1, h2, h3 { font-family: var(--font-head); font-weight: 600; text-wrap: balance; }
p { text-wrap: pretty; }
ul[class], ol[class] { padding: 0; list-style: none; }
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--accent); color: var(--accent-ink); }

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

.num, table, .kpi-value { font-variant-numeric: tabular-nums lining-nums; }

/* Schibsted's tabular set also widens . and :, so text in the heading face keeps proportional spacing */
h1, h2, h3, th, .strategy-name, .kpi-label, .kpi.lead .kpi-value, .pill, .crs-tag, .btn, .eyebrow,
.brand-name, .field label, .notice-banner strong, .validity-link, .cor-crs {
  font-variant-numeric: normal;
}
[hidden], .view[hidden] { display: none !important; }

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

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 400;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: var(--navy);
  color: #fff;
  font-family: var(--font-head);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lift);
  transform: translateY(-200%);
  transition: transform var(--t-quick) var(--ease-out);
}

.skip-link:focus-visible {
  transform: translateY(0);
  outline: 3px solid var(--navy-focus);
  outline-offset: 2px;
}

main.canvas:focus {
  outline: none;
}

/* ---------- Shell ---------- */
.mobile-bar { display: none; }
.sidebar-backdrop { display: none; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100svh;
}

/* The sidebar is the locomotive: NSE navy with the livery flash under the name. */
.sidebar {
  position: sticky;
  top: 0;
  height: 100svh;
  display: flex;
  flex-direction: column;
  padding: 20px 12px 16px 14px;
  background: var(--navy);
  border-right: 1px solid var(--sidebar-border);
  color: var(--navy-ink);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--navy-3) transparent;
}

.sidebar :focus-visible { outline-color: var(--navy-focus); }

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 6px;
  min-width: 0;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex: none;
}

.brand-text {
  min-width: 0;
  width: max-content;
  max-width: 100%;
}

.brand-name {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  width: 100%;
  font-family: var(--font-head);
  font-size: 1.12rem;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0.02em;
  color: #fff;
}

.brand-primary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  width: 100%;
  color: #fff;
}

.brand-sub-row {
  display: flex;
  align-items: flex-start;
  gap: 0;
  width: 100%;
}

.brand-sub-row::after {
  content: "";
  flex: 1;
  height: 2px;
  border-radius: 0 1px 1px 0;
  background: linear-gradient(90deg, var(--nse-blue) 0%, var(--nse-blue) 65%, rgba(10, 63, 184, 0.45) 100%);
}

.brand-sub {
  display: inline-flex;
  align-items: center;
  padding: 2px 11px 2px 7px;
  background: var(--nse-red);
  color: #fff;
  font-family: var(--font-head);
  font-size: 0.63rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  line-height: 1.3;
  clip-path: polygon(0 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
}

.brand-scope {
  margin-top: 5px;
  font-size: var(--fs-small);
  line-height: 1.3;
  color: var(--navy-muted);
  white-space: nowrap;
}

/* One short line per group so the scope never overflows the brand column */
.brand-scope-line {
  display: block;
}

/* Livery flash: blue, white and red with an upswept end, drawn in on load */
.livery {
  height: 12px;
  margin: 18px 6px 22px;
  background: var(--livery);
  clip-path: polygon(0 0, 100% 0, calc(100% - 18px) 100%, 0 100%);
  transform-origin: left center;
  animation: livery-in var(--t-slow) var(--ease-out) 120ms both;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar .group-label {
  margin: 26px 10px 8px;
  font-family: var(--font-head);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--navy-muted);
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--nav-row);
  padding: 0 10px 0 14px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--navy-ink);
  font-size: var(--fs-body);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--t-ui) var(--ease-out), color var(--t-ui) var(--ease-out);
}

/* Platform-edge marker that grows in on the active item */
.nav-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 3px;
  background: var(--nse-red);
  transform: scaleY(0);
  transition: transform var(--t-ui) var(--ease-out);
}

.nav-item svg {
  width: 17px;
  height: 17px;
  flex: none;
  stroke-width: 1.5;
  opacity: 0.85;
  transition: transform var(--t-ui) var(--ease-out);
}

.nav-item:hover { background: var(--navy-2); color: #fff; }
.nav-item:hover svg { transform: translateX(2px); }

.nav-item[aria-current="page"] {
  background: var(--navy-3);
  color: #fff;
  font-weight: 600;
}

.nav-item[aria-current="page"]::before { transform: scaleY(1); }
.nav-item[aria-current="page"] svg { opacity: 1; }

.preset-btn {
  position: relative;
  display: block;
  width: 100%;
  padding: 8px 10px 8px 14px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--t-ui) var(--ease-out);
}

.preset-btn::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 3px;
  background: var(--nse-blue);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
  transform: scaleY(0);
  transition: transform var(--t-ui) var(--ease-out);
}

.preset-btn:hover { background: var(--navy-2); }
.preset-btn[aria-pressed="true"] { background: var(--navy-3); }
.preset-btn[aria-pressed="true"]::before { transform: scaleY(1); }

.preset-title,
.preset-sub {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-title {
  font-size: 0.88rem;
  line-height: 1.35;
  font-weight: 600;
  color: #fff;
}

.preset-sub {
  font-size: var(--fs-small);
  line-height: 1.35;
  color: var(--navy-muted);
}

.sidebar .bottom {
  margin-top: auto;
  padding: 16px 10px 0;
  border-top: 1px solid var(--navy-3);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 36px;
  margin-bottom: 6px;
  padding: 0 11px;
  border: 1px solid var(--navy-3);
  border-radius: var(--radius-control);
  background: var(--navy-2);
  color: var(--navy-ink);
  font-family: var(--font-head);
  font-size: 0.84rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--t-ui) var(--ease-out), border-color var(--t-ui) var(--ease-out), color var(--t-ui) var(--ease-out);
}

.theme-toggle-btn:hover {
  background: var(--navy-3);
  border-color: rgba(255, 255, 255, 0.24);
  color: #fff;
}

.sidebar .stamp { color: var(--navy-muted); }

.desk-note {
  margin-bottom: 4px;
  font-size: var(--fs-small);
  line-height: 1.45;
  color: var(--navy-ink);
}

.provenance {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--navy-3);
  font-size: var(--fs-small);
  color: var(--navy-muted);
}

.provenance a {
  color: var(--navy-ink);
  text-decoration: underline;
  text-decoration-color: rgba(201, 207, 219, 0.35);
  text-underline-offset: 2px;
  transition: color var(--t-ui) var(--ease-out), text-decoration-color var(--t-ui) var(--ease-out);
}

.provenance a:hover {
  color: #fff;
  text-decoration-color: currentColor;
}

.btn.sidebar-close { display: none; }

.canvas {
  min-width: 0;
  padding: calc(var(--pad) * 0.8) var(--pad) calc(var(--pad) * 1.5);
}

.canvas > .view {
  max-width: var(--canvas-max);
}

/* ---------- Title block ---------- */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-family: var(--font-head);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.eyebrow::before {
  content: "";
  width: 22px;
  height: 7px;
  background: var(--livery);
  clip-path: polygon(0 0, 100% 0, calc(100% - 5px) 100%, 0 100%);
}

.title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 24px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  background: var(--gradient-rule) left bottom / 100% 3px no-repeat;
}

.title-row h1 {
  font-size: var(--fs-title);
  line-height: 1.08;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.title-row .sub {
  margin-top: 8px;
  max-width: 68ch;
  color: var(--muted);
  font-size: var(--fs-lede);
  line-height: 1.5;
}

/* The calculator's verdict reads as the desk's answer, so it is set in ink */
#calc-verdict-sub { color: var(--ink); }

.title-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  flex: none;
}

.stamp {
  color: var(--faint);
  font-size: var(--fs-small);
}

/* ---------- Panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--card-pad);
  min-width: 0;
}

.panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 16px;
}

.panel h2 {
  font-size: var(--fs-section);
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.panel .meta {
  color: var(--faint);
  font-size: var(--fs-small);
}

/* ---------- KPI strip: the first tile is a departure board ---------- */
.kpis {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.kpi {
  min-width: 0;
  padding: 18px var(--card-pad);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.kpi-label {
  font-family: var(--font-head);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
  color: var(--muted);
}

.kpi-value {
  margin-top: 6px;
  font-size: 1.55rem;
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.kpi-value small {
  margin-left: 4px;
  font-size: 0.85rem;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
}

.kpi-sub {
  margin-top: 6px;
  font-size: var(--fs-small);
  line-height: 1.45;
  color: var(--muted);
}

.kpi-sub .pos { color: var(--positive); font-weight: 600; }
.kpi-sub .neg { color: var(--negative); font-weight: 600; }
.kpi-sub .warn { color: var(--warning); font-weight: 600; }

.kpi.lead {
  position: relative;
  overflow: hidden;
  background:
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 4px),
    var(--board-bg);
  border-color: var(--board-bg);
  box-shadow: var(--shadow-board);
  color: var(--board-ink);
}

/* A thin livery flash along the top edge of the board */
.kpi.lead::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--livery);
  z-index: 2;
}

/* Subtle LED dot-matrix texture matching www.apswood.uk's departure board */
.kpi.lead::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle, transparent 0 1px, var(--board-bg) 1.4px) 0 0 / 3px 3px;
  opacity: 0.28;
}

.kpi.lead > * {
  position: relative;
  z-index: 1;
}

.kpi.lead .kpi-label {
  color: var(--board-ink);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.kpi.lead .kpi-value {
  font-family: var(--font-head);
  font-size: var(--fs-kpi);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--board-ink);
}

.kpi.lead .kpi-value small { color: var(--board-sub); font-family: var(--font); }
.kpi.lead .kpi-sub { color: var(--board-sub); }
.kpi.lead .kpi-sub .pos { color: var(--board-pos); }
.kpi.lead .kpi-sub .neg { color: var(--board-neg); }
.kpi.lead .kpi-sub .warn { color: var(--board-warn); }

/* Values settle into place each time the journey is recalculated */
.kpis.is-updated .kpi-value,
.kpis.is-updated .kpi-sub {
  animation: board-settle var(--t-calm) var(--ease-out) both;
}

.kpis.is-updated .kpi:nth-child(2) .kpi-value { animation-delay: 60ms; }
.kpis.is-updated .kpi:nth-child(3) .kpi-value { animation-delay: 120ms; }

.sub.is-updated { animation: fade-soft var(--t-calm) var(--ease-out) both; }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  margin: 0 calc(var(--card-pad) * -1);
  padding: 0 var(--card-pad);
  scrollbar-width: thin;
  scrollbar-color: var(--active) transparent;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-table);
}

th {
  height: 38px;
  padding: 0 12px;
  text-align: left;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  transition: background-color var(--t-ui) var(--ease-out);
}

th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--paper) 70%, transparent); }
th.n, td.n { text-align: right; white-space: nowrap; }
td.money { font-weight: 700; color: var(--ink); }

/* ---------- Pills and tags ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  font-family: var(--font-head);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--pill-neutral-bg);
  color: var(--pill-neutral-ink);
  white-space: nowrap;
  flex: none;
}

.pill.pos { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.pill.neg { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pill.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }

/* Station codes read like small nameboards */
.crs-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid var(--crs-border);
  background: var(--crs-bg);
  color: #fff;
  font-family: var(--font-head);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  line-height: 1.45;
  white-space: nowrap;
}

/* ---------- Controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--control-height);
  padding: 0 18px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--control);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-head);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color var(--t-ui) var(--ease-out),
    border-color var(--t-ui) var(--ease-out),
    color var(--t-ui) var(--ease-out),
    box-shadow var(--t-ui) var(--ease-out),
    transform var(--t-ui) var(--ease-out);
}

.btn:hover {
  background: var(--paper);
  border-color: var(--muted);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
  transition-duration: var(--t-quick);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
}

.btn.ghost:hover {
  background: var(--raised);
  color: var(--ink);
  transform: none;
  box-shadow: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field label {
  font-family: var(--font-head);
  font-size: 0.86rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.field .hint {
  font-size: var(--fs-small);
  color: var(--muted);
  line-height: 1.4;
}

.field .hint:empty { display: none; }

.input,
select.input {
  height: var(--control-height);
  padding: 0 12px;
  border: 1px solid var(--control);
  border-radius: var(--radius-control);
  background-color: var(--surface);
  color: var(--ink);
  width: 100%;
  min-width: 0;
  transition: border-color var(--t-ui) var(--ease-out), box-shadow var(--t-ui) var(--ease-out);
}

select.input {
  appearance: none;
  padding-right: 36px;
  background-image: var(--select-chevron);
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}

.input:hover { border-color: var(--muted); }
.input:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-wash); }
.input::placeholder { color: var(--faint); }

/* Segmented choices behave like the design system's chips: sliding thumb + draggable track */
.segmented {
  position: relative;
  display: inline-flex;
  width: max-content;
  max-width: 100%;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius-pill);
  background: var(--raised);
  user-select: none;
  -webkit-user-select: none;
}

.segmented.is-draggable {
  touch-action: pan-y;
  cursor: grab;
}

.segmented.is-dragging {
  cursor: grabbing;
}

.segmented .seg-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  border-radius: var(--radius-pill);
  background: var(--seg-active-bg);
  box-shadow: 0 1px 3px rgba(11, 19, 43, 0.25);
  pointer-events: none;
  z-index: 0;
  transition: transform 220ms var(--ease-drawer), width 220ms var(--ease-drawer), box-shadow 160ms var(--ease-drawer);
  will-change: transform, width;
}

.segmented.is-dragging .seg-thumb {
  transition: width 120ms var(--ease-drawer), box-shadow 120ms var(--ease-drawer);
  box-shadow: 0 3px 10px rgba(11, 19, 43, 0.34);
}

.segmented button {
  position: relative;
  z-index: 1;
  min-height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 0.86rem;
  cursor: inherit;
  white-space: nowrap;
  transition:
    background-color var(--t-ui) var(--ease-out),
    color var(--t-ui) var(--ease-out);
}

.segmented:not(.has-thumb) button:hover { color: var(--ink); background: color-mix(in srgb, var(--surface) 55%, transparent); }
.segmented.has-thumb button:hover { color: var(--ink); }

.segmented:not(.has-thumb) button[aria-pressed="true"] {
  background: var(--seg-active-bg);
  color: var(--seg-active-ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(11, 19, 43, 0.25);
}

.segmented.has-thumb button[aria-pressed="true"] {
  background: transparent;
  color: var(--seg-active-ink);
  font-weight: 600;
}

.empty-state {
  padding: 22px 18px;
  border: 1px dashed var(--control);
  border-radius: var(--radius-card);
  background: var(--paper);
  color: var(--muted);
  text-align: center;
  font-size: var(--fs-body);
}

/* ---------- Entrances ---------- */
/* Each view arrives with an 8px fade-up, its blocks following one after another. */
.view:not([hidden]) > *,
.view:not([hidden]) .calc-left-col > *,
.view:not([hidden]) .calc-results > *,
.view:not([hidden]) .calc-bottom-pair > * {
  animation: rise var(--t-calm) var(--ease-out) both;
}

.view:not([hidden]) > :nth-child(2) { animation-delay: 70ms; }
.view:not([hidden]) > :nth-child(3) { animation-delay: 140ms; }
.view:not([hidden]) > :nth-child(4) { animation-delay: 210ms; }
.view:not([hidden]) .calc-left-col > :nth-child(2),
.view:not([hidden]) .calc-results > :nth-child(2),
.view:not([hidden]) .calc-bottom-pair > :nth-child(2) { animation-delay: 140ms; }
.view:not([hidden]) .calc-results > :nth-child(3) { animation-delay: 200ms; }
.view:not([hidden]) .calc-results > :nth-child(4) { animation-delay: 260ms; }

/* The rule under each title draws across as the view opens */
.view:not([hidden]) .title-row { animation: rise var(--t-calm) var(--ease-out) both, rule-draw var(--t-slow) var(--ease-out) 120ms both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-soft {
  from { opacity: 0.25; }
  to { opacity: 1; }
}

@keyframes board-settle {
  from { opacity: 0; transform: translateY(5px); filter: blur(2px); }
  to { opacity: 1; transform: none; filter: none; }
}

@keyframes rule-draw {
  from { background-size: 0% 3px; }
  to { background-size: 100% 3px; }
}

@keyframes livery-in {
  from { transform: scaleX(0); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- Tablet and phone (<= 960px) ---------- */
@media (max-width: 960px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    min-height: auto;
  }

  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    height: 56px;
    padding: 0 12px 0 8px;
    background: var(--navy);
    color: #fff;
  }

  .mobile-bar::after {
    content: "";
    position: absolute;
    inset: auto 0 -5px 0;
    height: 5px;
    background: var(--livery);
  }

  .mobile-bar :focus-visible { outline-color: var(--navy-focus); }
  .mobile-bar .btn.ghost { color: #fff; }
  .mobile-bar .btn.ghost:hover { background: var(--navy-3); color: #fff; }
  .mobile-bar .stamp { color: var(--navy-muted); }

  .mobile-bar-left,
  .mobile-bar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  .mobile-bar-right { flex: none; }

  .mobile-theme-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-control);
  }

  .mobile-bar .brand-mark { width: 26px; height: 26px; }

  .mobile-bar-title {
    font-family: var(--font-head);
    font-size: 1.05rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 250;
    width: min(320px, 86vw);
    height: 100%;
    padding-top: 12px;
    visibility: hidden;
    transform: translateX(-102%);
    transition: transform 0.25s var(--ease-drawer), visibility 0s linear 0.25s;
  }

  .sidebar.open {
    visibility: visible;
    transform: none;
    transition: transform 0.25s var(--ease-drawer), visibility 0s;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 240;
    background: rgba(8, 14, 18, 0.5);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s var(--ease-drawer), visibility 0s linear 0.25s;
  }

  .sidebar-backdrop.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.25s var(--ease-drawer), visibility 0s;
  }

  .btn.sidebar-close { display: inline-flex; color: var(--navy-ink); }
  .btn.sidebar-close:hover { background: var(--navy-3); color: #fff; }

  .canvas { padding: 24px 16px 40px; }

  .title-row {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 14px;
  }

  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi.lead { grid-column: 1 / -1; }
}

@media (max-width: 768px) {
  .table-wrap {
    position: relative;
    padding: 0 var(--card-pad) 0 0;
    background:
      linear-gradient(to right, var(--surface) 30%, transparent) left center / 28px 100% no-repeat local,
      linear-gradient(to left, var(--surface) 30%, transparent) right center / 28px 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%, rgba(11, 19, 43, 0.14), transparent) left center / 14px 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%, rgba(11, 19, 43, 0.14), transparent) right center / 14px 100% no-repeat scroll;
  }

  .table-wrap table th:first-child,
  .table-wrap table td:first-child:not([colspan]) {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--surface);
    padding-left: var(--card-pad);
    padding-right: 14px;
    box-shadow: 1px 0 0 var(--rule);
  }

  .table-wrap table th:first-child {
    z-index: 3;
  }

  .table-wrap table td:first-child[colspan] {
    padding-left: var(--card-pad);
  }

  .table-wrap table tbody tr:hover td:first-child:not([colspan]) {
    background: var(--paper);
  }

  .strategy-table tr.is-winner td:first-child {
    background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  }
}

@media (max-width: 640px) {
  .segmented:not(.full-row) {
    display: flex;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .segmented:not(.full-row)::-webkit-scrollbar {
    display: none;
  }

  .segmented:not(.full-row) button {
    flex: none;
  }
}

@media (max-width: 480px) {
  .title-actions { width: 100%; }
  .title-actions .btn { flex: 1; }
  .kpi { padding: 14px 16px; }
}

/* Touch screens get 44px targets throughout */
@media (pointer: coarse) {
  :root { --control-height: 44px; --nav-row: 44px; }
  .segmented button { min-height: 38px; }
  .mobile-theme-btn {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Print: the comparison on paper, without the chrome ---------- */
@media print {
  body { background: #fff; }
  .app { display: block; }
  .sidebar, .sidebar-backdrop, .mobile-bar, .mobile-verdict-bar, .title-actions, .btn, .skip-link { display: none !important; }
  .canvas { padding: 0; }
  .panel, .kpi { box-shadow: none; break-inside: avoid; }
  .kpi.lead { background: #fff; color: #000; border: 1px solid #000; }
  .kpi.lead .kpi-label, .kpi.lead .kpi-value, .kpi.lead .kpi-sub { color: #000; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
