:root {
  --bg: #0d0f12;
  --surface: #171a1f;
  --surface-2: #20242b;
  --line: #2b3038;
  --text: #eef1f5;
  --muted: #8d96a3;
  --accent: #ff6b3d;      /* runner orange */
  --accent-ink: #1a0b05;
  --good: #3ccf7a;
  --warn: #f5b942;
  --bad: #ff5c6c;
  --blue: #5aa7ff;
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f6; --surface: #ffffff; --surface-2: #eceef2; --line: #dde1e7;
    --text: #12151a; --muted: #687280; --accent: #e8521f; --accent-ink: #fff;
    --good: #18a957; --warn: #c98a07; --bad: #d93848; --blue: #2f7fe0;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(var(--tabs-h) + env(safe-area-inset-bottom)) 0;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
main { max-width: 640px; margin: 0 auto; padding: 12px 16px 96px; }
h1 { font-size: 28px; margin: 8px 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 0 8px; font-weight: 600; }
h3 { font-size: 17px; margin: 0 0 2px; }
p { margin: 6px 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.hdr { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.sync { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); display: inline-block; }
.dot.pending { background: var(--warn); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: 10px 0;
}
.card.done { border-color: color-mix(in srgb, var(--good) 55%, var(--line)); }
.card.link { display: block; color: inherit; text-decoration: none; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.tag.gym { color: var(--blue); }
.tag.run { color: var(--accent); }
.tag.strength { color: var(--blue); } .tag.running { color: var(--accent); }
.tag.recovery { color: var(--good); } .tag.schedule { color: var(--warn); }

button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 16px;
  background: var(--surface-2); color: var(--text); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
}
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; color: var(--muted); padding: 8px 10px; min-height: 36px; }
button.small { padding: 6px 10px; min-height: 34px; font-size: 14px; border-radius: 10px; }
button.block, .btn.block { width: 100%; }
button:disabled { opacity: .5; }
button.danger { color: var(--bad); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* week strip */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 12px 0 4px; }
.week button { flex-direction: column; gap: 2px; padding: 8px 0; min-height: 60px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.week button.sel { border-color: var(--accent); }
.week button.today .d { color: var(--accent); }
.week .l { font-size: 11px; color: var(--muted); font-weight: 600; }
.week .d { font-size: 17px; }
.week .st { width: 8px; height: 8px; border-radius: 50%; }
.st.done { background: var(--good); }
.st.part { background: var(--warn); }
.st.miss { border: 1.5px solid var(--bad); }
.st.plan { border: 1.5px solid var(--muted); }
.st.none { visibility: hidden; }

/* checklist */
.check { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.check:first-of-type { border-top: 0; }
.tick {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); flex: none;
  display: grid; place-items: center; color: transparent; font-weight: 800; font-size: 16px;
}
.tick.on { background: var(--good); border-color: var(--good); color: #fff; }
.tick.part { border-color: var(--warn); color: var(--warn); font-size: 11px; }

/* workout logger */
.ex { padding: 14px; }
.ex .meta { font-size: 13px; color: var(--muted); }
.sets { display: grid; grid-template-columns: 28px 1fr 18px 1fr 48px; gap: 8px; align-items: center; margin-top: 10px; }
.sets .hd { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.sets .n { color: var(--muted); font-size: 14px; text-align: center; }
.sets .x { color: var(--muted); text-align: center; }
.sets input { text-align: center; padding: 8px 4px; font-variant-numeric: tabular-nums; }
.sets .setbtn { width: 48px; height: 44px; padding: 0; border-radius: 12px; font-size: 20px; }
.sets .setbtn.on { background: var(--good); color: #fff; }
.sets .row-done input { color: var(--good); }
.rpe { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.rpe button { padding: 0; min-height: 40px; border-radius: 9px; }
.rpe button.on { background: var(--accent); color: var(--accent-ink); }

/* rest timer */
#timer {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 10px);
  max-width: 616px; margin: 0 auto; background: var(--text); color: var(--bg); border-radius: 16px;
  padding: 10px 12px 10px 18px; display: flex; align-items: center; gap: 10px; z-index: 20;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
#timer .t { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; flex: 1; }
#timer button { background: color-mix(in srgb, var(--bg) 12%, transparent); color: var(--bg); min-height: 38px; padding: 6px 12px; }
#timer.over .t { color: var(--accent); }

/* tabs */
#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
#tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; }
#tabs a.on { color: var(--accent); }
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 10px); transform: translate(-50%, -150%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600;
  transition: transform .25s; z-index: 30; max-width: calc(100% - 32px); text-align: center; font-size: 14px;
}
#toast.show { transform: translate(-50%, 0); }

/* stats + charts */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { fill: var(--muted); font-size: 10px; font-family: inherit; }
svg.chart .grid { stroke: var(--line); stroke-width: 1; }
svg.chart .bar { fill: var(--accent); }
svg.chart .bar.cur { fill: color-mix(in srgb, var(--accent) 55%, transparent); }
svg.chart .tgt { stroke: var(--muted); stroke-dasharray: 3 3; fill: none; }
svg.chart .ln { stroke: var(--blue); stroke-width: 2; fill: none; }
svg.chart .ln2 { stroke: var(--accent); stroke-width: 2; fill: none; }
svg.chart .pt { fill: var(--blue); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.list-item:first-child { border-top: 0; }

.sug .apply-line { font-variant-numeric: tabular-nums; font-weight: 600; margin-top: 8px; }
.sug.applied { opacity: .7; }
.sug.dismissed { opacity: .45; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 6px 4px 6px 10px; border-radius: 999px; background: var(--surface-2); font-size: 14px; }
.chip button { min-height: 24px; padding: 0 6px; background: transparent; color: var(--muted); }
.sched-row { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.sched-row:first-child { border-top: 0; }
.sched-row select { width: auto; min-height: 32px; padding: 4px 8px; font-size: 14px; }
.exedit { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.exedit .grid5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.exedit .grid5 input { padding: 8px 4px; text-align: center; }
.exedit .grid5 span { font-size: 11px; color: var(--muted); display: block; text-align: center; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
