:root {
  --bg: #f4f5f7; --card: #ffffff; --soft: #eef0f3; --fg: #15181d; --muted: #6b7280; --line: #e3e6ea;
  --accent: #3b82f6; --accent-fg: #fff; --good: #10b981; --warn: #f59e0b; --bad: #ef4444; --new: #f0662a;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --card: #1b1f25; --soft: #252a31; --fg: #eef0f3; --muted: #9aa3ae; --line: #2c323a; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.4 -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif; }
body.sheet-open { overflow: hidden; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: var(--fg); background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
textarea { resize: vertical; margin-top: 6px; }
input[type=color] { padding: 2px; height: 42px; }
input[type=file] { background: none; border: 0; padding: 6px 0; }
.loading { padding: 40vh 0; text-align: center; color: var(--muted); }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 18px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.brand { font-weight: 700; letter-spacing: -0.01em; }
.sync-dot { width: 26px; height: 26px; border: 0; background: none; position: relative; padding: 0; }
.sync-dot::after { content: ''; position: absolute; inset: 8px; border-radius: 50%; background: var(--good); }
.sync-dot.pending::after { background: var(--warn); }
.sync-dot.off::after { background: var(--muted); }
.sync-dot.err::after { background: var(--bad); }
main { padding: 4px 16px calc(env(safe-area-inset-bottom) + 96px); max-width: 640px; margin: 0 auto; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--card); border-top: 1px solid var(--line); padding: 6px 0 calc(env(safe-area-inset-bottom) + 4px); }
.tabbar button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; }
.tabbar svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar button.on { color: var(--accent); }

.page-h { font-size: 28px; letter-spacing: -0.02em; margin: 10px 2px 12px; }
.hero { display: flex; justify-content: space-between; align-items: center; margin: 8px 2px 14px; }
.hero-date { color: var(--muted); font-size: 14px; }
.hero-title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.streak { text-align: center; background: var(--card); border-radius: var(--radius); padding: 8px 14px; min-width: 76px; }
.streak-n { font-size: 26px; font-weight: 800; color: var(--new); line-height: 1.1; }
.streak-l { font-size: 11px; color: var(--muted); }

.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 14px; }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.card p { margin: 4px 0 10px; }
.card.soft { background: var(--soft); }
.card.warn { border: 2px solid var(--warn); }
.card.accent { border: 2px solid var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 0 4px; }

.sess-head { display: flex; justify-content: space-between; align-items: baseline; margin: 18px 4px 8px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.sess-head.big { font-size: 15px; color: var(--fg); text-transform: none; letter-spacing: 0; }
.link { border: 0; background: none; color: var(--accent); padding: 8px 0; font-size: 15px; text-transform: none; letter-spacing: 0; font-weight: 500; }

.ex-card { position: relative; display: flex; align-items: center; width: 100%; text-align: left; border: 0; background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; gap: 8px; }
.ex-card.alt { outline: 2px dashed var(--muted); }
.ex-main { flex: 1; min-width: 0; }
.ex-name { font-weight: 600; font-size: 16px; }
.ex-meta { color: var(--muted); font-size: 14px; margin-top: 1px; }
.ex-setup { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; font-size: 13px; }
.setup-txt { color: var(--muted); }
.load { font-weight: 600; font-size: 13px; }
.edited { color: var(--accent); }
.chev { color: var(--muted); font-size: 22px; }
.new-badge { position: absolute; top: -6px; right: 10px; background: var(--new); color: #fff; font-size: 10px; font-weight: 800; letter-spacing: 0.05em; padding: 2px 6px; border-radius: 6px; }
.new-badge.inline { position: static; margin-right: 6px; vertical-align: 2px; }
.new-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--new); flex: none; }

.chip { display: inline-flex; align-items: center; gap: 5px; background: var(--soft); border-radius: 999px; padding: 3px 10px 3px 4px; font-size: 14px; }
.chip.sm { font-size: 12px; padding: 2px 8px 2px 3px; }
.chip i { width: 16px; height: 16px; border-radius: 50%; display: inline-block; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25), 0 0 0 1px rgba(0,0,0,0.15); }
.chip.sm i { width: 13px; height: 13px; }
.chip .chip { padding: 0; background: none; }
.chip .x { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 0 0 4px; }

.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px 16px; margin: 8px 0; background: var(--soft); font-weight: 600; font-size: 16px; text-align: center; }
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.big { padding: 17px; font-size: 18px; margin-top: 18px; }
.btn.ghost { background: none; color: var(--muted); font-weight: 500; }
.btn.danger { background: none; color: var(--bad); font-weight: 500; }
.btn.small { display: inline-block; width: auto; padding: 8px 14px; font-size: 14px; margin: 4px 6px 4px 0; }
.btn:disabled { opacity: 0.5; }
.btn-col .btn { margin: 6px 0; }
.icon { border: 0; background: var(--soft); border-radius: 8px; width: 32px; height: 32px; font-size: 16px; padding: 0; }
.icon:disabled { opacity: 0.3; }

