/* ============================================================
   Base: reset, the signage face, focus, links, buttons, fields,
   headings, utilities and the shared small transitions.
   ============================================================ */

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* the app never scrolls the document: the panel, the page and the sheet
     are the scrollers, so the fixed bars never bounce */
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--page-bg);
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: var(--t-body);
  line-height: 1.45;
  color: var(--text);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern";
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; }
svg { flex: none; }
* { -webkit-tap-highlight-color: transparent; }

h1, h2, h3, h4 { margin: 0; line-height: 1.1; letter-spacing: -0.03em; font-weight: 800; }
p { margin: 0 0 0.8em; }
p:last-child { margin-bottom: 0; }

/* Numbers in a transport app are read down a column: tabular everywhere a
   time or a count is set (components opt in with .num too). */
.num, time, .tabular { font-variant-numeric: tabular-nums lining-nums; }

/* ---------------- Focus ----------------
   One ring: the action green, 2px, never removed. Mouse clicks don't show
   it (focus-visible), keyboards always do. */
:focus { outline: none; }
:focus-visible { outline: var(--focus); outline-offset: 2px; }
.sign :focus-visible, .view-head :focus-visible { outline-color: var(--sign-ink); }

.is-hidden, [hidden] { display: none !important; }

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

/* ---------------- Skip link ---------------- */
.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 2000;
  padding: 10px 14px;
  background: var(--sign-bg);
  color: var(--sign-ink);
  font-weight: 800;
  text-decoration: none;
  border-radius: var(--radius);
  transform: translateY(-160%);
  transition: transform var(--duration-quick) var(--ease-smooth-out);
}
.skip-link:focus { transform: none; outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- Links ---------------- */
a { color: inherit; }
.link, .prose a {
  color: var(--text);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
.link:hover, .prose a:hover { text-decoration-thickness: 2px; }

/* ---------------- The label voice ----------------
   Uppercase micro type with open tracking: DATE, HOURS, PLATFORM, THIS
   WEEKEND. It names things; it never carries a sentence. */
.label {
  margin: 0;
  color: var(--muted);
  font-size: var(--t-micro);
  font-weight: 800;
  letter-spacing: 0.09em;
  line-height: 1.3;
  text-transform: uppercase;
}

/* ---------------- Headings ----------------
   The heavy rule is the top edge of a signage plate; it opens a section.
   Two rule weights in the system: this 6px one and the hairline. */
.section-heading {
  margin: 28px 0 12px;
  padding-top: 14px;
  border-top: 6px solid var(--text);
  font-size: var(--t-lede);
  font-weight: 800;
  letter-spacing: -0.025em;
}
.section-heading:first-child { margin-top: 4px; }
.section-heading + .section-sub { margin-top: -4px; }
.section-sub { margin: 0 0 12px; color: var(--muted); font-size: var(--t-small); line-height: 1.5; }

/* A group label over a list: THIS WEEKEND / NEXT WEEK, on a hairline. */
.group-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 0;
  padding: 0 0 8px;
  border-bottom: 1px solid var(--border);
}
.group-label:first-child { margin-top: 4px; }

/* ---------------- Buttons ----------------
   Square, 2px ink border, the hard shadow only on hover (it lifts the one
   thing the pointer is on). .btn-dark is the sign; .btn-accent the one
   primary action on a screen. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 2px solid var(--text);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition:
    transform var(--duration-quick) var(--ease-smooth-out),
    box-shadow var(--duration-quick) var(--ease-smooth-out),
    background-color var(--duration-quick) var(--ease-smooth-out);
}
.btn svg { width: 18px; height: 18px; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-hover); }
}
.btn:active { transform: translate(1px, 1px); box-shadow: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: default; transform: none; box-shadow: none; }
.btn-dark { background: var(--sign-bg); border-color: var(--sign-bg); color: var(--sign-ink); box-shadow: inset 0 0 0 1px var(--sign-edge); }
.btn-accent { background: var(--accent-solid); border-color: var(--accent-solid); color: var(--on-accent); }
.btn-danger { background: var(--danger-solid); border-color: var(--danger-solid); color: var(--on-danger); }
.btn-quiet { border-width: 1px; border-color: var(--border-strong); }
.btn-small { min-height: 34px; padding: 6px 11px; font-size: var(--t-small); }
.btn-block { display: flex; width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* An icon on its own: 44px target, no box at rest. */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  text-decoration: none;
  transition: box-shadow var(--duration-quick) var(--ease-smooth-out), background-color var(--duration-quick) var(--ease-smooth-out);
}
.icon-btn svg { width: 22px; height: 22px; }
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { box-shadow: inset 0 -3px 0 currentColor; }
}
.icon-btn:active { opacity: 0.65; }

