:root {
  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #efede8; --text: #1b1b1f; --muted: #6b6b74;
  --border: #e3e0da; --accent: #f04e2a; --accent-soft: #fde6df; --accent-ink: #fff;
  --good: #1f9d6b; --good-soft: #dcf3e8; --warn: #c98d00; --warn-soft: #fbefcc; --bad: #d6453d;
  --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1012; --surface: #18191c; --surface-2: #222327; --text: #f2f2f3; --muted: #9a9aa3;
    --border: #2b2c31; --accent: #ff6a45; --accent-soft: #3a1f18; --accent-ink: #fff;
    --good: #34c58a; --good-soft: #16302a; --warn: #f2b632; --warn-soft: #3a2f12; --bad: #ef5b52;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1012; --surface: #18191c; --surface-2: #222327; --text: #f2f2f3; --muted: #9a9aa3;
  --border: #2b2c31; --accent: #ff6a45; --accent-soft: #3a1f18; --accent-ink: #fff;
  --good: #34c58a; --good-soft: #16302a; --warn: #f2b632; --warn-soft: #3a2f12; --bad: #ef5b52;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
#app { max-width: 560px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
body.fullscreen #app { padding-bottom: 120px; }
.boot { color: var(--muted); text-align: center; margin-top: 40vh; }

h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; margin: 0 0 10px; letter-spacing: -.01em; }
h3 { font-size: 1rem; margin: 0 0 6px; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
small, .muted { color: var(--muted); }
.muted { font-size: .9rem; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.center { text-align: center; }
.mt { margin-top: 16px; } .mt-s { margin-top: 8px; }
.num { font-variant-numeric: tabular-nums; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .card + .section, .section + .card { margin-top: 12px; }
.card.hero { background: linear-gradient(135deg, var(--accent), #ff8a3d); color: #fff; border: 0; }
.card.hero .muted, .card.hero small { color: rgba(255,255,255,.85); }
.card.soft { background: var(--surface-2); box-shadow: none; }
.card.warn { background: var(--warn-soft); border-color: transparent; }
.card.good { background: var(--good-soft); border-color: transparent; }
.section-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 24px 4px 8px; }

.quote { font-size: 1.05rem; font-weight: 500; line-height: 1.4; }
.quote::before { content: "“"; font-size: 2.4rem; line-height: 0; vertical-align: -.45em; margin-right: 2px; color: var(--accent); }

/* ── Buttons ── */
button, .btn { font: inherit; cursor: pointer; border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; background: var(--surface-2); color: var(--text); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; }
button:active, .btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-big { width: 100%; padding: 18px; font-size: 1.1rem; border-radius: 14px; }
.card.hero .btn-big { background: #fff; color: var(--accent); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: .9rem; border-radius: 10px; }
.link { background: none; padding: 0; min-height: 0; color: var(--accent); font-weight: 600; }
button:disabled { opacity: .45; }

/* ── Form ── */
label { display: block; font-size: .9rem; font-weight: 600; margin-bottom: 4px; }
input, select, textarea { font: inherit; width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); min-height: 44px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field + .field { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: .9rem; min-height: 38px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--surface-2); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.good { background: var(--good-soft); color: var(--good); }
.hero .pill { background: rgba(255,255,255,.2); color: #fff; }

/* ── Header ── */
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.streak { text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 6px 12px; min-width: 64px; }
.streak b { display: block; font-size: 1.4rem; line-height: 1.1; }
.streak small { font-size: .7rem; }

/* ── Week strip ── */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.week .d { font-size: .72rem; color: var(--muted); font-weight: 600; }
.week .dot { width: 34px; height: 34px; margin: 4px auto 0; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; font-weight: 700; border: 2px solid var(--border); }
.dot.done { background: var(--good); border-color: var(--good); color: #fff; }
.dot.missed { border-color: var(--bad); color: var(--bad); }
.dot.pending { border-color: var(--accent); color: var(--accent); }
.dot.rest { border-style: dashed; color: var(--muted); }

/* ── Checklist ── */
.check { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); width: 100%; background: none; border-radius: 0; text-align: left; font-weight: 500; min-height: 48px; }
.check:last-child { border-bottom: 0; }
.check .box { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--border); display: grid; place-items: center; flex: none; }
.check.on .box { background: var(--good); border-color: var(--good); }
.check.on .box::after { content: ""; width: 7px; height: 12px; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -1px); }
.check .grow small { display: block; }

/* ── Progress bars ── */
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.bar.good > i { background: var(--good); }
.hero .bar { background: rgba(255,255,255,.25); } .hero .bar > i { background: #fff; }

/* ── Exercise images (two frames alternate to show the movement) ── */
.exfig { position: relative; aspect-ratio: 4/3; border-radius: 12px; overflow: hidden; background: #fff; }
.exfig img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.exfig img + img { animation: flip 2s steps(1) infinite; }
@keyframes flip { 0% { opacity: 0; } 50% { opacity: 1; } }
.exfig.none { display: grid; place-items: center; background: var(--surface-2); font-size: 2.5rem; }
.exthumb { width: 64px; height: 48px; border-radius: 8px; flex: none; aspect-ratio: auto; }
.imgnote { font-size: .82rem; color: var(--muted); margin-top: 6px; }
.cues { margin: 8px 0 0; padding-left: 20px; }
.cues li { margin-bottom: 4px; }

/* ── List rows ── */
.list > * { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; }
.list > *:last-child { border-bottom: 0; }

/* ── Workout player ── */
.player-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.steps { display: flex; gap: 4px; margin-bottom: 14px; }
.steps i { flex: 1; height: 4px; border-radius: 4px; background: var(--surface-2); }
.steps i.on { background: var(--accent); }
.steps i.done { background: var(--good); }
.set { display: grid; grid-template-columns: 32px 1fr 1fr 52px; gap: 8px; align-items: center; margin-top: 8px; }
.set.head { font-size: .75rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.set .n { font-weight: 700; color: var(--muted); text-align: center; }
.set input, .set select { text-align: center; padding: 10px 6px; font-weight: 700; font-size: 1.05rem; }
.set .tick { width: 52px; height: 48px; padding: 0; border-radius: 12px; border: 2px solid var(--border); background: var(--surface); }
.set.done .tick { background: var(--good); border-color: var(--good); color: #fff; }
.set.done input, .set.done select { background: var(--good-soft); border-color: transparent; }
.coachnote { background: var(--accent-soft); color: var(--text); border-radius: 12px; padding: 10px 12px; font-size: .92rem; margin-top: 12px; }
.navbtns { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--border); display: flex; gap: 10px; max-width: 560px; margin: 0 auto; z-index: 5; }
.navbtns button { flex: 1; }

.bigtimer { font-size: 4.5rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; letter-spacing: -.03em; line-height: 1; margin: 12px 0; }
.interval-label { text-align: center; font-size: 1.3rem; font-weight: 700; }
.interval.rest .bigtimer { color: var(--muted); }
.interval.work .bigtimer { color: var(--accent); }

#restbar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); max-width: 536px; margin: 0 auto; background: var(--text); color: var(--bg); border-radius: 16px; padding: 10px 12px 10px 16px; display: flex; align-items: center; gap: 10px; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
body.fullscreen #restbar { bottom: calc(84px + env(safe-area-inset-bottom)); }
#restbar[hidden] { display: none; }
#restbar b { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
#restbar button { background: rgba(127,127,127,.25); color: inherit; min-height: 36px; padding: 6px 12px; }

/* ── Tabs ── */
#tabs { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border); display: flex; z-index: 10; }
#tabs[hidden] { display: none; }
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .72rem; font-weight: 600; color: var(--muted); text-decoration: none; }
#tabs a.on { color: var(--accent); }
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Toast & sheet ── */
#toast { position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top)); transform: translate(-50%, -120%); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 600; transition: transform .25s; z-index: 50; max-width: calc(100% - 32px); text-align: center; }
#toast.show { transform: translate(-50%, 0); }
dialog#sheet { border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 88vh; border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text); }
@media (min-width: 600px) { dialog#sheet { margin: auto; max-width: 520px; border-radius: 20px; } }
dialog#sheet::backdrop { background: rgba(0,0,0,.5); }
.sheet-body { padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 88vh; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.x { background: var(--surface-2); width: 36px; height: 36px; min-height: 36px; padding: 0; border-radius: 50%; font-size: 1.2rem; }

/* ── Charts ── */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

.heat { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.heat i { height: 18px; border-radius: 4px; background: var(--surface-2); }
.heat i.done { background: var(--good); } .heat i.missed { background: var(--bad); opacity: .55; }
.heat i.rest { background: transparent; border: 1px dashed var(--border); } .heat i.today { outline: 2px solid var(--accent); }

.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.badge { text-align: center; padding: 10px 6px; border-radius: 12px; background: var(--surface-2); font-size: .75rem; font-weight: 600; }
.badge b { display: block; font-size: 1.6rem; }
.badge.locked { opacity: .35; filter: grayscale(1); }

.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photos figure { margin: 0; position: relative; }
.photos img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 10px; display: block; }
.photos figcaption { font-size: .7rem; color: var(--muted); text-align: center; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.compare img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 12px; }

.plate { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; }
.plate .pie { width: 96px; height: 96px; border-radius: 50%; background: conic-gradient(var(--good) 0 50%, var(--accent) 50% 75%, var(--warn) 75% 100%); }
.plate ul { list-style: none; padding: 0; margin: 0; font-size: .9rem; }
.plate li { display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.plate li i { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.scale .chip { padding: 8px 0; text-align: center; justify-content: center; }

.confetti { font-size: 3.5rem; text-align: center; animation: pop .6s ease-out; }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }
