:root {
  color-scheme: light;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --swim: #0ea5e9;
  --bike: #16a34a;
  --run: #f97316;
  --brick: #d946ef;
  --strength: #a855f7;
  --rest: #94a3b8;
  --crit-bg: #fff7ed;
  --crit-border: #fdba74;
  --crit-text: #9a3412;
  --good-bg: #f0fdf4;
  --good-border: #86efac;
  --good-text: #166534;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 64px;
  --max: 520px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-ink: #0f172a;
  --bike: #22c55e;
  --crit-bg: #431407;
  --crit-border: #c2410c;
  --crit-text: #fed7aa;
  --good-bg: #052e16;
  --good-border: #16a34a;
  --good-text: #bbf7d0;
  --shadow: none;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0 auto;
  max-width: var(--max);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding: calc(12px + var(--safe-top)) 16px calc(var(--nav-h) + 20px + var(--safe-bottom));
  -webkit-text-size-adjust: 100%;
}

body.auth-screen { padding-bottom: calc(28px + var(--safe-bottom)); }
body.has-actions { padding-bottom: calc(var(--nav-h) + 84px + var(--safe-bottom)); }
body.overlay-open { overflow: hidden; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
input, textarea, select { font-size: 16px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

a { color: var(--accent); }

h1 {
  margin: 0;
  font-size: 1.65rem;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.03em;
}

h2 {
  margin: 22px 0 10px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

h2:first-child { margin-top: 0; }

h3 { margin: 0; font-size: 0.95rem; }

.top { margin-bottom: 14px; }

.top-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.top-text { flex: 1; min-width: 0; }

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.subtitle, .hint, .card-detail, .disclaimer, .focus-line {
  color: var(--muted);
  font-size: 0.88rem;
}

.subtitle { margin: 4px 0 0; }
.focus-line { margin: 0 0 10px; font-weight: 600; color: var(--text); }
.disclaimer { margin-top: 22px; font-size: 0.78rem; }
.goal { margin: 0 0 12px; font-size: 0.92rem; }

.icon-btn, .text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--surface2);
  font-weight: 700;
}

.text-btn { padding: 0 12px; font-size: 0.85rem; }
.icon-btn { font-size: 1.35rem; }
.icon-btn.is-disabled { opacity: 0.35; }

.switcher {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
}

.card, .stat {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 8px;
}

a.card {
  display: block;
  text-decoration: none;
  color: inherit;
}

.card.today {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 28%, transparent);
}

.card.recovery { border-left: 4px solid #14b8a6; }
.session { border-left: 4px solid var(--rest); }
.session.sport-swim { border-left-color: var(--swim); }
.session.sport-bike { border-left-color: var(--bike); }
.session.sport-run { border-left-color: var(--run); }
.session.sport-brick { border-left-color: var(--brick); }
.session.sport-strength { border-left-color: var(--strength); }
.session.status-done { background: color-mix(in srgb, var(--good-bg) 65%, var(--surface)); }
.session.status-skipped { opacity: 0.72; }
.session.status-skipped .card-title { text-decoration: line-through; }

.card-header, .progress-head, .part-head, .rpe-head, .week-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.card-date, .sport-label { font-size: 0.78rem; font-weight: 700; color: var(--muted); }
.card-title { font-size: 1rem; font-weight: 700; margin-top: 2px; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }

.badge {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--text);
}
.badge.today { background: var(--accent); color: var(--accent-ink); }
.badge.done { background: var(--bike); color: white; }
.badge.skipped, .badge.optional { background: var(--surface2); color: var(--muted); }
.badge.test { background: var(--run); color: white; }
.badge.recovery { background: #14b8a6; color: white; }
.badge.zone { text-transform: none; letter-spacing: 0; font-size: 0.72rem; }

.day { scroll-margin-top: 84px; margin-top: 8px; }
.day h2 {
  margin: 14px 0 8px;
  font-size: 0.95rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
  font-weight: 800;
}
.day.today h2 { color: var(--accent); }
.rest-line {
  margin: 0 0 8px;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface2) 55%, transparent);
}

.daystrip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  padding: 6px 0 8px;
  margin: 0 -4px 6px;
}

