:root {
  --accent: #ff6b35;
  --accent-soft: rgba(255,107,53,.14);
  --on-accent: #fff;
  --bg: #f2f2f7;
  --card: #ffffff;
  --card2: #f7f7fa;
  --text: #111114;
  --muted: #6e6e76;
  --line: rgba(60,60,67,.14);
  --good: #22a55b;
  --warn: #e8a10c;
  --bad: #e5484d;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --r: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card2: #2a2a2d;
    --text: #f5f5f7;
    --muted: #9a9aa2;
    --line: rgba(255,255,255,.1);
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
#app { padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 96px); max-width: 640px; margin: 0 auto; }
#app.no-tabs { padding-bottom: calc(var(--safe-bottom) + 24px); }
.hidden { display: none !important; }

/* Headings */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 2px 14px; }
.page-head h1 { font-size: 32px; line-height: 1.1; margin: 0; letter-spacing: -.02em; font-weight: 800; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
h2.sec { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; display: flex; justify-content: space-between; align-items: center; }
h2.sec .link { text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--accent); font-weight: 600; background: none; border: 0; padding: 0; }

/* Cards */
.card { background: var(--card); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
.card.tight { padding: 4px 0; }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 11px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mt { margin-top: 12px; } .mt2 { margin-top: 20px; } .mb { margin-bottom: 12px; }
.big { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.huge { font-size: 44px; font-weight: 900; letter-spacing: -.03em; line-height: 1; }
.accent { color: var(--accent); }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Buttons */
.btn { appearance: none; border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 700; background: var(--accent); color: var(--on-accent); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .08s, opacity .15s; }
.btn:active { transform: scale(.97); opacity: .85; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: var(--card2); color: var(--text); }
.btn.danger { background: rgba(229,72,77,.12); color: var(--bad); }
.btn.sm { padding: 8px 12px; border-radius: 11px; font-size: 14px; }
.btn.lg { padding: 17px 20px; font-size: 18px; border-radius: 16px; }
.btn[disabled] { opacity: .4; }
.icon-btn { appearance: none; border: 0; background: var(--card2); width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; cursor: pointer; flex: none; color: var(--text); }
.icon-btn.accent { background: var(--accent); color: var(--on-accent); }

/* Challenge hero */
.hero { position: relative; overflow: hidden; border-radius: 24px; padding: 20px; color: #fff; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #000)); margin-bottom: 12px; box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 35%, transparent); }
.hero .label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; opacity: .85; }
.hero .daynum { font-size: 64px; font-weight: 900; line-height: .95; letter-spacing: -.04em; }
.hero .of { font-size: 20px; font-weight: 700; opacity: .8; }
.hero .bar { height: 10px; background: rgba(255,255,255,.25); border-radius: 99px; overflow: hidden; margin-top: 14px; }
.hero .bar > i { display: block; height: 100%; background: #fff; border-radius: 99px; }
.hero .meta { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-top: 8px; opacity: .92; }
.hero .ring { position: absolute; right: -30px; top: -30px; width: 170px; height: 170px; border-radius: 50%; border: 22px solid rgba(255,255,255,.1); }
.hero .phase { display: inline-block; margin-top: 8px; background: rgba(255,255,255,.2); padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; }

/* Up next */
.upnext { border: 2px solid var(--accent); }
.upnext .kicker { font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.upnext .title { font-size: 22px; font-weight: 800; margin: 4px 0 2px; letter-spacing: -.01em; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--card2); color: var(--muted); white-space: nowrap; }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.bad { background: rgba(229,72,77,.13); color: var(--bad); }
.chip.warn { background: rgba(232,161,12,.15); color: var(--warn); }
.chip.good { background: rgba(34,165,91,.14); color: var(--good); }

/* Lists */
.list { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.item { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line); min-height: 52px; }
.item:last-child { border-bottom: 0; }
.item .t { font-weight: 600; }
.item .s { font-size: 13px; color: var(--muted); }
.item.done .t { text-decoration: line-through; color: var(--muted); }
.item.tap { cursor: pointer; }
.item.tap:active { background: var(--card2); }
.chev::after { content: "›"; color: var(--muted); font-size: 22px; margin-left: 4px; }
.check { appearance: none; flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--muted); background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: all .15s; padding: 0; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on::after { content: ""; width: 8px; height: 14px; border: solid var(--on-accent); border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px,-1px); }
.prio { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.prio.p2 { background: var(--bad); } .prio.p1 { background: var(--warn); } .prio.p0 { background: transparent; }

/* Progress */
.pbar { height: 8px; background: var(--card2); border-radius: 99px; overflow: hidden; }
.pbar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }

/* Tiles */
.tile { background: var(--card); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-height: 96px; border: 0; text-align: left; }
.tile:active { transform: scale(.98); }
.tile .ic { font-size: 22px; }
.tile .v { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.tile .l { font-size: 13px; color: var(--muted); font-weight: 600; }

/* Forms */
.field { margin-bottom: 14px; }
.field > label, .lbl { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 4px 6px; }
.input, select.input, textarea.input { width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2); outline: none; font-size: 16px; -webkit-appearance: none; appearance: none; }
textarea.input { min-height: 110px; resize: vertical; }
.input:focus { border-color: var(--accent); }
.input.sm { padding: 9px 10px; border-radius: 10px; }
.seg { display: flex; background: var(--card2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; font-weight: 700; font-size: 14px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.seg.dense button { padding: 9px 1px; font-size: 13px; }
.days { display: flex; gap: 6px; }
.days button { flex: 1; aspect-ratio: 1; max-width: 46px; border-radius: 50%; border: 0; background: var(--card2); font-weight: 800; font-size: 14px; cursor: pointer; color: var(--muted); }
.days button.on { background: var(--accent); color: var(--on-accent); }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--card2); border-radius: 99px; transition: .2s; cursor: pointer; border: 1px solid var(--line); }
.switch span::before { content: ""; position: absolute; width: 27px; height: 27px; left: 1px; top: 1px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 2px 4px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }
.swatches { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 2px rgba(255,255,255,.4); }
.swatch.on { border-color: var(--text); }
.color-input { width: 44px; height: 44px; border: 0; padding: 0; border-radius: 50%; overflow: hidden; background: none; }

/* Tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around; padding: 6px 6px calc(var(--safe-bottom) + 6px); background: color-mix(in srgb, var(--card) 86%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-top: 1px solid var(--line); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 10px; font-weight: 700; padding: 4px 0; }
.tabbar a .ti { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabbar a.on { color: var(--accent); }
.tabbar a.on .ti { filter: none; opacity: 1; }

/* Sheet (modal) */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; animation: fade .2s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; background: var(--bg); border-radius: 22px 22px 0 0; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 16px calc(var(--safe-bottom) + 24px); animation: up .25s cubic-bezier(.2,.8,.2,1); max-width: 640px; margin: 0 auto; }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 92px); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 600; font-size: 15px; z-index: 80; opacity: 0; pointer-events: none; transition: all .25s; max-width: 90vw; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Rest timer bar */
.restbar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-bottom) + 72px); z-index: 30; background: var(--text); color: var(--bg); border-radius: 18px; padding: 12px 14px; display: flex; align-items: center; gap: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: 616px; margin: 0 auto; }
.restbar .tm { font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums; }
.restbar button { background: rgba(127,127,127,.25); color: inherit; border: 0; border-radius: 10px; padding: 8px 10px; font-weight: 700; }

