/* ── Tokens ─────────────────────────────────────────────────────────── */

:root {
  color-scheme: light dark;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Helvetica Neue", Inter, system-ui, sans-serif;

  /* Surfaces */
  --bg:            #f2f2f7;
  --surface:       #ffffff;
  --surface-sunk:  #ffffff;
  --fill:          rgba(120, 120, 128, 0.10);
  --fill-strong:   rgba(120, 120, 128, 0.16);

  /* Text */
  --label:      #1d1d1f;
  --label-2:    rgba(60, 60, 67, 0.60);
  --label-3:    rgba(60, 60, 67, 0.32);

  /* Grades */
  --green:  #34c759;
  --blue:   #007aff;
  --red:    #ff3b30;
  --black:  #1c1c1e;
  --skills: #ff9500;
  --link:   #8e8e93;
  --road:   #a2845e;

  /* Grade wash behind a run row. Kept faint: it is what separates rows
     without a rule, and a second cue for grade — the glyph is the first. */
  --tint:  0.065;

  /* A card reads as a card because it is white on a tinted canvas.
     No stroke, no shadow — that is the whole mechanism. */

  --r-card: 24px;
  --r-row:  14px;
  --r-thumb: 9px;

  --ease: cubic-bezier(0.4, 0, 0.6, 1);   /* Apple's standard, symmetric */
  --t:    0.32s;
  --t-quick: 0.24s;
  --t-hover: 0.1s;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #000000;
    --surface:      #1c1c1e;
    --surface-sunk: #141416;
    --fill:         rgba(120, 120, 128, 0.24);
    --fill-strong:  rgba(120, 120, 128, 0.36);

    --label:   #f5f5f7;
    --label-2: rgba(235, 235, 245, 0.60);
    --label-3: rgba(235, 235, 245, 0.30);

    --green:  #30d158;
    --blue:   #0a84ff;
    --red:    #ff453a;
    --black:  #d1d1d6;
    --skills: #ff9f0a;
    --link:   #98989d;
    --road:   #ac8e68;

    --tint: 0.15;
  }
}

/* ── Base ───────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 0 max(48px, env(safe-area-inset-bottom));
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.47059;
  letter-spacing: -0.022em;
  color: var(--label);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 20px;
}

a { color: inherit; text-decoration: none; }

/* ── Masthead ───────────────────────────────────────────────────────── */

.masthead { padding: 64px 0 24px; }

.masthead h1 {
  margin: 0;
  font-size: 48px;
  line-height: 1.08349;
  font-weight: 600;
  letter-spacing: -0.003em;
}

.standfirst {
  margin: 14px 0 0;
  font-size: 21px;
  line-height: 1.381;
  letter-spacing: 0.011em;
  font-weight: 400;
  color: var(--label-2);
  max-width: 30em;
}

/* ── Day switcher ───────────────────────────────────────────────────── */

.daybar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 10px 0 12px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 2px;
  border-radius: 11px;
  background: var(--fill);
}

.segmented button {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 7px 12px;
  font: inherit;
  font-size: 15px;
  font-weight: 590;
  letter-spacing: -0.01em;
  color: var(--label);
  background: transparent;
  border-radius: 9px;
  cursor: pointer;
  transition: background var(--t-quick) var(--ease), transform var(--t-quick) var(--ease);
}

.segmented button[aria-selected="true"] {
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.10), 0 0 0 0.5px rgba(0,0,0,0.04);
}

@media (prefers-color-scheme: dark) {
  .segmented button[aria-selected="true"] { background: #48484a; box-shadow: none; }
}

.segmented button:active { transform: scale(0.97); }

/* ── Day stats ──────────────────────────────────────────────────────── */

.daystats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 0 4px;
}

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 14px;
  line-height: 1.42859;
  letter-spacing: -0.016em;
  color: var(--label-2);
}

.stat b {
  font-size: 15px;
  font-weight: 640;
  color: var(--label);
  font-variant-numeric: tabular-nums;
}

/* ── Blocks ─────────────────────────────────────────────────────────── */

.day { padding-top: 12px; }

.block { margin: 20px 0; }

.block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 10px;
  padding: 0 4px 10px;
}

