/*
 * Europe 2026 — a cute paper travel journal you can still read at arm's length
 * on a station platform.
 *
 * The look: warm cream paper, sage green, a serif with real character
 * (Fraunces) for headings, a handwritten script (Caveat) for the little
 * flourishes, dotted timeline rails, and a soft watercolor vignette per city.
 *
 * Three display modes, cycled from the header:
 *   light  default — the journal
 *   dark   evenings and dim train carriages, same palette by candlelight
 *   sun    direct sunlight — pure black on pure white, heavier weights, larger
 *          base size, thicker rules. Not "light mode with more contrast": every
 *          mid-tone is removed, because mid-tones are what disappear in glare.
 *
 * Nothing here is smaller than 15px, and nothing tappable is under 44px.
 */

@font-face {
  font-family: 'Fraunces';
  src: url('../fonts/fraunces.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'Caveat';
  src: url('../fonts/caveat.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}

:root {
  --bg:        #f7f2e5;
  --surface:   #fffdf4;
  --surface-2: #efe9d6;
  --ink:       #40402e;
  --ink-2:     #6f6b56;
  --ink-3:     #99947c;
  --rule:      #ddd6bd;
  --accent:    #7d8c5c;
  --accent-ink:#fffdf4;
  --critical:  #b35d38;
  --critical-bg:#f7e9de;
  --pending:   #8a6d16;
  --pending-bg:#f7f0d8;
  --good:      #5c7a44;

  --radius: 16px;
  --rule-w: 1px;
  --pad: 18px;
  --base: 17px;
  --display: 'Fraunces', ui-serif, "Iowan Old Style", Palatino, Georgia, serif;
  --script: 'Caveat', 'Bradley Hand', cursive;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --weight-body: 400;
  --weight-strong: 600;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

:root[data-theme="dark"] {
  --bg: #181910; --surface: #222317; --surface-2: #2c2d1f;
  --ink: #f0ecda; --ink-2: #b5b099; --ink-3: #85806a;
  --rule: #383a29; --accent: #a4b382; --accent-ink: #181910;
  --critical: #e0916a; --critical-bg: #2f2119;
  --pending: #d9c26a; --pending-bg: #2a2618;
  --good: #a3c184;
}

:root[data-theme="sun"] {
  --bg: #ffffff; --surface: #ffffff; --surface-2: #ffffff;
  --ink: #000000; --ink-2: #000000; --ink-3: #1a1a1a;
  --rule: #000000; --accent: #a33000; --accent-ink: #ffffff;
  --critical: #b00000; --critical-bg: #ffffff;
  --pending: #6b4c00; --pending-bg: #ffffff;
  --good: #005c00;
  --rule-w: 2px;
  --base: 19px;
  --radius: 6px;
  --weight-body: 500;
  --weight-strong: 800;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  font: var(--weight-body) var(--base)/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
  /* Itinerary prose contains long station names, booking codes and the odd
     bare URL. None of them may push the page sideways. */
  overflow-wrap: anywhere;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
  overscroll-behavior-y: contain;
}

h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.2; margin: 0; }
:root[data-theme="sun"] h1,
:root[data-theme="sun"] h2,
:root[data-theme="sun"] h3 { font-weight: 700; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }

/* ------------------------------------------------------------------ chrome */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(var(--safe-t) + 10px) var(--pad) 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: var(--rule-w) solid var(--rule);
}
:root[data-theme="sun"] .topbar { background: var(--bg); backdrop-filter: none; }

.topbar__brand {
  background: none; border: 0; padding: 4px 0; margin: 0;
  color: inherit; text-align: left; font: inherit; cursor: pointer;
  display: flex; flex-direction: column; gap: 1px; min-height: 44px; justify-content: center;
}
.topbar__trip { font-family: var(--display); font-size: 1.15rem; font-weight: 600; letter-spacing: .01em; }
.topbar__dates { font: 600 1.02rem/1 var(--script); color: var(--accent); }
:root[data-theme="sun"] .topbar__dates { font: var(--weight-body) .78rem/1 var(--sans); color: var(--ink-2); letter-spacing: .09em; text-transform: uppercase; }

.topbar__actions { display: flex; gap: 6px; }
.iconbtn {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink);
  border: var(--rule-w) solid var(--rule); border-radius: 50%;
  font-size: 1.15rem; cursor: pointer;
}
.iconbtn:active { background: var(--accent); color: var(--accent-ink); }
.iconbtn.is-busy span { animation: spin 900ms linear infinite; display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.syncbar {
  padding: 9px var(--pad); font-size: .84rem; text-align: center;
  border-bottom: var(--rule-w) solid var(--rule);
  background: var(--surface-2); color: var(--ink-2);
}
.syncbar[data-kind="error"] { background: var(--critical-bg); color: var(--critical); font-weight: var(--weight-strong); }
.syncbar[data-kind="ok"] { color: var(--good); }

main {
  padding: 20px var(--pad) calc(96px + var(--safe-b));
  max-width: 720px; margin: 0 auto;
  outline: none;
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: var(--rule-w) solid var(--rule);
  padding-bottom: var(--safe-b);
}
:root[data-theme="sun"] .tabs { background: var(--bg); backdrop-filter: none; }
.tabs button {
  appearance: none; background: none; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 2px 8px; min-height: 56px;
  color: var(--ink-3); font: var(--weight-body) .7rem/1 var(--sans);
  letter-spacing: .05em; text-transform: uppercase;
}
.tabs button svg { width: 21px; height: 21px; }
.tabs button[aria-current="page"] { color: var(--accent); font-weight: var(--weight-strong); }

/* ------------------------------------------------------------------- type */

.pagehead { margin-bottom: 20px; }
.pagehead h1 { font-size: 1.72rem; letter-spacing: -.015em; }
/* Subtitles are handwritten — the journal voice. Sun mode overrides this back
   to the sans, because script in glare is vanity. */
.pagehead p {
  margin: 4px 0 0; color: var(--ink-2);
  font: 600 1.35rem/1.25 var(--script);
}
:root[data-theme="sun"] .pagehead p { font: var(--weight-body) .95rem/1.5 var(--sans); }

/* The soft watercolor vignette above a day — arched like a little doorway. */
.cityimg {
  display: block; width: 100%; max-height: 190px; object-fit: cover;
  border-radius: 999px 999px var(--radius) var(--radius);
  border: var(--rule-w) solid var(--rule);
  margin: 0 0 16px;
}
:root[data-theme="dark"] .cityimg { opacity: .88; }
:root[data-theme="sun"] .cityimg { display: none; }

.eyebrow {
  display: flex; align-items: center; gap: 10px;
  font-size: .74rem; letter-spacing: .13em; text-transform: uppercase;
  color: var(--accent); font-weight: var(--weight-strong);
  margin: 30px 0 10px;
}
/* The little dotted flourish after every section label. */
.eyebrow::after {
  content: ""; flex: 0 0 34px;
  border-top: 2px dotted color-mix(in srgb, var(--accent) 55%, transparent);
}
.eyebrow:first-child { margin-top: 0; }

.muted { color: var(--ink-2); }
.tiny { font-size: .82rem; }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--surface);
  border: var(--rule-w) solid var(--rule);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px color-mix(in srgb, var(--ink) 5%, transparent);
}
:root[data-theme="sun"] .card { box-shadow: none; }
.card > :last-child { margin-bottom: 0; }
.card__title { font-size: 1.1rem; margin-bottom: 4px; }
.card__sub { color: var(--ink-2); font-size: .9rem; }

