/* ===================================================================
   Snowboarding Analytics — mobile-first responsive
   ===================================================================
   Mobile-first ladder:
     base:        phones (any width)
     >= 640px:    large phones / tablets in portrait
     >= 960px:    tablets landscape / small desktop
     >= 1280px:   desktop wide
   ================================================================ */

:root {
  --bg:        #0e1116;
  --bg-elev:   #161b22;
  --bg-elev-2: #1c232b;
  --border:    #30363d;
  --text:      #e6edf3;
  --text-dim:  #8b949e;
  --text-mute: #6e7681;
  --accent:    #2f81f7;
  --accent-2:  #58a6ff;
  --good:      #3fb950;
  --warn:      #d29922;
  --bad:       #f85149;
  --purple:    #a371f7;

  --radius:   12px;
  --radius-sm: 8px;
  --shadow:   0 1px 2px rgba(0,0,0,0.4), 0 4px 12px rgba(0,0,0,0.25);

  --topbar-h:    56px;
  --bottomnav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
               "Segoe UI", system-ui, sans-serif;
  font-size: 16px;     /* iOS won't auto-zoom inputs at 16+ */
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  padding-bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 16px);
}

a { color: var(--accent); text-decoration: none; }
a:active { color: var(--accent-2); }

/* ---------------- Topbar ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: rgba(14, 17, 22, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}
.iconbtn {
  background: transparent;
  border: none;
  color: var(--text);
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.iconbtn:active { color: var(--accent); }
.iconbtn[hidden] { visibility: hidden; }   /* hold layout */

/* ---------------- Bottom nav ---------------- */

.bottomnav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(14, 17, 22, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.bottomnav.nav4 { grid-template-columns: repeat(4, 1fr); }
.navitem {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--bottomnav-h);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.navitem.disabled {
  opacity: 0.35;
  pointer-events: none;
}
.navitem.active { color: var(--accent); }
.navitem:active { color: var(--accent-2); }

/* ---------------- Content shell ---------------- */

#app {
  padding:
    16px
    calc(16px + var(--safe-right))
    16px
    calc(16px + var(--safe-left));
  max-width: 1400px;
  margin: 0 auto;
}
@media (min-width: 640px) {
  #app { padding-left: max(20px, calc(20px + var(--safe-left)));
         padding-right: max(20px, calc(20px + var(--safe-right)));
         padding-top: 20px; padding-bottom: 80px; }
}
@media (min-width: 960px) {
  #app { padding: 28px 32px 96px; }
}

.loading, .error {
  text-align: center;
  color: var(--text-dim);
  padding: 80px 16px;
  font-size: 15px;
}
.error { color: var(--bad); }
.loading-sub {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-mute);
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}

/* ---------------- Headings & section labels ---------------- */

