:root {
  --snow: #f7f9fb;
  --ink: #1f2a44;
  --ink-soft: #4a5672;
  --sea: #2b6ca3;
  --sea-deep: #173f68;      /* legend panel: the sea, a few shades deeper */
  --sea-line: #2f5f8f;
  --frost: #b9cad9;         /* muted text on the legend */
  --red: #e0453a;           /* route travelled + bus, same as on the map */
  --yellow: #f5b91e;        /* current stop, same as the HOKKAIDO lettering */
  --serif: 'Trirong', serif;
  --sans: 'IBM Plex Sans Thai Looped', system-ui, sans-serif;
  --plan-w: 320px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--sea); color: var(--ink); font: 400 15px/1.6 var(--sans); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }

.stage { position: fixed; inset: 0; overflow: hidden; }
/* Clip 3D labels at the scene edge and keep their per-label z-index inside the scene. */
.view { position: absolute; inset: 0; overflow: hidden; z-index: 0; }

/* Caption sits on the map like a printed map title: no box, a snow halo keeps it legible. */
.caption { position: absolute; top: 20px; left: 24px; pointer-events: none; text-shadow: 0 0 6px var(--snow), 0 0 12px var(--snow), 0 0 2px var(--snow); }
.caption h1 { margin: 0; font: 700 clamp(34px, 5vw, 56px)/1 var(--serif); letter-spacing: -0.01em; }
.caption p { margin: 6px 0 0; font-size: 15px; color: var(--ink-soft); }
.caption .route { margin-top: 2px; font: 500 19px/1.3 var(--serif); color: var(--ink); }

/* Printed snapshot of the current place */
.photo { position: absolute; left: 24px; bottom: 24px; width: 300px; margin: 0; background: var(--snow); padding: 8px 8px 6px; border: 1px solid rgb(31 42 68 / 0.25); transform: rotate(-1.5deg); }
.photo img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; background: var(--frost); transition: opacity 0.35s ease; }
.photo img.loading { opacity: 0; }
.photo figcaption { display: flex; flex-direction: column; padding-top: 4px; font-size: 12px; line-height: 1.4; color: var(--ink-soft); }
.photo-note:empty { display: none; }
.photo-note { color: var(--ink); }
.photo-credit { color: inherit; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-credit:hover { text-decoration: underline; }

.follow { position: absolute; left: 50%; bottom: 24px; transform: translateX(calc(-50% - var(--plan-w) / 2)); border: 0; background: var(--sea-deep); color: var(--snow); border-radius: 999px; padding: 8px 16px; font-size: 14px; }

/* ---------- itinerary legend ---------- */
.plan { position: absolute; top: 16px; right: 16px; max-height: calc(100% - 32px); width: var(--plan-w); background: var(--sea-deep); color: var(--snow); border-radius: 16px; padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; overflow: hidden; }

.plan-days { display: flex; gap: 4px; padding: 3px; background: rgb(0 0 0 / 0.18); border-radius: 999px; align-self: flex-start; }
.plan-days button { border: 0; background: none; color: var(--frost); border-radius: 999px; padding: 4px 14px; font-size: 14px; }
.plan-days button[aria-pressed='true'] { background: var(--snow); color: var(--sea-deep); font-weight: 600; }

.plan-now { display: flex; align-items: center; gap: 14px; }
.play { flex: 0 0 auto; width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--red); display: grid; place-items: center; }
.play svg { width: 24px; height: 24px; fill: var(--snow); }
.clock { font: 700 40px/1 var(--serif); font-variant-numeric: tabular-nums; }

.itinerary { position: relative; flex: 0 1 auto; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--sea-line) transparent; }
.stops { list-style: none; margin: 0; padding: 0 0 0 30px; display: flex; flex-direction: column; }

