/* Raconteur Road — Tracks page.
   Same literary-press palette as the coming-soon page. No tile-based basemap;
   the world is drawn as faint country outlines on paper. */

@font-face {
  font-family: 'Newsreader';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/Newsreader-Regular.woff2') format('woff2');
}
@font-face {
  font-family: 'Newsreader';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/Newsreader-Italic.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/JetBrainsMono-Regular.woff2') format('woff2');
}

:root {
  --paper: #fafaf8;
  --paper-warm: #f4f1ea;
  --ink: #1a1a1a;
  --rule: #d8d3c8;
  --pencil: #b8b0a0;
  --accent: #6b5d4f;
  --quiet: #4a4a4a;
  --amber: #a87a3c;
  --header-h: 64px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Page header (top of /tracks/). Direct-child selector so the
   modal's <header class="modal-handle"> deep inside doesn't
   inherit position: fixed + top: 0 and yank itself out of the
   modal to the top of the page. */
body > header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  padding: 0 1.5rem;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}

.wordmark {
  font-weight: 400;
  font-size: 1.25rem;
  letter-spacing: 0.01em;
  margin: 0;
}
.wordmark a {
  color: inherit;
  text-decoration: none;
}
.wordmark a:hover {
  color: var(--accent);
}

/* Mode toggle (sits at the top of .cat-panel below the header).
   Same visual language as the .cat-btn selector below it for
   consistency: mono labels, low-key chrome, active state inverts. */
.mode-toggle {
  display: flex;
  gap: 0.2rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
}
.mode-btn {
  flex: 1;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--quiet);
  background: transparent;
  border: 1px solid transparent;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 1px;
  text-align: center;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.mode-btn:hover { color: var(--ink); }
.mode-btn.active {
  color: var(--ink);
  background: var(--paper-warm);
  border-color: var(--rule);
}

#map {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0; bottom: 0;
  background: var(--paper);
}

/* MapLibre tweaks — keep it quiet. */
.maplibregl-canvas-container,
.maplibregl-canvas { background: var(--paper); }
.maplibregl-ctrl-attrib {
  background: rgba(250, 250, 248, 0.85) !important;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.65rem !important;
  color: var(--quiet);
}
.maplibregl-ctrl-attrib a {
  color: var(--accent);
}
.maplibregl-ctrl-bottom-right { display: none; }  /* hide attribution to keep the aesthetic; will re-add a discreet credit elsewhere */

/* Category panel: selector + stats + heatmap legend stacked at the
   bottom-left of the map. Single container so the three children
   share width + alignment + a single backing panel. */
.cat-panel {
  position: fixed;
  left: 1.5rem;
  bottom: 1rem;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: rgba(250, 250, 248, 0.92);
  padding: 0.4rem 0.5rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 1px;
  min-width: 11rem;
}

/* Category selector. Acts as both filter and key. */
.categories {
  display: flex;
  gap: 0.2rem;
}
.cat-btn {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--quiet);
  background: transparent;
  border: 1px solid transparent;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  border-radius: 1px;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.cat-btn:hover { color: var(--ink); }
.cat-btn.active {
  color: var(--ink);
  background: var(--paper-warm);
  border-color: var(--rule);
}
.cat-swatch {
  display: inline-block;
  width: 0.9rem;
  height: 2px;
  flex-shrink: 0;
}
/* All swatches share the cycling gradient -- v68 uniform-style: every
   category renders in the same red->yellow palette. */
.cat-swatch-biking,
.cat-swatch-unimog,
.cat-swatch-other {
  background: linear-gradient(to right, #7a0c0c, #c5471d, #fc7404, #ffd60a);
}

/* Per-category stats: km totals + ride counts. Vertical when "All" is
   selected (3 lines), single line otherwise. updateStats() in tracks.js
   sets the content. */
.cat-stats {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.68rem;
  color: var(--quiet);
  line-height: 1.5;
  white-space: pre-line;
  padding: 0.2rem 0.1rem;
  border-top: 1px solid var(--rule);
}
.cat-stats .stats-row {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
}
.cat-stats .stats-label { color: var(--ink); }
.cat-stats .stats-value { color: var(--quiet); }

/* Heatmap density legend. Gradient bar + low/high labels. The bar's
   background is set by updateLegend() in tracks.js to match the
   currently-selected category's color stops. */
.heatmap-legend {
  border-top: 1px solid var(--rule);
  padding-top: 0.35rem;
}
.legend-bar {
  height: 6px;
  width: 100%;
  border-radius: 1px;
  background: linear-gradient(to right, #7a0c0c, #c5471d, #fc7404, #ffd60a);
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.62rem;
  color: var(--quiet);
  margin-top: 0.15rem;
}

/* Content modal: a floating card pinned to top-right by default and
   draggable by the handle bar. No full-viewport backdrop -- the map
   stays fully visible and interactive while the modal is open so the
   reader can see where the pebble they're viewing actually sits. */
.modal {
  position: fixed;
  top: calc(var(--header-h) + 0.75rem);
  right: 1rem;
  width: 360px;
  max-width: calc(100vw - 2rem);
  max-height: calc(100vh - var(--header-h) - 1.5rem);
  overflow: hidden;
  display: none;
  flex-direction: column;
  z-index: 20;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}
.modal[aria-hidden="false"] { display: flex; }
/* Drag bar: darker than the photo + paper body below it so the handle
   reads as a distinct grabbable region, not as a margin. Ink fill,
   paper-warm content. */
.modal-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 2.1rem;
  padding: 0 0.6rem;
  background: var(--ink);
  color: var(--paper-warm);
  cursor: move;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.modal-handle-grip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--paper-warm);
}
.modal-handle-grip svg { display: block; }
.modal-handle-text {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--paper-warm);
}
.modal-close {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--paper-warm);
  cursor: pointer;
  padding: 0 0.35rem;
}
.modal-close:hover { color: var(--paper); }
.modal-thumb {
  width: 100%;
  height: auto;
  max-height: 220px;
  object-fit: cover;
  display: block;
  border-bottom: 1px solid var(--rule);
}
.modal-body {
  padding: 0.7rem 0.9rem 0.9rem;
  overflow: auto;
  flex: 1;
}
.modal-title {
  margin: 0 0 0.2rem;
  font-size: 1.1rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--ink);
}
.modal-meta {
  margin: 0 0 0.4rem;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.66rem;
  color: var(--quiet);
}
.modal-caption {
  margin: 0 0 0.8rem;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--quiet);
}
.modal-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.modal-link {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.68rem;
  color: var(--paper);
  background: var(--ink);
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--ink);
  border-radius: 1px;
  text-decoration: none;
  transition: opacity 0.12s;
}
.modal-link:hover { opacity: 0.85; }
.modal-link-secondary {
  background: transparent;
  color: var(--ink);
}

