/* Lift Log v2 — "chalk and iron".
   Plate colors encode sessions (Upper A red, Lower A blue, Upper B yellow, Lower B green, Physique chalk). */
:root {
    --slate: #18202b;
    --slate-2: #202a37;
    --slate-3: #2a3646;
    --line: #334154;
    --chalk: #eceee8;
    --chalk-dim: #b9c0c9;
    --muted: #8796a8;
    --plate-red: #e0483e;
    --plate-blue: #3d7fdb;
    --plate-yellow: #e8b931;
    --plate-green: #3fa36b;
    --plate-chalk: #d9dcd3;
    --ok: #3fa36b;
    --warn: #e8b931;
    --danger: #e0483e;
    --accent: var(--plate-chalk);
    --r-lg: 18px;
    --r-md: 12px;
    --r-sm: 8px;
    --tab-h: 64px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
    font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: var(--slate);
    color: var(--chalk);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 3px solid var(--plate-yellow); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* session plate colors */
[data-plate="upper_a"] { --accent: var(--plate-red); }
[data-plate="lower_a"] { --accent: var(--plate-blue); }
[data-plate="upper_b"] { --accent: var(--plate-yellow); }
[data-plate="lower_b"] { --accent: var(--plate-green); }
[data-plate="physique"], [data-plate="other"] { --accent: var(--plate-chalk); }

/* ---------- shell ---------- */
.app { min-height: 100%; padding: calc(var(--safe-t) + 14px) 16px calc(var(--tab-h) + var(--safe-b) + 24px); max-width: 560px; margin: 0 auto; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.topbar h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.topbar .sub { color: var(--chalk-dim); margin-top: 4px; font-size: 0.95rem; }
.sync-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: 1px; }
.sync-dot.pending { background: var(--warn); }
.sync-dot.offline { background: var(--muted); }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--slate-2); flex: none; }
.icon-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    display: grid; grid-template-columns: repeat(4, 1fr);
    background: rgba(24, 32, 43, 0.96); border-top: 1px solid var(--line);
    backdrop-filter: blur(10px);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 0.75rem; font-weight: 600; }
.tabbar button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--chalk); }

/* ---------- blocks ---------- */
section { margin-bottom: 26px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.section-head h2 { font-size: 1.1rem; font-weight: 700; }
.section-head .link { color: var(--chalk-dim); font-size: 0.9rem; font-weight: 600; padding: 6px 0 6px 10px; }
.panel { background: var(--slate-2); border-radius: var(--r-md); padding: 14px; }
.panel + .panel { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 8px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 48px; padding: 0 18px; border-radius: 999px; font-weight: 700;
    background: var(--slate-3); color: var(--chalk);
}
.btn.primary { background: var(--accent); color: #10161e; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; border: 1px solid var(--danger); color: #ffb3ad; }
.btn:disabled { opacity: 0.5; }

/* coach note */
.coach-note { border-left: 4px solid var(--plate-chalk); background: var(--slate-2); padding: 12px 14px; border-radius: 0 var(--r-md) var(--r-md) 0; margin-bottom: 18px; }
.coach-note p { white-space: pre-wrap; }
.coach-note .who { font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }

/* ---------- today hero ---------- */
.session-hero { position: relative; border-radius: var(--r-lg); background: var(--slate-2); overflow: hidden; }
.session-hero .plate-band { height: 6px; background: var(--accent); }
.session-hero .body { padding: 16px; }
.session-hero h2 { font-size: 2.1rem; font-weight: 850; letter-spacing: -0.03em; line-height: 1; }
.session-hero .focus { color: var(--chalk-dim); margin-top: 6px; }
.phase-chip { display: inline-block; font-size: 0.8rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--slate-3); color: var(--chalk-dim); margin-bottom: 10px; }
.phase-chip.ramp { color: var(--plate-yellow); }
.phase-chip.deload { color: #9ec3ff; }
.thumb-strip { display: flex; gap: 6px; overflow-x: auto; margin: 14px -16px 0; padding: 0 16px 2px; scrollbar-width: none; }
.thumb-strip::-webkit-scrollbar { display: none; }
.thumb-strip img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--r-sm); background: #fff; flex: none; }
.hero-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 16px; }
.rest-hero h2 { font-size: 1.6rem; }

/* week strip */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day { text-align: center; padding: 8px 0 10px; border-radius: var(--r-sm); background: var(--slate-2); }
.day .d { font-size: 0.72rem; color: var(--muted); font-weight: 700; }
.day .pip { width: 22px; height: 22px; margin: 6px auto 0; border-radius: 50%; border: 3px solid var(--accent); }
.day[data-plate="off"] .pip { border-color: var(--slate-3); border-style: dashed; }
.day.done .pip { background: var(--accent); }
.day.missed .pip { border-color: var(--muted); opacity: 0.5; }
.day.today { outline: 2px solid var(--chalk-dim); }
.day .n { font-size: 0.7rem; color: var(--chalk-dim); margin-top: 4px; }

