/* ============================================================
   Gym&Jam — Design System
   Editorial training log · warm paper · single accent · tabular data
   ============================================================ */
:root {
  --paper: #f2efe8;
  --paper-2: #eae6db;
  --surface: #ffffff;
  --surface-2: #f6f3ec;
  --surface-3: #ece7db;
  --border: #ddd7c8;
  --border-strong: #c7c0ac;
  --ink: #1b1a16;
  --ink-2: #33302a;
  --text-dim: #6a6459;
  --text-faint: #98917f;

  --accent: #e0451f;
  --accent-dark: #bf3714;
  --accent-soft: #fbe7df;
  --accent-ink: #ffffff;

  --pos: #2e7d46;
  --neg: #c23a24;

  --solid: #1b1a16;
  --on-solid: #ffffff;
  --danger-soft: #fbeae6;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 1px 2px rgba(30, 25, 15, 0.05), 0 12px 28px -18px rgba(30, 25, 15, 0.28);
  --sidebar-w: 250px;
  color-scheme: light;
}

/* ---- Dark theme ------------------------------------------- */
:root[data-theme="dark"] {
  --paper: #131210;
  --paper-2: #1a1813;
  --surface: #1e1c16;
  --surface-2: #26231b;
  --surface-3: #302b21;
  --border: #332f26;
  --border-strong: #474131;
  --ink: #f2eee5;
  --ink-2: #d8d2c4;
  --text-dim: #a79f8d;
  --text-faint: #7d7563;

  --accent: #ef5a31;
  --accent-dark: #d84a24;
  --accent-soft: #33201a;
  --accent-ink: #ffffff;

  --pos: #4bb56e;
  --neg: #e56750;

  --solid: #2c2820;
  --on-solid: #f2eee5;
  --danger-soft: #3a201a;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 34px -18px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: "Inter", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3, .brand-name, .display, .stat-value, .num { font-family: "Space Grotesk", sans-serif; }
.num, .stat-value, .set-vol, .history-metric b, .record-val b, .hd-day, .set-pill { font-variant-numeric: tabular-nums; }

::selection { background: var(--accent); color: #fff; }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 20px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b0a894; background-clip: content-box; }

/* ============================================================
   Layout
   ============================================================ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  padding: 24px 16px;
  display: flex; flex-direction: column; gap: 28px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; height: 100vh;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px 4px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 9px;
  background: var(--solid); color: var(--accent);
  display: grid; place-items: center;
}
.brand-logo svg { width: 22px; height: 22px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -0.4px; color: var(--ink); }
.brand-tag { font-size: 10px; color: var(--text-faint); letter-spacing: 1.8px; text-transform: uppercase; font-weight: 600; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 10.5px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase; color: var(--text-faint); padding: 0 12px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-dim);
  font: inherit; font-weight: 500; font-size: 14.5px;
  cursor: pointer; text-align: left; transition: background 0.14s, color 0.14s;
  position: relative;
}
.nav-item svg { width: 19px; height: 19px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.is-active { background: var(--solid); color: var(--on-solid); font-weight: 600; }
.nav-item.is-active svg { opacity: 1; }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 14px; }
.streak-badge {
  padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); display: flex; flex-direction: column; gap: 2px;
}
.streak-top { display: flex; align-items: baseline; gap: 8px; }
.streak-num { font-family: "Space Grotesk"; font-weight: 700; font-size: 30px; line-height: 1; color: var(--ink); }
.streak-unit { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.streak-label { font-size: 11px; color: var(--text-faint); letter-spacing: 0.8px; text-transform: uppercase; font-weight: 600; }
.streak-badge.is-hot .streak-num { color: var(--accent); }

.sidebar-actions { display: flex; gap: 8px; }
.ghost-btn {
  flex: 1; padding: 9px; border-radius: var(--radius-xs); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim); font: inherit; font-size: 12.5px; font-weight: 600;
  cursor: pointer; transition: all 0.14s;
}
.ghost-btn:hover { border-color: var(--border-strong); color: var(--ink); background: var(--surface-2); }

.main { flex: 1; min-width: 0; padding: 36px 44px 70px; max-width: 1120px; margin: 0 auto; width: 100%; }

/* ============================================================
   View header
   ============================================================ */
.view-head { margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1.5px solid var(--border); }
.view-head .eyebrow { color: var(--accent); font-size: 11.5px; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase; }
.view-head h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.8px; margin-top: 6px; color: var(--ink); }
.view-head .subtitle { color: var(--text-dim); margin-top: 6px; font-size: 14.5px; max-width: 60ch; }
.view-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background 0.14s, border-color 0.14s, transform 0.1s, color 0.14s;
  white-space: nowrap;
}
.btn svg { width: 17px; height: 17px; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-accent { background: var(--solid); color: var(--on-solid); }
.btn-accent:hover { opacity: 0.9; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--surface); color: var(--neg); border-color: color-mix(in srgb, var(--neg) 35%, var(--border)); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 8px 13px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center; border-radius: var(--radius-xs);
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  cursor: pointer; transition: all 0.14s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { color: var(--ink); border-color: var(--border-strong); }
.icon-btn.danger:hover { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, var(--border)); background: var(--danger-soft); }

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.section-title { font-size: 15px; font-weight: 600; letter-spacing: -0.2px; color: var(--ink); display: flex; align-items: center; gap: 9px; font-family: "Space Grotesk"; }
.section-title .step { font-family: "Space Grotesk"; font-size: 12px; font-weight: 700; width: 22px; height: 22px; border-radius: 6px; background: var(--solid); color: var(--on-solid); display: grid; place-items: center; letter-spacing: 0; }
.count-pill { font-family: "Inter"; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 20px; background: var(--surface-3); color: var(--text-dim); }

