:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #16181d;
  --ink-2: #5a5e66;
  --line: #e2e0da;
  --accent: #e5562a;
  --accent-ink: #ffffff;
  --good: #1f7a4d;
  --bad: #b3261e;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1b1e24;
    --ink: #f1f1ee;
    --ink-2: #a3a7ae;
    --line: #2c3038;
    --accent: #f06a3d;
    --accent-ink: #14100e;
    --good: #5fc892;
    --bad: #f2867f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }
h1 { font-size: 1.45rem; line-height: 1.2; margin: 0 0 4px; text-wrap: balance; }
h2 { font-size: 1.05rem; margin: 28px 0 10px; }
p { margin: 0 0 10px; }
.muted { color: var(--ink-2); }
.small { font-size: 0.87rem; }

.bar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { grid-column: 2; font-weight: 700; text-decoration: none; letter-spacing: -0.01em; }
.back { grid-column: 1; grid-row: 1; justify-self: start; font-size: 0.95rem; color: var(--ink-2);
        text-decoration: none; padding: 6px 12px 6px 0; }
.back[hidden] { display: none; }

main { max-width: 720px; margin: 0 auto; padding: 20px 16px 120px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.stack > * + * { margin-top: 12px; }

/* buttons and inputs */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; width: 100%;
  border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer;
}
.button.quiet { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.button.danger { background: transparent; color: var(--bad); border: 1px solid var(--line); }
.button[disabled] { opacity: 0.5; cursor: default; }
label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 6px; }
input[type="text"], input[type="password"] {
  width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink); font: inherit;
}
select {
  width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink); font: inherit;
}
input[hidden] { display: none; }
input[type="file"] { width: 100%; font: inherit; color: var(--ink-2); }
input[type="file"]::file-selector-button {
  min-height: 44px; margin-right: 12px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600;
}
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.link { background: none; border: 0; padding: 8px 0; color: var(--accent); font: inherit;
        text-decoration: underline; cursor: pointer; }
.rename { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.rename[hidden] { display: none; }
.rename input { flex: 1 1 100%; }
.rename .button { flex: 1; width: auto; }
.login { max-width: 380px; margin: 12vh auto 0; }

/* route list */
.route-row {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center;
  text-decoration: none; padding: 10px;
}
.route-row img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.route-row strong { display: block; }
.chev { color: var(--ink-2); font-size: 1.3rem; }
.empty { text-align: center; padding: 36px 16px; color: var(--ink-2); }

/* hold picker */
.picker {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #000; line-height: 0; touch-action: pan-x pan-y pinch-zoom;
}
.picker img { width: 100%; height: auto; display: block; }
.picker svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.hold { fill: transparent; stroke: rgba(255, 255, 255, 0.55); stroke-width: 1.5; cursor: pointer;
        vector-effect: non-scaling-stroke; paint-order: stroke; }
.hold.on { fill: rgba(255, 255, 255, 0.12); stroke: #fff; stroke-width: 3;
           filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.9)); }
.hit { fill: transparent; stroke: transparent; stroke-width: 22; vector-effect: non-scaling-stroke;
       pointer-events: all; cursor: pointer; }
.hold.volume { stroke-dasharray: 7 5; }
.sketch { fill: rgba(229, 86, 42, 0.25); stroke: #fff; stroke-width: 2.5; pointer-events: none;
          vector-effect: non-scaling-stroke; }
.sketch.dot { stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; }
svg.drawing { cursor: crosshair; }
svg.drawing .hit { pointer-events: none; }
.drawbar { margin-top: 12px; }
.drawbar .row { display: flex; gap: 8px; margin-top: 8px; }
.drawbar .row .button { flex: 1; width: auto; padding: 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink); font: inherit; cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.chip i { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(128, 128, 128, 0.5); }
.chip span { color: var(--ink-2); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.savebar > div { max-width: 688px; margin: 0 auto; }

/* climbs */
.climb-row { display: flex; justify-content: space-between; gap: 12px; align-items: center;
             text-decoration: none; padding: 14px 16px; }
.state { font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.state.done { color: var(--good); }
.state.failed { color: var(--bad); }

.progress { text-align: center; padding: 40px 16px; }
.spinner {
  width: 40px; height: 40px; margin: 0 auto 18px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* results */
video { width: 100%; border-radius: var(--radius); background: #000; display: block; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.tile b { display: block; font-size: 1.45rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile span { font-size: 0.82rem; color: var(--ink-2); }
.coach { margin-top: 16px; }
.coach p:last-child { margin-bottom: 0; }
.insight h3 { font-size: 1rem; margin: 0 0 4px; }
.insight .tip { border-left: 3px solid var(--accent); padding-left: 10px; margin-top: 8px; }
.shots { display: flex; gap: 8px; margin-top: 12px; }
.shots figure { margin: 0; flex: 0 1 140px; }
.shots img, .figure img { width: 100%; border-radius: 10px; display: block; }
.shots figcaption { font-size: 0.8rem; color: var(--ink-2); margin-top: 4px; }
.figure { background: #fcfcfb; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.map { max-width: 420px; margin: 0 auto; }
ul.plain { margin: 0; padding-left: 18px; }
ul.plain li + li { margin-top: 6px; }
.sequence { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.changes { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin: 4px 0 8px; }
.changes th, .changes td { text-align: left; padding: 8px 8px 8px 0; border-bottom: 1px solid var(--line); }
.changes thead th { font-size: 0.82rem; font-weight: 600; color: var(--ink-2); }
.changes tbody th { font-weight: 400; }
.changes td:last-child { text-align: right; padding-right: 0; font-size: 0.87rem; font-weight: 600; }
.changes .up { color: var(--good); }
.changes .down { color: var(--bad); }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: 96px; z-index: 10;
  max-width: 480px; margin: 0 auto; padding: 14px 16px;
  background: var(--ink); color: var(--bg); border-radius: 12px;
}

@media (min-width: 600px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .button { width: auto; }
  .savebar .button { width: 100%; }
}
