/* TOWNHOP — design system (motion direction: docs/design/motion-direction.md).
   Dark, map-first, cinematic. Mint = route + system UI; amber = the active town. */
:root {
  color-scheme: dark;

  /* Surfaces */
  --bg: #080b11; --surface-0: #0b0e14; --surface-1: #11161f; --surface-2: #161d28;
  --line: #1e2630; --line-soft: #2a3340;
  /* Ink */
  --ink: #e6edf3; --muted: #8b97a4; --faint: #707d8b;
  /* Brand mint */
  --accent: #5ad1a0; --accent-bright: #7dffc4; --accent-deep: #062019;
  --accent-glow: rgba(90,209,160,.35);
  /* Active "you are here" amber */
  --hot: #ffb454; --hot-bright: #ffd166; --hot-glow: rgba(255,180,84,.40);
  --scrim: rgba(8,11,17,.72);

  /* Type */
  --font-display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;

  /* Motion (shemon's easing vocabulary) */
  --d-fast: .25s; --d-base: .40s; --d-smooth: .70s; --d-cine: 1.4s;
  --ease-out-soft: cubic-bezier(.2,.7,.2,1);
  --ease-out-snap: cubic-bezier(.2,.8,.2,1);
  --stagger: .045s;
}

* { box-sizing: border-box; }
/* Visible keyboard focus for everything interactive (a11y). */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font-sans);
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

header {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .7rem 1.1rem; background: var(--surface-1); border-bottom: 1px solid var(--line);
  position: relative; z-index: 500;
}
h1 { font: 700 1.55rem/1 var(--font-display); letter-spacing: .02em; margin: 0; }
h1 .hop { color: var(--accent); }

#f { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
#f .arrow { color: var(--muted); }
input, select {
  padding: .5rem .6rem; border-radius: 9px; border: 1px solid var(--line-soft);
  background: var(--surface-0); color: var(--ink); font: 500 .9rem var(--font-sans);
  transition: border-color var(--d-fast) var(--ease-out-snap), box-shadow var(--d-fast) var(--ease-out-snap);
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
#from, #to { width: 9.5rem; }
#interval { width: 4.5rem; }
button {
  padding: .52rem .95rem; border: 0; border-radius: 9px; cursor: pointer;
  background: var(--accent); color: var(--accent-deep); font: 700 .9rem var(--font-sans);
  transition: transform var(--d-fast) var(--ease-out-snap), background var(--d-fast), box-shadow var(--d-fast);
}
button:hover { transform: translateY(-1px); box-shadow: 0 4px 14px var(--accent-glow); }
button:active { transform: translateY(0); }
button:disabled { opacity: .55; cursor: progress; transform: none; box-shadow: none; }

.saved { display: flex; align-items: center; gap: .4rem; margin-left: auto; }
#saved { max-width: 12rem; }
#save { background: var(--surface-2); color: var(--ink); }
#save:hover { box-shadow: none; background: var(--line-soft); }

main { flex: 1; display: flex; min-height: 0; position: relative; }
#map { flex: 1; min-height: 0; background: var(--surface-0); }

/* Floating travel control bar over the map */
#travelbar {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; gap: .4rem; z-index: 600;
  background: rgba(11,14,20,.82); backdrop-filter: blur(9px);
  border: 1px solid var(--line); border-radius: 999px; padding: .4rem .5rem;
  box-shadow: 0 8px 28px rgba(0,0,0,.55);
}
#travelbar[hidden] { display: none; }
#travelbar button { background: transparent; color: var(--ink); border-radius: 999px; padding: .42rem .7rem; font-weight: 600; }
#travelbar button:hover { background: var(--surface-2); box-shadow: none; transform: none; }
#travelbar #play { background: var(--accent); color: var(--accent-deep); }
#travelbar #play:hover { background: var(--accent-bright); }

/* The traveler dot that rides the route line */
.traveler span {
  display: block; width: 18px; height: 18px; border-radius: 50%;
  background: var(--hot); border: 2px solid #2a1500;
  box-shadow: 0 0 12px var(--hot-glow), 0 0 0 6px rgba(255,180,84,.14);
}
#panel {
  width: 360px; max-width: 44vw; overflow-y: auto; padding: .85rem;
  background: var(--surface-0); border-left: 1px solid var(--line);
  scrollbar-width: thin; scrollbar-color: var(--line-soft) transparent;
}
.hint { color: var(--muted); margin: .2rem 0 .7rem; font-family: var(--font-mono); font-size: .8rem; letter-spacing: .04em; }