/* ============================================================
   Muscle group chips
   ============================================================ */
.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.group-chip {
  --c: var(--ink);
  position: relative; padding: 13px 14px 13px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; transition: border-color 0.14s, background 0.14s;
  display: flex; align-items: center; gap: 11px; text-align: left;
}
.group-chip .g-mark {
  width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
  display: grid; place-items: center; font-family: "Space Grotesk"; font-weight: 700; font-size: 12.5px;
  background: color-mix(in srgb, var(--c) 14%, var(--surface)); color: var(--c); letter-spacing: 0.5px;
}
.group-chip .g-info { min-width: 0; }
.group-chip .g-name { font-weight: 600; font-size: 14px; color: var(--ink); }
.group-chip .g-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }
.group-chip:hover { border-color: var(--c); }
.group-chip.is-selected { border-color: var(--c); background: color-mix(in srgb, var(--c) 8%, var(--surface)); box-shadow: inset 0 0 0 1px var(--c); }
.group-chip.is-selected .g-mark { background: var(--c); color: #fff; }
.g-emoji, .g-bar { display: none; }

/* ============================================================
   Today / Session builder
   ============================================================ */
.today-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
.date-field { display: flex; flex-direction: column; gap: 5px; }
.date-field label { font-size: 11px; color: var(--text-faint); font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; }

.input, .select, textarea.input {
  padding: 10px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 14.5px;
  transition: border 0.14s, box-shadow 0.14s;
}
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder { color: var(--text-faint); }
textarea.input { resize: vertical; min-height: 46px; width: 100%; }
.select { cursor: pointer; }

.empty-hint {
  text-align: center; padding: 44px 20px; color: var(--text-dim);
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
}
.empty-hint .emoji { display: none; }
.empty-hint b { color: var(--ink); font-weight: 700; }

/* Exercise block */
.ex-block { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.ex-block + .ex-block { margin-top: 12px; }
.ex-head { display: flex; align-items: center; gap: 12px; padding: 13px 15px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.ex-head .ex-dot { width: 8px; height: 28px; border-radius: 3px; flex-shrink: 0; }
.ex-head .ex-name { font-weight: 600; font-size: 15px; color: var(--ink); }
.ex-head .ex-group { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.8px; font-weight: 600; margin-top: 1px; }
.ex-head .ex-vol { margin-left: auto; font-size: 12px; color: var(--text-dim); }
.ex-head .ex-vol b { color: var(--ink); font-family: "Space Grotesk"; font-size: 14px; font-variant-numeric: tabular-nums; }

.last-time { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 15px 0; font-size: 12.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.last-time > span { font-size: 10px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; color: var(--text-faint); background: var(--surface-3); padding: 3px 8px; border-radius: 5px; }
.last-time em { font-style: normal; color: var(--text-faint); margin-left: auto; font-size: 11.5px; }

.reuse-item { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 12px 14px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); cursor: pointer; transition: all 0.13s; }
.reuse-item:hover { border-color: var(--border-strong); background: var(--surface-2); }
.reuse-item + .reuse-item { margin-top: 8px; }
.reuse-date { display: flex; flex-direction: column; align-items: center; width: 40px; flex-shrink: 0; border-right: 1px solid var(--border); padding-right: 12px; }
.reuse-date b { font-family: "Space Grotesk"; font-size: 20px; font-weight: 700; line-height: 1; color: var(--ink); }
.reuse-date span { font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-faint); font-weight: 600; margin-top: 2px; }
.reuse-info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 5px; }
.reuse-name { font-weight: 600; font-size: 14.5px; color: var(--ink); }
.reuse-tags { display: flex; gap: 5px; flex-wrap: wrap; }
.reuse-sub { font-size: 12.5px; color: var(--text-dim); }
.reuse-item > svg { color: var(--text-faint); flex-shrink: 0; }

/* Routine (template) cards */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; align-items: start; }
.tpl-card { display: flex; flex-direction: column; gap: 12px; }
.tpl-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.tpl-name { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; color: var(--ink); line-height: 1.25; }
.tpl-tags { display: flex; gap: 5px; flex-wrap: wrap; }
.tpl-ex { list-style: none; display: flex; flex-direction: column; gap: 7px; margin: 2px 0; padding: 14px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.tpl-ex li { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--ink-2); }
.tpl-ex li .ex-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.tpl-ex li em { margin-left: auto; font-style: normal; color: var(--text-faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.tpl-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; }
.tpl-meta { font-size: 12px; color: var(--text-faint); }
.tpl-foot .btn svg { width: 15px; height: 15px; }
.share-box { display: flex; gap: 8px; }
.share-box .input { flex: 1; min-width: 0; font-size: 13px; }

.sets-table { padding: 4px 12px 12px; }
.set-row { display: grid; grid-template-columns: 30px 1fr 1fr auto auto; gap: 10px; align-items: center; padding: 6px 2px; }
.set-row.set-head { padding-bottom: 2px; padding-top: 10px; }
.set-row.set-head span { font-size: 10.5px; color: var(--text-faint); font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; }
.set-row.set-head .opt { display: inline-block; margin-left: 5px; padding: 1px 6px; border-radius: 5px; background: var(--surface-3); color: var(--text-dim); font-weight: 600; letter-spacing: 0.2px; text-transform: none; }
.set-hint { margin: 8px 2px 2px; font-size: 12px; color: var(--text-faint); line-height: 1.4; }
.set-idx { width: 28px; height: 28px; border-radius: 6px; background: var(--surface-3); display: grid; place-items: center; font-weight: 700; font-size: 12.5px; color: var(--text-dim); font-family: "Space Grotesk"; }
.set-input { width: 100%; padding: 9px 11px; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink); font: inherit; font-size: 14.5px; text-align: center; font-variant-numeric: tabular-nums; }
.set-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.set-vol { font-size: 12.5px; color: var(--text-dim); text-align: right; min-width: 64px; }
.pr-tag { font-size: 9.5px; font-weight: 800; color: #fff; background: var(--accent); padding: 2px 6px; border-radius: 4px; letter-spacing: 0.6px; vertical-align: middle; }
.add-set-btn {
  margin: 8px 2px 2px; width: calc(100% - 4px); padding: 9px; border-radius: 7px;
  border: 1px dashed var(--border-strong); background: transparent; color: var(--text-dim);
  font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; transition: all 0.14s;
}
.add-set-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.summary-row { display: flex; flex-wrap: wrap; gap: 0; margin-top: 18px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.summary-cell { flex: 1; min-width: 100px; padding: 14px 16px; border-right: 1px solid var(--border); }
.summary-cell:last-child { border-right: none; }
.summary-cell .s-label { font-size: 11px; color: var(--text-faint); font-weight: 600; letter-spacing: 0.6px; text-transform: uppercase; }
.summary-cell .s-value { font-family: "Space Grotesk"; font-size: 22px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.summary-cell .s-value small { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.summary-cell.accent .s-value { color: var(--accent); }

/* Exercise picker */
.picker-search { position: relative; margin-bottom: 14px; }
.picker-search input { width: 100%; padding-left: 38px; }
.picker-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--text-faint); }
.picker-list { display: flex; flex-direction: column; gap: 4px; max-height: 46vh; overflow-y: auto; padding-right: 4px; }
.picker-group-label { font-size: 10.5px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; margin: 14px 2px 4px; display: flex; align-items: center; gap: 7px; }
.picker-group-label::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.picker-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--surface-2); cursor: pointer; transition: all 0.13s; text-align: left; width: 100%;
}
.picker-item:hover { background: var(--surface); border-color: var(--border-strong); }
.picker-item .pi-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.picker-item .pi-name { font-weight: 500; font-size: 14px; color: var(--ink); }

