:root {
  --bg: #14110f;
  --surface: #1e1a17;
  --surface-2: #28221e;
  --line: #3a322c;
  --text: #f2ebe1;
  --muted: #a89c8f;
  --accent: #ff6a3d;
  --accent-ink: #1a0d07;
  --left: #b48cff;          /* left-side emphasis */
  --right: #6fc2b0;
  --ok: #7fcf6a;
  --warn: #f0b443;
  --radius: 14px;
  --font: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4efe6; --surface: #fffaf2; --surface-2: #efe7da; --line: #ddd2c2;
    --text: #1d1916; --muted: #6d6257; --accent: #e04f1f; --accent-ink: #fff;
    --left: #7a4fe0; --right: #23887a; --ok: #3d8f2b; --warn: #b7780d;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f4efe6; --surface: #fffaf2; --surface-2: #efe7da; --line: #ddd2c2;
  --text: #1d1916; --muted: #6d6257; --accent: #e04f1f; --accent-ink: #fff;
  --left: #7a4fe0; --right: #23887a; --ok: #3d8f2b; --warn: #b7780d;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font);
  min-height: 100dvh; padding-bottom: calc(76px + var(--safe-b));
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 750; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: 0.02em; text-transform: uppercase; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 14px; height: 14px; border-radius: 4px; background: var(--accent); box-shadow: 4px 4px 0 var(--left); }
.topbar-meta { font-size: 12px; color: var(--muted); text-align: right; }

main { padding: 16px 16px 110px; max-width: 720px; margin: 0 auto; outline: none; }
.stack > * + * { margin-top: 14px; }

/* Tab bar */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 9px;
  font-size: 11px; color: var(--muted); text-decoration: none; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }

/* Cards & bits */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.tight { padding: 10px 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.accent { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.chip.left { background: color-mix(in srgb, var(--left) 20%, transparent); color: var(--left); }
.chip.main { background: var(--accent); color: var(--accent-ink); }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px;
  padding: 11px 16px; font-weight: 700; cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.danger { color: #ff7a7a; }
.btn:active { transform: translateY(1px); }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 650; padding: 4px 0; cursor: pointer; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* Day picker */
.day-grid { display: grid; gap: 10px; }
.day-card { display: block; text-decoration: none; color: inherit; position: relative; overflow: hidden; }
.day-card .letter {
  position: absolute; right: -6px; top: -18px; font-size: 110px; font-weight: 900; line-height: 1;
  color: var(--surface-2); pointer-events: none; letter-spacing: -0.05em;
}
.day-card > * { position: relative; }
.day-card.next { border-color: var(--accent); }
.day-card h2 { font-size: 20px; }
.day-card .focus { color: var(--muted); font-size: 13px; margin-top: 4px; max-width: 80%; }
.day-card .meta { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }

/* Session */
.session-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.warmup li { margin: 6px 0; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin-top: 1px; flex: none; }
details.card > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "+"; color: var(--muted); font-size: 20px; line-height: 1; }
details.card[open] > summary::after { content: "−"; }
details.card[open] > summary { margin-bottom: 10px; }

.block { padding: 0; overflow: hidden; }
.block-head .btn { white-space: nowrap; flex: none; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.block-tag { font-family: var(--mono); font-weight: 800; color: var(--accent); font-size: 13px; }
.block-sub { font-size: 12px; color: var(--muted); }
.ex { padding: 12px 14px; border-top: 1px solid var(--line); }
.ex:first-of-type { border-top: 0; }
.ex-title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ex-title h3 { font-size: 16px; }
.ex-presc { font-size: 13px; color: var(--muted); margin-top: 2px; }
.ex-notes { font-size: 12.5px; color: var(--muted); margin-top: 4px; border-left: 2px solid var(--line); padding-left: 8px; }
.ex-setup { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.ex-setup b { color: var(--text); font-weight: 650; margin-right: 4px; }
.ex-swapped { font-size: 12px; color: var(--accent); margin-top: 2px; }
.swap-list { display: grid; gap: 6px; margin-top: 8px; }
.swap-opt { text-align: left; display: grid; gap: 2px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; cursor: pointer; }
.swap-opt span { font-size: 12px; color: var(--muted); }
.swap-opt.on { border-color: var(--accent); }
.ex-last { font-size: 12px; color: var(--muted); margin-top: 6px; font-family: var(--mono); }
.sets { margin-top: 10px; display: grid; gap: 6px; }
.set {
  display: grid; grid-template-columns: 44px 1fr 1fr 48px; gap: 6px; align-items: center;
}
.set.single { grid-template-columns: 44px 1fr 48px; }
.set-label { font-family: var(--mono); font-size: 12px; color: var(--muted); font-weight: 700; }
.set-label .side { display: inline-block; min-width: 14px; text-align: center; border-radius: 4px; font-size: 11px; padding: 0 3px; margin-left: 2px; }
.set-label .side.L { background: var(--left); color: #fff; }
.set-label .side.R { background: color-mix(in srgb, var(--right) 30%, transparent); color: var(--right); }
.field { position: relative; }
.field input {
  width: 100%; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  padding: 0 34px 0 10px; font-family: var(--mono); font-size: 16px; font-variant-numeric: tabular-nums;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field .unit { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--muted); pointer-events: none; }
.done-btn {
  height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer;
  display: grid; place-items: center;
}
.done-btn svg { width: 20px; height: 20px; stroke: var(--muted); fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.set.is-done .done-btn { background: var(--ok); border-color: var(--ok); }
.set.is-done .done-btn svg { stroke: #0d1a09; }
.set.is-done input { color: var(--muted); }
.set.extra .set-label { color: var(--left); }
.ex-actions { margin-top: 8px; display: flex; gap: 12px; }
.finisher { border-style: dashed; }

/* Rest bar */
.rest-bar {
  position: fixed; left: 12px; right: 12px; bottom: calc(70px + var(--safe-b)); z-index: 7; max-width: 696px; margin: 0 auto;
  background: var(--text); color: var(--bg); border-radius: 16px; padding: 10px 14px 14px;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
[hidden] { display: none !important; }
.rest-label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; opacity: .7; }
.rest-time { font-family: var(--mono); font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rest-actions { display: flex; gap: 6px; }
.rest-actions button { border: 0; border-radius: 10px; padding: 8px 10px; background: color-mix(in srgb, var(--bg) 12%, transparent); font-weight: 750; cursor: pointer; color: inherit; }
.rest-progress { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: color-mix(in srgb, var(--bg) 15%, transparent); overflow: hidden; }
.rest-progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s linear; }
.rest-bar.done { background: var(--accent); color: var(--accent-ink); }

/* Lists */
.list { display: grid; gap: 8px; }
.list a.item { display: block; text-decoration: none; color: inherit; }
.item .title { font-weight: 700; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kv > div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.kv .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.kv .v { font-family: var(--mono); font-size: 18px; font-weight: 750; font-variant-numeric: tabular-nums; }
.kv .v small { font-size: 11px; color: var(--muted); font-weight: 600; }

/* Charts */
.chart { width: 100%; height: 180px; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font: 10px var(--mono); }
.chart .s0 { stroke: var(--accent); }
.chart .s1 { stroke: var(--left); }
.chart .s2 { stroke: var(--right); }
.chart .d0 { fill: var(--accent); }
.chart .d1 { fill: var(--left); }
.chart .d2 { fill: var(--right); }
.chart path { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.balance-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.balance-row:first-child { border-top: 0; }
.bal-bar { grid-column: 1 / -1; height: 8px; border-radius: 6px; background: var(--surface-2); position: relative; overflow: hidden; }
.bal-bar span { position: absolute; top: 0; bottom: 0; left: 0; background: var(--left); border-radius: 6px; }
.bal-bar::after { content: ""; position: absolute; left: 100%; top: -2px; bottom: -2px; width: 2px; background: var(--text); transform: translateX(-2px); }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
label.lbl { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 650; }
label.lbl input, label.lbl select, label.lbl textarea {
  height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 0 10px; font-size: 16px; color: var(--text); width: 100%;
}
label.lbl textarea { height: auto; min-height: 70px; padding: 10px; resize: vertical; }
select { appearance: none; }

/* Plan prose */
.prose { font-size: 14.5px; }
.prose p { margin: 6px 0; }
.prose ul { margin: 6px 0; padding-left: 20px; }
.prose li { margin: 4px 0; }
.prose strong { color: var(--text); }
.phase { border-left: 3px solid var(--accent); padding-left: 10px; margin: 10px 0; }
table.plan-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.plan-table th, table.plan-table td { text-align: left; padding: 7px 6px; border-top: 1px solid var(--line); vertical-align: top; }
table.plan-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; border-top: 0; }
.plan-block { border-top: 1px solid var(--line); padding: 10px 0 4px; }
.plan-ex { padding: 6px 0 6px 10px; border-left: 2px solid var(--line); margin: 6px 0; }
.plan-ex .mono { margin-top: 2px; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; top: calc(64px + var(--safe-t)); transform: translate(-50%, -20px); opacity: 0; z-index: 9;
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-weight: 650; font-size: 14px;
  transition: .2s ease; pointer-events: none; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 640px) {
  .day-grid { grid-template-columns: repeat(3, 1fr); }
  .day-card .focus { max-width: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