/* The pinned next-up card. Deliberately the loudest thing on the screen. */
.next {
  border: calc(var(--rule-w) * 2) solid var(--accent);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 22px;
}
.next__label {
  font-size: .72rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent); font-weight: var(--weight-strong);
}
.next__title { font-size: 1.5rem; margin: 8px 0 2px; letter-spacing: -.01em; }
.next__route { color: var(--ink-2); font-size: 1rem; }
.next__count {
  font: var(--weight-strong) 2.6rem/1 var(--display);
  letter-spacing: -.02em; margin: 14px 0 2px;
  font-variant-numeric: tabular-nums;
}
.next__count.is-soon { color: var(--critical); }
.next__when { color: var(--ink-2); font-size: .92rem; }

/* Each fact is its own bordered tile rather than a cell in a ruled table: the
   number of facts varies per leg, and a table leaves an empty box where the
   platform would be on a leg that has no platform. */
.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px; margin: 16px 0 0;
}
.fact {
  background: var(--surface-2); padding: 11px 12px;
  border: var(--rule-w) solid var(--rule); border-radius: 10px;
}
.fact dt {
  font-size: .68rem; letter-spacing: .11em; text-transform: uppercase;
  color: var(--ink-3); font-weight: var(--weight-strong);
}
.fact dd {
  margin: 3px 0 0; font: var(--weight-strong) 1.3rem/1.1 var(--display);
  font-variant-numeric: tabular-nums;
}
.fact dd.is-code { font-family: var(--mono); font-size: 1.05rem; letter-spacing: .04em; }
.fact--wide { grid-column: 1 / -1; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 12px 18px;
  background: var(--surface-2); color: var(--ink);
  border: var(--rule-w) solid var(--rule); border-radius: 10px;
  font: var(--weight-strong) 1rem var(--sans); text-decoration: none;
  cursor: pointer; width: 100%;
}
.btn + .btn { margin-top: 8px; }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn--row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn--row .btn { margin-top: 0; }
.btn:active { transform: translateY(1px); }

