/* ── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; text-align: inherit; }
button:disabled { cursor: default; }
ul, ol { list-style: none; }
svg.icon { flex-shrink: 0; display: inline-block; vertical-align: middle; }

/* ── Design tokens (dark default) ──────────────────── */
:root {
  --bg: #0b0b10;
  --bg-glow: radial-gradient(1200px 500px at 10% -10%, rgba(91, 108, 255, 0.16), transparent 60%),
             radial-gradient(900px 400px at 110% 10%, rgba(168, 85, 247, 0.10), transparent 60%);
  --surface: #15151c;
  --surface-2: #1f1f29;
  --surface-3: #2a2a36;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f5f5f7;
  --text-2: #c9c9d1;
  --muted: #8b8b98;
  --faint: #5c5c6a;
  --accent: #5b8cff;
  --accent-2: #a855f7;
  --accent-grad: linear-gradient(135deg, #3b82f6 0%, #6d5cf6 55%, #a855f7 100%);
  --accent-soft: rgba(91, 140, 255, 0.15);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.13);
  --danger: #f43f5e;
  --danger-soft: rgba(244, 63, 94, 0.12);
  --warn: #f59e0b;
  --gold: #fbbf24;
  --gold-soft: rgba(251, 191, 36, 0.13);
  --violet: #a855f7;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);
  --glass: rgba(18, 18, 25, 0.72);
  --radius: 18px;
  --radius-sm: 12px;
  --chart-grid: rgba(255, 255, 255, 0.06);
  --heat-0: #1d1d26;
  --heat-1: #2b4a8f;
  --heat-2: #4f7cff;
  --heat-3: #9b7bff;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f5fa;
  --bg-glow: radial-gradient(1200px 500px at 10% -10%, rgba(91, 108, 255, 0.10), transparent 60%),
             radial-gradient(900px 400px at 110% 10%, rgba(168, 85, 247, 0.07), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f0f1f7;
  --surface-3: #e4e6ef;
  --border: rgba(15, 23, 42, 0.07);
  --border-strong: rgba(15, 23, 42, 0.14);
  --text: #0f1222;
  --text-2: #33384d;
  --muted: #6b7086;
  --faint: #a2a6b8;
  --accent: #3b6cf6;
  --accent-soft: rgba(59, 108, 246, 0.1);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.1);
  --gold: #d99a06;
  --gold-soft: rgba(245, 158, 11, 0.12);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 60px rgba(15, 23, 42, 0.18);
  --glass: rgba(255, 255, 255, 0.78);
  --chart-grid: rgba(15, 23, 42, 0.07);
  --heat-0: #e9ebf3;
  --heat-1: #b9c9ff;
  --heat-2: #6d8fff;
  --heat-3: #7c4dff;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    --bg: #f4f5fa;
    --bg-glow: radial-gradient(1200px 500px at 10% -10%, rgba(91, 108, 255, 0.10), transparent 60%),
               radial-gradient(900px 400px at 110% 10%, rgba(168, 85, 247, 0.07), transparent 60%);
    --surface: #ffffff;
    --surface-2: #f0f1f7;
    --surface-3: #e4e6ef;
    --border: rgba(15, 23, 42, 0.07);
    --border-strong: rgba(15, 23, 42, 0.14);
    --text: #0f1222;
    --text-2: #33384d;
    --muted: #6b7086;
    --faint: #a2a6b8;
    --accent: #3b6cf6;
    --accent-soft: rgba(59, 108, 246, 0.1);
    --success: #16a34a;
    --success-soft: rgba(22, 163, 74, 0.1);
    --gold: #d99a06;
    --gold-soft: rgba(245, 158, 11, 0.12);
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 20px 60px rgba(15, 23, 42, 0.18);
    --glass: rgba(255, 255, 255, 0.78);
    --chart-grid: rgba(15, 23, 42, 0.07);
    --heat-0: #e9ebf3;
    --heat-1: #b9c9ff;
    --heat-2: #6d8fff;
    --heat-3: #7c4dff;
    color-scheme: light;
  }
}