.daypill {
  appearance: none;
  border: 0;
  background: transparent;
  border-radius: 12px;
  min-height: 64px;
  padding: 6px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--muted);
}
.daypill.today {
  background: var(--accent);
  color: var(--accent-ink);
}
.dow { font-size: 0.68rem; font-weight: 700; }
.dom { font-size: 0.95rem; font-weight: 800; }
.dots { display: flex; gap: 2px; min-height: 6px; align-items: center; }
.dot { width: 6px; height: 6px; border-radius: 99px; background: var(--rest); display: block; }
.dot.sport-swim { background: var(--swim); }
.dot.sport-bike { background: var(--bike); }
.dot.sport-run { background: var(--run); }
.dot.sport-brick { background: var(--brick); }
.dot.sport-strength { background: var(--strength); }
.daypill.today .dot { background: var(--accent-ink); }

.bar-track {
  height: 8px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.bar-track.thin { height: 6px; }
.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  width: 0;
}
.bar-fill.swim { background: var(--swim); }
.bar-fill.run { background: var(--run); }
.bar-fill.recovery { background: #14b8a6; }

.progress-head strong { font-size: 1.15rem; }
.progress-head span, .stat-label { color: var(--muted); font-size: 0.75rem; }
.stat { text-align: left; }
.stat-value { font-size: 1.25rem; font-weight: 800; }
.stat-value span { color: var(--muted); font-weight: 700; font-size: 1rem; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.alert {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 10px;
  font-size: 0.88rem;
  border: 1px solid;
}
.alert strong { display: block; margin-bottom: 2px; }
.alert.crit { background: var(--crit-bg); border-color: var(--crit-border); color: var(--crit-text); }
.alert.good { background: var(--good-bg); border-color: var(--good-border); color: var(--good-text); }
.alert p { margin: 0 0 4px; }
.alert p:last-child { margin: 0; }

.part {
  padding: 12px 0;
  border-bottom: 1px solid var(--surface2);
}
.part:last-child { border-bottom: 0; }
.parts {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 4px 16px;
  margin-bottom: 12px;
}
.part-struct { margin: 6px 0 0; font-weight: 800; }
.part-text { margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }
.pace { margin: 6px 0 0; font-variant-numeric: tabular-nums; font-size: 0.92rem; }
.pace strong { font-size: 1rem; }

.chips, .quick-row, .btn-row, .video-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chips, .quick-row { margin-top: 8px; }

.chip, .chip-btn, .video-link {
  appearance: none;
  border: 1px solid var(--surface2);
  background: var(--surface2);
  color: var(--text);
  border-radius: 999px;
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
}
.chip-btn.on, .rpe-btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.video-link { background: transparent; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; font-weight: 700; color: var(--muted); margin-bottom: 12px; }
.field input, .field textarea {
  width: 100%;
  border: 1px solid var(--surface2);
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 48px;
  color: var(--text);
}
.search-field { margin-top: 4px; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  min-height: 48px;
  padding: 12px 14px;
  font-weight: 800;
  background: var(--surface2);
  color: var(--text);
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--surface2); }
.btn-text {
  background: transparent;
  color: var(--muted);
  min-height: 44px;
}
.btn-row .btn, .actionbar .btn { flex: 1; }
.logout { width: 100%; margin-top: 18px; }

.actionbar {
  position: fixed;
  z-index: 40;
  left: 50%;
  transform: translateX(-50%);
  width: min(var(--max), 100%);
  bottom: calc(var(--nav-h) + var(--safe-bottom));
  display: flex;
  gap: 8px;
  padding: 8px 16px 10px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
}

.rpe-row { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.rpe-btn {
  appearance: none;
  border: 0;
  background: var(--surface2);
  border-radius: 10px;
  min-height: 40px;
  font-weight: 800;
  padding: 0;
}
.rpe-block { margin-bottom: 12px; }
.rpe-head { margin-bottom: 6px; font-size: 0.82rem; font-weight: 700; color: var(--muted); }

.section-title {
  margin: 0 0 8px;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  text-transform: none;
  color: var(--text);
}

.preview { font-weight: 800; color: var(--text); }

.status-banner.done { background: var(--good-bg); border-color: var(--good-border); color: var(--good-text); }
.status-banner.skipped { color: var(--muted); }
.status-line { font-weight: 800; margin: 0 0 4px; }

nav {
  position: fixed;
  z-index: 50;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(var(--max), 100%);
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-top: 1px solid var(--surface2);
  backdrop-filter: blur(16px);
}
nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 700;
  min-height: 44px;
}
nav a.active { color: var(--accent); }
.nav-icon { font-size: 1.25rem; line-height: 1; }

.hero-stat { display: flex; gap: 14px; align-items: center; }
.ring { position: relative; width: 92px; height: 92px; flex: none; }
.ring svg { width: 100%; height: 100%; }
.ring-bg, .ring-fg { fill: none; stroke-width: 3.2; }
.ring-bg { stroke: var(--surface2); }
.ring-fg {
  stroke: var(--accent);
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}
.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}
.ring-label span { font-size: 0.68rem; color: var(--muted); font-weight: 700; }