.btnbar { margin-top: 14px; }

/* --------------------------------------------------------------- notices */

.note {
  border-left: 3px solid var(--rule); padding: 9px 0 9px 13px;
  margin: 10px 0; font-size: .95rem;
}
.note--critical { border-color: var(--critical); background: var(--critical-bg); color: var(--critical); padding-right: 12px; border-radius: 0 8px 8px 0; font-weight: var(--weight-strong); }
.note--pending { border-color: var(--pending); background: var(--pending-bg); color: var(--pending); padding-right: 12px; border-radius: 0 8px 8px 0; }
.note--gate { border-color: var(--accent); color: var(--ink); }

.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: .72rem; letter-spacing: .07em; text-transform: uppercase;
  font-weight: var(--weight-strong);
  border: var(--rule-w) solid var(--rule); color: var(--ink-2);
}
.pill--booked { color: var(--accent-ink); border-color: var(--accent); background: var(--accent); }
.pill--walkin { color: var(--accent); border-color: var(--accent); }
.pill--decide { color: var(--pending); border-color: var(--pending); }
.pill--urgent { color: var(--critical); border-color: var(--critical); }
.pill--gate { color: var(--accent); border-color: var(--accent); }

/* ------------------------------------------------------------------ lists */

.rows { border-top: var(--rule-w) solid var(--rule); }
.row {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 14px 2px; min-height: 60px;
  border-bottom: var(--rule-w) solid var(--rule);
  background: none; border-left: 0; border-right: 0; border-top: 0;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
  text-decoration: none;
}
.row__lead {
  flex: 0 0 54px; text-align: center;
  font-family: var(--display); line-height: 1.05;
}
.row__lead b { display: block; font-size: 1.4rem; font-weight: 600; }
.row__lead span { display: block; font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.row__main { flex: 1 1 auto; min-width: 0; }
.row__title { font-weight: var(--weight-strong); }
.row__sub { color: var(--ink-2); font-size: .88rem; margin-top: 2px; }
.row__end { flex: 0 0 auto; color: var(--ink-3); font-size: 1.2rem; }
.row.is-today { background: var(--surface); }
.row.is-today .row__lead b { color: var(--accent); }
.row.is-past { opacity: .5; }

/* The day's schedule runs down a dotted rail with a dot per stop, like the
   printable planners this design is stolen from. */
.timeline {
  margin: 4px 0 0 4px; padding-left: 16px;
  border-left: 2px dotted color-mix(in srgb, var(--accent) 45%, transparent);
}
.tl {
  position: relative;
  display: grid; grid-template-columns: 56px 1fr; gap: 12px;
  padding: 9px 0;
}
.tl::before {
  content: ""; position: absolute; left: -22px; top: 16px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent);
}
.tl__t {
  font: var(--weight-strong) 1rem/1.4 var(--mono);
  font-variant-numeric: tabular-nums; color: var(--ink-2);
}
.tl--critical::before { background: var(--critical); border-color: var(--critical); }
.tl--critical .tl__t { color: var(--critical); }
.tl--critical .tl__d { font-weight: var(--weight-strong); }
:root[data-theme="sun"] .timeline { border-left-style: solid; }

.bullets { margin: 0; padding-left: 20px; }
.bullets li { margin: 6px 0; }
.bullets li.d1 { list-style: none; margin-left: -8px; color: var(--ink-2); font-size: .93rem; }
.bullets li.d2 { list-style: none; margin-left: 0; color: var(--ink-3); font-size: .9rem; }

.group { margin-bottom: 18px; }
.group__head { font-size: 1.05rem; margin: 22px 0 8px; }

/* ------------------------------------------------------------- checklist */

