:root {
  color-scheme: light;
  --bg: #f7f2ec;
  --card: #fffcf8;
  --line: #ece2d6;
  --ink: #1d1613;
  --muted: #8b7c6e;
  --accent: #96243f;
  --accent-soft: #f1e4d4;
  /* The previous period in comparisons: a warm gray that recedes but still clears 3:1 on the card. */
  --previous: #9a8a79;
  --dark: #2f2220;
  --dark-2: #241a18;
  --live: #4f8259;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius: 22px;
  font-family: var(--sans);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
p, h1, h2 { margin: 0; }
h1, h2 { font-family: var(--serif); font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: clamp(2.1rem, 8vw, 2.9rem); line-height: 1.05; }
h2 { font-size: clamp(1.5rem, 5.5vw, 1.9rem); line-height: 1.15; margin-top: 2px; }
img { display: block; max-width: 100%; }
svg { width: 100%; height: 100%; }

.shell {
  display: grid;
  gap: 14px;
  width: min(100%, 620px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}

.eyebrow { color: var(--muted); font-size: .69rem; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.eyebrow.on-dark, .eyebrow.on-photo { color: rgba(255, 255, 255, .62); }
.muted { color: var(--muted); font-size: .85rem; }
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 2px 4px; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; padding: 9px; border-radius: 13px; background: var(--accent-soft); color: var(--accent); flex: none; }
.brand-name { font-family: var(--serif); font-size: 1.32rem; font-weight: 700; }
.status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .84rem; white-space: nowrap; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: #c3b6a8; flex: none; }
.status.live .dot { background: var(--live); box-shadow: 0 0 0 4px rgba(79, 130, 89, .16); }
.status.warn { color: #a8701c; }
.status.warn .dot { background: #c98a2b; box-shadow: 0 0 0 4px rgba(201, 138, 43, .16); }
.status.stale { color: var(--accent); }
.status.stale .dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(150, 36, 63, .14); }

.topbar-end { display: flex; align-items: center; gap: 10px; }
.icon-button { display: grid; place-items: center; width: 38px; height: 38px; padding: 9px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--muted); cursor: pointer; }
.icon-button:hover { color: var(--accent); background: var(--accent-soft); }
.icon-button svg { width: 100%; height: 100%; }

/* Settings sheet */
.sheet { width: min(100% - 24px, 520px); max-height: min(100% - 24px, 760px); margin: auto; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); box-shadow: 0 24px 60px rgba(47, 34, 32, .25); }
.sheet::backdrop { background: rgba(36, 26, 24, .45); backdrop-filter: blur(2px); }
.sheet-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin: 0 0 6px; }
.setting-group { padding: 18px 0; border-top: 1px solid var(--line); }
.setting-group:first-of-type { border-top: 0; }
.setting-group[hidden] { display: none; }
.field-label { font-weight: 700; font-size: .95rem; }
.field-help { margin-top: 8px; color: var(--muted); font-size: .8rem; line-height: 1.45; }
.field-help code { font-size: .78rem; }
.field { width: 100%; margin-top: 10px; padding: 11px 13px; border: 1px solid #e0d3c3; border-radius: 12px; background: #fff; color: var(--ink); font: inherit; font-size: .9rem; }
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.field.compact { width: auto; margin: 0; padding: 7px 10px; }
.webhook-state { margin-top: 6px; color: var(--muted); font-size: .86rem; }
.webhook-state b { color: var(--live); }
.webhook-form { display: flex; gap: 8px; align-items: end; }
.webhook-form .field { flex: 1; min-width: 0; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.button { padding: 10px 15px; border: 1px solid var(--line); border-radius: 99px; background: var(--card); color: var(--ink); font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.button:hover { background: var(--accent-soft); }
.button.primary { margin-top: 10px; border-color: var(--accent); background: var(--accent); color: #fff; }
.button.primary:hover { background: #7e1d35; }
.button.quiet { border-color: transparent; color: var(--accent); }
.button:disabled { opacity: .5; cursor: default; }
.toggle { display: flex; align-items: start; gap: 12px; margin-top: 14px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle b { display: block; font-size: .9rem; }
.toggle small { display: block; margin-top: 2px; color: var(--muted); font-size: .78rem; }
.switch { position: relative; flex: none; width: 40px; height: 24px; margin-top: 1px; border-radius: 99px; background: #e0d3c3; transition: background .18s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .18s; }
.toggle input:checked + .switch { background: var(--accent); }
.toggle input:checked + .switch::after { transform: translateX(16px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle input:disabled + .switch { opacity: .5; }
.weekly-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 12px 0 0 52px; color: var(--muted); font-size: .84rem; }
.field::placeholder { color: #b8a998; }
/* Pinned to the bottom of the sheet, so feedback is visible wherever the button that caused it is. */
.sheet-message { position: sticky; bottom: -22px; margin: 0 -22px -22px; padding: 12px 22px 16px; border-top: 1px solid transparent; background: var(--card); font-size: .84rem; font-weight: 600; }
.sheet-message:empty { padding: 0; border: 0; }
.sheet-message:not(:empty) { border-top-color: var(--line); }
.sheet-message.ok { color: var(--live); }
.sheet-message.error { color: var(--accent); }

/* Hero photo */
.hero { position: relative; overflow: hidden; border-radius: var(--radius); isolation: isolate; }
.hero img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 45%; position: absolute; inset: 0; }
.hero-body {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 22px;
  min-height: 330px;
  padding: 22px;
  color: #fff;
  background: linear-gradient(180deg, rgba(20, 8, 6, .55) 0%, rgba(20, 8, 6, .06) 42%, rgba(20, 8, 6, .5) 100%);
  text-shadow: 0 1px 14px rgba(0, 0, 0, .35);
}
.hero h1 { margin-top: 6px; }
.route {
  display: inline-flex; align-items: center; gap: 9px; align-self: start;
  padding: 10px 17px; border: 1px solid rgba(255, 255, 255, .38); border-radius: 99px;
  background: rgba(28, 14, 12, .3); backdrop-filter: blur(7px);
  font-size: .85rem; font-weight: 600;
}
.route svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.route-arrow { opacity: .7; }

/* Live card */
section.live { padding: 22px; border-radius: var(--radius); background: linear-gradient(165deg, var(--dark), var(--dark-2)); color: #f6efe6; }
.range-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 4px; margin-bottom: 22px; border-radius: 99px; background: rgba(255, 255, 255, .07); }
.range-picker button { border: 0; border-radius: 99px; padding: 11px 8px; background: transparent; color: rgba(255, 255, 255, .62); font: inherit; font-size: .92rem; cursor: pointer; transition: background .18s, color .18s; }
.range-picker button.active { background: #ecdcc4; color: #2b201e; font-weight: 600; }
.live-line { font-family: var(--serif); font-size: 1.22rem; font-style: italic; margin: 7px 0 20px; color: #efe3d5; }
.speed { display: flex; align-items: baseline; gap: 4px; margin-top: 6px; color: #fff; }
.speed span { font-size: clamp(3.6rem, 17vw, 5rem); font-weight: 800; line-height: .85; letter-spacing: -.05em; }
.speed small { font-size: .95rem; font-weight: 600; opacity: .75; }
.live-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 24px; }
.live-tiles > div { padding: 13px 15px; border: 1px solid rgba(255, 255, 255, .13); border-radius: 15px; background: rgba(255, 255, 255, .04); }
.mini-label { color: rgba(255, 255, 255, .55); font-size: .78rem; }
.mini-value { margin-top: 5px; font-size: 1.28rem; font-weight: 700; }

/* Journey */
.journey { padding: 22px; background: linear-gradient(140deg, #f7ecdd 0%, #fffcf8 62%); border-color: #eadcc9; }
.journey-head { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.journey-total { text-align: right; flex: none; }
.journey-value { font-size: clamp(1.7rem, 7vw, 2.2rem); font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.journey-of { margin-top: 4px; color: var(--muted); font-size: .84rem; }
.track { display: grid; grid-template-columns: auto minmax(60px, 1fr) auto; align-items: center; gap: 10px; margin: 22px 0 14px; }
.track-label { font-size: .78rem; font-weight: 700; }
.track-bar { height: 9px; border-radius: 99px; background: #e2d2bd; }
.track-fill { position: relative; height: 100%; min-width: 9px; border-radius: 99px; background: var(--accent); transition: width .5s ease; }
.track-dot { position: absolute; right: -5px; top: 50%; width: 19px; height: 19px; transform: translate(0, -50%); border: 3px solid #fffcf8; border-radius: 50%; background: var(--accent); box-shadow: 0 2px 6px rgba(88, 20, 34, .3); }
.journey-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .84rem; }
.journey-foot b { color: var(--ink); font-size: .95rem; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { padding: 17px; }
.tile-icon { display: grid; place-items: center; width: 36px; height: 36px; padding: 9px; margin-bottom: 15px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); }
.tile-value { margin-top: 9px; font-size: clamp(1.45rem, 6vw, 1.75rem); font-weight: 800; letter-spacing: -.02em; }

/* Comparison */
.compare-card { padding: 22px 20px; }
.change { flex: none; padding: 6px 11px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.change.down { background: #efe9e2; color: var(--muted); }
.change[hidden] { display: none; }
.compare-line { margin-top: 12px; color: var(--muted); font-size: .9rem; }
.compare-line b { color: var(--ink); font-size: 1.05rem; }
.legend { display: flex; gap: 16px; margin-top: 16px; color: var(--muted); font-size: .78rem; }
.legend > span { display: inline-flex; align-items: center; gap: 7px; }
.key { display: inline-block; width: 16px; height: 2px; border-radius: 1px; }
.key.now { background: var(--accent); }
.key.before { background: var(--previous); }

/* Pace chart: running totals, so "so far" against "by this point" is one glance. */
.pace { position: relative; margin-top: 8px; touch-action: pan-y; }
#pace-chart { display: block; width: 100%; height: 190px; overflow: visible; }
.pace .gridline { stroke: #efe6db; stroke-width: 1; }
.pace .baseline { stroke: #e3d7c8; stroke-width: 1; }
.pace .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.pace .line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pace .line.now { stroke: var(--accent); }
.pace .line.before { stroke: var(--previous); }
.pace .wash { fill: var(--accent); opacity: .1; }
.pace .now-rule { stroke: #e3d7c8; stroke-width: 1; }
.pace .dot { stroke: var(--card); stroke-width: 2; }
.pace .dot.now { fill: var(--accent); }
.pace .dot.before { fill: var(--previous); }
.pace .end-label { font-size: 11.5px; font-weight: 700; fill: var(--ink); font-variant-numeric: tabular-nums; }
.pace .end-label.before { font-weight: 600; fill: var(--muted); }
.pace .crosshair { stroke: #cdbfae; stroke-width: 1; }
.pace-tip { position: absolute; top: 0; min-width: 132px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); box-shadow: 0 6px 18px rgba(47, 34, 32, .12); font-size: .78rem; pointer-events: none; }
.pace-tip p { display: flex; align-items: center; gap: 7px; }
.pace-tip p + p { margin-top: 3px; }
.pace-tip .tip-title { color: var(--muted); margin-bottom: 5px; }
.pace-tip b { font-variant-numeric: tabular-nums; }
.pace-tip .tip-name { color: var(--muted); }
.compare-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 12px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.compare-value { margin-top: 6px; font-size: 1.2rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.compare-was { margin-top: 2px; color: var(--muted); font-size: .78rem; }
.compare-stats abbr { text-decoration: underline dotted; cursor: help; }
[hidden] { display: none !important; }

/* Personal bests */
.records-card { padding: 22px 20px; }
.records-card[hidden] { display: none; }
.streak { display: flex; align-items: center; gap: 14px; margin-top: 18px; padding: 15px 16px; border-radius: 16px; background: var(--accent-soft); }
.streak-icon { display: grid; place-items: center; width: 42px; height: 42px; padding: 9px; border-radius: 13px; background: var(--card); color: var(--accent); flex: none; }
.streak-value { font-family: var(--serif); font-size: 1.2rem; font-weight: 700; }
.streak-value #streak-days { font-family: var(--sans); font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.streak-note { margin-top: 2px; color: var(--muted); font-size: .84rem; }
.bests { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 14px; margin-top: 20px; }
.best-value { margin-top: 6px; font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.best-when { margin-top: 2px; color: var(--muted); font-size: .8rem; }
.best-new { display: inline-block; margin-left: 6px; padding: 2px 7px; border-radius: 99px; background: var(--accent); color: #fff; font-size: .62rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; vertical-align: 3px; }

.export-link { display: inline-flex; align-items: center; gap: 6px; flex: none; padding: 8px 13px; border: 1px solid var(--line); border-radius: 99px; color: var(--accent); font-size: .82rem; font-weight: 600; text-decoration: none; }
.export-link svg { width: 15px; height: 15px; }
.export-link:hover { background: var(--accent-soft); }

/* Chart */
.chart-card, .log-card { padding: 22px 20px; }
.section-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.section-heading .muted { flex: none; padding-top: 2px; }
.chart-wrap { position: relative; margin-top: 22px; }
#speed-chart { display: block; width: 100%; height: 190px; overflow: visible; }
.grid { stroke: #e3d7c8; stroke-width: 1; stroke-dasharray: 2 6; vector-effect: non-scaling-stroke; }
.speed-line { fill: none; stroke: var(--accent); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: .88rem; }
.chart-empty[hidden] { display: none; }
.axis { display: flex; justify-content: space-between; position: relative; margin-top: 14px; color: var(--muted); font-size: .8rem; }
.axis-noon { position: absolute; transform: translateX(-50%); }
.axis-noon[hidden] { display: none; }

/* Activity log */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; margin-top: 16px; }
th, td { padding: 15px 6px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
th { border-bottom: 1px solid var(--line); color: var(--muted); font-size: .69rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
tbody tr + tr td { border-top: 1px solid var(--line); }
td { font-size: .95rem; font-variant-numeric: tabular-nums; }
.when-day { font-weight: 700; }
.when-time { margin-top: 3px; color: var(--muted); font-size: .8rem; }
.empty { color: var(--muted); text-align: center !important; padding: 34px 6px; }

@media (min-width: 560px) {
  .hero-body { min-height: 400px; padding: 26px; }
  section.live, .journey, .compare-card, .records-card, .chart-card, .log-card { padding: 26px; }
  #pace-chart { height: 210px; }
  #speed-chart { height: 220px; }
}

@media (min-width: 900px) {
  .shell { width: min(100%, 1080px); grid-template-columns: 1fr 1fr; gap: 16px; padding-top: 30px; }
  .topbar, .journey, .compare-card, .records-card, .chart-card, .log-card { grid-column: 1 / -1; }
  .bests { grid-template-columns: repeat(4, 1fr); }
  .hero-body { min-height: 100%; }
  .tiles { grid-column: 1 / -1; grid-template-columns: repeat(4, 1fr); }
  section.live { display: flex; flex-direction: column; }
  .live-tiles { margin-top: auto; padding-top: 24px; }
  #speed-chart { height: 260px; }
}

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