/* ============================================================
   Stats
   ============================================================ */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0; margin-bottom: 22px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.stat-card { padding: 20px 22px; position: relative; border-right: 1px solid var(--border); }
.stat-card:last-child { border-right: none; }
.stat-card .stat-icon { display: none; }
.stat-card .stat-label { font-size: 11px; color: var(--text-faint); font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; }
.stat-card .stat-value { font-size: 30px; font-weight: 700; margin-top: 8px; letter-spacing: -0.8px; color: var(--ink); }
.stat-card .stat-value small { font-size: 13px; color: var(--text-dim); font-weight: 600; letter-spacing: 0; }
.stat-card .stat-delta { font-size: 12px; margin-top: 5px; font-weight: 600; }
.stat-delta.up { color: var(--pos); }
.stat-delta.down { color: var(--neg); }

.seg { display: inline-flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 22px; }
.seg-btn { padding: 8px 20px; border: none; background: transparent; color: var(--text-dim); font: inherit; font-size: 13.5px; font-weight: 600; border-radius: 6px; cursor: pointer; transition: all 0.14s; }
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-active { background: var(--solid); color: var(--on-solid); }

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.chart-card { padding: 22px; }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.chart-head h3 { font-size: 15px; font-weight: 600; color: var(--ink); }
.chart-head .hint { font-size: 11.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.6px; font-weight: 600; }
.chart-wrap { width: 100%; }
.chart-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 14px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-dim); }
.legend-dot { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.legend-item b { color: var(--ink); font-weight: 600; }

.record-row { display: flex; align-items: center; gap: 14px; padding: 13px 2px; border-bottom: 1px solid var(--border); }
.record-row:last-child { border-bottom: none; }
.record-rank { width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; font-weight: 700; font-size: 12.5px; background: var(--surface-3); color: var(--text-dim); flex-shrink: 0; font-family: "Space Grotesk"; }
.record-rank.top { background: var(--solid); color: var(--on-solid); }
.record-name { font-weight: 600; font-size: 14.5px; color: var(--ink); }
.record-meta { font-size: 12px; color: var(--text-faint); margin-top: 1px; }
.record-val { margin-left: auto; text-align: right; }
.record-val b { font-family: "Space Grotesk"; font-size: 17px; font-weight: 700; color: var(--ink); }
.record-val span { display: block; font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.6px; font-weight: 600; }

.select-inline { padding: 7px 11px; font-size: 13px; }

/* ============================================================
   History
   ============================================================ */
.history-list { display: flex; flex-direction: column; gap: 12px; }
.history-card { padding: 0; overflow: hidden; }
.history-top { display: flex; align-items: center; gap: 16px; padding: 16px 20px; cursor: pointer; transition: background 0.14s; }
.history-top:hover { background: var(--surface-2); }
.history-date { text-align: center; flex-shrink: 0; width: 50px; border-right: 1px solid var(--border); padding-right: 15px; }
.history-date .hd-day { font-family: "Space Grotesk"; font-size: 24px; font-weight: 700; line-height: 1; color: var(--ink); }
.history-date .hd-mon { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 1px; font-weight: 600; margin-top: 2px; }
.history-info { min-width: 0; flex: 1; }
.history-groups { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 6px; }
.g-tag { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 4px; color: #fff; letter-spacing: 0.3px; }
.history-summary { font-size: 13px; color: var(--text-dim); }
.history-metrics { display: flex; gap: 20px; margin-left: auto; text-align: right; flex-shrink: 0; }
.history-metric b { font-family: "Space Grotesk"; font-size: 17px; font-weight: 700; display: block; color: var(--ink); }
.history-metric span { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.history-chevron { color: var(--text-faint); transition: transform 0.2s; flex-shrink: 0; }
.history-card.is-open .history-chevron { transform: rotate(180deg); }
.history-body { padding: 0 20px; max-height: 0; overflow: hidden; transition: max-height 0.3s ease, padding 0.3s; }
.history-card.is-open .history-body { max-height: 1600px; padding: 4px 20px 20px; }
.history-ex { padding: 12px 0; border-top: 1px solid var(--border); }
.history-ex-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; color: var(--ink); }
.history-ex-name .ex-dot { width: 8px; height: 8px; border-radius: 2px; }
.history-sets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.set-pill { font-size: 12.5px; padding: 4px 10px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); }
.set-pill b { color: var(--ink); font-weight: 600; }
.history-actions { display: flex; gap: 8px; padding: 14px 20px 0; border-top: 1px solid var(--border); margin-top: 4px; }

/* ============================================================
   Exercises library
   ============================================================ */
.lib-filters { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 22px; }
.filter-chip {
  padding: 7px 13px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.14s;
  display: inline-flex; align-items: center; gap: 7px;
}
.filter-chip:hover { color: var(--ink); border-color: var(--border-strong); }
.filter-chip.is-active { background: var(--solid); color: var(--on-solid); border-color: var(--solid); }
.filter-chip .fc-dot { width: 8px; height: 8px; border-radius: 2px; }
.filter-chip .count-pill { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.filter-chip.is-active .count-pill { background: color-mix(in srgb, var(--on-solid) 20%, transparent); color: var(--on-solid); }

.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.lib-card { display: flex; align-items: center; gap: 12px; padding: 14px 15px; }
.lib-icon { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; font-family: "Space Grotesk"; font-weight: 700; font-size: 13px; flex-shrink: 0; letter-spacing: 0.5px; }
.lib-card { cursor: pointer; transition: border-color 0.14s, transform 0.1s; }
.lib-card:hover { border-color: var(--border-strong); }
.lib-card:active { transform: scale(0.99); }
.lib-icon { overflow: hidden; }
.lib-thumb { width: 100%; height: 100%; object-fit: cover; display: block; background: #fff; }
.lib-name { font-weight: 600; font-size: 14px; color: var(--ink); }

/* Exercise detail media (2-frame pseudo-animation from start/end photos) */
.ex-media-frame { position: relative; width: 100%; aspect-ratio: 3 / 2; border-radius: var(--radius-sm); overflow: hidden; background: #fff; border: 1px solid var(--border); margin-bottom: 16px; }
.ex-media-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.ex-media-frame .frame-b { opacity: 0; }
.ex-media-frame.animate .frame-b { animation: exFrame 1.4s steps(1, end) infinite; }
@keyframes exFrame { 0%, 50% { opacity: 0; } 50.01%, 100% { opacity: 1; } }
.ex-media-empty { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--text-faint); font-size: 13px; }
.ex-media-frame.img-error img { display: none; }
.ex-media-frame.img-error .ex-media-empty { display: flex; }
.ex-media-mark { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-family: "Space Grotesk"; font-weight: 700; font-size: 15px; background: color-mix(in srgb, var(--c) 15%, var(--surface)); color: var(--c); }

.ex-detail-stats { margin-bottom: 14px; }
.eds-line { font-size: 14px; color: var(--ink); font-weight: 500; }
.eds-sub { font-size: 12.5px; color: var(--text-faint); margin-top: 3px; }
.ex-instructions { font-size: 13.5px; color: var(--text-dim); line-height: 1.55; white-space: pre-wrap; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 4px; }
.modal-head p .g-tag { vertical-align: middle; }
.lib-cat { font-size: 12px; color: var(--text-faint); }
.lib-badge { margin-left: auto; font-size: 9.5px; font-weight: 700; padding: 2px 7px; border-radius: 4px; background: var(--surface-3); color: var(--text-faint); letter-spacing: 0.6px; }

/* ============================================================
   Modal
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(27, 26, 22, 0.42); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 100; padding: 20px; animation: fade 0.16s ease;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(540px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow); animation: pop 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; gap: 12px; }
.modal-head h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.4px; color: var(--ink); }
.modal-head p { font-size: 13px; color: var(--text-dim); margin-top: 3px; }
.modal-field { margin-bottom: 16px; }
.modal-field label { display: block; font-size: 12px; font-weight: 700; color: var(--text-dim); margin-bottom: 7px; letter-spacing: 0.4px; text-transform: uppercase; }
.modal-field .input, .modal-field .select { width: 100%; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

/* ============================================================
   Toast
   ============================================================ */
.toast-host { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 11px; padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--solid); border: 1px solid var(--solid); color: var(--on-solid);
  box-shadow: var(--shadow); font-size: 14px; font-weight: 500; animation: toastIn 0.24s cubic-bezier(0.2,0.9,0.3,1.15);
}
.toast .t-icon { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; font-size: 12px; font-weight: 700; }
.toast.success .t-icon { background: var(--pos); color: #fff; }
.toast.error .t-icon { background: var(--accent); color: #fff; }
.toast.info .t-icon { background: color-mix(in srgb, var(--on-solid) 18%, transparent); color: var(--on-solid); }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } }

/* ============================================================
   Auth screen
   ============================================================ */
.auth-overlay {
  position: fixed; inset: 0; z-index: 300;
  display: grid; place-items: center; padding: 24px;
  background-color: var(--paper);
  background-image: url("../assets/auth-bg.svg");
  background-size: cover;
  background-position: center;
  animation: fade 0.2s ease;
}
.auth-card { position: relative; z-index: 1; }

/* Floating theme toggle */
.theme-toggle {
  position: fixed; bottom: 22px; right: 22px; z-index: 350;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow);
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
}
.theme-toggle:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.theme-toggle svg { width: 20px; height: 20px; }
.js-theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .js-theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .js-theme-toggle .icon-sun { display: block; }
.auth-card {
  width: min(400px, 100%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow);
  animation: pop 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand .brand-logo { width: 42px; height: 42px; border-radius: 10px; }
.auth-brand .brand-name { font-family: "Space Grotesk"; font-weight: 700; font-size: 19px; letter-spacing: -0.4px; }
.auth-brand .brand-tag { font-size: 10px; color: var(--text-faint); letter-spacing: 1.8px; text-transform: uppercase; font-weight: 600; }
.auth-tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 20px; }
.auth-tab { flex: 1; padding: 9px; border: none; background: transparent; color: var(--text-dim); font: inherit; font-size: 13.5px; font-weight: 600; border-radius: 6px; cursor: pointer; transition: all 0.14s; }
.auth-tab.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.auth-form .modal-field { margin-bottom: 14px; }
.auth-error { background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--neg) 30%, var(--border)); color: var(--neg); font-size: 13px; font-weight: 500; padding: 10px 12px; border-radius: var(--radius-xs); margin-bottom: 14px; }
.auth-form .btn-block { margin-top: 4px; }
.auth-foot { text-align: center; font-size: 12px; color: var(--text-faint); margin-top: 18px; }
.auth-foot b { color: var(--text-dim); }

