/* railbuddy — catppuccin mocha
   palette ref: https://catppuccin.com/palette
*/
:root {
  --base:     #1e1e2e;
  --mantle:   #181825;
  --crust:    #11111b;
  --surface0: #313244;
  --surface1: #45475a;
  --surface2: #585b70;
  --overlay0: #6c7086;
  --overlay1: #7f849c;
  --overlay2: #9399b2;
  --subtext0: #a6adc8;
  --subtext1: #bac2de;
  --text:     #cdd6f4;
  --lavender: #b4befe;
  --blue:     #89b4fa;
  --sapphire: #74c7ec;
  --sky:      #89dceb;
  --teal:     #94e2d5;
  --green:    #a6e3a1;
  --yellow:   #f9e2af;
  --peach:    #fab387;
  --maroon:   #eba0ac;
  --red:      #f38ba8;
  --mauve:    #cba6f7;
  --pink:     #f5c2e7;

  --axe-netherite: #4a3a36;
  --axe-diamond:   var(--sky);
  --axe-iron:      var(--subtext0);
  --axe-golden:    var(--yellow);
  --axe-stone:     var(--overlay1);
  --axe-wooden:    var(--peach);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--base);
  color: var(--text);
  overflow: hidden;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--lavender); }
h1, h2 { font-weight: 600; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
small { color: var(--subtext0); }

/* ─── header ─── */
.banner {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 14px;
  background: var(--mantle);
  border-bottom: 1px solid var(--surface0);
  height: 46px;
  flex-shrink: 0;
}
.banner h1 { margin: 0; color: var(--text); letter-spacing: 0; line-height: 1; }

/* fontmark lockup: Caveat brush "omokami's" + Fraunces italic bold service line */
.wordmark { display: inline-flex; align-items: center; gap: 10px; }
.wordmark .logo {
  width: 28px; height: 28px; flex-shrink: 0;
  transform-origin: 65% 65%;
}
@keyframes axe-swing {
  0%   { transform: rotate(0); }
  40%  { transform: rotate(-18deg); }
  100% { transform: rotate(0); }
}
.wordmark:hover .logo,
.wordmark:active .logo { animation: axe-swing 0.55s cubic-bezier(0.4, 0, 0.2, 1.4); }
.wm-stack {
  display: inline-flex; flex-direction: column; align-items: flex-start;
  line-height: 1;
}
.wm-name {
  font-family: "Caveat", "Brush Script MT", cursive;
  font-weight: 700;
  font-size: 22px;
  color: var(--mauve);
  line-height: 0.9;
  letter-spacing: 0.5px;
  transform: rotate(-3deg);          /* tiny tilt — gives it personality */
  transform-origin: left center;
  margin-bottom: -3px;                /* nestle into the service line below */
}
.wm-service {
  font-family: "Fraunces", "Times New Roman", serif;
  font-style: italic;
  font-weight: 800;
  font-size: 13px;
  color: var(--subtext1);
  letter-spacing: -0.01em;
  line-height: 1;
}

/* about + hire pages: large display version of the same wordmark */
.about-page .wordmark .logo { width: 48px; height: 48px; }
.about-page .wm-name    { font-size: 44px; margin-bottom: -8px; transform: rotate(-4deg); }
.about-page .wm-service { font-size: 22px; }
.banner .sub { color: var(--subtext0); font-size: 12px; }
.banner .filler { flex: 1; }
.banner .filter {
  display: flex; align-items: center; gap: 6px;
  color: var(--subtext0); cursor: pointer; font-size: 12px;
}
.banner .filter input { accent-color: var(--mauve); }
.banner nav { display: flex; gap: 12px; font-size: 12px; }

/* ─── layout ─── desktop */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "sidebar map"
    "stats   stats";
  height: calc(100vh - 46px);
}
.sidebar       { grid-area: sidebar; display: flex; flex-direction: column;
  background: var(--mantle); border-right: 1px solid var(--surface0); overflow: hidden; }
