:root {
  --bg: #FBF7F2;
  --surface: #FFFFFF;
  --surface-2: #F4EEE6;
  --ink: #1F2328;
  --muted: #6B6F76;
  --line: #ECE4DA;
  --run: #EE5A36;
  --run-soft: #FDE3DA;
  --walk: #1F9486;
  --walk-soft: #D5EFEA;
  --calm: #7A6FD0;
  --calm-soft: #E7E4FA;
  --good: #1F9486;
  --accent: #EE5A36;
  --accent-ink: #FFFFFF;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 6px 20px rgba(40, 30, 20, .06);
  --radius: 20px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171A;
    --surface: #1F2226;
    --surface-2: #272B30;
    --ink: #F3F1EE;
    --muted: #A0A5AB;
    --line: #2E3338;
    --run: #FF7753;
    --run-soft: #3A2620;
    --walk: #36BCAB;
    --walk-soft: #1B3431;
    --calm: #A59CF0;
    --calm-soft: #2A2842;
    --good: #36BCAB;
    --accent: #FF7753;
    --accent-ink: #1A0E0A;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { display: block; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 20px) 16px calc(var(--safe-bottom) + 96px);
  outline: none;
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(var(--safe-bottom) + 6px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  backdrop-filter: saturate(1.4) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; color: var(--muted); font-size: 11px; font-weight: 600;
  border-radius: 12px;
}
.tabbar svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent); }