/* macro bars */
.macro { margin-top: 10px; }
.macro .label { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--chalk-dim); }
.bar { height: 8px; border-radius: 4px; background: var(--slate-3); overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--plate-yellow); border-radius: 4px; }
.bar.protein > i { background: var(--plate-green); }

/* meal checklist */
.meal { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.meal:first-child { border-top: 0; }
.check { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; }
.check svg { width: 18px; height: 18px; stroke: #10161e; stroke-width: 3; fill: none; opacity: 0; }
.check[aria-pressed="true"] { background: var(--plate-green); border-color: var(--plate-green); }
.check[aria-pressed="true"] svg { opacity: 1; }
.meal .t { font-weight: 650; }
.meal .items { font-size: 0.82rem; color: var(--muted); }
.meal .k { text-align: right; font-size: 0.85rem; color: var(--chalk-dim); }

/* inputs */
.field { display: block; }
.field span { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 4px; }
.input, textarea.input, select.input {
    width: 100%; min-height: 48px; border-radius: var(--r-sm); border: 1px solid var(--line);
    background: var(--slate); padding: 10px 12px; color: var(--chalk);
}
textarea.input { min-height: 84px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* ---------- workout screen ---------- */
.workout-head { position: sticky; top: 0; z-index: 10; margin: calc(-1 * (var(--safe-t) + 14px)) -16px 14px; padding: calc(var(--safe-t) + 12px) 16px 12px; background: var(--slate); border-bottom: 3px solid var(--accent); }
.workout-head h1 { font-size: 1.4rem; font-weight: 800; }
.ex-card { display: grid; grid-template-columns: 76px 1fr; gap: 12px; padding: 10px; border-radius: var(--r-md); background: var(--slate-2); width: 100%; text-align: left; }
.ex-card + .ex-card { margin-top: 8px; }
.ex-card img { width: 76px; height: 76px; border-radius: var(--r-sm); object-fit: cover; background: #fff; }
.ex-card .name { font-weight: 700; line-height: 1.2; }
.ex-card .rx { font-size: 0.86rem; color: var(--chalk-dim); margin-top: 3px; }
.ex-card .last { font-size: 0.8rem; color: var(--muted); margin-top: 3px; }
.ex-card .prog { display: flex; gap: 4px; margin-top: 6px; }
.ex-card .prog i { width: 18px; height: 6px; border-radius: 3px; background: var(--slate-3); }
.ex-card .prog i.on { background: var(--accent); }
.ex-card.complete { opacity: 0.6; }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(5, 8, 12, 0.6); z-index: 40; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 94vh; overflow-y: auto;
    background: var(--slate); border-radius: 22px 22px 0 0; border-top: 4px solid var(--accent);
    padding: 10px 16px calc(var(--safe-b) + 112px); max-width: 560px; margin: 0 auto;
    animation: rise 0.22s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0.4; } to { transform: none; opacity: 1; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font-size: 1.35rem; font-weight: 800; line-height: 1.15; }

/* demo animation: two frames, crossfade */
.demo { position: relative; aspect-ratio: 4 / 3; border-radius: var(--r-md); overflow: hidden; background: #fff; margin: 12px 0; }
.demo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.demo img.f1 { animation: frame 2.4s ease-in-out infinite; }
@keyframes frame { 0%, 35% { opacity: 0; } 50%, 85% { opacity: 1; } 100% { opacity: 0; } }
.demo .paused-note { display: none; }
@media (prefers-reduced-motion: reduce) {
    .demo { aspect-ratio: auto; display: grid; grid-template-columns: 1fr 1fr; }
    .demo img { position: static; height: auto; }
    .demo img.f1 { animation: none; opacity: 1; }
    .sheet { animation: none; }
}
.howto { margin: 8px 0 0 1.2em; padding: 0; color: var(--chalk-dim); font-size: 0.92rem; }
.howto li + li { margin-top: 4px; }
details.more summary { cursor: pointer; color: var(--chalk-dim); font-weight: 600; padding: 8px 0; }
.target { background: var(--slate-2); border-radius: var(--r-md); padding: 12px 14px; margin-top: 10px; }
.target b { font-size: 1.05rem; }

/* the set logger — the one loud thing */
.sets { margin-top: 14px; }
.set { display: grid; grid-template-columns: 26px 1fr 1fr 52px; gap: 8px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.set .idx { font-weight: 800; color: var(--muted); text-align: center; }
.stepper { display: grid; grid-template-columns: 38px 1fr 38px; align-items: center; background: var(--slate-2); border-radius: var(--r-md); height: 64px; }
.stepper button { height: 100%; font-size: 1.5rem; font-weight: 700; color: var(--chalk-dim); }
.stepper input {
    width: 100%; min-width: 0; text-align: center; background: transparent; border: 0;
    font-size: 1.85rem; font-weight: 850; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; padding: 0;
}
.stepper .unit { display: block; text-align: center; font-size: 0.68rem; color: var(--muted); margin-top: -4px; }
.stepper .val { display: flex; flex-direction: column; align-items: center; }
.set .done-btn { width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; }
.set .done-btn svg { width: 24px; height: 24px; stroke: var(--chalk-dim); stroke-width: 3; fill: none; }
.set.is-done .done-btn { background: var(--accent); border-color: var(--accent); }
.set.is-done .done-btn svg { stroke: #10161e; }
.set.is-done .stepper input { color: var(--accent); }
.rir-row { grid-column: 2 / 4; display: flex; gap: 6px; align-items: center; font-size: 0.8rem; color: var(--muted); }
.rir-row button { min-width: 34px; height: 30px; border-radius: 15px; background: var(--slate-2); color: var(--chalk-dim); font-weight: 700; }
.rir-row button[aria-pressed="true"] { background: var(--chalk-dim); color: #10161e; }

.rest-bar {
    position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 12px); z-index: 45; max-width: 536px; margin: 0 auto;
    background: var(--chalk); color: #10161e; border-radius: 999px; padding: 8px 8px 8px 20px;
    display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 800;
}
.rest-bar .clock { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.rest-bar button { background: #10161e; color: var(--chalk); border-radius: 999px; height: 40px; padding: 0 14px; font-weight: 700; }
.rest-bar.over { background: var(--plate-green); }

/* chips & lists */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { padding: 8px 12px; border-radius: 999px; background: var(--slate-2); font-size: 0.85rem; color: var(--chalk-dim); }
.chip[aria-pressed="true"] { background: var(--chalk-dim); color: #10161e; font-weight: 700; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.bullets { margin: 6px 0 0 1.1em; padding: 0; color: var(--chalk-dim); font-size: 0.92rem; }
.bullets li + li { margin-top: 5px; }

/* plan */
.plan-session { border-left: 5px solid var(--accent); }
.plan-ex { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.92rem; }
.plan-ex:first-of-type { border-top: 0; }
.plan-ex .rx { color: var(--chalk-dim); text-align: right; white-space: nowrap; }
.change { font-size: 0.9rem; }
.change .who { color: var(--muted); font-size: 0.8rem; }
.badge { display: inline-block; font-size: 0.72rem; font-weight: 800; border-radius: 6px; padding: 2px 6px; background: var(--slate-3); color: var(--chalk-dim); }
.badge.claude { background: #e7e1d3; color: #2a2418; }
.badge.warn { background: var(--plate-yellow); color: #10161e; }

/* progress charts */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .avg { stroke: var(--plate-green); stroke-width: 3; fill: none; }
.chart .pt { fill: var(--chalk-dim); }
.chart .lbl { fill: var(--muted); font-size: 11px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--slate-2); border-radius: var(--r-md); padding: 10px 12px; }
.stat b { display: block; font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.78rem; color: var(--muted); }
.lift { display: grid; grid-template-columns: 1fr 96px; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.lift:first-child { border-top: 0; }
.lift svg { width: 96px; height: 32px; }
.lift svg path { stroke: var(--accent); stroke-width: 2.5; fill: none; }

/* connect screen */
.connect { max-width: 420px; margin: 12vh auto 0; }
.connect h1 { font-size: 2.2rem; font-weight: 850; letter-spacing: -0.03em; }
.connect p { color: var(--chalk-dim); margin: 10px 0 20px; }

.toast {
    position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 60;
    background: var(--chalk); color: #10161e; padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 0.9rem;
    opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; }
.empty { color: var(--muted); padding: 18px 0; }

/* session picker on Today: each chip carries its plate color */
.pick-row { margin-top: 2px; }
.pick-chip { background: var(--slate); border: 2px solid transparent; display: inline-flex; align-items: center; gap: 7px; min-height: 40px; }
.pick-chip::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
.pick-chip[aria-pressed="true"] { background: var(--slate-3); color: var(--chalk); border-color: var(--accent); font-weight: 700; }
.claude-change { border-left-color: #e7e1d3; }