.map-wrap      { grid-area: map; position: relative; overflow: hidden; }
.stats-section { grid-area: stats; background: var(--mantle); border-top: 1px solid var(--surface0); }
/* detail on desktop floats over the map (position: fixed) — no grid area */

/* ─── trip list ─── */
.trip-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.trip-list li { border-bottom: 1px solid var(--surface0); }

.trip-row {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "route status" "meta status";
  gap: 4px 8px;
  padding: 10px 14px;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.trip-row:hover { background: var(--surface0); }
.trip-row:focus-visible { outline: 2px solid var(--mauve); outline-offset: -2px; }
li[aria-current="true"] .trip-row {
  background: var(--surface0);
  border-left-color: var(--mauve);
}
li.failed .trip-row { border-left-color: var(--red); }
li.failed[aria-current="true"] .trip-row { background: color-mix(in srgb, var(--red) 14%, var(--surface0)); }
li.unconfirmed .trip-row { border-left-color: var(--overlay0); }

.route { grid-area: route; display: flex; gap: 6px; align-items: baseline; font-weight: 600; color: var(--text); }
.route .arrow { color: var(--overlay0); }
.route .from, .route .to { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.meta { grid-area: meta; display: flex; gap: 10px; color: var(--subtext0); font-size: 12px; }
.status-dot { grid-area: status; width: 8px; height: 8px; border-radius: 50%; background: var(--green); align-self: center; }
li.failed .status-dot { background: var(--red); }
li.unconfirmed .status-dot { background: var(--overlay0); }

.load-more {
  padding: 10px; color: var(--subtext0);
  background: var(--mantle); border-top: 1px solid var(--surface0);
  text-align: center; width: 100%;
}
.load-more:hover { color: var(--text); }

/* skeleton + empty */
.skeleton { padding: 12px 14px; }
.skeleton .line {
  height: 10px; border-radius: 3px; margin-bottom: 6px;
  background: linear-gradient(90deg, var(--surface0) 0%, var(--surface1) 50%, var(--surface0) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}
.skeleton .line.a { width: 70%; }
.skeleton .line.b { width: 40%; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.empty { padding: 32px 16px; text-align: center; color: var(--subtext0); font-size: 13px; }

/* ─── map ─── */
#map { width: 100%; height: 100%; background: var(--crust); }
.leaflet-container { background: var(--crust); font-family: inherit; }
.leaflet-control-zoom a {
  background: var(--mantle); color: var(--text); border-color: var(--surface1);
}
.leaflet-control-zoom a:hover { background: var(--surface0); color: var(--lavender); }

/* ─── detail panel (collapsible <details>) ─── */
/* desktop: floats over the map area via position: fixed (it's no longer inside
   .map-wrap, so absolute positioning would float into the wrong parent) */
.detail {
  position: fixed;
  top: 58px; right: 12px;
  width: 300px;
  max-height: calc(100vh - 140px);
  overflow: hidden;
  background: color-mix(in srgb, var(--mantle) 96%, transparent);
  border: 1px solid var(--surface0);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  z-index: 500;
  font-size: 13px;
}
.detail summary {
  cursor: pointer;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 8px;
  list-style: none;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid transparent;
}
.detail summary::-webkit-details-marker { display: none; }
.detail summary::before {
  content: "▸"; color: var(--overlay1); font-size: 12px; transition: transform 0.15s;
}
.detail[open] summary::before { transform: rotate(90deg); }
.detail[open] summary { border-bottom-color: var(--surface0); }
.detail summary .route { font-size: 13px; }
.detail summary .close {
  margin-left: auto; color: var(--overlay0); font-size: 18px; line-height: 1; padding: 0 4px;
}
.detail summary .close:hover { color: var(--red); }
.detail .body { padding: 12px 14px; overflow-y: auto; max-height: calc(100vh - 220px); }

.detail .failed-banner {
  margin-bottom: 10px; padding: 6px 10px;
  background: color-mix(in srgb, var(--red) 20%, var(--surface0));
  border-left: 3px solid var(--red);
  font-size: 12px; color: var(--maroon);
  border-radius: 0 4px 4px 0;
}
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0; font-size: 12px; }
.detail dt { color: var(--subtext0); }
.detail dd { margin: 0; color: var(--text); }
.detail .route-stats-row { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--surface1); }
.detail .route-stats-link {
  display: inline-block; font-size: 12px;
  color: var(--sapphire); text-decoration: none;
}
.detail .route-stats-link:hover { color: var(--lavender); text-decoration: underline; }

/* route-filter badge inside stats summary */
.stats-route-badge {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: 8px;
  padding: 2px 4px 2px 8px;
  background: color-mix(in srgb, var(--mauve) 22%, var(--surface0));
  border: 1px solid color-mix(in srgb, var(--mauve) 40%, var(--surface1));
  border-radius: 10px;
  font-size: 11px; color: var(--text); font-weight: 500;
}
.stats-route-badge .route-pill { white-space: nowrap; }
.stats-route-badge .clear-route {
  font-size: 14px; line-height: 1; color: var(--subtext0);
  padding: 0 4px;
}
.stats-route-badge .clear-route:hover { color: var(--red); }

/* view toggle (top-right of map; zoom controls sit top-left) */
.view-toggle {
  position: absolute;
  top: 12px; right: 12px;
  display: inline-flex;
  background: color-mix(in srgb, var(--mantle) 94%, transparent);
  border: 1px solid var(--surface0);
  border-radius: 6px;
  padding: 2px;
  z-index: 500;
  font-size: 12px;
}
.view-toggle button {
  padding: 5px 11px;
  color: var(--subtext0);
  border-radius: 4px;
  transition: background 0.12s, color 0.12s;
}
.view-toggle button:hover { color: var(--text); }
.view-toggle button[aria-pressed="true"] {
  background: var(--mauve);
  color: var(--crust);
}

/* legends (bottom-left, stackable) */
.legend {
  position: absolute;
  bottom: 12px; left: 12px;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: color-mix(in srgb, var(--mantle) 92%, transparent);
  border: 1px solid var(--surface0);
  border-radius: 4px;
  font-size: 11px;
  color: var(--subtext0);
  z-index: 500;
}
.legend .ramp {
  display: inline-block;
  width: 80px; height: 8px; border-radius: 2px;
  background: linear-gradient(to right, #440154, #3b528b, #21918c, #5ec962, #fde725);
}
.legend.cleans-legend { bottom: 46px; }     /* stack above the speed legend */
.legend.cleans-legend .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #fab387;                       /* catppuccin peach */
}
.legend small { color: var(--overlay1); }

/* slim tooltip on per-clean markers */
.leaflet-tooltip.speed-tip {
  background: var(--surface0); color: var(--text);
  border: 1px solid var(--surface1);
  font-size: 11px; padding: 2px 6px;
  box-shadow: none;
}
.leaflet-tooltip.speed-tip::before { display: none; }

/* ─── stats footer ─── */
.stats-section details {
  border-top: 1px solid var(--surface0);
}
.stats-section summary {
  cursor: pointer;
  padding: 8px 14px;
  display: flex; align-items: center; gap: 10px;
  list-style: none;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  background: var(--mantle);
}
.stats-section summary::-webkit-details-marker { display: none; }
.stats-section summary::before {
  content: "▾"; color: var(--overlay1); transition: transform 0.15s;
}
.stats-section details:not([open]) summary::before { transform: rotate(-90deg); }
.stats-section summary .label-tag { color: var(--mauve); }
.stats-section summary select {
  margin-left: auto;
  background: var(--surface0); color: var(--text);
  border: 1px solid var(--surface1); border-radius: 4px;
  padding: 2px 6px; font: inherit; font-size: 12px;
}
.stats-section .stats-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 18px;
  padding: 14px 18px 16px;
  background: var(--base);
  border-top: 1px solid var(--surface0);
}
.stats-section .stat { display: flex; flex-direction: column; gap: 2px; }
.stats-section .stat .num { font-size: 20px; color: var(--lavender); font-variant-numeric: tabular-nums; }
.stats-section .stat .lbl { font-size: 11px; color: var(--subtext0); text-transform: uppercase; letter-spacing: 0.04em; }
.stats-section .axe-tally {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; gap: 8px;
  padding-top: 4px;
}
.axe-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 8px;
  background: var(--surface0); border: 1px solid var(--surface1);
  border-radius: 12px;
  font-size: 12px; color: var(--text);
}
.axe-chip .axe-icon {
  width: 14px; height: 14px;
  display: inline-block;
  border-radius: 2px;
  background: var(--axe-iron);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.3);
}
.axe-chip[data-tier="netherite"] .axe-icon { background: var(--axe-netherite); }
.axe-chip[data-tier="diamond"]   .axe-icon { background: var(--axe-diamond); }
.axe-chip[data-tier="iron"]      .axe-icon { background: var(--axe-iron); }
.axe-chip[data-tier="golden"]    .axe-icon { background: var(--axe-golden); }
.axe-chip[data-tier="stone"]     .axe-icon { background: var(--axe-stone); }
.axe-chip[data-tier="wooden"]    .axe-icon { background: var(--axe-wooden); }
.axe-chip .axe-count { color: var(--subtext0); font-variant-numeric: tabular-nums; }