/* ---------------- Fields ---------------- */
.field { display: grid; gap: 6px; margin: 0 0 12px; }
.field > .label { color: var(--muted); }
.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  /* 16px or a phone browser zooms the page when the field takes focus */
  font-size: max(16px, var(--t-body));
  transition: border-color var(--duration-quick) var(--ease-smooth-out);
}
.input::placeholder { color: var(--muted); opacity: 1; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* The search bar: one box, the field inside carries no edge of its own. */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 6px 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--duration-quick) var(--ease-smooth-out);
}
.search-bar:focus-within { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.search-bar > svg { width: 20px; height: 20px; color: var(--muted); }
.search-bar input {
  flex: 1;
  min-width: 0;
  height: 46px;
  border: 0;
  padding: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  font-size: max(16px, var(--t-body));
  font-weight: 600;
}
.search-bar input::placeholder { color: var(--muted); opacity: 1; }
.search-bar input:focus { outline: none; }
.search-bar input::-webkit-search-cancel-button { display: none; }

/* ---------------- Codes: run numbers, car numbers, trip ids ----------------
   Set in mono on a small black plate, the way a set number is painted. */
.code {
  display: inline-block;
  padding: 0 5px;
  border-radius: var(--radius);
  background: var(--sign-bg);
  color: var(--sign-ink);
  font-family: var(--mono);
  font-size: 0.8em;
  font-weight: 500;
  line-height: 1.55;
  white-space: nowrap;
  vertical-align: 0.06em;
  box-shadow: inset 0 0 0 1px var(--sign-edge);
}
.code-muted { background: var(--border); color: var(--text); box-shadow: none; }

/* Tags: small uppercase facts on a row (LIVE, DEMO, EXPRESS). */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: var(--radius);
  background: var(--sign-bg);
  color: var(--sign-ink);
  font-size: var(--t-micro);
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.35;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px var(--sign-edge);
}
.tag-outline { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong); }
.tag-alert { background: var(--danger-solid); color: #fff; }
.tag-accent { background: var(--accent-solid); color: var(--on-accent); }

/* ---------------- Prose ---------------- */
.prose { line-height: 1.6; max-width: 34em; }
.prose p { margin: 0 0 0.9em; }
.muted { color: var(--muted); }
.small { font-size: var(--t-small); }
.micro { font-size: var(--t-micro); }

/* ---------------- Nerd mode ----------------
   Run numbers, set types, car numbers and consist details are marked
   .nerd-only and disappear when the reader turns nerd mode off, with no
   re-render. */
html:not(.nerd) .nerd-only { display: none !important; }

/* ---------------- Small shared transitions ---------------- */
.t-rise { animation: t-rise var(--duration-fast) var(--ease-smooth-out) both; }
.t-rise-list > :nth-child(-n+8) { animation: t-rise var(--duration-fast) var(--ease-smooth-out) both; }
.t-rise-list > :nth-child(2) { animation-delay: calc(var(--duration-stagger) * 1); }
.t-rise-list > :nth-child(3) { animation-delay: calc(var(--duration-stagger) * 2); }
.t-rise-list > :nth-child(4) { animation-delay: calc(var(--duration-stagger) * 3); }
.t-rise-list > :nth-child(5) { animation-delay: calc(var(--duration-stagger) * 4); }
.t-rise-list > :nth-child(6) { animation-delay: calc(var(--duration-stagger) * 5); }
.t-rise-list > :nth-child(7) { animation-delay: calc(var(--duration-stagger) * 6); }
.t-rise-list > :nth-child(8) { animation-delay: calc(var(--duration-stagger) * 7); }
@keyframes t-rise {
  from { opacity: 0; transform: translateY(var(--distance-small)); }
  to { opacity: 1; transform: none; }
}

.t-swap { display: inline-block; }
.t-swap.is-swapping { animation: t-swap-in var(--text-swap-dur) var(--ease-in-out) both; }
@keyframes t-swap-in {
  from { opacity: 0; transform: translateY(var(--text-swap-translate-y)); filter: blur(var(--text-swap-blur)); }
  to { opacity: 1; transform: none; filter: blur(0); }
}

.is-shaking { animation: t-shake calc(var(--shake-dur-a) * 2 + var(--shake-dur-b) * 2) linear; }
@keyframes t-shake {
  0% { transform: translateX(0); }
  28.57% { transform: translateX(var(--shake-distance)); }
  57.14% { transform: translateX(calc(var(--shake-distance) * -1)); }
  78.57% { transform: translateX(var(--shake-overshoot)); }
  100% { transform: translateX(0); }
}

@keyframes t-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: var(--pulse-min); }
}

/* ---------------- Reduced motion ----------------
   The device preference and the reader's own override (html.reduce-motion,
   set by app.js from settings) both stop every animation and transition.
   A view transition (the theme flip) is skipped by script. */
@media (prefers-reduced-motion: reduce) {
  html:not(.allow-motion) *, html:not(.allow-motion) *::before, html:not(.allow-motion) *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
}
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after {
  animation-duration: 1ms !important;
  animation-iteration-count: 1 !important;
  animation-delay: 0ms !important;
  transition-duration: 1ms !important;
  transition-delay: 0ms !important;
  scroll-behavior: auto !important;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: var(--duration-fast);
  animation-timing-function: var(--ease-in-out);
}