/* Vertical route rail with the travelled part in red and the bus riding on it */
.rail { position: absolute; left: 10px; top: 0; bottom: 0; width: 20px; cursor: ns-resize; touch-action: none; z-index: 1; }
.rail::before { content: ''; position: absolute; left: 8px; top: var(--rail-top, 0); height: var(--rail-len, 100%); width: 4px; border-radius: 2px; background: var(--sea-line); }
.rail-done { position: absolute; left: 8px; top: var(--rail-top, 0); width: 4px; border-radius: 2px; background: var(--red); height: 0; }
.rail-bus { position: absolute; left: -2px; width: 24px; height: 24px; margin-top: -12px; border-radius: 50%; background: var(--red); border: 2px solid var(--snow); display: grid; place-items: center; }
.rail-bus svg { width: 13px; height: 13px; fill: var(--snow); }

.stop-row { all: unset; box-sizing: border-box; display: grid; grid-template-columns: 44px 40px 1fr; align-items: center; column-gap: 10px; width: 100%; padding: 8px 4px 8px 6px; border-radius: 10px; cursor: pointer; }
.stop-row:hover { background: rgb(255 255 255 / 0.06); }
.stop-row:focus-visible { outline: 2px solid var(--yellow); }
.stop-time { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--frost); }
.stop-thumb { width: 40px; height: 40px; border-radius: 50%; background: var(--sea-line) center / cover; border: 2px solid var(--sea-line); }
.stop-name { font-weight: 500; line-height: 1.3; }
.stop-sub { grid-column: 3; font-size: 13px; line-height: 1.35; color: var(--frost); margin-top: 2px; }
.stop-sub:empty { display: none; }
.stops li.passed .stop-thumb { border-color: var(--red); }
.stops li.current .stop-name, .stops li.current .stop-time { color: var(--yellow); }
.stops li.current .stop-thumb { border-color: var(--yellow); }
.stops li.current .stop-sub { color: var(--snow); }

/* Photo inside the current row: phones only (desktop uses the floating snapshot). */
.row-photo { display: none; margin: 0 4px 10px 60px; }
.row-photo img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 8px; background: var(--sea-line); }
.row-photo figcaption { margin-top: 4px; font-size: 11px; line-height: 1.4; color: var(--frost); }
.row-photo a { color: inherit; text-decoration: none; }

/* Markers shared by the 3D view: round photo of the place, order number in a badge. */
.stop-wrap { position: relative; }
.stop-pin { position: relative; width: 40px; height: 40px; border-radius: 50%; background: var(--frost) center / cover; border: 2px solid var(--snow); box-shadow: 0 0 0 1px var(--ink); }
.stop-pin span { position: absolute; right: -6px; bottom: -4px; width: 18px; height: 18px; border-radius: 50%; background: var(--snow); border: 1.5px solid var(--ink); color: var(--ink); font: 600 10px/15px var(--sans); text-align: center; }
.stop-pin.passed span { background: var(--ink); color: var(--snow); }
.stop-label { font: 500 12px/1.2 var(--sans); color: var(--ink); text-shadow: 0 0 4px var(--snow), 0 0 8px var(--snow); white-space: nowrap; margin-top: 4px; transform: translateX(-50%); position: absolute; left: 50%; top: 100%; }
.landmark-label { font: 500 12px/1.2 var(--sans); color: var(--ink-soft); text-shadow: 0 0 3px var(--snow), 0 0 6px var(--snow); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .photo img { transition: none; }
}

/* Phone: the legend becomes a sheet along the bottom and the current row carries the photo. */
@media (max-width: 720px) {
  :root { --plan-w: 0px; }
  .plan { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; height: 44vh; max-height: none; padding: 12px 14px; gap: 10px; }
  .itinerary { flex: 1 1 auto; }
  .plan-now { position: absolute; top: 10px; right: 14px; gap: 10px; }
  .play { width: 44px; height: 44px; }
  .clock { font-size: 30px; }
  .caption { left: 16px; top: 14px; }
  .photo { display: none; }
  .stops li.current .row-photo { display: block; }
  .follow { bottom: calc(44vh + 18px); transform: translateX(-50%); }
  .stop-pin { width: 32px; height: 32px; }
}