/* Prev / next navigation row at the bottom of the modal. Splits the
   width 50/50 so the row reads as a single segmented control. The
   arrow keys nav the modal too (keyboard handler in tracks.js). */
.modal-nav {
  display: flex;
  border-top: 1px solid var(--rule);
  margin-top: 0.2rem;
}
.modal-nav-btn {
  flex: 1;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--quiet);
  background: var(--paper);
  border: none;
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  transition: color 0.12s, background 0.12s;
}
.modal-nav-btn:hover {
  color: var(--ink);
  background: var(--paper-warm);
}
.modal-nav-btn:first-child { text-align: left;  border-right: 1px solid var(--rule); }
.modal-nav-btn:last-child  { text-align: right; }

/* Trip pill: shows the currently-active trip below the cat-panel
   when ?trip=<id> is set, or after a user clicks a journey-card
   link. The × clears the trip and returns the map to its full
   un-filtered state. */
.trip-pill {
  position: fixed;
  left: 1.5rem;
  bottom: 0.5rem;
  z-index: 5;
  display: none;
  align-items: center;
  gap: 0.45rem;
  background: var(--ink);
  color: var(--paper);
  padding: 0.35rem 0.5rem 0.35rem 0.7rem;
  border-radius: 1px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.7rem;
  max-width: calc(100vw - 3rem);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}
.trip-pill[aria-hidden="false"] { display: inline-flex; }
.trip-pill-label { color: var(--pencil); }
.trip-pill-title { color: var(--paper); }
.trip-pill-clear {
  background: transparent;
  border: none;
  color: var(--pencil);
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.2rem;
  cursor: pointer;
}
.trip-pill-clear:hover { color: var(--paper); }
/* When trip pill is shown, lift the cat-panel above it so they don't overlap. */
body:has(.trip-pill[aria-hidden="false"]) .cat-panel {
  bottom: calc(1rem + 2.4rem);
}

/* Content-mode visibility helpers. The .heatmap-legend hides when
   the map is in Content mode (no heatmap rendering, nothing to
   legend). setMode() in tracks.js toggles body.mode-content. */
body.mode-content .heatmap-legend { display: none; }

/* Tiny build-version stamp in bottom-right. Visible-at-a-glance so
   the phone can confirm which deploy actually loaded after a cache
   bust, without needing devtools. Low opacity, no pointer events. */
.version-stamp {
  position: fixed;
  right: 0.5rem;
  bottom: 0.5rem;
  z-index: 4;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.65rem;
  color: var(--quiet);
  opacity: 0.55;
  pointer-events: none;
  user-select: none;
  background: rgba(250, 250, 248, 0.7);
  padding: 0.15rem 0.4rem;
  border-radius: 1px;
}

/* Mobile. */
@media (max-width: 600px) {
  :root { --header-h: 56px; }
  body > header { padding: 0 0.75rem; }
  .wordmark { font-size: 1rem; }
  .mode-btn { font-size: 0.62rem; padding: 0.25rem 0.5rem; }
  .cat-panel {
    left: 0.5rem;
    bottom: 0.5rem;
    padding: 0.3rem 0.4rem 0.4rem;
    gap: 0.3rem;
    min-width: 10rem;
  }
  .cat-btn { font-size: 0.62rem; padding: 0.2rem 0.35rem; }
  .cat-stats { font-size: 0.62rem; }
  .legend-labels { font-size: 0.58rem; }
  .modal-dialog { margin: 2vh auto; max-height: 96vh; }
  .modal-title { font-size: 1.15rem; }
}

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