/* ─── about page ─── */
.about-page {
  max-width: 720px; margin: 0 auto; padding: 40px 24px 60px;
  overflow-y: auto; height: 100vh;
}
.about-page h1 { color: var(--mauve); margin-top: 0; font-size: 28px; }
.about-page h2 { color: var(--lavender); margin-top: 28px; font-size: 18px; }
.about-page p { color: var(--subtext1); }
.about-page code {
  background: var(--surface0); padding: 1px 6px; border-radius: 3px; font-size: 13px;
}
.about-page .back { display: inline-block; margin-bottom: 16px; color: var(--blue); }
.about-page ul { padding-left: 18px; margin: 8px 0 12px; }
.about-page li { color: var(--subtext1); margin-bottom: 8px; }
.about-page li::marker { color: var(--mauve); }

.about-page ul.attribution { padding-left: 16px; }
.about-page ul.attribution li { margin-bottom: 4px; font-size: 13px; color: var(--subtext1); }
.about-page ul.attribution a { color: var(--blue); }
.about-page ul.attribution a:hover { color: var(--lavender); }

/* ─── mobile ─── */
/* stack order top→bottom: stats / map / detail / list.
   stats at top so they're always visible; map gets the prime middle slot;
   detail sits collapsed right above the list so it never covers the stats. */
@media (max-width: 767px) {
  body { overflow-y: auto; overflow-x: hidden; height: auto; }
  .layout {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
      "stats"
      "map"
      "detail"
      "sidebar";
    height: auto;
  }
  .stats-section { grid-area: stats; border-top: 0; border-bottom: 1px solid var(--surface0); }
  .map-wrap      { grid-area: map; height: 50vh; }
  .sidebar       { grid-area: sidebar;
                   max-height: none; overflow-y: visible;
                   border-right: 0; border-top: 1px solid var(--surface0); }
  /* detail returns to normal document flow — a thin collapsed bar above the list */
  .detail {
    grid-area: detail;
    position: static;
    top: auto; right: auto;
    width: auto; max-height: none;
    border-radius: 0;
    border: 0;
    border-top: 1px solid var(--surface0);
    box-shadow: none;
    background: var(--mantle);
  }
  .detail .body { max-height: 40vh; overflow-y: auto; }

  .stats-section .stats-body {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 12px; padding: 10px;
  }
  .banner { gap: 8px; padding: 6px 10px; height: auto; flex-wrap: wrap; }
  .banner .sub { display: none; }
}
