:root {
  --bg: #0f1115; --card: #1a1d24; --card2: #22262f; --line: #2c313b;
  --text: #eceef1; --muted: #8d939e; --accent: #3d8bfd; --accent-dim: #1d3a66;
  --green: #2fbf71; --green-dim: #153d29; --warn: #f2b13d; --danger: #ff5c5c; --purple: #a78bfa;
  --r: 14px; --dock: 64px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior-y: contain; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { font-size: 26px; margin: 0; }
h2 { font-size: 18px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pre { white-space: pre-wrap; }

#view { padding: 12px 14px calc(var(--dock) + 110px); max-width: 680px; margin: 0 auto; padding-top: max(12px, env(safe-area-inset-top)); }

/* Dock: rest bar, mini bar, tabs */
#dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; }
#tabs { display: flex; background: #13161b; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; color: var(--muted); font-size: 11px; }
#tabs svg { width: 24px; height: 24px; fill: currentColor; }
#tabs a.on { color: var(--accent); }
body.focus #tabs { display: none; }
#minibar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 10px 8px; padding: 11px 14px; background: var(--accent-dim); border: 1px solid var(--accent); border-radius: var(--r); }
#minibar b { font-weight: 600; }
#restbar { margin: 0 10px 8px; background: var(--card2); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
#restbar .rb { display: flex; align-items: center; gap: 8px; padding: 9px 10px 9px 14px; }
#restbar .rt { font-size: 20px; font-variant-numeric: tabular-nums; font-weight: 700; flex: 1; }
#restbar .rt small { font-size: 12px; color: var(--muted); font-weight: 500; margin-right: 6px; }
#restbar .prog { height: 3px; background: var(--accent); transition: width .5s linear; }
[hidden] { display: none !important; }

/* Generic */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 16px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 10px; padding: 10px 16px; background: var(--card2); font-weight: 600; white-space: nowrap; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { display: flex; width: 100%; margin: 10px 0; padding: 13px; }
.btn.ghost { background: var(--card); border: 1px solid var(--line); }
.btn.primary-ghost { background: var(--accent-dim); color: #cfe1ff; }
.btn.danger-ghost { background: transparent; color: var(--danger); }
.btn.danger { background: #3a1717; color: var(--danger); }
.icon { border: 0; background: transparent; padding: 6px; border-radius: 8px; display: inline-flex; }
.icon svg { width: 24px; height: 24px; fill: currentColor; }
.link { color: var(--accent); font-weight: 600; font-size: 14px; background: none; border: 0; padding: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin: 10px 0; }
.sect-head { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 4px; }
.group { margin: 18px 0 2px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--accent); color: #fff; margin-left: 8px; vertical-align: 2px; }
.badge.pr { background: #4a3a10; color: var(--warn); }
.day { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 8px; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
details.notes { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; margin: 10px 0; }
details.notes summary { font-weight: 600; cursor: pointer; }
details.notes .pre { margin-top: 8px; color: #c9cdd4; font-size: 14px; }
.eyebrow { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.resume { display: flex; align-items: center; justify-content: space-between; border-color: var(--accent); background: var(--accent-dim); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 8px; margin: 12px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 12px; color: var(--muted); }
input.text, textarea.text, select.text { width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; outline: none; }
input.text:focus, textarea.text:focus { border-color: var(--accent); }
textarea.text { min-height: 220px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.chip { border: 1px solid var(--line); background: var(--card); padding: 6px 12px; border-radius: 99px; font-size: 13px; font-weight: 600; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Routine cards */
.routine { display: flex; align-items: center; gap: 12px; }
.routine.next { border-color: var(--accent); }
.routine-body { flex: 1; min-width: 0; }
.routine-title { font-weight: 700; font-size: 16px; margin-bottom: 3px; }
.routine .muted { font-size: 13px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ex-line { padding: 12px 0; border-bottom: 1px solid var(--line); }
.ex-line:last-child { border-bottom: 0; }
.ex-line b { display: block; }
.callout { background: #232016; border-left: 3px solid var(--warn); padding: 8px 10px; border-radius: 6px; font-size: 13.5px; color: #e6dcc2; margin: 6px 0; white-space: pre-wrap; }

/* Active workout */
.wk-head { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: -12px -14px 8px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); background: rgba(15,17,21,.94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.wk-time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px; }
.wk-name { width: 100%; background: transparent; border: 0; font-size: 22px; font-weight: 700; padding: 6px 0; outline: none; }
.wk-notes { width: 100%; background: transparent; border: 0; color: var(--muted); resize: none; outline: none; padding: 0 0 6px; }
.ex { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 12px 6px; margin: 12px 0; }
.ex.ss { border-left: 3px solid var(--purple); }
.ex-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ex-name { color: var(--accent); font-weight: 700; font-size: 16px; }
.ss-tag { font-size: 11px; font-weight: 700; color: var(--purple); border: 1px solid var(--purple); border-radius: 6px; padding: 0 5px; margin-right: 6px; vertical-align: 2px; }
.ex-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 2px 0 4px; }
.rest-btn { border: 0; background: var(--card2); border-radius: 7px; padding: 3px 8px; font-size: 12.5px; color: var(--accent); font-weight: 600; }
.ex-note { width: 100%; background: transparent; border: 0; color: var(--muted); resize: none; outline: none; font-size: 13.5px; padding: 4px 0; }
.srow { display: grid; grid-template-columns: 34px minmax(0, 1fr) 68px 58px 40px; gap: 6px; align-items: center; padding: 4px 4px; margin: 0 -4px; border-radius: 9px; }
.srow.head { font-size: 11.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding-top: 6px; }
.srow.head span:nth-child(n+3) { text-align: center; }
.srow.done { background: var(--green-dim); }
.stype { border: 0; background: var(--card2); border-radius: 7px; height: 32px; font-weight: 700; font-size: 14px; }
.stype.t-w { color: var(--warn); } .stype.t-d { color: var(--purple); } .stype.t-f { color: var(--danger); }
.srow.done .stype { background: transparent; }
.prev { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: none; border: 0; text-align: left; padding: 0; }
.srow input { width: 100%; height: 34px; text-align: center; background: var(--card2); border: 1px solid transparent; border-radius: 8px; font-weight: 600; font-size: 15px; outline: none; }
.srow input:focus { border-color: var(--accent); }
.srow input::placeholder { color: #5f6570; font-weight: 500; }
.srow.done input { background: transparent; }
.chk { height: 32px; border: 0; border-radius: 8px; background: var(--card2); color: var(--muted); font-size: 17px; font-weight: 800; }
.srow.done .chk { background: var(--green); color: #fff; }
.add-set { width: 100%; border: 0; background: var(--card2); border-radius: 9px; padding: 8px; margin: 8px 0 6px; font-weight: 600; font-size: 14px; }
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* History */
.wcard h3 { margin: 0 0 2px; font-size: 16px; }
.wcard .sum { font-size: 13.5px; color: #c4c8cf; margin-top: 8px; line-height: 1.55; }
.wex { padding: 10px 0; border-bottom: 1px solid var(--line); }
.wex:last-child { border-bottom: 0; }
.wset { display: flex; gap: 12px; font-size: 14px; padding: 2px 0; font-variant-numeric: tabular-nums; }
.wset .n { width: 22px; color: var(--muted); font-weight: 700; }
.wset .n.t-w { color: var(--warn); } .wset .n.t-d { color: var(--purple); } .wset .n.t-f { color: var(--danger); }
.list-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 2px; border-bottom: 1px solid var(--line); gap: 10px; }
.list-row .muted { font-size: 12.5px; }

/* Chart */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .dot { fill: var(--accent); }
.chart text { fill: var(--muted); font-size: 10px; }

/* Sheets & overlays */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; background: var(--card); border-radius: 18px 18px 0 0; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); max-height: 80vh; overflow: auto; }
.sheet-title { text-align: center; color: var(--muted); font-size: 13px; padding: 8px 0 10px; }
.sheet-btn { display: block; width: 100%; border: 0; background: var(--card2); padding: 14px; border-radius: 12px; margin: 6px 0; font-weight: 600; font-size: 15px; }
.sheet-btn.danger { color: var(--danger); }
.sheet-btn.cancel { background: transparent; color: var(--muted); }
.overlay { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; }
.overlay-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.overlay-head input { flex: 1; }
.overlay-body { flex: 1; overflow: auto; padding: 4px 14px 90px; }
.overlay-foot { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.pick { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 4px; border-bottom: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.pick.on { color: var(--accent); }
.pick .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.pick.on .tick { background: var(--accent); border-color: var(--accent); }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.setting select { background: var(--card2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.setting input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }

.callout.news { background: #14233d; border-left-color: var(--accent); color: #d6e5ff; }
.demo-btn { color: var(--muted); }
.demo-btn.has { color: var(--accent); }
.demo-frame { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 12px; overflow: hidden; margin-bottom: 12px; }
.demo-frame.tall { aspect-ratio: 9 / 16; max-height: 70vh; margin-left: auto; margin-right: auto; width: auto; }
.demo-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.demo-media { display: block; width: 100%; max-height: 60vh; object-fit: contain; background: #000; border-radius: 12px; margin-bottom: 12px; }
.update-bar { position: fixed; left: 10px; right: 10px; top: max(10px, env(safe-area-inset-top)); z-index: 70; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px 10px 16px; background: var(--card2); border: 1px solid var(--accent); border-radius: var(--r); font-weight: 600; font-size: 14px; }

#toast { position: fixed; left: 50%; top: 16px; transform: translate(-50%, -80px); background: #2a2f39; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; z-index: 60; transition: transform .25s; max-width: 90vw; font-weight: 600; font-size: 14px; }
#toast.show { transform: translate(-50%, max(0px, env(safe-area-inset-top))); }
.spacer { height: 40px; }