/* Workout sets */
.set-row { display: grid; grid-template-columns: 34px 1fr 1fr 40px; gap: 8px; align-items: center; margin-bottom: 8px; }
.set-row .n { font-weight: 800; color: var(--muted); text-align: center; }
.set-row input { text-align: center; }
.set-row.logged input { background: var(--accent-soft); border-color: transparent; }

/* Charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }

/* Onboarding */
.ob { min-height: calc(100vh - 60px); display: flex; flex-direction: column; }
.ob .step { color: var(--muted); font-weight: 700; font-size: 13px; margin: 10px 0 0; }
.ob h1 { font-size: 34px; letter-spacing: -.03em; margin: 8px 0 8px; line-height: 1.1; }
.ob p.lead { color: var(--muted); font-size: 17px; margin: 0 0 22px; }
.ob .foot { margin-top: auto; padding-top: 20px; display: flex; gap: 10px; }
.choice { display: block; width: 100%; text-align: left; background: var(--card); border: 2px solid transparent; border-radius: 18px; padding: 16px; margin-bottom: 12px; cursor: pointer; box-shadow: var(--shadow); }
.choice.on { border-color: var(--accent); }
.choice b { display: block; font-size: 17px; margin-bottom: 4px; }
.modgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mod { background: var(--card); border: 2px solid transparent; border-radius: 16px; padding: 12px; text-align: left; cursor: pointer; box-shadow: var(--shadow); }
.mod.on { border-color: var(--accent); background: var(--accent-soft); }
.mod .ic { font-size: 22px; }
.mod b { display: block; font-size: 14px; margin-top: 4px; }

/* Misc */
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty .ic { font-size: 40px; margin-bottom: 6px; }
.principle { font-style: italic; font-size: 15px; }
.kpi { text-align: center; }
.kpi .v { font-size: 22px; font-weight: 800; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.timer-face { font-size: 72px; font-weight: 900; text-align: center; font-variant-numeric: tabular-nums; letter-spacing: -.03em; margin: 10px 0; }
.mood-row { display: flex; gap: 6px; }
.mood-row button { flex: 1; font-size: 24px; padding: 8px 0; border-radius: 12px; border: 2px solid transparent; background: var(--card2); cursor: pointer; }
.mood-row button.on { border-color: var(--accent); background: var(--accent-soft); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
a { color: var(--accent); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti i { position: absolute; top: -10px; width: 8px; height: 14px; border-radius: 2px; animation: fall 1.4s ease-in forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: .6; } }