.block-badge {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 9px;
  border-radius: 9px;
  background: var(--label);
  color: var(--bg);
  font-size: 15px;
  font-weight: 640;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.block-title {
  font-size: 21px;
  line-height: 1.19048;
  font-weight: 600;
  letter-spacing: 0.011em;
}

.block-sub {
  margin-left: auto;
  font-size: 14px;
  color: var(--label-2);
  white-space: nowrap;
}

.block.is-soft .block-badge {
  background: var(--fill-strong);
  color: var(--label);
}

.block.is-optional .block-title::after {
  content: "Optional";
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 12px;
  font-weight: 590;
  letter-spacing: 0;
  color: var(--label-2);
  vertical-align: 3px;
}

.card {
  padding: 8px;
  border-radius: var(--r-card);
  background: var(--surface);
}

/* ── Run row ────────────────────────────────────────────────────────── */

.run {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: var(--r-row);
  background: color-mix(in srgb, var(--g) calc(var(--tint) * 100%), transparent);
  transition: background var(--t-hover) var(--ease), transform var(--t-hover) var(--ease);
}

.run + .run { margin-top: 5px; }

a.run { cursor: pointer; -webkit-tap-highlight-color: transparent; }

@media (hover: hover) {
  a.run:hover {
    background: color-mix(in srgb, var(--g) calc(var(--tint) * 210%), transparent);
  }
}

a.run:active { transform: scale(0.985); }

.run-name {
  font-size: 17px;
  line-height: 1.29;
  font-weight: 590;
  letter-spacing: -0.022em;
  overflow-wrap: anywhere;
}

.run-meta {
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.38;
  letter-spacing: -0.008em;
  color: var(--label-2);
}

.run-grade { font-weight: 590; color: color-mix(in srgb, var(--g) 78%, var(--label)); }

@media (prefers-color-scheme: dark) {
  .run-grade { color: var(--g); }
}

.run-note::before { content: " · "; color: var(--label-3); }

/* Grade + character glyph */
.glyph { display: block; width: 34px; height: 34px; }

/* Thumbnail */
.thumb {
  position: relative;
  width: 104px;
  height: 59px;
  flex: none;
  border-radius: var(--r-thumb);
  overflow: hidden;
  background: var(--fill-strong);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(0,0,0,0.22), rgba(0,0,0,0.04) 62%);
}

.play {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  z-index: 1;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
  transition: scale var(--t-hover) var(--ease);
}

.play svg { width: 11px; height: 13px; margin-left: 1.5px; fill: #1c1c1e; }

@media (hover: hover) { a.run:hover .play { scale: 1.12; } }

.nofilm {
  padding-right: 6px;
  font-size: 13px;
  color: var(--label-3);
  letter-spacing: -0.005em;
  white-space: nowrap;
}

/* Links and fire roads move you between trails — they sit back. */
.run.is-transit {
  padding-top: 6px;
  padding-bottom: 6px;
  background: none;
}

.run.is-transit .run-name { font-size: 15px; font-weight: 510; color: var(--label-2); }
.run.is-transit .run-meta { font-size: 12px; }
.run.is-transit .glyph { opacity: 0.75; }

/* ── Key ────────────────────────────────────────────────────────────── */

.key { margin: 34px 0 0; }

.key h2 {
  margin: 0 0 12px;
  padding: 0 4px;
  font-size: 21px;
  line-height: 1.19048;
  font-weight: 600;
  letter-spacing: 0.011em;
}

.key-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px;
  padding: 10px;
  border-radius: var(--r-card);
  background: var(--surface);
}

.key-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--g) calc(var(--tint) * 100%), transparent);
}

.key-item span {
  font-size: 14px;
  font-weight: 560;
  letter-spacing: -0.008em;
}

.key-note {
  margin: 14px 4px 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--label-2);
}

/* ── Footer ─────────────────────────────────────────────────────────── */

.foot {
  margin-top: 36px;
  padding: 0 4px;
  font-size: 13px;
  line-height: 1.55;
  letter-spacing: -0.008em;
  color: var(--label-2);
}

/* ── Motion ─────────────────────────────────────────────────────────── */

@keyframes swap {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.day { animation: swap var(--t) var(--ease); }

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

/* ── Narrow ─────────────────────────────────────────────────────────── */

@media (max-width: 734px) {
  .masthead h1 { font-size: 40px; line-height: 1.1; letter-spacing: 0em; }
  .standfirst { font-size: 19px; line-height: 1.42105; letter-spacing: 0.012em; }
}

@media (max-width: 420px) {
  .wrap { padding: 0 14px; }
  .masthead { padding-top: 44px; }
  .run { grid-template-columns: 30px minmax(0, 1fr) auto; gap: 10px; padding: 8px; }
  .glyph { width: 30px; height: 30px; }
  .thumb { width: 88px; height: 50px; }
  /* Narrow screens wrap the count onto its own line rather than dropping
     it — it is the only place a break says what you ride down on. */
  .block-sub { flex-basis: 100%; margin: -2px 0 0 40px; white-space: normal; }
}

.run-text { display: block; min-width: 0; }
.run-name, .run-meta { display: block; }

.run-dist::before,
.run-note::before { content: " · "; color: var(--label-3); }

.run-meta > :first-child::before { content: none; }

.run-dist { font-variant-numeric: tabular-nums; }

.plus {
  display: inline-block;
  margin-left: 5px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  color: var(--g);
  vertical-align: 1px;
}

/* ── Player ─────────────────────────────────────────────────────────── */

/* Scroll is pinned while the sheet is up; body.top preserves the position. */
body.is-playing {
  position: fixed;
  inset-inline: 0;
  overflow: hidden;
  width: 100%;
}

.player {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
}

.player[hidden] { display: none; }

.player-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  -webkit-backdrop-filter: saturate(140%) blur(24px);
  backdrop-filter: saturate(140%) blur(24px);
  animation: scrim-in var(--t) var(--ease);
}

