/* ---------------------------------------------------------------- fonts */
@font-face {
  font-family: 'Inter';
  src: url('fonts/inter.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Manrope';
  src: url('fonts/manrope.woff2') format('woff2');
  font-weight: 200 800;
  font-display: swap;
}

/* ---------------------------------------------------------------- tokens */
:root {
  --ok: #3f7a4f;
  --ok-soft: #e1eedf;
  --warn: #9a5b07;
  --warn-soft: #f8eedb;
  --danger: #b33a2e;
  --danger-soft: #f8e5e1;
  --rail: #f6f4ea;
  --shadow: 0 1px 2px rgb(28 42 33 / .05), 0 6px 20px rgb(28 42 33 / .07);
  --shadow-lg: 0 -8px 40px rgb(28 42 33 / .18);
  --radius: 20px;
  --radius-sm: 12px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --fast: 140ms;
  --med: 200ms;
  --slow: 260ms;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Manrope', var(--font);
  color-scheme: light;
}
/* dark: follows the phone unless forced with data-mode (set in the app's colour settings) */
:root[data-mode='dark'] {
  --ok: #8fcf9a;
  --ok-soft: #1b2b1e;
  --warn: #e9b866;
  --warn-soft: #2e2615;
  --danger: #f19a8f;
  --danger-soft: #34201c;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 20px rgb(0 0 0 / .28);
  --shadow-lg: 0 -8px 40px rgb(0 0 0 / .5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-mode='light']) {
    --ok: #8fcf9a;
    --ok-soft: #1b2b1e;
    --warn: #e9b866;
    --warn-soft: #2e2615;
    --danger: #f19a8f;
    --danger-soft: #34201c;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 20px rgb(0 0 0 / .28);
    --shadow-lg: 0 -8px 40px rgb(0 0 0 / .5);
    color-scheme: dark;
  }
}
/* colour schemes (public/lib/theme.js lists them); --logo is the icon tile, the same in light and dark */
:root, :root[data-scheme='salvia'] {
  --bg: #eef2ec;
  --surface: #fbfcf9;
  --surface-2: #e3eadf;
  --ink: #1c2a21;
  --ink-2: #3c4d41;
  --muted: #69786c;
  --line: #d6dfd2;
  --accent: #4f6f54;
  --accent-ink: #ffffff;
  --accent-soft: #dfe9db;
  --logo: #56755b;
}
:root[data-scheme='pizarra'] {
  --bg: #edf1f5;
  --surface: #fbfcfd;
  --surface-2: #e2e8ef;
  --ink: #1a2433;
  --ink-2: #3a4759;
  --muted: #66748a;
  --line: #d3dbe5;
  --accent: #3d5a80;
  --accent-ink: #ffffff;
  --accent-soft: #dde6f1;
  --logo: #3d5a80;
}
:root[data-scheme='arena'] {
  --bg: #f4efe7;
  --surface: #fdfbf7;
  --surface-2: #ebe3d6;
  --ink: #2b2219;
  --ink-2: #4d4134;
  --muted: #7d6f60;
  --line: #e1d7c8;
  --accent: #b0532f;
  --accent-ink: #ffffff;
  --accent-soft: #f3dfd3;
  --logo: #b0532f;
}
:root[data-scheme='ciruela'] {
  --bg: #f2eff5;
  --surface: #fcfbfd;
  --surface-2: #e8e2ee;
  --ink: #261e30;
  --ink-2: #463b52;
  --muted: #75697f;
  --line: #ddd5e5;
  --accent: #6b4a8a;
  --accent-ink: #ffffff;
  --accent-soft: #e8def2;
  --logo: #6b4a8a;
}
:root[data-scheme='grafito'] {
  --bg: #f2f2f0;
  --surface: #ffffff;
  --surface-2: #e7e7e4;
  --ink: #1b1b1a;
  --ink-2: #3d3d3b;
  --muted: #6f6f6b;
  --line: #dcdcd8;
  --accent: #222221;
  --accent-ink: #ffffff;
  --accent-soft: #e4e4e1;
  --logo: #2b2b2a;
}
:root[data-scheme='salvia'][data-mode='dark'] {
  --bg: #0f1410;
  --surface: #161d17;
  --surface-2: #1f2820;
  --ink: #e5ece2;
  --ink-2: #c1ccbf;
  --muted: #8d9b8d;
  --line: #283329;
  --accent: #a9c4a4;
  --accent-ink: #132016;
  --accent-soft: #223024;
}
:root[data-scheme='pizarra'][data-mode='dark'] {
  --bg: #0e1218;
  --surface: #151b23;
  --surface-2: #1d252f;
  --ink: #e3e9f1;
  --ink-2: #bcc6d3;
  --muted: #8794a6;
  --line: #26303c;
  --accent: #9db8dc;
  --accent-ink: #0f1a29;
  --accent-soft: #1e2a3a;
}
:root[data-scheme='arena'][data-mode='dark'] {
  --bg: #15110d;
  --surface: #1d1813;
  --surface-2: #27201a;
  --ink: #efe6da;
  --ink-2: #cfc2b2;
  --muted: #9a8b7a;
  --line: #322a22;
  --accent: #e79a76;
  --accent-ink: #2a140a;
  --accent-soft: #3a2519;
}
:root[data-scheme='ciruela'][data-mode='dark'] {
  --bg: #121016;
  --surface: #1a171f;
  --surface-2: #241f2b;
  --ink: #ebe5f1;
  --ink-2: #c9bfd3;
  --muted: #958aa1;
  --line: #2e2836;
  --accent: #c3a6e0;
  --accent-ink: #1f1230;
  --accent-soft: #2d2340;
}
:root[data-scheme='grafito'][data-mode='dark'] {
  --bg: #0d0d0d;
  --surface: #161616;
  --surface-2: #202020;
  --ink: #ededeb;
  --ink-2: #c4c4c1;
  --muted: #8f8f8b;
  --line: #2a2a2a;
  --accent: #ededeb;
  --accent-ink: #111111;
  --accent-soft: #262626;
}
@media (prefers-color-scheme: dark) {
  :root[data-scheme='salvia']:not([data-mode='light']) {
    --bg: #0f1410;
    --surface: #161d17;
    --surface-2: #1f2820;
    --ink: #e5ece2;
    --ink-2: #c1ccbf;
    --muted: #8d9b8d;
    --line: #283329;
    --accent: #a9c4a4;
    --accent-ink: #132016;
    --accent-soft: #223024;
  }
  :root[data-scheme='pizarra']:not([data-mode='light']) {
    --bg: #0e1218;
    --surface: #151b23;
    --surface-2: #1d252f;
    --ink: #e3e9f1;
    --ink-2: #bcc6d3;
    --muted: #8794a6;
    --line: #26303c;
    --accent: #9db8dc;
    --accent-ink: #0f1a29;
    --accent-soft: #1e2a3a;
  }
  :root[data-scheme='arena']:not([data-mode='light']) {
    --bg: #15110d;
    --surface: #1d1813;
    --surface-2: #27201a;
    --ink: #efe6da;
    --ink-2: #cfc2b2;
    --muted: #9a8b7a;
    --line: #322a22;
    --accent: #e79a76;
    --accent-ink: #2a140a;
    --accent-soft: #3a2519;
  }
  :root[data-scheme='ciruela']:not([data-mode='light']) {
    --bg: #121016;
    --surface: #1a171f;
    --surface-2: #241f2b;
    --ink: #ebe5f1;
    --ink-2: #c9bfd3;
    --muted: #958aa1;
    --line: #2e2836;
    --accent: #c3a6e0;
    --accent-ink: #1f1230;
    --accent-soft: #2d2340;
  }
  :root[data-scheme='grafito']:not([data-mode='light']) {
    --bg: #0d0d0d;
    --surface: #161616;
    --surface-2: #202020;
    --ink: #ededeb;
    --ink-2: #c4c4c1;
    --muted: #8f8f8b;
    --line: #2a2a2a;
    --accent: #ededeb;
    --accent-ink: #111111;
    --accent-soft: #262626;
  }
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 400 15px/1.45 var(--font);
  font-feature-settings: 'cv11', 'ss01';
  background: radial-gradient(140% 55% at 50% -12%, color-mix(in srgb, var(--accent) 22%, var(--bg)) 0%, var(--bg) 62%) no-repeat, var(--bg);
  min-height: 100dvh;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -.02em; margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.ic {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tnum { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { display: block; width: 34px; height: 34px; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgb(28 42 33 / .2); }
/* logo colours follow the scheme */
.lg-tile { fill: #ffffff; } /* the logo is always on white, whatever the scheme */
.lg-hz { fill: color-mix(in srgb, var(--logo) 82%, #fff); }
.lg-sl { fill: color-mix(in srgb, var(--logo) 55%, #fff); }
.lg-rail { fill: var(--rail); }

/* ---------------------------------------------------------------- opening animation
   A Mitre train comes down the logo's tracks and brakes to a stop in front of you, flashes its
   lights, then the app shows through. ~2.6 s; a tap skips it. */
.splash {
  position: fixed; inset: 0; z-index: 100; overflow: hidden;
  background: #15201a;
  transition: opacity .5s cubic-bezier(.4, 0, .2, 1);
}
.splash canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; transition: opacity .45s ease-out; }
.splash.ready canvas { opacity: 1; }
.splash.out { opacity: 0; pointer-events: none; }
.splash-brand {
  position: absolute; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 64px);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: #fff; font: 750 26px/1 var(--font-display); letter-spacing: -.02em;
  text-shadow: 0 1px 14px rgb(0 0 0 / .45);
  opacity: 0; transform: translateY(8px);
  transition: opacity .7s cubic-bezier(.2, .8, .2, 1) .2s, transform .7s cubic-bezier(.2, .8, .2, 1) .2s;
}
.splash.ready .splash-brand { opacity: 1; transform: none; }
.splash-brand .logo { width: 40px; height: 40px; border-radius: 12px; box-shadow: 0 4px 14px rgb(0 0 0 / .35); }
.wordmark { font: 700 17px/1 var(--font-display); letter-spacing: -.02em; }

main { max-width: 640px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-left)) calc(32px + env(safe-area-inset-bottom)); }

/* ---------------------------------------------------------------- segmented control */
.segmented {
  --n: 2;
  position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 3px; border-radius: 12px; background: var(--surface-2);
  isolation: isolate;
}
.segmented > button, .segmented > label {
  position: relative; z-index: 1;
  border: 0; background: none; padding: 7px 14px; border-radius: 9px;
  font-weight: 550; font-size: 14px; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  transition: color var(--med) var(--ease);
}
.segmented > [aria-selected='true'], .segmented > .on { color: var(--ink); }
.segmented .thumb {
  position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 3px;
  width: calc((100% - 6px) / var(--n));
  border-radius: 9px; background: var(--surface); box-shadow: 0 1px 3px rgb(16 24 40 / .12);
  transform: translateX(calc(var(--i, 0) * 100%));
  transition: transform var(--slow) var(--ease);
}
.segmented.small > button { padding: 6px 12px; font-size: 13.5px; }
.segmented.full { display: grid; }
.segmented label input { position: absolute; opacity: 0; pointer-events: none; }
#days { --n: 3; flex: 1; }
.date-btn { position: relative; }
.date-btn .ic { width: 16px; height: 16px; }
.date-btn input[type=date] {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; border: 0; padding: 0; cursor: pointer;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; font-size: 14.5px;
  transition: transform var(--fast) var(--ease), background-color var(--med) var(--ease), border-color var(--med) var(--ease), opacity var(--med);
}
.btn .ic { width: 18px; height: 18px; }
.btn:active, .icon-btn:active, .select-btn:active, .branch-row:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 90%, var(--ink)); }
.btn.ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: color-mix(in srgb, var(--line) 50%, var(--muted)); }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  transition: transform var(--fast) var(--ease), background-color var(--med) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.danger { color: var(--danger); }
.icon-btn.spinning .ic { animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- today */
.toolbar { display: flex; gap: 10px; align-items: center; }
.greet { margin: 4px 2px 14px; font: 750 26px/1.15 var(--font-display); letter-spacing: -.025em; }
.status {
  display: flex; align-items: center; gap: 8px; min-height: 20px;
  margin: 12px 2px 14px; font-size: 13px; color: var(--muted);
}
.status::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none;
  transition: background-color var(--med);
}
.status.live::before { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.status.offline::before { background: var(--warn); }
.status.error::before { background: var(--danger); }
.status:empty::before { display: none; }
.stack { display: grid; gap: 12px; }

.card {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.enter { animation: enter var(--slow) var(--ease) backwards; animation-delay: calc(var(--i, 0) * 35ms); }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 75%, transparent); color: var(--ink-2);
  font-size: 12.5px; font-weight: 550; font-variant-numeric: tabular-nums;
}
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.live { background: var(--ok-soft); color: var(--ok); }
.chip.live::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  animation: live-pulse 1.6s ease-in-out infinite;
}
@keyframes live-pulse { 50% { opacity: .35; } }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.options { list-style: none; margin: 10px 0 0; padding: 0; }
.options li {
  display: grid; grid-template-columns: minmax(8.4em, auto) 1fr auto; align-items: center; gap: 12px;
  padding: 9px 2px; border-top: 1px solid var(--line); font-size: 13.5px;
}
.options .t { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.options .t em { font-style: normal; font-weight: 600; font-size: 12px; color: var(--warn); margin-left: 4px; }
.options .t small { font-weight: 450; color: var(--muted); }
.options .d { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.options .tag { font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.options li.cancelled .t { text-decoration: line-through; color: var(--muted); }
.options li.cancelled .tag { color: var(--danger); }
.options li.late .tag { color: var(--warn); }
.plan-warn { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; font-size: 13.5px; color: var(--ink-2); }
.plan-warn .ic { width: 18px; height: 18px; color: var(--warn); }

.empty {
  display: grid; justify-items: center; gap: 10px; text-align: center;
  padding: 40px 20px; color: var(--muted);
}
.empty .ic { width: 36px; height: 36px; stroke-width: 1.4; color: color-mix(in srgb, var(--muted) 70%, transparent); }
.empty h3 { color: var(--ink); font-size: 16px; }
.empty p { margin: 0; max-width: 300px; font-size: 14px; }

.skeleton { height: 178px; padding: 16px; }
.skeleton i {
  display: block; height: 12px; border-radius: 6px; margin-bottom: 10px;
  background: linear-gradient(90deg, var(--surface-2) 0%, color-mix(in srgb, var(--surface-2) 40%, var(--surface)) 50%, var(--surface-2) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
}
.skeleton i:nth-child(1) { width: 40%; }
.skeleton i:nth-child(2) { width: 60%; height: 10px; }
.skeleton i:nth-child(3) { height: 74px; border-radius: 14px; margin-top: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------------------------------------------------------------- routines */
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 2px 16px; }
.section-head h1 { font-size: 26px; }
.section-head p { margin: 2px 0 0; font-size: 14px; }
.dots { display: inline-flex; gap: 3px; }
.dots span {
  display: grid; place-items: center; width: 20px; height: 20px; border-radius: 6px;
  font-size: 10.5px; font-weight: 700; color: var(--muted); background: var(--surface-2);
}
.backup { margin-top: 18px; text-align: center; }

/* colours: scheme swatches (each a mini logo) + light/dark */
.appearance { display: grid; justify-items: center; gap: 12px; margin-top: 28px; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.swatch {
  position: relative; display: grid; justify-items: center; gap: 4px; padding: 0; border: 0; background: none;
  font-size: 11.5px; font-weight: 600; color: var(--muted);
}
.swatch i { display: block; width: 34px; height: 34px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .08), 0 1px 3px rgb(0 0 0 / .18); transition: transform var(--fast) var(--ease); }
.swatch:active i { transform: scale(.94); }
.swatch[aria-checked='true'] { color: var(--ink); }
.swatch[aria-checked='true'] i { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--logo); }

/* "where I slept": picks the starting point for the day's routines */
.stay { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.stay > .ic { width: 18px; height: 18px; color: var(--muted); }
.stay .segmented { flex: 1; min-width: 0; }
.stay .segmented > button { overflow: hidden; text-overflow: ellipsis; }
.stay .segmented > button .ic { width: 15px; height: 15px; }
.tc-title small .ic.moon { color: var(--accent); }

/* routine form: alternative start */
.alt-start { margin: 4px 0 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.alt-start summary {
  display: flex; align-items: center; gap: 8px; padding: 11px 12px; cursor: pointer; list-style: none;
  font-weight: 600; font-size: 14px; color: var(--ink-2);
}
.alt-start summary::-webkit-details-marker { display: none; }
.alt-start summary .ic { width: 18px; height: 18px; color: var(--muted); }
.alt-start summary .chev { margin-left: auto; transition: transform var(--med) var(--ease); }
.alt-start[open] summary .chev { transform: rotate(90deg); }
.alt-fields { padding: 0 12px 4px; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.center { justify-content: center; }

/* ---------------------------------------------------------------- sheets */
dialog.sheet {
  position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: rgb(8 12 20 / 0);
  display: flex; align-items: flex-end; justify-content: center;
  transition: background-color var(--slow) var(--ease);
}
dialog.sheet:not([open]) { display: none; }
dialog.sheet::backdrop { background: transparent; }
dialog.sheet.open { background: rgb(8 12 20 / .38); }
.sheet-panel {
  width: 100%; max-width: 560px; max-height: calc(100dvh - 24px - env(safe-area-inset-top));
  overflow: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: var(--shadow-lg);
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform var(--slow) var(--ease);
}
.sheet-panel.tall { min-height: 60dvh; }
dialog.sheet.open .sheet-panel { transform: none; }
@media (min-width: 700px) {
  dialog.sheet { align-items: center; }
  .sheet-panel { border-radius: 22px; transform: translateY(16px) scale(.98); opacity: 0; transition: transform var(--med) var(--ease), opacity var(--med) var(--ease); }
  dialog.sheet.open .sheet-panel { opacity: 1; }
}
.sheet-grip { width: 36px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { font-size: 19px; }
.sheet-head .icon-btn { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; }
.sheet-head .icon-btn .ic { width: 17px; height: 17px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 18px; }
.sheet-actions.editing { grid-template-columns: auto 1fr 2fr; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.sheet-actions .btn { min-height: 46px; }

/* ---------------------------------------------------------------- form */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: .01em; }
.field input:not([type=checkbox]):not([type=radio]), .field select {
  width: 100%; min-height: 44px; padding: 0 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface);
  font-size: 16px; /* prevents iOS zoom on focus */
  transition: border-color var(--fast), box-shadow var(--fast);
  appearance: none; -webkit-appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7686' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px; padding-right: 34px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.suffix { position: relative; }
.suffix em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 13px; color: var(--muted); pointer-events: none; }
.suffix input { padding-right: 40px !important; }
.grid-3 { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 10px; }
.grid-3 .field { margin-bottom: 0; }

.select-btn {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  min-height: 54px; padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface);
  transition: transform var(--fast) var(--ease), border-color var(--fast);
}
.select-btn:hover { border-color: color-mix(in srgb, var(--line) 50%, var(--muted)); }
.select-btn-text { flex: 1; display: grid; min-width: 0; }
.select-btn-text strong { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-btn-text small { color: var(--muted); font-size: 12.5px; }
.select-btn > .ic { color: var(--muted); }
.lv-swatch { flex: none; width: 64px; height: 36px; border-radius: 7px; box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.branch-art { display: grid; place-items: center; flex: none; width: 64px; }
.any-icon {
  display: grid; place-items: center; flex: none; width: 64px; height: 36px; border-radius: 8px;
  background: var(--surface-2); color: var(--muted);
}
.any-icon .ic { width: 16px; height: 16px; }
.line-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--dot, var(--line)); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--surface) 30%, transparent); }

.route-fields { position: relative; display: grid; grid-template-columns: 14px 1fr 40px; gap: 0 10px; align-items: center; }
.route-inputs .field:last-child { margin-bottom: 14px; }
.route-rail { display: grid; grid-template-rows: auto 1fr auto; justify-items: center; height: 56%; margin-top: 4px; }
.route-rail i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--accent); background: var(--surface); }
.route-rail i:last-child { background: var(--accent); }
.route-rail b { width: 2px; background: repeating-linear-gradient(var(--line) 0 4px, transparent 4px 7px); }
.swap { border-radius: 50%; width: 38px; height: 38px; }
.swap .ic { width: 18px; height: 18px; transition: transform var(--med) var(--ease); }
.swap.turn .ic { transform: rotate(180deg); }

.days-picker { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.days-picker label { position: relative; }
.days-picker input { position: absolute; opacity: 0; pointer-events: none; }
.days-picker span {
  display: grid; place-items: center; height: 40px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 650; font-size: 14px; color: var(--muted);
  cursor: pointer; user-select: none;
  transition: background-color var(--med) var(--ease), color var(--med) var(--ease), border-color var(--med) var(--ease), transform var(--fast) var(--ease);
}
.days-picker span:active { transform: scale(.94); }
.days-picker input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.days-picker input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
#mode-seg { --n: 2; }
#mode-seg label { cursor: pointer; padding: 9px 8px; }
#mode-seg label:has(input:checked) { color: var(--ink); }
.form-error {
  display: flex; gap: 8px; align-items: flex-start; margin: 14px 0 0; padding: 10px 12px; border-radius: 12px;
  background: var(--danger-soft); color: var(--danger); font-size: 13.5px; animation: enter var(--med) var(--ease);
}

/* ---------------------------------------------------------------- branch picker */
.branch-row {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 11px 12px; border: 0; border-radius: 12px; background: none;
  transition: background-color var(--fast), transform var(--fast) var(--ease);
}
.branch-row:hover { background: var(--surface-2); }
.branch-row > span:not(.line-dot) { display: grid; flex: 1; min-width: 0; }
.branch-row strong { font-weight: 600; font-size: 15px; }
.branch-row small { color: var(--muted); font-size: 12.5px; }
.branch-row.selected { background: var(--accent-soft); }
.branch-row.selected strong { color: var(--accent); }
.branch-row.any { margin-bottom: 6px; }
.line-list { display: grid; gap: 2px; border-top: 1px solid var(--line); padding-top: 6px; }
.line-group > .branch-row .chev { color: var(--muted); transition: transform var(--med) var(--ease); }
.line-group.open > .branch-row .chev { transform: rotate(90deg); }
.line-branches {
  display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--med) var(--ease);
}
.line-group.open .line-branches { grid-template-rows: 1fr; }
.line-branches > div { overflow: hidden; padding-left: 24px; }
.line-branches .branch-row { padding: 9px 12px; }
.line-branches .note { padding: 8px 12px; font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--bg);
  font-size: 14px; font-weight: 550; box-shadow: var(--shadow);
  transition: transform var(--med) var(--ease), opacity var(--med) var(--ease);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------------------------------------------------------------- views */
.view.is-entering { animation: view-in var(--med) var(--ease); }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } }

@media (max-width: 380px) {
  .times .dep { font-size: 30px; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-3 .field:first-child { grid-column: 1 / -1; }
}

/* Respect users who ask for less motion. */
@media (prefers-reduced-motion: reduce) {
  .splash { display: none; }
  *, *::before, *::after {
    animation-duration: 1ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

/* ---------------------------------------------------------------- live data indicators */
.chip.sched { background: var(--surface-2); color: var(--muted); }
.src { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; background: var(--line); box-shadow: inset 0 0 0 1.5px var(--muted); }
.src.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.live-btn { margin-bottom: 14px; }
.live-btn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: live-pulse 1.6s ease-in-out infinite; }
.live-intro { margin: -4px 2px 8px; }
.live-conn { margin: 0 2px 12px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.live-group { border-top: 1px solid var(--line); padding: 12px 2px 6px; }
.live-group header { display: flex; align-items: center; gap: 12px; }
.live-group header div { display: grid; min-width: 0; }
.live-group header small { color: var(--muted); font-size: 12.5px; }
.live-sum { margin: 8px 0 0; font-size: 13.5px; color: var(--ink-2); }
.live-group .tag.on { color: var(--ok); }

/* ---------------------------------------------------------------- main-train states & picking */
.chip small { font-weight: 500; opacity: .75; }
.chip.pick-reset { border: 0; cursor: pointer; background: var(--surface); color: var(--ink-2); font: inherit; font-size: 12.5px; font-weight: 600; }
.chip.pick-reset .ic { width: 13px; height: 13px; }

/* ================================================================ train cards
   A little station scene per card; the line's train approaches the platform, leaves when it
   departs, and is gone when it is no longer available (see renderPlans / placeTrains). */
.tc { border: 0; border-radius: 22px; }
.tc.routine { cursor: pointer; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.tc.routine .tc-body { transition: background-color var(--fast); }
.tc.routine:active .tc-body { background: var(--surface-2); }
.scene {
  position: relative; height: 104px; overflow: hidden;
  background: linear-gradient(180deg, #79b8ea 0%, #cfe6f6 100%);
}
/* sky by the time of the trip */
.scene.sky-dawn { background: linear-gradient(180deg, #9cc0e4 0%, #f3d2ab 70%, #f7c58f 100%); }
.scene.sky-dusk { background: linear-gradient(180deg, #4f68ab 0%, #c9789a 55%, #f2a86a 100%); }
.scene.sky-night {
  background:
    radial-gradient(1px 1px at 12% 22%, #fff 99%, transparent), radial-gradient(1px 1px at 28% 12%, #fff 99%, transparent),
    radial-gradient(1.5px 1.5px at 44% 30%, #fff 99%, transparent), radial-gradient(1px 1px at 63% 16%, #fff 99%, transparent),
    radial-gradient(1px 1px at 81% 34%, #fff 99%, transparent), radial-gradient(1.5px 1.5px at 92% 14%, #fff 99%, transparent),
    linear-gradient(180deg, #0e1a36 0%, #283d6b 100%);
}
.scene .sun {
  position: absolute; z-index: 0; top: 14px; left: 56%; width: 22px; height: 22px; border-radius: 50%;
  background: #ffd866; box-shadow: 0 0 0 6px rgb(255 216 102 / .25), 0 0 26px 8px rgb(255 216 102 / .45);
}
.sky-dawn .sun { top: 40px; left: 18%; background: #ffc56b; box-shadow: 0 0 22px 10px rgb(255 190 110 / .55); }
.sky-dusk .sun { top: 44px; left: 52%; width: 26px; height: 26px; background: #ff9a5a; box-shadow: 0 0 26px 12px rgb(255 140 90 / .5); }
.sky-night .sun { top: 14px; left: 58%; width: 18px; height: 18px; background: transparent; box-shadow: inset -5px 3px 0 0 #f4ecd2, 0 0 14px 2px rgb(244 236 210 / .2); }
.scene .cloud {
  position: absolute; z-index: 0; top: 18px; width: 46px; height: 12px; border-radius: 12px; background: rgb(255 255 255 / .85);
  animation: cloud 48s linear infinite;
}
.scene .cloud::before { content: ''; position: absolute; left: 10px; top: -8px; width: 22px; height: 16px; border-radius: 50%; background: inherit; }
.scene .cloud.c2 { top: 34px; width: 34px; height: 9px; opacity: .7; animation-duration: 66s; animation-delay: -30s; }
.scene .cloud.c2::before { left: 7px; top: -6px; width: 16px; height: 12px; }
.sky-dusk .cloud { background: rgb(255 214 200 / .7); }
.sky-night .cloud { background: rgb(160 175 210 / .18); }
@keyframes cloud { from { transform: translateX(-60px); } to { transform: translateX(460px); } }
/* golden plane trees behind the station, two depths */
.scene .trees {
  position: absolute; z-index: 0; left: 0; right: 0; bottom: 8px; height: 46px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='46'%3E%3Cg fill='%23d9b04a'%3E%3Ccircle cx='14' cy='26' r='14'/%3E%3Ccircle cx='36' cy='18' r='16'/%3E%3Ccircle cx='60' cy='28' r='13'/%3E%3Ccircle cx='84' cy='20' r='15'/%3E%3Ccircle cx='106' cy='27' r='14'/%3E%3C/g%3E%3Cg fill='%23b4892c'%3E%3Ccircle cx='24' cy='36' r='12'/%3E%3Ccircle cx='70' cy='38' r='12'/%3E%3Ccircle cx='98' cy='38' r='11'/%3E%3C/g%3E%3Crect y='36' width='120' height='10' fill='%23a07a2a'/%3E%3C/svg%3E") repeat-x left bottom / 120px 46px,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='46'%3E%3Cg fill='%2394a05a'%3E%3Ccircle cx='10' cy='30' r='11'/%3E%3Ccircle cx='32' cy='26' r='12'/%3E%3Ccircle cx='55' cy='31' r='10'/%3E%3Ccircle cx='76' cy='27' r='12'/%3E%3C/g%3E%3C/svg%3E") repeat-x 40px 4px / 90px 46px;
  opacity: .9;
}
.sky-dusk .trees { filter: brightness(.72) saturate(1.1); }
.sky-night .trees { filter: brightness(.32) saturate(.6); }
.sky-night .station, .sky-night .track { filter: brightness(.7); }
.compact .scene { height: 84px; }
.compact .scene .trees { height: 38px; }
.tc-line {
  position: absolute; z-index: 3; top: 10px; left: 12px;
  padding: 3px 10px; border-radius: 999px; background: var(--tr); color: var(--tr-ink);
  font-size: 12px; font-weight: 700; letter-spacing: .02em;
}
.tc-goal {
  position: absolute; z-index: 3; top: 9px; right: 12px;
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--ink-2);
  font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.tc-goal .ic { width: 14px; height: 14px; }
/* station: canopy on two posts over a low platform, right of centre */
.station { position: absolute; z-index: 0; right: 4%; width: 46%; bottom: 8px; height: 62px; }
.station i { position: absolute; display: block; }
.station .roof { top: 4px; left: -3%; right: -3%; height: 7px; border-radius: 4px; background: #5b636a; }
.station .post { top: 10px; bottom: 10px; width: 3px; background: #6c757c; }
.station .post:nth-of-type(2) { left: 14%; }
.station .post:nth-of-type(3) { right: 14%; }
.station .platform { left: 0; right: 0; bottom: 0; height: 11px; border-radius: 2px 2px 0 0; background: #b9b4aa; box-shadow: inset 0 2px 0 color-mix(in srgb, #f2c230 80%, transparent); }
.compact .station { display: none; }
/* track: rail over sleepers along the bottom */
.track {
  position: absolute; z-index: 1; left: 0; right: 0; bottom: 3px; height: 6px;
  background:
    linear-gradient(color-mix(in srgb, var(--ink) 45%, transparent), color-mix(in srgb, var(--ink) 45%, transparent)) 0 0 / 100% 2px no-repeat,
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--ink) 25%, transparent) 0 6px, transparent 6px 13px) 0 3px / 100% 3px no-repeat;
}
/* the train: --p 0 = off-screen left, 1 = stopped at the platform */
.train {
  --p: 0;
  position: absolute; z-index: 2; bottom: 4px; width: 74%;
  left: calc(-74% + var(--p) * 96%);
  transition: left 1.6s cubic-bezier(.33, .7, .3, 1);
}
.train svg { display: block; width: 100%; height: auto; filter: drop-shadow(0 2px 2px rgb(0 0 0 / .18)); }
.train.parked { left: 13%; transition: none; }
.compact .train.parked { left: 24%; width: 66%; }
.train.moving svg { animation: rumble .22s linear infinite; }
@keyframes rumble { 50% { transform: translateY(.6px); } }
.train .lamp { animation: lamp 2.4s ease-in-out infinite; }
@keyframes lamp { 50% { opacity: .55; } }
/* leaving: accelerate out of the station, then the card redraws without it */
.train.leave { animation: leave 2.4s cubic-bezier(.55, 0, .8, .2) forwards; }
.train.leave svg { animation: rumble .16s linear infinite; }
@keyframes leave { to { transform: translateX(150%); } }

.tc-body { padding: 10px 16px 14px; }
.tc-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.tc-title b { font: 700 15.5px/1.25 var(--font-display); letter-spacing: -.01em; white-space: nowrap; }
.tc-title small { display: inline-flex; align-items: center; gap: 4px; min-width: 0; color: var(--muted); font-size: 12.5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tc-title small .ic { width: 12px; height: 12px; flex: none; }
.tc-main { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; margin-top: 6px; }
.tc-times { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; }
.tc-times .src { align-self: center; margin-right: 0; }
.tc-times .dep { font: 750 38px/1 var(--font); letter-spacing: -.035em; }
.tc-times .arr { display: inline-flex; align-items: center; gap: 3px; font-size: 18px; font-weight: 550; color: var(--ink-2); }
.tc-times .arr .ic { width: 15px; height: 15px; color: var(--muted); }
.tc-leave {
  display: grid; justify-items: center; line-height: 1.1; padding: 8px 12px 7px; border-radius: 16px; min-width: 76px;
  background: color-mix(in srgb, var(--tr) 14%, var(--surface)); color: color-mix(in srgb, var(--tr) 70%, var(--ink));
}
.tc-main.hurry .tc-leave { background: var(--danger-soft); }
.tc-main.missed .tc-leave { background: var(--surface-2); color: var(--muted); }
.tc-leave .count { font: 750 28px/1 var(--font); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tc-leave .count.urgent { color: var(--danger); }
.tc-leave small { display: inline-flex; align-items: center; gap: 3px; margin-top: 3px; color: inherit; opacity: .8; font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tc-leave small .ic { width: 13px; height: 13px; }
.tc-main.hurry .count, .tc-main.hurry .dep { color: var(--danger); }
.tc-main.missed .dep, .tc-main.missed .arr { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 2px; }
.tc-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tc-meta .chip { background: var(--surface-2); }
.tc-meta .chip.warn { background: var(--warn-soft); }
.tc-meta .chip.danger { background: var(--danger-soft); }
.tc-meta .chip .ic { width: 13px; height: 13px; }
.chip.soft { color: var(--muted); }
.alert-btn { border: 0; cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 650; }
.tc-alerts { margin-top: 8px; padding: 8px 12px; border-radius: 12px; background: var(--warn-soft); color: var(--ink-2); font-size: 13px; line-height: 1.4; animation: enter var(--med) var(--ease); }
.tc-alerts p { margin: 4px 0; }
.tc-alerts b { color: var(--warn); }
.tc-pills { display: flex; gap: 6px; margin-top: 12px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.tc-pills::-webkit-scrollbar { display: none; }
.pill {
  position: relative; flex: none; padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  font: 650 13.5px/1 var(--font); font-variant-numeric: tabular-nums;
  transition: background-color var(--fast), color var(--fast), transform var(--fast) var(--ease);
}
button.pill { cursor: pointer; }
button.pill:active { transform: scale(.95); }
.pill sup { margin-left: 3px; font-size: 10px; color: var(--warn); }
.pill.sel { background: var(--tr); border-color: var(--tr); color: var(--tr-ink); }
.pill.sel sup { color: inherit; }
.pill.rec::after { content: ''; position: absolute; top: 3px; right: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--tr); }
.pill.next { border-color: var(--warn); }
.pill.gone { opacity: .4; text-decoration: line-through; }
.pill.cx { color: var(--danger); text-decoration: line-through; opacity: .7; }
.compact .tc-body { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.compact .tc-title { flex-direction: column; align-items: flex-start; gap: 2px; }
.compact .tc-title { flex: 1; }
.compact .tc-title small { max-width: 100%; }
.compact .dots { flex: none; }
.compact .dots span.on { background: color-mix(in srgb, var(--tr) 18%, var(--surface)); color: color-mix(in srgb, var(--tr) 75%, var(--ink)); }
/* a trip that is over for today: greyed out, empty track */
.tc.done { filter: grayscale(1); opacity: .55; }
.live-intro .src { margin: 0 4px 0 0; }
.next-btn { border: 1.5px solid var(--warn); background: var(--surface) !important; color: var(--ink); cursor: pointer; font: inherit; font-size: 13px; font-weight: 700; }
.next-btn sup { font-size: 10px; color: var(--warn); }