.check {
  display: flex; gap: 13px; align-items: flex-start; width: 100%;
  padding: 15px 2px; border: 0; border-bottom: var(--rule-w) solid var(--rule);
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.check__box {
  flex: 0 0 26px; width: 26px; height: 26px; margin-top: 1px;
  border: 2px solid var(--ink-3); border-radius: 7px;
  display: grid; place-items: center; font-size: .95rem; color: transparent;
}
.check[aria-pressed="true"] .check__box { background: var(--good); border-color: var(--good); color: var(--bg); }
.check[aria-pressed="true"] .check__main { opacity: .5; text-decoration: line-through; }
.check__title { font-weight: var(--weight-strong); }
.check__detail { color: var(--ink-2); font-size: .88rem; margin-top: 4px; }

/* ------------------------------------------------------------- converter */

.conv { display: grid; grid-template-columns: 1fr; gap: 10px; }
.conv input {
  width: 100%; padding: 14px; font: var(--weight-strong) 1.5rem var(--mono);
  background: var(--surface-2); color: var(--ink);
  border: var(--rule-w) solid var(--rule); border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.conv__row { display: flex; gap: 8px; }
.conv__row button {
  flex: 1; min-height: 46px; border-radius: 9px; cursor: pointer;
  background: var(--surface-2); color: var(--ink-2);
  border: var(--rule-w) solid var(--rule); font: var(--weight-strong) .95rem var(--sans);
}
.conv__row button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.conv__out { font: var(--weight-strong) 2rem var(--display); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- phrasebook */

.phrase {
  padding: 11px 0; border-bottom: var(--rule-w) solid var(--rule);
  font-size: 1rem; line-height: 1.45;
}
.search {
  width: 100%; padding: 13px 15px; margin-bottom: 6px;
  background: var(--surface-2); color: var(--ink);
  border: var(--rule-w) solid var(--rule); border-radius: 10px;
  font: var(--weight-body) 1rem var(--sans);
}

#phrase-langs { margin-bottom: 10px; }

.phrase-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; margin-top: 8px;
}
.phrase-card__text { flex: 1; min-width: 0; }
.phrase-native { margin: 0; font-size: 1.1rem; font-weight: var(--weight-strong); line-height: 1.3; }
.phrase-pron { margin: 2px 0 0; font-style: italic; color: var(--accent); font-size: .92rem; }
.phrase-en { margin: 3px 0 0; color: var(--ink-2); font-size: .9rem; }

.play {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface-2); color: var(--ink);
  border: var(--rule-w) solid var(--rule);
  font-size: .9rem; padding-left: 3px; /* optical centre for the ▶ glyph */
}
.play.is-playing { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* --------------------------------------------------------------- streetwise */

.scam { margin-top: 8px; }
.scam .card__sub { margin-top: 4px; }

.safety {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; min-height: 50px; padding: 12px 15px; margin: 0 0 12px;
  text-align: left;
  background: var(--surface); color: var(--ink);
  border: calc(var(--rule-w) * 2) solid var(--accent); border-radius: 12px;
  font: var(--weight-strong) .95rem/1.35 var(--sans);
}

/* --------------------------------------------------------------- lightbox */

.lightbox {
  position: fixed; inset: 0; z-index: 60;
  background: #fff; color: #000;
  display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 8px) 8px calc(var(--safe-b) + 8px);
}
.lightbox[hidden] { display: none; }
.lightbox__close {
  align-self: flex-end; min-height: 44px; padding: 10px 20px;
  background: #000; color: #fff; border: 0; border-radius: 10px;
  font: 600 1rem var(--sans); cursor: pointer;
}
.lightbox__body {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; overflow: auto; padding: 8px;
}
.lightbox__body img {
  width: min(92vw, 92vh, 560px); height: auto;
  image-rendering: pixelated; /* a 2D code must not be softened by upscaling */
}
.lightbox__cap { font: 600 1.05rem var(--sans); text-align: center; color: #000; }
.lightbox__cap small { display: block; font-weight: 400; color: #444; margin-top: 3px; }

/* ------------------------------------------------------------------ misc */

.empty { color: var(--ink-2); padding: 28px 0; text-align: center; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; margin: 0; font-size: .95rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-weight: var(--weight-strong); }
.kv dd.is-code { font-family: var(--mono); letter-spacing: .03em; }

.total { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: var(--rule-w) solid var(--rule); }
.total:last-child { border-bottom: 0; }
.total b { font-family: var(--display); font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.total--grand { border-top: calc(var(--rule-w) * 2) solid var(--ink); border-bottom: 0; margin-top: 6px; padding-top: 14px; }
.total--grand b { font-size: 1.5rem; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0s !important; transition: none !important; }
}