/* ── Base ──────────────────────────────────────────── */
html { background: var(--bg); }
body {
  background: var(--bg-glow), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(150px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.app { max-width: 720px; margin: 0 auto; }
.num { font-variant-numeric: tabular-nums; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 20px 12px;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.topbar .sub { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }

main { padding: 16px; animation: fade-up 0.28s ease both; }
h2 { font-size: 19px; font-weight: 750; letter-spacing: -0.01em; }
h3 { font-size: 15px; font-weight: 700; margin: 18px 0 8px; }
h3.flush, h2.flush { margin: 0; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.small { font-size: 13px; }
.tiny { font-size: 11px; }
.center { text-align: center; }
.pad { padding: 32px 0; }
.row { display: flex; align-items: center; gap: 8px; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 26px 2px 10px; }
.section-title h2 { font-size: 20px; }
.eyebrow { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes grow-y { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes grow-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes shimmer { from { background-position: -200% 0; } to { background-position: 200% 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 12px 14px; border-radius: 14px;
  background: var(--surface-2); color: var(--text); font-weight: 650; text-align: center;
  border: 1px solid var(--border);
  transition: transform 0.12s ease, filter 0.15s ease, background 0.15s ease;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; }
.btn.primary { background: var(--accent-grad); color: #fff; border-color: transparent; box-shadow: 0 6px 20px rgba(91, 108, 255, 0.35); }
.btn.success { background: var(--success); color: #fff; border-color: transparent; box-shadow: 0 6px 18px rgba(34, 197, 94, 0.3); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger-text { background: transparent; border-color: transparent; color: var(--danger); }
.btn.soft { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.btn.small { width: auto; padding: 8px 13px; font-size: 14px; border-radius: 12px; }
.btn.big { padding: 16px; font-size: 16px; border-radius: 16px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 12px; color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.filled { background: var(--surface-2); border: 1px solid var(--border); }

/* ── Cards ─────────────────────────────────────────── */
.card {
  display: block; width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-link { text-align: left; transition: transform 0.15s ease, border-color 0.15s ease; }
.card-link:hover { border-color: var(--border-strong); }
.card-link:active { transform: scale(0.99); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h3 { margin: 0; display: flex; align-items: center; gap: 8px; }
.card-head h3 .icon { color: var(--accent); }

/* Hero (home) */
.hero {
  position: relative; overflow: hidden;
  border-radius: 24px; padding: 20px;
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 18px 40px rgba(91, 108, 255, 0.35);
}
.hero::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(500px 220px at 85% -20%, rgba(255, 255, 255, 0.28), transparent 60%),
              radial-gradient(300px 200px at -10% 120%, rgba(0, 0, 0, 0.18), transparent 60%);
  pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }
.hero-top { display: flex; align-items: center; gap: 16px; }
.hero h2 { font-size: 23px; font-weight: 800; }
.hero p { color: rgba(255, 255, 255, 0.82); font-size: 14px; }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.hero-stat { background: rgba(255, 255, 255, 0.14); border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 14px; padding: 10px 12px; backdrop-filter: blur(6px); }
.hero-stat small { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: rgba(255, 255, 255, 0.8); text-transform: uppercase; letter-spacing: 0.05em; }
.hero-stat .delta-mini { display: block; font-size: 11px; font-weight: 700; color: rgba(255, 255, 255, 0.85); margin-top: 2px; }
.hero-stat strong { display: block; white-space: nowrap; font-size: 19px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.hero .ring-track { stroke: rgba(255, 255, 255, 0.22); }
.hero .ring-fill { stroke: #fff; }
.hero .ring-label strong { color: #fff; }
.hero .ring-label small { color: rgba(255, 255, 255, 0.8); }

.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 14px; }
.week-day { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; color: rgba(255, 255, 255, 0.75); }
.week-day i { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; background: rgba(255, 255, 255, 0.12); font-style: normal; }
.week-day.done i { background: #fff; color: #5b5cf0; }
.week-day.today { color: #fff; }
.week-day.today i { outline: 2px solid rgba(255, 255, 255, 0.85); outline-offset: 1px; }

/* Ring */
.ring { position: relative; flex-shrink: 0; }
.ring svg { display: block; transform: rotate(-90deg); }
.ring-track { stroke: var(--surface-3); }
.ring-fill { stroke: url(#ring-grad); transition: stroke-dashoffset 0.9s cubic-bezier(.2,.8,.2,1); }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; line-height: 1.1; }
.ring-label strong { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ring-label small { font-size: 10px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }

/* Routine cards */
.routine-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 460px) { .routine-grid { grid-template-columns: 1fr; } }
.routine-card { display: flex; flex-direction: column; gap: 10px; }
.routine-card h3 { margin: 0; font-size: 17px; }
.routine-meta { display: flex; gap: 12px; font-size: 12px; color: var(--muted); font-weight: 600; }
.routine-meta span { display: inline-flex; align-items: center; gap: 4px; }
.routine-thumbs { display: flex; }
.routine-thumbs > * { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--surface); margin-left: -8px; background: #fff; object-fit: cover; }
.routine-thumbs > *:first-child { margin-left: 0; }
.routine-card .btn { margin-top: auto; }
.empty-card { text-align: center; padding: 26px 16px; border-style: dashed; box-shadow: none; background: transparent; }
.empty-card .icon { color: var(--accent); margin-bottom: 8px; }

/* Inputs */
select, .field input, .input, textarea.notes {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
select { appearance: none; -webkit-appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b8b98' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select { color: var(--text); font-size: 15px; width: 100%; font-weight: 400; }

/* Segmented control & chips */
.segmented { display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; }
.segmented button { flex: 1; padding: 6px 10px; border-radius: 9px; font-size: 13px; font-weight: 650; color: var(--muted); white-space: nowrap; transition: background 0.15s ease, color 0.15s ease; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 11px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12.5px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.chip.primary { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.gold { background: var(--gold-soft); color: var(--gold); border-color: transparent; }
button.chip { transition: background 0.15s ease, color 0.15s ease; }
button.chip.active { background: var(--text); color: var(--bg); border-color: transparent; }
.chip-scroll { display: flex; gap: 6px; overflow-x: auto; padding: 2px 16px 4px; margin: 0 -16px; scrollbar-width: none; }
.chip-scroll::-webkit-scrollbar { display: none; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile-icon { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; margin-bottom: 10px; }
.tile-icon.blue { background: rgba(91, 140, 255, 0.15); color: #5b8cff; }
.tile-icon.violet { background: rgba(168, 85, 247, 0.15); color: #b57bff; }
.tile-icon.orange { background: rgba(249, 115, 22, 0.15); color: #fb923c; }
.tile-icon.green { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.tile-icon.gold { background: var(--gold-soft); color: var(--gold); }
.tile-icon.pink { background: rgba(236, 72, 153, 0.15); color: #f472b6; }
.tile small { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.tile strong { display: block; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile .delta { font-size: 12px; font-weight: 700; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }
.delta.flat { color: var(--muted); }

.stats { display: flex; gap: 18px; flex-wrap: wrap; }
.stats div small { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 11.5px; font-weight: 600; }
.stats div strong { font-size: 16px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stats.centered { justify-content: center; }

/* ── Workout editor ────────────────────────────────── */
.live-bar {
  position: sticky; top: calc(62px + env(safe-area-inset-top)); z-index: 4;
  margin: -16px -16px 14px; padding: 12px 16px 10px;
  background: var(--glass); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
.live-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.live-stats div { display: flex; flex-direction: column; }
.live-stats small { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); font-weight: 650; }
.live-stats strong { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.progress { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 10px; }
.progress span { display: block; height: 100%; border-radius: 3px; background: var(--accent-grad); transition: width 0.4s ease; }

.workout-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.workout-name {
  flex: 1; min-width: 0;
  background: none; border: none; font-size: 24px; font-weight: 800; letter-spacing: -0.02em;
  padding: 2px 0; border-bottom: 2px solid transparent;
}
.workout-name:focus { outline: none; border-bottom-color: var(--accent); }
textarea.notes { width: 100%; resize: vertical; margin-bottom: 14px; font-size: 14px; min-height: 42px; }

.ex-block { position: relative; padding: 14px 14px 12px; }
.ex-block.superset { border-left: 4px solid var(--ss); }
.ss-label { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 800; color: var(--ss); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.ex-title { display: flex; align-items: center; gap: 12px; }
.ex-thumb { width: 46px; height: 46px; border-radius: 14px; background: #fff; object-fit: cover; flex-shrink: 0; box-shadow: 0 0 0 1px var(--border); }
.ex-title-text { flex: 1; min-width: 0; text-align: left; }
.ex-title-text strong { display: block; font-size: 16px; font-weight: 750; color: var(--text); }
.ex-title-text small { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.ex-tools { display: flex; align-items: center; gap: 6px; margin: 10px 0 6px; flex-wrap: wrap; }
.pill-select { display: inline-flex; align-items: center; gap: 6px; padding: 0 0 0 10px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 700; }
.pill-select select { background-color: transparent; border: none; padding: 6px 26px 6px 0; color: var(--accent); font-weight: 700; font-size: 12.5px; box-shadow: none; }
.ex-notes { flex: 1; min-width: 120px; background: none; border: none; padding: 6px 2px; font-size: 13.5px; color: var(--muted); }
.ex-notes:focus { outline: none; color: var(--text); }

.sets { width: 100%; border-collapse: separate; border-spacing: 0 4px; font-size: 14px; }
.sets th { color: var(--faint); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; text-align: center; padding: 2px; }
.sets td { text-align: center; padding: 3px 2px; transition: background 0.25s ease; }
.sets td.prev button { color: var(--muted); font-size: 13px; padding: 5px 4px; border-radius: 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sets td.prev button:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.sets tr.done td { background: var(--success-soft); }
.sets tr.done td:first-child { border-radius: 12px 0 0 12px; }
.sets tr.done td:last-child { border-radius: 0 12px 12px 0; }
.sets tr.pr td { background: var(--gold-soft); }
.set-input {
  width: 100%; max-width: 76px; padding: 8px 4px; text-align: center;
  background: var(--surface-2); border: 1px solid transparent; border-radius: 10px;
  font-weight: 650; font-variant-numeric: tabular-nums;
}
.set-input.rpe { max-width: 46px; }
.set-input::placeholder { color: var(--faint); font-weight: 500; }
tr.done .set-input { background: transparent; }
.set-label {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 28px; padding: 0 5px; border-radius: 9px;
  background: var(--surface-2); font-weight: 800; font-size: 13px;
}
.set-label.type-warmup { color: var(--warn); background: rgba(245, 158, 11, 0.13); }
.set-label.type-drop { color: var(--violet); background: rgba(168, 85, 247, 0.13); }
.set-label.type-failure { color: var(--danger); background: var(--danger-soft); }
.set-num { position: relative; display: inline-flex; }
.pr-badge { position: absolute; top: -7px; right: -9px; color: var(--gold); filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
.check {
  display: inline-grid; place-items: center;
  width: 36px; height: 32px; border-radius: 10px;
  background: var(--surface-2); color: var(--faint);
  transition: background 0.2s ease, color 0.2s ease, transform 0.12s ease;
}
.check:active { transform: scale(0.9); }
tr.done .check { background: var(--success); color: #fff; animation: pop 0.3s ease; }
.add-set { margin-top: 6px; padding: 9px; font-size: 14px; }

/* Confetti burst for PRs */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti i { position: absolute; width: 8px; height: 12px; border-radius: 2px; opacity: 0; animation: confetti 1.1s cubic-bezier(.2,.7,.3,1) forwards; }
@keyframes confetti {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); }
}

/* Menus */
.menu { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.menu-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); text-align: left; font-weight: 600; transition: background 0.15s ease; }
.menu-item:hover { background: var(--surface-2); }
.menu-item:last-child { border-bottom: none; }
.menu-item .icon { color: var(--muted); }
.menu-item.selected { color: var(--accent); }
.menu-item.selected .icon { color: var(--accent); }
.menu-item.danger, .menu-item.danger .icon { color: var(--danger); }
.menu-item .chev { margin-left: auto; color: var(--faint); }

/* ── Library ───────────────────────────────────────── */
.search-wrap { position: relative; }
.search-wrap .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search {
  width: 100%; padding: 12px 14px 12px 40px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.filters { display: flex; gap: 6px; margin: 8px 0 4px; }
.filters select { flex: 1; min-width: 0; font-size: 13px; padding: 7px 28px 7px 10px; }
.lib-count { margin: 8px 2px 2px; }
.list-head { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; padding: 16px 4px 6px; }
.ex-list { display: flex; flex-direction: column; gap: 6px; }
.ex-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px 8px 8px; text-align: left; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease; }
.ex-row:hover { border-color: var(--border-strong); }
.ex-row:active { transform: scale(0.99); }
.ex-row-img { width: 52px; height: 52px; border-radius: 12px; background: #fff; flex-shrink: 0; object-fit: cover; }
.thumb-ph { display: inline-flex; align-items: center; justify-content: center; background: var(--accent-grad) !important; color: #fff; font-weight: 800; font-size: 18px; }
.ex-row-text { flex: 1; min-width: 0; }
.ex-row strong { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ex-row small { color: var(--muted); font-size: 12.5px; }
.ex-row .chev { color: var(--faint); }
.ex-row .tick { display: none; }
.ex-row.selected { background: var(--accent-soft); border-color: var(--accent); }
.ex-row.selected .tick { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; }
.ex-row.selected .chev { display: none; }
.ex-row .spark { flex-shrink: 0; }
.picker-bar { position: sticky; bottom: calc(-24px - env(safe-area-inset-bottom)); padding: 14px 0 6px; background: linear-gradient(transparent, var(--bg) 35%); }

/* ── Modal / bottom sheet ─────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in 0.2s ease;
}
.modal[hidden] { display: none; }
.sheet {
  position: relative;
  width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 26px 26px 0 0;
  padding: 10px 16px calc(28px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
  animation: sheet-up 0.32s cubic-bezier(.2,.8,.2,1);
}
.sheet::before { content: ''; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--surface-3); margin: 0 auto 10px; }
@media (min-width: 760px) {
  .modal { align-items: center; }
  .sheet { border-radius: 26px; max-height: 86vh; }
  .sheet::before { display: none; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-head h2 { min-width: 0; overflow-wrap: anywhere; font-size: 21px; }

.detail-hero { display: grid; grid-template-columns: 132px 1fr; gap: 14px; align-items: center; margin-bottom: 14px; }
.detail-hero .gif { width: 132px; height: 132px; border-radius: 18px; object-fit: cover; background: #fff; }
.detail-hero .frames { position: relative; display: block; width: 132px; height: 132px; border-radius: 18px; overflow: hidden; background: #fff; }
.frames img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* Start photo underneath; the end photo blinks in for the second half of each cycle. */
.frames img:last-child { animation: frame-swap 1.8s steps(1) infinite; }
@keyframes frame-swap { 0% { opacity: 0; } 50% { opacity: 1; } 100% { opacity: 0; } }
.detail-hero .thumb-ph { width: 132px; height: 132px; border-radius: 18px; font-size: 44px; }
.mini-stats { display: grid; gap: 8px; }
.mini-stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; }
.mini-stat small { display: block; font-size: 11px; color: var(--muted); font-weight: 650; }
.mini-stat strong { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.gif-large { width: 100%; max-width: 360px; margin: 0 auto; display: block; border-radius: var(--radius); background: #fff; }
.attr { font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }
.steps { counter-reset: step; display: flex; flex-direction: column; gap: 10px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 26px 1fr; gap: 10px; font-size: 14.5px; color: var(--text-2); }
.steps li::before { content: counter(step); display: grid; place-items: center; width: 26px; height: 26px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 13px; }
.records { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.record { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); }
.record .tile-icon { width: 30px; height: 30px; margin-bottom: 6px; }
.record small { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.record strong { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rm-table { width: 100%; border-collapse: collapse; }
.rm-table td { padding: 9px 4px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.rm-table td:nth-child(2) { width: 50%; }
.rm-table td:last-child { text-align: right; font-weight: 750; }
.rm-bar { height: 6px; border-radius: 3px; background: var(--accent-grad); transform-origin: left; animation: grow-x 0.6s ease both; }
.session + .session { margin-top: 10px; }
.session-sets { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.session-sets li { display: flex; align-items: center; gap: 10px; font-size: 14px; font-variant-numeric: tabular-nums; }
.session-sets .set-label { min-width: 24px; height: 24px; font-size: 12px; }
.session-sets .icon { color: var(--gold); }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.notes-view { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; font-size: 14px; white-space: pre-wrap; color: var(--text-2); }

/* Summary & PRs */
.summary { text-align: center; padding-top: 6px; }
.summary-badge { width: 76px; height: 76px; margin: 4px auto 10px; border-radius: 24px; display: grid; place-items: center; background: var(--accent-grad); color: #fff; box-shadow: 0 12px 30px rgba(91, 108, 255, 0.45); animation: pop 0.5s ease; }
.summary h2 { font-size: 24px; }
.summary h3, .summary .pr-row { text-align: left; }
.summary .chips { justify-content: flex-start; }
.summary-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0 4px; }
.summary-stats div { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 6px; }
.summary-stats small { display: block; font-size: 11px; color: var(--muted); font-weight: 650; }
.summary-stats strong { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pr-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 12px; margin-bottom: 8px; background: var(--gold-soft); border: 1px solid rgba(251, 191, 36, 0.25); border-radius: 14px; font-size: 14px; }
.pr-row .icon { color: var(--gold); }
.pr-row > span:last-child { white-space: nowrap; font-weight: 800; }
.pr-pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: var(--gold-soft); color: var(--gold); }

/* ── History ───────────────────────────────────────── */
.calendar .cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.calendar .cal-head strong { font-size: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-dow { font-size: 11px; font-weight: 700; color: var(--faint); padding-bottom: 4px; }
.cal-day { aspect-ratio: 1; display: grid; place-items: center; border-radius: 12px; font-size: 13.5px; font-weight: 650; color: var(--text-2); position: relative; }
.cal-day.other { color: var(--faint); opacity: 0.45; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-day.trained { background: var(--accent-grad); color: #fff; box-shadow: 0 4px 12px rgba(91, 108, 255, 0.3); }
.cal-day.trained:hover { filter: brightness(1.1); }
.cal-summary { display: flex; gap: 16px; margin-top: 12px; font-size: 13px; color: var(--muted); font-weight: 600; }
.cal-summary strong { color: var(--text); }
.month-head { display: flex; align-items: baseline; gap: 8px; margin: 24px 4px 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 800; }
.history-card h3 { margin: 0; font-size: 17px; }
.history-card .when { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; font-weight: 600; margin-top: 2px; }
.history-card .stats { margin: 12px 0; padding: 10px 12px; background: var(--surface-2); border-radius: 12px; justify-content: space-between; }
.history-ex { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; padding: 4px 0; }
.history-ex .lhs { display: flex; align-items: center; gap: 10px; min-width: 0; }
.history-ex .lhs img, .history-ex .lhs .thumb-ph { width: 28px; height: 28px; border-radius: 8px; background: #fff; object-fit: cover; flex-shrink: 0; font-size: 12px; }
.history-ex .lhs span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-ex > span:last-child { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ── Charts ────────────────────────────────────────── */
.chart-card .card-head { margin-bottom: 4px; }
.chart-headline { display: flex; align-items: baseline; gap: 10px; margin: 2px 0 2px; }
.chart-headline strong { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: auto; display: block; margin-top: 8px; overflow: visible; touch-action: pan-y; }
.chart .grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .bar { fill: url(#bar-grad); transform-box: fill-box; transform-origin: bottom; animation: grow-y 0.6s cubic-bezier(.2,.8,.2,1) both; }
.chart .bar.muted { fill: var(--surface-3); }
.chart g:hover .bar { filter: brightness(1.15); }
.chart .avg { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }
.chart .avg-label { fill: var(--muted); font-size: 10px; font-weight: 700; }
.chart .hit { fill: transparent; }
.chart .line { fill: none; stroke: url(#line-grad); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1s cubic-bezier(.4,0,.2,1) forwards; }
.chart .area { opacity: 0; animation: fade-in 0.6s 0.4s ease forwards; }
.chart .dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart .dot.pr { stroke: var(--gold); fill: var(--gold); }
.chart .dot.last { fill: var(--accent); stroke: var(--surface); stroke-width: 3; }
.chart .dot.last.pr { fill: var(--gold); }
.chart .last-label { fill: var(--text); font-size: 11px; font-weight: 800; }
.chart .crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .focus-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 3; }
.chart-empty { padding: 26px 0; text-align: center; }
.chart-legend { display: flex; align-items: center; gap: 12px; margin-top: 10px; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.heatmap-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.heatmap { min-width: 340px; }
.heat { fill: var(--heat-0); transition: filter 0.15s ease; }
.heat:hover { filter: brightness(1.3); }
.heat.l1 { fill: var(--heat-1); }
.heat.l2 { fill: var(--heat-2); }
.heat.l3 { fill: var(--heat-3); }
.heat-legend { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 8px; font-size: 11px; color: var(--muted); font-weight: 600; }
.heat-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.hbars { display: flex; flex-direction: column; gap: 9px; margin-top: 10px; }
.hbar { display: grid; grid-template-columns: 112px 1fr 38px; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar-track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: var(--accent-grad); border-radius: 5px; transform-origin: left; animation: grow-x 0.7s cubic-bezier(.2,.8,.2,1) both; }
.hbar-value { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.tooltip {
  position: absolute; z-index: 40; transform: translate(-50%, -100%); pointer-events: none;
  background: var(--text); color: var(--bg);
  border-radius: 10px; padding: 6px 10px; font-size: 12px; font-weight: 700; white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.bw-form { margin: 12px 0 4px; }
.bw-form input { flex: 1; min-width: 0; }

/* Settings */
.settings-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.settings-group + .settings-group { margin-top: 14px; }
.setting { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); width: 100%; text-align: left; }
.setting:last-child { border-bottom: none; }
.setting .tile-icon { width: 32px; height: 32px; margin: 0; border-radius: 10px; }
.setting-text { flex: 1; min-width: 0; font-weight: 650; }
.setting-text small { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.setting select { font-size: 13.5px; padding: 6px 28px 6px 10px; max-width: 58%; text-overflow: ellipsis; }
.setting-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.setting .chev { color: var(--faint); }
.setting.danger .setting-text { color: var(--danger); }
.switch { position: relative; width: 46px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); transition: background 0.2s ease; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); transition: transform 0.2s cubic-bezier(.2,.8,.2,1); }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(18px); }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper strong { min-width: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.stepper .icon-btn { width: 30px; height: 30px; background: var(--surface-2); }

/* Hevy import mapping */
.map-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.map-row:last-child { border-bottom: none; }

/* Plate calculator */
.pc-result { margin-top: 16px; }
.barbell { display: flex; align-items: center; justify-content: center; gap: 3px; padding: 18px 8px; margin: 8px 0 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 110px; }
.bar-rod { height: 10px; width: 46px; background: linear-gradient(#cfd3dc, #8d93a1); border-radius: 3px; }
.bar-sleeve { height: 16px; width: 14px; background: linear-gradient(#cfd3dc, #8d93a1); border-radius: 2px; }
.plate { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 52px; border-radius: 5px; font-weight: 800; color: #fff; background: #555; font-size: 10px; writing-mode: vertical-rl; text-orientation: mixed; box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
.plate.p25, .plate.p45 { background: #e5484d; height: 92px; }
.plate.p20, .plate.p35 { background: #3e7bfa; height: 86px; }
.plate.p15 { background: #f5c518; color: #111; height: 78px; }
.plate.p10 { background: #30a46c; height: 66px; }
.plate.p5 { background: #e9e9ee; color: #111; height: 54px; }
.plate.p2_5, .plate.p1_25 { background: #7c7c88; height: 42px; width: 16px; }

/* ── Rest timer ────────────────────────────────────── */
.restbar {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 9;
  bottom: calc(86px + env(safe-area-inset-bottom));
  width: calc(100% - 24px); max-width: 696px;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 20px; overflow: hidden;
  background: var(--glass); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  animation: sheet-up 0.3s ease;
}
.restbar[hidden] { display: none; }
.rest-ring { position: relative; width: 44px; height: 44px; flex-shrink: 0; }
.rest-ring svg { transform: rotate(-90deg); }
.rest-ring circle { fill: none; stroke-width: 4; }
.rest-ring .track { stroke: var(--surface-3); }
.rest-ring .fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.rest-ring .icon { position: absolute; inset: 0; margin: auto; color: var(--accent); }
.rest-text { flex: 1; display: flex; flex-direction: column; line-height: 1.1; }
.rest-text small { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
#rest-left { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ── Tab bar (floating) ────────────────────────────── */
.tabbar {
  position: fixed; z-index: 10; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: calc(100% - 24px); max-width: 480px;
  display: flex; padding: 6px;
  background: var(--glass); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border-strong); border-radius: 24px;
  box-shadow: var(--shadow-lg);
}
.tabbar button {
  position: relative; flex: 1;
  padding: 7px 0 6px; border-radius: 18px; font-size: 10.5px; font-weight: 700; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: color 0.2s ease, background 0.2s ease;
}
.tabbar button.active { color: var(--accent); background: var(--accent-soft); }
#active-dot {
  position: absolute; top: 5px; right: calc(50% - 20px);
  width: 9px; height: 9px; border-radius: 50%; background: var(--success);
  box-shadow: 0 0 0 2px var(--surface), 0 0 10px var(--success);
}

.toast[hidden], .tooltip[hidden] { display: none; }
.toast {
  position: fixed; left: 50%; top: calc(74px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 30;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 700; white-space: nowrap;
  box-shadow: var(--shadow-lg);
  animation: fade-up 0.25s ease;
}