h1 { font-size: 30px; line-height: 1.15; margin: 4px 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 20px; margin: 28px 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 17px; margin: 0; }
.eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.sub { color: var(--muted); margin: 0 0 18px; }
p { margin: 0 0 10px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.card.flat { box-shadow: none; border: 1px solid var(--line); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 999px;
  font-weight: 700; font-size: 16px;
  background: var(--surface-2); color: var(--ink);
  transition: transform .08s ease, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.big { min-height: 58px; font-size: 18px; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { color: #D33F2A; }
.btn svg { width: 20px; height: 20px; fill: currentColor; }
.link { color: var(--accent); font-weight: 700; }

/* ---------- Next-up card ---------- */
.next {
  position: relative; overflow: hidden;
  padding: 20px 18px 18px;
}
.next .wk { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.next .wk h3 { font-size: 24px; letter-spacing: -0.01em; }
.next .mins { color: var(--muted); font-weight: 600; white-space: nowrap; }
.next .desc { margin: 8px 0 14px; font-size: 17px; }
.next .btn { margin-top: 16px; }

.timeline {
  display: flex; gap: 2px; height: 12px; border-radius: 999px; overflow: hidden;
  background: var(--surface-2);
}
.timeline span { display: block; min-width: 2px; }
.timeline .run { background: var(--run); }
.timeline .walk { background: var(--walk); }
.timeline .warmup, .timeline .cooldown { background: var(--calm); opacity: .75; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 13px; color: var(--muted); font-weight: 600; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend .run { background: var(--run); } .legend .walk { background: var(--walk); } .legend .calm { background: var(--calm); opacity: .75; }

.note-line {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--walk-soft); color: var(--ink);
  border-radius: 14px; padding: 12px 14px; font-size: 15px; margin-bottom: 14px;
}
.note-line svg { flex: none; width: 20px; height: 20px; stroke: var(--walk); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; margin-top: 1px; }

/* ---------- Progress ---------- */
.progress-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.progress-head b { font-size: 17px; }
.progress-head span { color: var(--muted); font-weight: 600; font-size: 14px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--walk); border-radius: 999px; transition: width .4s ease; }
.dots { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; margin-top: 14px; }
.dots .wcol { display: grid; gap: 5px; justify-items: center; }
.dots .wcol small { font-size: 11px; color: var(--muted); font-weight: 700; }
.dots button { width: 100%; max-width: 30px; aspect-ratio: 1; border-radius: 50%; background: var(--surface-2); border: 2px solid transparent; }
.dots button.done { background: var(--walk); }
.dots button.upnext { border-color: var(--accent); background: var(--run-soft); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 14px 12px; }
.stat b { display: block; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-weight: 600; font-size: 12.5px; }

/* ---------- Lists ---------- */
.week { padding: 16px 16px 6px; }
.week-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.week-head .pill { font-size: 12.5px; }
.week p { color: var(--muted); font-size: 14.5px; margin: 6px 0 8px; }
.day-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.day-row .check {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--line); display: grid; place-items: center;
}
.day-row .check svg { width: 16px; height: 16px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.day-row.done .check { background: var(--walk); border-color: var(--walk); }
.day-row.is-next .check { border-color: var(--accent); background: var(--run-soft); }
.day-row .dtext { flex: 1; min-width: 0; }
.day-row .dtext b { display: block; font-size: 15.5px; }
.day-row .dtext span { display: block; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day-row .chev { flex: none; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.easy { background: var(--walk-soft); color: var(--walk); }
.pill.good { background: var(--calm-soft); color: var(--calm); }
.pill.hard { background: var(--run-soft); color: var(--run); }
.pill.tough { background: var(--run); color: #fff; }
.pill.now { background: var(--run-soft); color: var(--run); }
.pill.fin { background: var(--walk-soft); color: var(--walk); }

.run-item { padding: 14px 16px; }
.run-item .top { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.run-item .top b { font-size: 16px; }
.run-item .meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.run-item .rnote { margin-top: 8px; font-size: 15px; white-space: pre-wrap; }
.run-item .actions { display: flex; gap: 16px; margin-top: 8px; }
.run-item .actions button { font-size: 14px; font-weight: 700; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- Settings ---------- */
.set-group { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.set-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); min-height: 56px; }
.set-row:first-child { border-top: 0; }
a.set-row { color: inherit; text-decoration: none; }
a.set-row > span { color: var(--muted); font-size: 22px; }
.set-row .lbl { flex: 1; min-width: 0; }
.set-row .lbl b { display: block; font-weight: 600; }
.set-row .lbl small { display: block; color: var(--muted); font-size: 13.5px; line-height: 1.35; margin-top: 2px; }
.set-row select { max-width: 55%; background: var(--surface-2); border: 0; border-radius: 10px; padding: 8px 10px; font-size: 15px; }
.switch { position: relative; flex: none; width: 51px; height: 31px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); transition: background .2s; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 25px; height: 25px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + i { background: var(--walk); border-color: var(--walk); }
.switch input:checked + i::after { transform: translateX(20px); }
.seg-ctl { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg-ctl button { padding: 6px 14px; border-radius: 8px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg-ctl button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.fineprint { color: var(--muted); font-size: 13.5px; padding: 0 4px; }

/* ---------- Sheet & dialog ---------- */
.sheet-backdrop, .dialog-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 12, 10, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s ease;
}
.dialog-backdrop { align-items: center; padding: 16px; z-index: 60; }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  background: var(--bg); border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(var(--safe-bottom) + 18px);
  animation: up .25s cubic-bezier(.2,.8,.2,1);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet .seglist { margin: 10px 0 6px; display: grid; gap: 4px; }
.sheet .seglist div { display: flex; justify-content: space-between; font-size: 15px; padding: 6px 12px; border-radius: 10px; background: var(--surface); }
.sheet .seglist div b { font-weight: 700; }
.sheet .seglist .run b { color: var(--run); }
.sheet .seglist .walk b { color: var(--walk); }
.sheet .seglist .calm b { color: var(--calm); }
.sheet .btns { display: grid; gap: 8px; margin-top: 16px; }
.dialog {
  width: 100%; max-width: 360px; background: var(--bg); border-radius: 22px; padding: 22px 20px 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: pop .2s ease;
}
.dialog h3 { font-size: 19px; margin-bottom: 6px; }
.dialog p { color: var(--muted); }
.dialog .btns { display: grid; gap: 8px; margin-top: 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 86px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14.5px;
  z-index: 70; box-shadow: var(--shadow); animation: fade .2s ease; max-width: calc(100% - 32px); text-align: center;
}

/* ---------- Workout ---------- */
.workout {
  --seg: var(--calm);
  position: fixed; inset: 0; z-index: 40;
  background: var(--seg); color: #fff;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--safe-top) + 10px) 16px calc(var(--safe-bottom) + 18px);
  transition: background-color .6s ease;
  overflow: hidden;
}
.workout[data-type="run"] { --seg: #EE5A36; }
.workout[data-type="walk"] { --seg: #1A8C7F; }
.workout[data-type="warmup"], .workout[data-type="cooldown"] { --seg: #6E63C6; }
.workout.paused { --seg: #4A4E55; }
.w-top { width: 100%; max-width: 520px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.w-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.18); }
.w-icon svg { width: 22px; height: 22px; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; fill: none; }
.w-title { font-weight: 700; font-size: 16px; opacity: .95; }
.w-gps { min-width: 44px; text-align: right; font-size: 12px; font-weight: 700; opacity: .85; }
.w-phase { margin-top: 2vh; font-size: clamp(34px, 11vw, 54px); font-weight: 800; letter-spacing: .02em; text-transform: uppercase; line-height: 1; }
.ring-wrap { position: relative; width: min(74vw, 42vh, 340px); aspect-ratio: 1; margin: 2.2vh 0 1vh; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 6; }
.ring-bg { stroke: rgba(255,255,255,.22); }
.ring-fg { stroke: #fff; stroke-linecap: round; stroke-dasharray: 282.743; stroke-dashoffset: 0; transition: stroke-dashoffset .25s linear; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.w-left { font-size: clamp(56px, 19vw, 92px); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.w-next { margin-top: 8px; font-weight: 600; font-size: 15px; opacity: .85; }
.w-caption { min-height: 2.9em; max-width: 440px; text-align: center; font-size: 16px; font-weight: 600; line-height: 1.35; opacity: .95; padding: 0 8px; }
.w-timeline { position: relative; width: 100%; max-width: 520px; margin-top: 1.2vh; }
.timeline.big { height: 14px; background: rgba(255,255,255,.2); }
.timeline.big .run { background: #FFB39E; }
.timeline.big .walk { background: #8FE0D5; }
.timeline.big .warmup, .timeline.big .cooldown { background: #CBC5F5; opacity: 1; }
.timeline.big span.past { opacity: .45; }
.playhead { position: absolute; top: -4px; width: 4px; height: 22px; margin-left: -2px; border-radius: 2px; background: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.15); left: 0; }
.w-count { margin-top: 8px; font-size: 13.5px; font-weight: 700; opacity: .8; }
.w-stats { width: 100%; max-width: 520px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: auto; padding-top: 2vh; }
.w-stats div { text-align: center; background: rgba(255,255,255,.14); border-radius: 14px; padding: 10px 4px; }
.w-stats span { display: block; font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.w-stats small { font-size: 11.5px; font-weight: 700; opacity: .8; }
.w-controls { display: flex; align-items: center; justify-content: center; gap: 28px; margin-top: 2.2vh; }
.w-ctl { width: 56px; height: 56px; border-radius: 50%; background: rgba(255,255,255,.2); display: grid; place-items: center; }
.w-ctl svg { width: 24px; height: 24px; fill: #fff; stroke: #fff; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.w-play { width: 84px; height: 84px; border-radius: 50%; background: #fff; display: grid; place-items: center; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
.w-play svg { width: 34px; height: 34px; stroke: var(--seg); fill: var(--seg); stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
.w-play .i-pause { fill: none; }
.w-play .i-play { display: none; }
.workout.paused .w-play .i-pause { display: none; }
.workout.paused .w-play .i-play { display: block; }
.w-ctl:active, .w-play:active, .w-icon:active { transform: scale(.94); }
.w-paused-note { height: 20px; margin-top: 8px; font-weight: 700; font-size: 14px; opacity: 0; }
.workout.paused .w-paused-note { opacity: .9; }
@media (max-height: 640px) {
  .w-phase { margin-top: 4px; }
  .ring-wrap { width: min(62vw, 36vh); }
  .w-caption { min-height: 2.6em; font-size: 15px; }
  .w-play { width: 72px; height: 72px; }
}

/* ---------- Finish ---------- */
.finish {
  position: fixed; inset: 0; z-index: 45; overflow: auto;
  background: var(--bg);
  padding: calc(var(--safe-top) + 24px) 16px calc(var(--safe-bottom) + 24px);
}
.finish .inner { max-width: 520px; margin: 0 auto; }
.finish .badge {
  width: 84px; height: 84px; border-radius: 50%; background: var(--walk); display: grid; place-items: center;
  margin: 8px auto 14px; box-shadow: 0 10px 30px color-mix(in srgb, var(--walk) 40%, transparent);
  animation: pop .4s cubic-bezier(.2,1.4,.4,1);
}
.finish .badge.partial { background: var(--calm); box-shadow: 0 10px 30px color-mix(in srgb, var(--calm) 40%, transparent); }
.finish .badge svg { width: 42px; height: 42px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.finish h1 { text-align: center; }
.finish .sub { text-align: center; }
.finish .stats { margin-top: 10px; }
.feel { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0 16px; }
.feel button {
  border-radius: 14px; padding: 12px 4px; background: var(--surface); border: 2px solid var(--line);
  font-weight: 700; font-size: 14px; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.feel button i { width: 14px; height: 14px; border-radius: 50%; display: block; }
.feel button[data-v="easy"] i { background: var(--walk); }
.feel button[data-v="good"] i { background: var(--calm); }
.feel button[data-v="hard"] i { background: color-mix(in srgb, var(--run) 60%, #fff); }
.feel button[data-v="tough"] i { background: var(--run); }
.feel button.on { border-color: var(--ink); background: var(--surface-2); }
textarea {
  width: 100%; min-height: 96px; resize: vertical; border-radius: 14px; border: 2px solid var(--line);
  background: var(--surface); padding: 12px 14px; font-size: 16px; line-height: 1.4;
}
textarea:focus { outline: none; border-color: var(--calm); }
.check-row { display: flex; align-items: center; gap: 12px; padding: 14px 0 4px; font-weight: 600; }
.check-row input { width: 22px; height: 22px; accent-color: var(--walk); }
.finish .btns { display: grid; gap: 8px; margin-top: 18px; }
.grad {
  text-align: center; background: linear-gradient(135deg, var(--run-soft), var(--calm-soft));
  border-radius: var(--radius); padding: 18px; margin: 6px 0 16px; font-weight: 700; font-size: 17px;
}

/* confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 46; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

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