.player-sheet {
  position: relative;
  width: min(940px, 100%);
  animation: sheet-in var(--t) var(--ease);
}

.player-bar {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 0 4px 12px;
  color: #fff;
}

.player-heading { min-width: 0; }

.player-title {
  display: block;
  font-size: 21px;
  line-height: 1.19048;
  font-weight: 600;
  letter-spacing: 0.011em;
}

.player-meta {
  display: block;
  margin-top: 2px;
  font-size: 14px;
  line-height: 1.42859;
  letter-spacing: -0.016em;
  color: rgba(235, 235, 245, 0.62);
}

.player-close {
  appearance: none;
  flex: none;
  margin-left: auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
  transition: background var(--t-hover) var(--ease);
}

.player-close svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
}

@media (hover: hover) {
  .player-close:hover { background: rgba(255, 255, 255, 0.28); }
}

.player-close:active { transform: scale(0.94); }

.player-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  overflow: hidden;
  background: #000;
}

.player-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

@keyframes scrim-in { from { opacity: 0; } }
@keyframes sheet-in { from { opacity: 0; transform: scale(0.97) translateY(10px); } }

@media (max-width: 420px) {
  .player { padding: 14px; }
  .player-frame { border-radius: 14px; }
  .player-title { font-size: 19px; }
}

/* ── Day line ───────────────────────────────────────────────────────── */

.dayline {
  margin: 0;
  padding: 14px 4px 0;
  font-size: 14px;
  line-height: 1.42859;
  letter-spacing: -0.016em;
}

.dayline-date { font-weight: 590; color: var(--label); }

.dayline-wx { color: var(--label-2); }
.dayline-wx::before { content: " · "; color: var(--label-3); }

/* ── Condition chip ─────────────────────────────────────────────────── */

.cond {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 4px 0 0;
  padding: 3px 9px 3px 6px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  font-weight: 590;
  letter-spacing: -0.004em;
  line-height: 1.4;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t-hover) var(--ease);
}

.cond svg { width: 12px; height: 12px; flex: none; }

.cond[data-tone="warn"] { background: rgba(255, 149, 0, 0.16); color: #a35a00; }
.cond[data-tone="damp"] { background: rgba(0, 122, 255, 0.13); color: #0057b3; }
.cond[data-tone="fine"] { background: rgba(52, 199, 89, 0.16); color: #1a7a37; }

@media (prefers-color-scheme: dark) {
  .cond[data-tone="warn"] { background: rgba(255, 159, 10, 0.22); color: #ffb340; }
  .cond[data-tone="damp"] { background: rgba(10, 132, 255, 0.22); color: #6cb6ff; }
  .cond[data-tone="fine"] { background: rgba(48, 209, 88, 0.22); color: #56d97a; }
}

@media (hover: hover) {
  .cond[data-tone="warn"]:hover { background: rgba(255, 149, 0, 0.28); }
  .cond[data-tone="damp"]:hover { background: rgba(0, 122, 255, 0.24); }
  .cond[data-tone="fine"]:hover { background: rgba(52, 199, 89, 0.28); }
}

.cond:active { transform: scale(0.96); }

/* ── Explanation bubble ─────────────────────────────────────────────── */

.bubble {
  position: fixed;
  z-index: 90;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(28, 28, 30, 0.96);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: #f5f5f7;
  font-size: 13px;
  line-height: 1.46;
  letter-spacing: -0.006em;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.28);
  animation: bubble-in var(--t-quick) var(--ease);
  pointer-events: none;
}

.bubble[hidden] { display: none; }

@media (prefers-color-scheme: dark) {
  .bubble { background: rgba(58, 58, 60, 0.96); }
}

@keyframes bubble-in { from { opacity: 0; transform: translateY(3px); } }