h2.section {
  margin: 24px 0 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

/* ---------------- Hero (per-run / per-session header) ---------------- */

.hero {
  background: linear-gradient(160deg, var(--bg-elev) 0%, var(--bg-elev-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.hero .meta {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.hero h1.title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0 0 4px;
}
.hero .when {
  font-size: 13px;
  color: var(--text-dim);
}
.hero .hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 16px;
}
.hero .stat .num {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.hero .stat .num .unit {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
  margin-left: 3px;
}
.hero .stat .lbl {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
@media (min-width: 640px) {
  .hero { padding: 24px 28px; }
  .hero h1.title { font-size: 26px; }
  .hero .hero-stats { grid-template-columns: repeat(4, 1fr); }
  .hero .stat .num { font-size: 26px; }
}
@media (min-width: 960px) {
  .hero .hero-stats { grid-template-columns: repeat(6, 1fr); }
}

/* ---------------- Stat cards grid ---------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
@media (min-width: 480px) { .cards { grid-template-columns: repeat(3, 1fr); }}
@media (min-width: 720px) { .cards { grid-template-columns: repeat(4, 1fr); }}
@media (min-width: 1100px){ .cards { grid-template-columns: repeat(6, 1fr); }}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.card .lbl {
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}
.card .num {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.card .num .unit {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 500;
  margin-left: 3px;
}
.card .num .sub {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  margin-top: 2px;
}
.card .num.bad  { color: var(--bad);  }
.card .num.warn { color: var(--warn); }
.card .num.good { color: var(--good); }

/* ---------------- Charts ---------------- */

.charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
@media (min-width: 720px)  { .charts { grid-template-columns: repeat(2, 1fr); }}
@media (min-width: 1280px) { .charts { grid-template-columns: repeat(3, 1fr); }}

.chart-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px 8px;
}
.chart-box.full { grid-column: 1 / -1; }
.chart-box h3 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.plot { height: 200px; width: 100%; }
@media (min-width: 720px)  { .plot { height: 220px; } }
@media (min-width: 1280px) { .plot { height: 240px; } }

#map {
  height: 320px;
  width: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
@media (min-width: 720px) { #map { height: 420px; } }
/* MapLibre GL JS (self-hosted vector basemap, ADR 026) — dark-theme the
   attribution to match the dashboard. */
.maplibregl-ctrl-attrib {
  background: rgba(14, 17, 22, 0.7) !important;
  color: var(--text-dim) !important;
  font-size: 10px !important;
}
.maplibregl-ctrl-attrib a { color: var(--accent-2) !important; }

/* ---------------- Story panel ---------------- */

.story {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  line-height: 1.65;
  font-size: 15px;
  margin-bottom: 16px;
}
.story h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.story p { margin: 0 0 12px; }
.story p:last-child { margin-bottom: 0; }
.story strong { color: var(--accent); font-weight: 600; }
.story .empty { color: var(--text-dim); font-style: italic; }

.story-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.story-prov {
  font-size: 10px;
  color: var(--text-mute);
  margin-bottom: 8px;
  text-transform: lowercase;
  opacity: 0.7;
}
.story-prov .pill {
  padding: 1px 7px;
  font-size: 10px;
}

/* Segmented control (mode toggle) */
.segctl {
  display: inline-flex;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.segbtn {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 28px;
  font-family: inherit;
}
.segbtn:active { color: var(--text); }
.segbtn.active {
  background: var(--accent);
  color: #fff;
}
@media (min-width: 480px) {
  .segbtn { padding: 6px 16px; font-size: 13px; min-height: 32px; }
}

/* Generic button */
.btn {
  appearance: none;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 40px;          /* tap target */
}
.btn:active { background: var(--bg); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:active { background: var(--accent-2); border-color: var(--accent-2); }

/* Share row inside story */
.share-row {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.share-actions {
  display: flex;
  gap: 8px;
}
.share-meta { font-size: 12px; color: var(--text-dim); }

/* ---------------- Run list (mobile cards / desktop table) ---------------- */

.runlist {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.runrow {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.runrow:active { background: var(--bg-elev-2); }
.runrow .num {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--accent);
}
.runrow .body .ttl {
  font-weight: 600;
  font-size: 15px;
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.runrow .body .meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-dim);
}
.runrow .stats {
  text-align: right;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.runrow .stats .big {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* desktop table view */
@media (min-width: 960px) {
  .runlist.runlist-table {
    display: table;
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
  }
  .runlist.runlist-table .runrow {
    display: table-row;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 0;
  }
  .runlist.runlist-table .runrow:last-child { border-bottom: none; }
  .runlist.runlist-table .runrow > * {
    display: table-cell;
    vertical-align: middle;
    padding: 12px 14px;
  }
  .runlist.runlist-table .runrow .num {
    width: 40px; margin: 0;
  }
  .runlist.runlist-table .runrow .stats {
    display: none;
  }
  .runlist.runlist-table .colcell {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 14px;
  }
  .runlist.runlist-table tr.runhead th {
    text-align: right;
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
    padding: 10px 14px;
    background: var(--bg-elev-2);
    border-bottom: 1px solid var(--border);
  }
  .runlist.runlist-table tr.runhead th:nth-child(-n+2) {
    text-align: left;
  }
}

/* ---------------- Day navigator (prev / calendar / next) ------------ */

.daynav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 14px;
}
.daynav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12px;
  text-decoration: none;
  min-height: 44px;
  font-variant-numeric: tabular-nums;
}
.daynav-btn:active { background: var(--bg-elev-2); }
.daynav-btn.disabled {
  pointer-events: none;
  opacity: 0.32;
}
.daynav-btn:nth-child(1) { justify-content: flex-start; }
.daynav-btn:nth-child(3) { justify-content: flex-end; text-align: right; }
.daynav-lbl {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: 0.02em;
}
@media (min-width: 640px) {
  .daynav-lbl { font-size: 13px; }
}

.daynav-current {
  appearance: none;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
}
.daynav-current:active { background: var(--bg-elev-2); }
.daynav-current .caret { color: var(--text-dim); margin-left: 2px; }
@media (min-width: 640px) { .daynav-current { padding: 10px 18px; } }

/* Calendar pop-over */
.cal-pop {
  position: absolute;
  z-index: 200;
  width: 320px;
  max-width: calc(100vw - 16px);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.cal-head {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: center;
  margin-bottom: 8px;
}
.cal-head .cal-title {
  text-align: center;
  font-weight: 600;
  font-size: 14px;
}
.cal-nav {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
.cal-nav:active { background: var(--bg-elev-2); }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-dow span {
  text-align: center;
  font-size: 10px;
  color: var(--text-mute);
  text-transform: uppercase;
  padding: 4px 0;
  letter-spacing: 0.04em;
}
.cal-day {
  text-align: center;
  padding: 8px 0;
  border-radius: 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-mute);
  text-decoration: none;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cal-day.has-data {
  background: var(--bg-elev-2);
  color: var(--accent);
  font-weight: 600;
}
.cal-day.has-data:active {
  background: var(--accent);
  color: #fff;
}
.cal-day.has-data:hover { background: rgba(47, 129, 247, 0.18); }
.cal-day.multi { position: relative; }
.cal-badge {
  position: absolute;
  top: 1px;
  right: 2px;
  font-size: 9px;
  line-height: 1;
  font-weight: 700;
  color: var(--accent-2);
}
.cal-day.current {
  background: var(--accent);
  color: #fff;
  outline: 2px solid var(--accent-2);
}

/* ---------------- Day timeline ribbon ---------------- */

.timeline {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 14px 12px;
  margin-bottom: 20px;
}
.timeline .lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.timeline .bar {
  position: relative;
  height: 22px;
  background: var(--bg-elev-2);
  border-radius: 4px;
  overflow: hidden;
}
.timeline .seg {
  position: absolute;
  top: 0; bottom: 0;
  opacity: 0.85;
}
.timeline .seg:hover { opacity: 1; }
.timeline .legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 14px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-dim);
}
.timeline .legend .swatch {
  width: 10px; height: 10px;
  border-radius: 2px;
  display: inline-block;
  margin-right: 5px;
  vertical-align: middle;
}

/* ---------------- Turn list ---------------- */

.turn-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.turn-table th, .turn-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
.turn-table th {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.turn-table tr:last-child td { border-bottom: none; }
.turn-table th:first-child, .turn-table td:first-child { text-align: left; }
.turn-table .side-A { color: var(--accent); }
.turn-table .side-B { color: var(--warn); }
/* Calibrated riders get Heel/Toe as the class name, so without these their
   side column has rendered grey since the Heel/Toe naming was introduced.
   SRV-15 phase 2 makes the gap visible (uncalibrated riders get the tint,
   calibrated ones do not), which is how it was found. */
.turn-table .side-Heel { color: var(--accent); }
.turn-table .side-Toe  { color: var(--warn); }
.turn-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* On phones, hide the less critical turn columns */
@media (max-width: 639px) {
  .turn-table .col-yaw,
  .turn-table .col-mean,
  .turn-table .col-ratio { display: none; }
}

/* ---------------- Quality / disclaimer pills ---------------- */

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 14px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.pill.warn { color: var(--warn); border-color: rgba(210,153,34,0.4); }
.pill.bad  { color: var(--bad);  border-color: rgba(248,81,73,0.4); }
.pill.good { color: var(--good); border-color: rgba(63,185,80,0.4); }
.pill.hw-thingy {
  color: #58d5e3;
  border-color: rgba(88, 213, 227, 0.4);
  background: rgba(88, 213, 227, 0.08);
}
.pill.hw-esp {
  color: #e39558;
  border-color: rgba(227, 149, 88, 0.4);
  background: rgba(227, 149, 88, 0.08);
}

/* ---------------- Snow condition banner & chip ---------------- */

/* Per-condition palette (text + ring + gradient backdrop). Kept consistent
   between banner and chip so the colour itself becomes the visual cue. */
.snow-groomed { --snow-fg: #58d5e3; --snow-glow: rgba(88, 213, 227, 0.18); }
.snow-mixed   { --snow-fg: #d8c060; --snow-glow: rgba(216, 192, 96, 0.18); }
.snow-rough   { --snow-fg: #e3a558; --snow-glow: rgba(227, 165, 88, 0.18); }
.snow-icy     { --snow-fg: #a8c8ff; --snow-glow: rgba(168, 200, 255, 0.18); }
.snow-unknown { --snow-fg: #8b949e; --snow-glow: rgba(139, 148, 158, 0.15); }

.snow-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin: 8px 0 18px;
  border-radius: 14px;
  border: 1px solid var(--snow-fg);
  background:
    linear-gradient(135deg, var(--snow-glow) 0%, transparent 60%),
    var(--bg-elev);
  color: var(--text);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.02);
}
.snow-banner-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  color: var(--snow-fg);
  background: var(--snow-glow);
  border: 1px solid var(--snow-fg);
}
.snow-banner-icon .snow-svg { width: 32px; height: 32px; }
.snow-banner-text { display: flex; flex-direction: column; gap: 2px; }
.snow-banner-eyebrow {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.snow-banner-headline {
  font-size: 20px;
  font-weight: 700;
  color: var(--snow-fg);
  line-height: 1.15;
}
.snow-banner-sub { font-size: 13px; color: var(--text-dim); }
@media (min-width: 720px) {
  .snow-banner { padding: 18px 20px; gap: 18px; }
  .snow-banner-icon { width: 68px; height: 68px; }
  .snow-banner-icon .snow-svg { width: 38px; height: 38px; }
  .snow-banner-headline { font-size: 24px; }
  .snow-banner-sub { font-size: 14px; }
}

.snow-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px 2px 6px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  color: var(--snow-fg);
  border: 1px solid var(--snow-fg);
  background: var(--snow-glow);
  margin-top: 6px;
  white-space: nowrap;
}
.snow-chip .snow-svg { width: 14px; height: 14px; }
.snow-chip-lbl { letter-spacing: 0.01em; }

/* ---------------- Collapsible section (mobile) ---------------- */

details.collapse {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0;
  margin-bottom: 12px;
}
details.collapse summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
details.collapse summary::-webkit-details-marker { display: none; }
details.collapse summary::after {
  content: "▾";
  color: var(--text-dim);
  transition: transform 0.2s ease;
}
details.collapse[open] summary::after { transform: rotate(180deg); }
details.collapse .body { padding: 0 16px 16px; }

/* ---------------- Trail link in hero titles ---------------- */
a.trail-link {
  color: inherit;
  border-bottom: 1px dashed rgba(47, 129, 247, 0.5);
  text-decoration: none;
}
a.trail-link:hover { color: var(--accent); }

/* ---------------- PR badges (run + session) ---------------- */
.pr-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 14px;
}
.pr-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg,
    rgba(255, 215, 0, 0.16), rgba(255, 165, 0, 0.10));
  border: 1px solid rgba(255, 215, 0, 0.35);
  color: #ffd863;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.pr-badge.tied { color: var(--text); border-color: var(--border);
                 background: var(--bg-elev-2); }

/* ---------------- App footer ---------------- */
.appfooter {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-elev);
  margin-top: 24px;
}
.appfooter a {
  color: var(--text-dim);
  text-decoration: none;
}
.appfooter a:hover { color: var(--accent); }

/* ---------------- Glossary & release notes pages ---------------- */
.glossary-dl {
  margin: 0 0 8px;
}
.glossary-dl dt {
  font-weight: 600;
  color: var(--text);
  margin-top: 16px;
  font-size: 14px;
}
.glossary-dl dd {
  margin: 4px 0 0 0;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}
.rel-date {
  font-weight: 400;
  color: var(--text-dim);
  font-size: 14px;
}
h3.rel-heading {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 20px 0 8px;
}
.rel-list {
  margin: 0;
  padding-left: 20px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.7;
}
.rel-list li { margin-bottom: 4px; }

/* ---------------- Turn table column hint (adj) ---------------- */
.col-hint {
  font-size: 9px;
  color: var(--text-mute);
  margin-left: 3px;
  font-weight: 400;
}

/* ---------------- Configure formulas page ---------------- */
.formula-intro {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-dim);
}
.formula-intro p { margin: 0 0 8px; }
.formula-intro p:last-child { margin-bottom: 0; }
.formula-intro p.muted { color: var(--text-mute); font-size: 12px; }
.formula-intro code {
  background: var(--bg-elev-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.formula-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 0 0 12px;
}
.formula-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 4px;
  flex-wrap: wrap;
}
.formula-head h3 {
  margin: 0;
  font-size: 15px;
  color: var(--text);
}
.formula-glossary-link {
  font-size: 12px;
  color: var(--text-mute);
  text-decoration: none;
}
.formula-glossary-link:hover { color: var(--accent); }
.formula-desc {
  margin: 4px 0 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
}
.formula-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 0 0 10px;
}
.formula-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  font-size: 13px;
}
@media (min-width: 540px) {
  .formula-row {
    grid-template-columns: 200px 1fr auto;
    align-items: center;
    gap: 12px;
  }
}
.formula-label {
  color: var(--text);
  font-weight: 500;
}
.formula-unit {
  color: var(--text-mute);
  font-weight: 400;
}
.formula-row input[type="text"],
.formula-row input[type="number"] {
  appearance: none;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  min-height: 38px;
  width: 100%;
  box-sizing: border-box;
}
.formula-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(47, 129, 247, 0.25);
}
.formula-expr-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.formula-hint {
  font-size: 11px;
  color: var(--text-mute);
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.formula-hint code {
  background: var(--bg-elev-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}
.formula-vars {
  font-size: 12px;
  color: var(--text-mute);
  margin: 4px 0 8px;
}
.formula-vars code {
  background: var(--bg-elev-2);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-dim);
}
.formula-affects {
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px dashed var(--border);
  padding-top: 8px;
  margin-top: 4px;
}
.formula-affects strong { color: var(--text); }
.formula-card-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.btn.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 12px;
  min-height: 32px;
  padding: 6px 12px;
}
.btn.btn-ghost:hover { color: var(--text); border-color: var(--text-mute); }
.formula-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  margin: 16px 0 8px;
  flex-wrap: wrap;
}
.formula-update-btn { min-width: 180px; }
.formula-msg {
  font-size: 12px;
  margin: 8px 0 0;
  min-height: 0;
}
.formula-msg:empty { display: none; }
.formula-msg.ok {
  color: #4ac26b;
  background: rgba(63, 185, 80, 0.10);
  border: 1px solid rgba(63, 185, 80, 0.30);
  border-radius: 6px;
  padding: 8px 10px;
}
.formula-msg.err {
  color: #ff7b72;
  background: rgba(248, 81, 73, 0.10);
  border: 1px solid rgba(248, 81, 73, 0.40);
  border-radius: 6px;
  padding: 8px 10px;
}
.formula-msg.ok a { color: inherit; text-decoration: underline; }
.formula-msg-global {
  margin-top: 12px;
  font-size: 13px;
}
.formula-pill { margin-left: 6px; }
.formula-footnote {
  margin: 24px 0 8px;
  font-size: 12px;
  color: var(--text-mute);
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.formula-footnote code {
  background: var(--bg-elev-2);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ---- Editable Python formulas (/#/code) ---- */
@media (min-width: 720px) {
}

/* "Custom formulas active" banner shown on run + session pages */
.formula-active-banner {
  background: rgba(210, 153, 34, 0.10);
  border: 1px solid rgba(210, 153, 34, 0.40);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.5;
}
.formula-active-banner a {
  color: var(--accent);
  text-decoration: underline;
}

/* Glossary "configurable" pill */
.pill.cfg {
  background: rgba(47, 129, 247, 0.12);
  border: 1px solid rgba(47, 129, 247, 0.45);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
}
.glossary-cfg-link {
  text-decoration: none;
  margin-left: 6px;
}
.glossary-cfg-link:hover { background: rgba(47, 129, 247, 0.25); }
.glossary-intro {
  font-size: 13px;
  color: var(--text-dim);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0 0 12px;
}

/* ---------------- Rebuild progress overlay ---------------- */

@keyframes formula-overlay-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes formula-card-pop {
  from { transform: scale(0.92); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

@keyframes formula-spin {
  to { transform: rotate(360deg); }
}

@keyframes formula-check-pop {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}


/* Slight tint on the overlay-card border once we've finished. */

@media (prefers-reduced-motion: reduce) {
}

/* Stat card pending async recompute */
.card-loading {
  opacity: 0.55;
  position: relative;
}
.card-loading::after {
  content: "recomputing…";
  position: absolute;
  bottom: 4px;
  right: 8px;
  font-size: 9px;
  color: var(--text-mute);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Server-side formula card variant */

/* uxv1 additions: auth, admin */
/* The actions cluster lives in the topbar's auto-sized 3rd grid column.
   min-width:0 lets it shrink so the account email can truncate instead of
   pushing the cluster off-screen on narrow phones. */
.topbar-actions { display: flex; gap: 8px; align-items: center; min-width: 0; padding-right: 4px; }
.topbar-link {
  color: var(--fg-muted, #9aa);
  text-decoration: none;
  padding: 4px 8px;
  font-size: 0.92em;
  white-space: nowrap;
}
.topbar-link:hover { color: var(--fg, #fff); }
/* Long emails on #/account link must not overflow the bar on phones. */
#uxv1-account-link {
  max-width: 38vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-card { max-width: 420px; margin: 60px auto; }
.auth-card h2 { margin: 0 0 18px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85em; color: var(--fg-muted, #9aa); }
.auth-card input { padding: 10px 12px; background: var(--bg, #0e1116); color: var(--fg, #fff); border: 1px solid #2a2f3a; border-radius: 6px; }
.auth-card button[type="submit"] { padding: 10px 16px; background: #4fa3ff; color: #001428; border: none; border-radius: 6px; font-weight: 600; cursor: pointer; }
.form-error { color: #f06868; min-height: 1.2em; }
.form-success { color: #6fde8a; min-height: 1.2em; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #1f2632; font-size: 0.92em; }
.admin-table th { color: var(--fg-muted, #9aa); font-weight: 600; }
.admin-table code { font-size: 0.75em; color: var(--fg-muted, #9aa); }
.danger { border-color: rgba(240, 104, 104, 0.4); }
.danger h3 { color: #f06868; }

/* uxv1 — section nav at the top, not the bottom.
   Scoped to body.uxv1-top-nav so the rules don't bleed into anything
   else that imports this stylesheet. */
body.uxv1-top-nav .bottomnav {
  position: sticky;
  top: var(--topbar-h, 56px);
  bottom: auto;
  left: auto; right: auto;
  border-top: none;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
body.uxv1-top-nav .bottomnav .navitem {
  height: 48px;
  flex-direction: row;
  gap: 8px;
}
body.uxv1-top-nav .bottomnav .navitem svg {
  width: 18px; height: 18px;
}
body.uxv1-top-nav main {
  padding-bottom: 24px;
}

/* Active-sessions panel (Account > Active sessions). */
.sessions-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.sessions-table th, .sessions-table td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid #1f2632;
  font-size: 0.92em;
}
.sessions-table th { color: var(--fg-muted, #9aa); font-weight: 600; }
.sessions-table .badge-current {
  display: inline-block; font-size: 0.7em; padding: 2px 7px;
  background: #4fa3ff; color: #001428; border-radius: 999px;
  vertical-align: middle; margin-left: 6px; font-weight: 700;
}
/* Session client class (ADR 033): web vs mobile-app session badge.
   Used in the account sessions table and admin login history. */
.badge-client {
  display: inline-block; font-size: 0.7em; padding: 2px 7px;
  background: rgba(154, 170, 170, 0.18); color: var(--fg-muted, #9aa);
  border-radius: 999px; vertical-align: middle; margin-left: 6px;
  font-weight: 700;
}
.badge-client.mobile { background: rgba(44, 199, 119, 0.18); color: #2c7; }
/* Mount-calibration panel (admin > user detail, SRV-22). One card per board
   config; read-only, so nothing in it is interactive except the raw-terms
   <details>. */
.cal-card {
  border: 1px solid #1f2632; border-radius: 8px;
  padding: 12px 14px; margin: 10px 0;
}
.cal-card .stats { margin-top: 8px; }
.cal-card pre {
  background: rgba(154, 170, 170, 0.08); border-radius: 6px;
  padding: 8px 10px; margin: 6px 0 0;
}
.revoke-btn {
  background: transparent; color: #f06868;
  border: 1px solid rgba(240, 104, 104, 0.4); border-radius: 6px;
  padding: 4px 10px; font-size: 0.85em; cursor: pointer;
}
.revoke-btn:hover { background: rgba(240, 104, 104, 0.1); }
.revoke-btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ================= Admin → Board (ADR 029 as amended) ================= */

.board-filter-bar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin: 10px 0;
}
.board-select { font-size: 0.85em; }
.board-chip {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--line, #444); font-size: 0.75em;
  background: transparent; color: inherit; cursor: pointer;
}
.board-chip.on { background: var(--accent, #2f81f7); color: #fff; border-color: transparent; }
span.board-chip { cursor: default; }

.sessions-strip {
  display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0;
  padding: 8px; border: 1px dashed var(--line, #444); border-radius: 8px;
}
.session-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 0.82em;
  background: var(--panel, rgba(127,127,127,0.08));
}
.session-pill.stale { opacity: 0.45; }
.session-pill code { font-size: 0.9em; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.dirty { background: #f85149; }
.dot.unpushed { background: #d29922; }

.board-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  align-items: start; margin-top: 10px;
}
@media (max-width: 1000px) { .board-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px)  { .board-grid { grid-template-columns: 1fr; } }
.board-col {
  background: var(--panel, rgba(127,127,127,0.06));
  border-radius: 10px; padding: 8px; min-height: 120px;
}
.board-col-head {
  font-weight: 600; font-size: 0.9em; margin: 2px 4px 8px;
  display: flex; justify-content: space-between;
}
.board-card {
  background: var(--bg-elev, rgba(127,127,127,0.12));
  border: 1px solid var(--line, #444); border-radius: 8px;
  padding: 8px; margin-bottom: 8px; cursor: pointer;
}
.board-card:hover { border-color: var(--accent, #2f81f7); }
.board-card.archived { opacity: 0.55; }
.board-card-top {
  display: flex; align-items: center; gap: 6px; font-size: 0.8em;
}
.board-card-title { margin: 4px 0; font-size: 0.92em; line-height: 1.25; }
.board-card-meta { display: flex; align-items: center; gap: 6px; font-size: 0.75em; }

.prio-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.prio-low { background: #6e7681; }
.prio-normal { background: #2f81f7; }
.prio-high { background: #d29922; }
.prio-urgent { background: #f85149; }

.badge-bug, .badge-feature, .badge-agent {
  font-size: 0.7em; padding: 0 5px; border-radius: 4px; font-weight: 600;
}
.badge-bug { background: rgba(248, 81, 73, 0.18); color: #f85149; }
.badge-feature { background: rgba(47, 129, 247, 0.18); color: #2f81f7; }
.badge-agent { background: rgba(210, 153, 34, 0.2); color: #d29922; margin-left: 4px; }

.board-drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 60;
}
.board-drawer {
  position: absolute; top: 0; right: 0; height: 100%;
  width: min(580px, 100vw); overflow-y: auto;
  background: var(--bg, #fff); color: inherit;
  box-shadow: -6px 0 24px rgba(0, 0, 0, 0.35);
  padding: 16px 18px 40px;
}
.board-drawer.narrow { width: min(460px, 100vw); }
.board-drawer-head {
  display: flex; align-items: center; gap: 8px;
  position: sticky; top: -16px; background: inherit; padding: 6px 0;
}
.board-drawer-x { margin-left: auto; font-size: 1.1em; }
.board-drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.board-drawer-meta {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: end;
  font-size: 0.85em; margin: 10px 0;
}
.board-drawer-meta label { display: flex; flex-direction: column; gap: 2px; }
.board-session-banner {
  border-left: 3px solid #d29922; padding: 6px 10px; margin: 8px 0;
  background: rgba(210, 153, 34, 0.08); font-size: 0.85em;
}
.board-body {
  white-space: pre-wrap; font-size: 0.88em; background: var(--panel, rgba(127,127,127,0.07));
  padding: 10px; border-radius: 8px;
}
.board-link-row, .board-key {
  display: flex; align-items: center; gap: 8px; font-size: 0.85em;
  padding: 3px 0;
}
.board-link-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-link-add { display: flex; gap: 6px; margin-top: 6px; }
.board-comment { margin-bottom: 8px; font-size: 0.9em; }
.board-activity { font-size: 0.8em; max-height: 260px; overflow-y: auto; }
.board-form label { display: block; margin-bottom: 8px; font-size: 0.9em; }
.board-agent {
  border: 1px solid var(--line, #444); border-radius: 8px;
  padding: 10px; margin-bottom: 10px;
}
.board-key.revoked { opacity: 0.5; text-decoration: line-through; }
.board-secret {
  margin-top: 8px; padding: 8px; border-radius: 8px;
  background: rgba(45, 190, 96, 0.1); border: 1px solid #2dbe60;
  font-size: 0.85em; word-break: break-all;
}

/* ---- admin "view as" banner (ADR 041, SRV-43 Phase 2) ----
   The banner pins above the topbar, and body.subject-mode pushes the
   topbar (and the top-mode section nav, which sticks below it) down by
   the banner's height — without this, both pin at top:0 once scrolled
   and the banner permanently covers the topbar. */
:root { --subject-banner-h: 36px; }
#subject-banner {
  position: sticky; top: 0; z-index: 1000;
  box-sizing: border-box; height: var(--subject-banner-h);
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 0 14px;
  background: #9a6700; color: #fff;
  font-size: 0.92em; white-space: nowrap; overflow: hidden;
}
body.subject-mode .topbar { top: var(--subject-banner-h); }
body.subject-mode.uxv1-top-nav .bottomnav {
  top: calc(var(--subject-banner-h) + var(--topbar-h, 56px));
}
#subject-banner strong { color: #fff; }
#subject-banner button {
  background: rgba(255,255,255,0.16); color: #fff;
  border: 1px solid rgba(255,255,255,0.45); border-radius: 4px;
  padding: 2px 12px; cursor: pointer; font-size: 0.92em;
}
#subject-banner button:active { background: rgba(255,255,255,0.3); }