/* ============================================================
   Account box (sidebar)
   ============================================================ */
.account { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.account-info { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.account-avatar { width: 32px; height: 32px; border-radius: 8px; background: var(--solid); color: var(--on-solid); display: grid; place-items: center; font-family: "Space Grotesk"; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.account-meta { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.account-email { font-size: 12.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-status { display: flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--text-faint); font-weight: 600; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.account .icon-btn { flex-shrink: 0; }

/* ============================================================
   Rest timer
   ============================================================ */
.timer-fab {
  position: fixed; bottom: 22px; left: 22px; z-index: 250;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  display: none; place-items: center; cursor: pointer; box-shadow: var(--shadow);
  transition: transform 0.15s, border-color 0.15s;
}
.timer-fab:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.timer-fab svg { width: 21px; height: 21px; }

.timer-panel {
  position: fixed; z-index: 260; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  width: 300px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
  opacity: 0; pointer-events: none; transition: opacity 0.18s ease, transform 0.18s ease;
}
.timer-panel.is-open { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.timer-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.timer-modes { display: inline-flex; gap: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; }
.tmode { padding: 6px 12px; border: none; background: transparent; color: var(--text-dim); font: inherit; font-size: 12.5px; font-weight: 600; border-radius: 6px; cursor: pointer; transition: all 0.14s; }
.tmode:hover { color: var(--ink); }
.tmode.is-active { background: var(--solid); color: var(--on-solid); }
.timer-panel.mode-stopwatch .timer-presets { display: none; }
.timer-panel.mode-stopwatch .ctl-rest { display: none; }

.timer-dial { position: relative; width: 168px; height: 168px; margin: 4px auto 12px; }
.timer-dial svg { width: 100%; height: 100%; }
.timer-ring-bg { stroke: var(--surface-3); }
.timer-ring-fg { stroke: var(--accent); transition: stroke-dashoffset 0.2s linear; }
.timer-time {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: "Space Grotesk"; font-weight: 700; font-size: 38px; letter-spacing: -1px;
  color: var(--ink); font-variant-numeric: tabular-nums;
}
.timer-panel.is-done .timer-ring-fg { stroke: var(--pos); }
.timer-panel.is-done .timer-time { color: var(--pos); animation: timerPulse 0.8s ease infinite; }
@keyframes timerPulse { 50% { opacity: 0.35; } }

.timer-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.timer-preset {
  padding: 8px 0; border-radius: var(--radius-xs); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink); font: inherit; font-size: 12.5px; font-weight: 600;
  cursor: pointer; transition: all 0.13s; font-variant-numeric: tabular-nums;
}
.timer-preset:hover { border-color: var(--accent); color: var(--accent); }

.timer-controls { display: flex; align-items: center; justify-content: center; gap: 8px; }
.timer-controls .icon-btn { width: 40px; height: 34px; font-family: "Space Grotesk"; font-weight: 700; font-size: 12px; }
.timer-play {
  width: 48px; height: 48px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  transition: background 0.14s, transform 0.1s;
}
.timer-play:hover { background: var(--accent-dark); }
.timer-play:active { transform: scale(0.94); }
.timer-play svg { width: 22px; height: 22px; }

/* ============================================================
   Install banner (discreet, top)
   ============================================================ */
.install-banner {
  position: fixed; top: 12px; left: 50%; z-index: 240;
  transform: translateX(-50%) translateY(-160%);
  width: calc(100% - 24px); max-width: 440px;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
.install-banner.show { transform: translateX(-50%) translateY(0); }
.install-icon { width: 38px; height: 38px; border-radius: 9px; flex-shrink: 0; }
.install-text { flex: 1; min-width: 0; font-size: 13px; color: var(--text-dim); line-height: 1.35; }
.install-text b { color: var(--ink); font-weight: 700; }
.install-text .ios-share { width: 15px; height: 15px; vertical-align: -3px; color: var(--accent); }
.install-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* ============================================================
   Mobile top bar + account menu
   ============================================================ */
.topbar { display: none; }
.topbar-brand { display: flex; align-items: center; gap: 9px; }
.topbar-logo { width: 30px; height: 30px; border-radius: 8px; background: var(--solid); color: var(--accent); display: grid; place-items: center; }
.topbar-logo svg { width: 18px; height: 18px; }
.topbar-name { font-family: "Space Grotesk"; font-weight: 700; font-size: 16px; letter-spacing: -0.3px; color: var(--ink); }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.topbar-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); cursor: pointer; padding: 0; }
.topbar-btn:active { transform: scale(0.95); }
.topbar-btn svg { width: 19px; height: 19px; }
.account-avatar.sm { width: 30px; height: 30px; border-radius: 8px; font-size: 13px; }

.account-menu {
  position: fixed; z-index: 245; top: 60px; right: 12px; width: min(280px, calc(100% - 24px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; opacity: 0; transform: translateY(-8px); pointer-events: none; transition: opacity 0.18s, transform 0.18s;
}
.account-menu.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.account-menu .am-head { display: flex; align-items: center; gap: 11px; padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.account-menu .am-email { font-size: 13.5px; font-weight: 600; color: var(--ink); word-break: break-all; }
.account-menu .am-sync { font-size: 11.5px; margin-top: 2px; }

/* ============================================================
   Mobile nav
   ============================================================ */
.mobile-nav { display: none; }

/* ============================================================
   Utilities
   ============================================================ */
.view { animation: viewIn 0.26s ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } }
.mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mb-16 { margin-bottom: 16px; }
.row { display: flex; gap: 12px; align-items: center; }
.row-between { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.text-dim { color: var(--text-dim); }
.hidden { display: none !important; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-card:nth-child(2) { border-right: none; }
  .stat-card:nth-child(1), .stat-card:nth-child(2) { border-bottom: 1px solid var(--border); }
}
@media (max-width: 780px) {
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 80;
    padding: 10px 14px calc(10px); padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .main { padding: 20px 18px 96px; }
  .theme-toggle { display: none; }   /* moved into the top bar on mobile */
  .view-head h1 { font-size: 25px; }
  .history-metrics { width: 100%; justify-content: flex-start; margin-left: 0; margin-top: 12px; }
  .history-top { flex-wrap: wrap; }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 90;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  }
  .mnav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
    background: none; border: none; color: var(--text-faint); font: inherit; font-size: 10.5px; font-weight: 600;
    cursor: pointer; padding: 6px; border-radius: 8px; transition: color 0.14s;
  }
  .mnav-item svg { width: 21px; height: 21px; }
  .mnav-item.is-active { color: var(--accent); }
  .set-row { grid-template-columns: 28px 1fr 1fr auto; }
  .set-vol { display: none; }
  .summary-cell { min-width: 33%; }
  /* History action buttons wrap instead of overflowing to the right */
  .history-actions { flex-wrap: wrap; }
  .history-actions .btn { flex: 1 1 auto; justify-content: center; }
  .history-top { column-gap: 12px; }
  .history-metric { flex: 1; }
  .timer-panel { bottom: 24px; }
  .account-menu { top: 56px; }
}
/* Global guard against horizontal overflow on small screens */
@media (max-width: 780px) {
  .card, .view, .chart-card { max-width: 100%; }
  .chart-wrap { overflow: hidden; }
}
@media (max-width: 460px) {
  .view-head-row .btn { width: 100%; }
}