.week-row { display: block; text-decoration: none; color: inherit; padding: 10px 0; border-bottom: 1px solid var(--surface2); }
.week-row:last-child { border-bottom: 0; }
.week-rows { padding-top: 4px; padding-bottom: 4px; }

.css-chart svg { width: 100%; height: auto; display: block; }
.css-chart polyline { fill: none; stroke: var(--swim); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.css-chart circle { fill: var(--swim); }
.css-chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.css-chart .target-line { stroke: var(--run); stroke-dasharray: 4 3; stroke-width: 1.5; }
.css-chart .target-label { fill: var(--run); font-size: 10px; font-weight: 700; }

.history { list-style: none; margin: 12px 0 0; padding: 0; }
.history li { padding: 8px 0; border-top: 1px solid var(--surface2); }
.history a { display: flex; justify-content: space-between; gap: 8px; text-decoration: none; color: inherit; font-weight: 700; min-height: 32px; align-items: center; }
.history .hint { display: block; }

.target-list { list-style: none; margin: 12px 0 0; padding: 0; }
.target-list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--surface2); font-size: 0.88rem; }
.target-list span { color: var(--muted); text-align: right; }

.layout-row { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--surface2); font-size: 0.9rem; }
.layout-row:last-child { border-bottom: 0; }

.gloss-toggle {
  appearance: none;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  font-weight: 800;
  min-height: 44px;
  padding: 0;
}
.gloss.open .chev { transform: rotate(90deg); }
.chev { color: var(--muted); font-size: 1.2rem; }
.gloss-body { padding-top: 8px; }
.gloss-body p { margin: 0 0 8px; }

.empty { text-align: center; padding: 28px 18px; }
.empty-mark { font-size: 1.8rem; margin: 0 0 8px; }
.empty-title { font-size: 1.15rem; font-weight: 800; margin: 0 0 12px; letter-spacing: -0.02em; }
.empty .btn { width: 100%; margin-top: 8px; }

.auth { padding-top: 28px; }
.brand-mark { display: flex; gap: 8px; margin: 0 0 16px; }
.brand-mark .b { width: 42px; height: 10px; border-radius: 99px; display: block; }
.brand-mark .swim { background: var(--swim); }
.brand-mark .bike { background: var(--bike); }
.brand-mark .run { background: var(--run); }
.auth-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 16px 0; }
.auth-switch button {
  appearance: none;
  border: 0;
  background: var(--surface);
  border-radius: 12px;
  min-height: 44px;
  font-weight: 800;
  color: var(--muted);
}
.auth-switch button.on { background: var(--accent); color: var(--accent-ink); }
.auth .btn { width: 100%; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 42, 0.48);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.overlay[hidden] { display: none; }
.sheet {
  position: relative;
  width: min(var(--max), 100%);
  max-height: min(78vh, 640px);
  overflow: auto;
  background: var(--surface);
  color: var(--text);
  border-radius: 22px 22px 0 0;
  padding: 22px 18px calc(18px + var(--safe-bottom));
}
.sheet-close { position: absolute; top: 10px; right: 10px; }

.toast {
  position: fixed;
  z-index: 90;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 18px);
  transform: translateX(-50%) translateY(8px);
  max-width: calc(var(--max) - 32px);
  width: max-content;
  background: var(--text);
  color: var(--bg);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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

@media (min-width: 800px) {
  html { background: #e2e8f0; }
  html[data-theme="dark"] { background: #020617; }
}