.toggle-row { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.sheet .toggle-row { background: var(--soft); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background 0.2s; }
.switch span::after { content: ''; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(20px); }

.done-card .done-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.tag { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--soft); }
.tag.done { background: color-mix(in srgb, var(--good) 20%, transparent); color: var(--good); }
.tag.missed { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.update { padding: 4px 0; font-size: 14px; }

/* sheets */
#sheet-root .sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 20; opacity: 0; transition: opacity 0.2s; }
#sheet-root .sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--card); border-radius: 18px 18px 0 0; padding: 8px 18px calc(env(safe-area-inset-bottom) + 18px); transform: translateY(100%); transition: transform 0.25s ease; max-width: 640px; margin: 0 auto; }
#sheet-root.open .sheet-bg { opacity: 1; }
#sheet-root.open .sheet { transform: none; }
.sheet-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 10px; }
.sheet-title { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; margin: 4px 0 8px; }
.setup-box { background: var(--soft); border-radius: 12px; padding: 10px 12px; font-size: 14px; display: grid; gap: 3px; margin: 8px 0; }
.how { font-size: 15px; }
.field { margin: 14px 0; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hold-row { grid-template-columns: 1fr 90px 32px; margin-bottom: 6px; align-items: center; }
.stepper-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 40px; height: 36px; border: 0; border-radius: 10px; background: var(--soft); font-size: 20px; }
.stepper b { min-width: 44px; text-align: center; font-size: 17px; }
.row-btns { margin-top: 6px; }
.band-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.add-band { margin-top: 2px; }
.seg { display: flex; background: var(--soft); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

/* illustration */
.illus { background: var(--soft); border-radius: 14px; padding: 8px 8px 10px; margin: 10px 0; text-align: center; }
.illus svg { width: 100%; max-height: 230px; }
.illus-cap { font-size: 14px; font-weight: 600; min-height: 20px; }
.illus-note { font-size: 12px; color: var(--muted); margin-top: 2px; }
.illus-none { color: var(--muted); font-size: 13px; padding: 10px; text-align: center; }
.il-limb { fill: none; stroke: var(--fg); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.il-back { opacity: 0.35; }
.il-head { fill: var(--fg); }
.il-nose { fill: none; stroke: var(--fg); stroke-width: 2.5; stroke-linecap: round; }
.il-band { stroke-width: 3; stroke-linecap: round; }
.il-floor { stroke: var(--line); stroke-width: 2; }
.il-door { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 3 3; }
.il-anchor { fill: var(--muted); }
.il-handle { fill: var(--muted); }

/* workouts */
.cycle { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }
.cycle.inactive { opacity: 0.6; }
.cycle-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.cycle-name { font-size: 20px; font-weight: 700; }
.day { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
.day-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.day-tools { display: flex; gap: 6px; flex: none; }
.w-ex { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.w-ex-main { flex: 1; text-align: left; border: 0; background: var(--soft); border-radius: 10px; padding: 8px 12px; min-width: 0; }
.band-row { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 10px 0; border-bottom: 1px solid var(--line); text-align: left; }
.band-row > span:nth-child(2) { flex: 1; font-weight: 600; }
.swatch { width: 22px; height: 22px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(127,127,127,0.4); }

/* stats */
.range { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 6px; scrollbar-width: none; }
.range button, .sel-chips button { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
.range button.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.sel-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.sel-chips button { background: none; }
.sel-chips button.on { background: var(--c); border-color: var(--c); color: #fff; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.tiles.inner { grid-template-columns: repeat(2, 1fr); }
.tile { background: var(--card); border-radius: 12px; padding: 10px; text-align: center; }
.tiles.inner .tile { background: var(--soft); }
.tile-n { font-size: 20px; font-weight: 800; }
.tile-l { font-size: 11px; color: var(--muted); }
canvas { width: 100%; display: block; margin: 6px 0; }
.tbl-wrap { overflow-x: auto; max-height: 320px; overflow-y: auto; margin-top: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); }
th { position: sticky; top: 0; background: var(--card); font-weight: 600; }
th i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
details summary { color: var(--accent); padding: 8px 0; }
.w-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.w-row span:first-child { flex: 1; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.ph { border: 0; padding: 0; background: var(--soft); border-radius: 10px; overflow: hidden; position: relative; aspect-ratio: 3/4; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph span { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,0.6)); padding: 10px 6px 4px; }
.ph-prev { max-width: 100%; max-height: 200px; border-radius: 10px; margin-top: 8px; }
.ph-full { width: 100%; border-radius: 12px; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; background: var(--card); border-radius: 18px; padding: 24px; }
.login-card h1 { margin: 0 0 6px; }
.err { color: var(--bad); min-height: 20px; }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translate(-50%, 20px); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; transition: all 0.25s; z-index: 30; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