/* Numbered town markers */
.town-marker span {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: var(--accent-deep);
  font: 700 .8rem var(--font-mono); border: 2px solid var(--bg);
  box-shadow: 0 1px 5px rgba(0,0,0,.55);
}
/* Drop-in (JS sets .drop with animationDelay per index) */
.town-marker.drop span { animation: markerDrop .55s var(--ease-out-snap) both; }
@keyframes markerDrop {
  from { opacity: 0; transform: translateY(-14px) scale(.6); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
/* Active town: amber + breathing pulse ring */
.town-marker.active span { background: var(--hot); color: #2a1500; animation: pulse 1.8s var(--ease-out-soft) infinite; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 var(--hot-glow); }
  70%  { box-shadow: 0 0 0 13px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* Town-list panel cards */
.stop {
  position: relative; overflow: hidden;
  display: flex; gap: .7rem; align-items: flex-start; padding: .65rem .7rem; margin-bottom: .55rem;
  background: var(--surface-1); border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
  /* reveal: JS adds .in to fade+rise in, staggered */
  opacity: 0; transform: translateY(18px);
  transition: opacity var(--d-smooth) var(--ease-out-soft), transform var(--d-smooth) var(--ease-out-soft),
              border-color var(--d-fast) var(--ease-out-snap), background var(--d-fast);
}
.stop.in { opacity: 1; transform: translateY(0); }
/* cursor-tracked spotlight (JS sets --cx/--cy); sits BEHIND the content */
.stop::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 0;
  background: radial-gradient(150px circle at var(--cx, 50%) var(--cy, 50%), rgba(90,209,160,.13), transparent 70%);
  opacity: 0; transition: opacity var(--d-fast) var(--ease-out-soft);
}
.stop:hover::before { opacity: 1; }
.stop > * { position: relative; z-index: 1; }
.stop:hover { transform: translateY(-4px); border-color: var(--accent); background: var(--surface-2); }
.stop.active { border-color: var(--hot); box-shadow: 0 0 0 1px var(--hot-glow); }
.stop .num { font: 700 .8rem var(--font-mono); color: var(--accent); min-width: 1.9em; padding-top: .35rem; }
.stop.active .num { color: var(--hot); }
.stop .town { flex: 1; min-width: 0; }
.stop .town .eyebrow { display: block; font: 600 .66rem var(--font-mono); letter-spacing: .18em; text-transform: uppercase; color: var(--accent); margin-bottom: .12rem; }
.stop.active .town .eyebrow { color: var(--hot); }
.stop .town b { font: 600 1.05rem var(--font-display); display: block; }
.stop .town small { color: var(--faint); display: block; margin: .05rem 0 .4rem; font-family: var(--font-mono); font-size: .72rem; letter-spacing: .03em; }
.stop .vids { display: flex; gap: .35rem; flex-wrap: wrap; }
.stop .vids a, .stop .vids button.thumb { padding: 0; border: 0; background: none; cursor: pointer; border-radius: 6px; display: block; line-height: 0; }
.stop .vids img { width: 86px; height: 48px; object-fit: cover; border-radius: 6px; display: block; transition: transform var(--d-fast) var(--ease-out-snap); }
.stop .vids a:hover img, .stop .vids button.thumb:hover img { transform: scale(1.05); }
.stop .none { color: var(--faint); font-size: .8rem; font-style: italic; }

@media (max-width: 640px) {
  main { flex-direction: column; }
  #panel { width: auto; max-width: none; max-height: 46vh; border-left: 0; border-top: 1px solid var(--line); }
  header { padding: .6rem .7rem; gap: .5rem; }
  h1 { font-size: 1.25rem; width: 100%; }
  #f { width: 100%; gap: .35rem; }
  #from, #to { flex: 1 1 38%; width: auto; min-width: 0; }
  #interval { flex: 0 0 4rem; }
  #f select, #f button[type="submit"] { flex: 1 1 auto; }
  .saved { width: 100%; margin-left: 0; }
  #saved { flex: 1 1 auto; max-width: none; }
  #travelbar { bottom: 10px; }
}

/* Footage takeover: fullscreen embedded player over a dimmed, blurred map */
#stage {
  position: fixed; inset: 0; z-index: 2000; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1rem;
  background: var(--scrim); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  opacity: 0; transition: opacity var(--d-base) var(--ease-out-soft);
}
#stage.show { opacity: 1; }
#stage[hidden] { display: none; }
.stage-frame {
  width: min(92vw, 1100px); aspect-ratio: 16/9; background: #000; border-radius: 12px;
  overflow: hidden; box-shadow: 0 24px 70px rgba(0,0,0,.65);
  transform: scale(.94); transition: transform var(--d-smooth) var(--ease-out-soft);
}
#stage.show .stage-frame { transform: scale(1); }
.stage-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.stage-caption { font: 600 1.15rem var(--font-display); color: var(--ink); letter-spacing: .02em; }
#stage-close {
  position: absolute; top: 18px; right: 22px; width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--ink); font-size: 1.5rem; line-height: 1; cursor: pointer;
}
#stage-close:hover { background: var(--line-soft); }

/* Page-load loader: decode wordmark + counter, once per session */
#loader {
  position: fixed; inset: 0; z-index: 9999; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .7rem;
  transition: opacity .9s var(--ease-out-soft);
}
#loader.done { opacity: 0; pointer-events: none; }
#loader .lo-word { font: 700 clamp(40px,9vw,108px) var(--font-display); letter-spacing: .04em; color: var(--ink); }
#loader .lo-count { font: 600 1rem var(--font-mono); color: var(--accent); letter-spacing: .35em; }

/* Filmic grain + vignette over the canvas (pointer-events:none, below UI) */
.grain { position: fixed; inset: 0; pointer-events: none; z-index: 400;
  background: radial-gradient(ellipse at center, transparent 58%, rgba(0,0,0,.22) 100%); }
.grain::before {
  content: ""; position: absolute; inset: -50%; opacity: .045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 1s steps(4) infinite;
}
@keyframes grain {
  0%{transform:translate(0,0)} 25%{transform:translate(-4%,3%)} 50%{transform:translate(3%,-4%)}
  75%{transform:translate(-3%,-3%)} 100%{transform:translate(4%,3%)}
}

/* Motion is enhancement, never a gate (ADR-0002) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .stop { opacity: 1; transform: none; }
  .grain::before { display: none; }
  #loader { display: none; }
}
