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

html, body { margin: 0; padding: 0; }

html {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Day/night crossfade (the "lerp" into 07:00 / 17:00). Snaps under
   reduced-motion. Component surfaces inherit via their own bg tokens. */
html, body { transition: background-color 0.7s ease, color 0.7s ease; }
@media (prefers-reduced-motion: reduce) { html, body { transition: none; } }

body {
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
  /* Pastoral page: cream paper with two soft riso overprints + hairline texture */
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 18% 12%, rgba(217, 164, 65, 0.06) 0, transparent 60%),
    radial-gradient(circle at 82% 92%, rgba(92, 140, 74, 0.05) 0, transparent 55%),
    var(--paper-texture);
  background-attachment: fixed, fixed, scroll;
  padding-top: max(var(--sp-4), env(safe-area-inset-top));
  padding-left: max(var(--sp-4), env(safe-area-inset-left));
  padding-right: max(var(--sp-4), env(safe-area-inset-right));
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

a {
  color: var(--ink);
  text-decoration: none;
}

.mono {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1;
}

.hand { font-family: var(--font-hand); }
.display { font-family: var(--font-display); letter-spacing: -0.005em; }

.muted { color: var(--ink-muted); }
.subtle { color: var(--ink-faint); }

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

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--am-deep);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ---------- Header / brand mark ---------- */
.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 52px;
  margin-bottom: var(--sp-6);
  padding-bottom: var(--sp-3);
  position: relative;
}

/* Tri-color stamped perforation rule under the header */
.app-header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background-image: repeating-linear-gradient(to right,
    var(--leaf) 0 12px, transparent 12px 22px,
    var(--am) 22px 28px, transparent 28px 38px,
    var(--pm) 38px 44px, transparent 44px 60px);
  opacity: 0.85;
}

.app-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
  position: relative;
}

/* The amber "stop dot" after the wordmark */
.app-header h1::after {
  content: "";
  display: inline-block;
  width: 9px; height: 9px;
  background: var(--am);
  border-radius: var(--r-full);
  margin-left: 7px;
  vertical-align: 0.14em;
  box-shadow: 0 0 0 4px rgba(217, 164, 65, 0.26);
}

.app-header .back {
  width: 44px; height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: -12px;
  margin-bottom: -8px;
  color: var(--ink-muted);
}

.app-header .gear {
  width: 44px; height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: -12px;
  margin-bottom: -8px;
  color: var(--ink-muted);
}

/* ---------- Bottom nav (station footer) ---------- */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--paper-light);
  background-image: var(--paper-texture);
  border-top: 1px solid var(--ink-line);
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 60px;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(80, 55, 20, 0.06);
  z-index: 10;
}

.bottom-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 48px;
  color: var(--ink-faint);
  border-radius: var(--r-sm);
  position: relative;
  transition: color var(--motion-fast) var(--ease-out);
}

.bottom-nav a[aria-current="page"] { color: var(--am-deep); }

/* Stamped underline tick on the active tab */
.bottom-nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  bottom: 4px; left: 50%;
  transform: translateX(-50%);
  width: 18px; height: 2px;
  background: var(--am);
  border-radius: var(--r-full);
}

.icon { width: 20px; height: 20px; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; flex-shrink: 0; }

/* ---------- Skeletons — "loading is waiting", show the shape ---------- */
@keyframes skel-fade {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 0.55; }
}

.skeleton {
  background: var(--ink-faint);
  border-radius: var(--r-sm);
  animation: skel-fade 1.8s ease-in-out infinite;
}

/* Literal infinite animations bypass the --motion-* token zeroing, so
   honor prefers-reduced-motion explicitly for decorative loops. */
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; opacity: 0.4; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-2px); }
  40%      { transform: translateX(2px); }
  60%      { transform: translateX(-2px); }
  80%      { transform: translateX(2px); }
}

.shake { animation: shake 200ms var(--ease-out); }

/* Torn ticket — a deleted/voided trip tears away (A14). */
@keyframes tear {
  0%   { opacity: 1; }
  100% { opacity: 0; transform: translateX(10px) rotate(1.2deg); clip-path: polygon(0 0, 100% 0, 95% 100%, 5% 90%); }
}
.tearing { animation: tear 240ms ease-in forwards; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .tearing { animation: none; opacity: 0.35; } }

/* ---------- Toast ---------- */
.toast-error {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-2);
  z-index: 20;
  max-width: calc(100vw - 32px);
}

@media (min-width: 720px) {
  body {
    max-width: 1100px;
    margin: 0 auto;
    padding-left: var(--sp-6);
    padding-right: var(--sp-6);
  }
}
