:root {
  --bg: #f4f3ee;
  --surface: #ffffff;
  --surface-2: #f1efe8;
  --border: rgba(0,0,0,0.10);
  --border-2: rgba(0,0,0,0.18);
  --text: #1c1c1a;
  --text-2: #5f5e5a;
  --text-3: #888780;
  --info-bg: #e6f1fb; --info: #185fa5;
  --success-bg: #e1f5ee; --success: #0f6e56;
  --warn-bg: #faeeda; --warn: #854f0b;
  --danger-bg: #fcebeb; --danger: #a32d2d;
  --purple-bg: #eeedfe; --purple: #3c3489; --purple-mid: #7f77dd;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a18; --surface: #232320; --surface-2: #2c2c29;
    --border: rgba(255,255,255,0.10); --border-2: rgba(255,255,255,0.18);
    --text: #f1efe8; --text-2: #b4b2a9; --text-3: #888780;
    --info-bg: #0c2c47; --info: #85b7eb;
    --success-bg: #0a3329; --success: #5dcaa5;
    --warn-bg: #3d2906; --warn: #ef9f27;
    --danger-bg: #3d1414; --danger: #f09595;
    --purple-bg: #26215c; --purple: #cecbf6; --purple-mid: #7f77dd;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}
.app { max-width: 480px; margin: 0 auto; min-height: 100%; padding-bottom: 76px; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 10px;
}
.topbar h1 { font-size: 17px; font-weight: 600; }
.topbar .sub { font-size: 12px; color: var(--text-2); }

/* ---- Bottom nav ---- */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  max-width: 480px; margin: 0 auto;
  display: flex; background: var(--surface);
  border-top: 0.5px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; padding: 9px 2px 7px; background: none; border: none;
  border-top: 2px solid transparent;
  font-size: 9.5px; color: var(--text-2); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-family: var(--font);
}
.nav-btn.active { color: var(--info); }
.nav-btn i { font-size: 21px; }

/* Library cards */
.lib-card { margin-bottom: 8px; }
.lib-head { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.lib-chevron { transition: transform 0.2s; }
.lib-detail .bar { background: var(--info); }

.screen { display: none; padding: 12px 0 8px; }
.screen.active { display: block; }
.section-head {
  padding: 14px 16px 8px; font-size: 12px; font-weight: 600;
  color: var(--text-2); text-transform: uppercase; letter-spacing: 0.05em;
  display: flex; justify-content: space-between; align-items: center;
}

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: var(--radius); margin: 0 12px 10px; overflow: hidden;
}
.card-header { padding: 14px 16px 0; display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 12px 16px 16px; }

.badge { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px; display: inline-block; }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-neutral { background: var(--surface-2); color: var(--text-2); }

/* ---- Streak ---- */
.streak-card {
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: var(--radius); margin: 12px; padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
}
.streak-flame {
  width: 48px; height: 48px; border-radius: 50%; background: var(--warn-bg);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.streak-flame i { font-size: 26px; color: var(--warn); }
.streak-num { font-size: 26px; font-weight: 600; line-height: 1; }
.streak-label { font-size: 12px; color: var(--text-2); margin-top: 3px; }

/* ---- Week strip ---- */
.week-days { display: flex; gap: 4px; margin: 10px 0 4px; }
.day-dot {
  flex: 1; min-height: 48px; border-radius: var(--radius-sm);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; background: var(--surface-2); color: var(--text-2);
  border: 0.5px solid var(--border); text-align: center; line-height: 1.15; padding: 3px 2px;
}
.day-dot.today { border: 1.5px solid var(--info); color: var(--info); background: var(--info-bg); }
.day-dot.flex { border: 1.5px solid var(--purple-mid); background: var(--purple-bg); color: var(--purple); }
.day-dot.done { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.day-dot.rest { opacity: 0.5; }

.prog-bar-wrap { background: var(--surface-2); border-radius: 4px; height: 6px; overflow: hidden; margin: 6px 0 2px; }
.prog-bar { height: 100%; border-radius: 4px; background: var(--info); transition: width 0.4s; }

/* ---- Exercise rows ---- */
.exercise-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 0.5px solid var(--border); }
.exercise-row:last-child { border-bottom: none; padding-bottom: 0; }
.ex-icon { width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--info-bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ex-icon i { font-size: 18px; color: var(--info); }
.ex-icon.amber { background: var(--warn-bg); }
.ex-icon.amber i { color: var(--warn); }
.ex-icon.purple { background: var(--purple-bg); }
.ex-icon.purple i { color: var(--purple); }
.ex-name { font-size: 14px; font-weight: 600; }
.ex-detail { font-size: 12px; color: var(--text-2); }
.ex-right { margin-left: auto; text-align: right; }
.ex-weight { font-size: 14px; font-weight: 600; }
.ex-change { font-size: 11px; color: var(--text-3); }
.ex-change.pos { color: var(--success); }

/* ---- Buttons ---- */
.btn {
  width: calc(100% - 24px); margin: 0 12px 12px; padding: 14px;
  border-radius: var(--radius); border: 0.5px solid var(--info);
  background: var(--info-bg); color: var(--info);
  font-size: 15px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font);
}
.btn:active { transform: scale(0.99); }
.btn i { font-size: 18px; }
.btn-success { border-color: var(--success); background: var(--success-bg); color: var(--success); }
.btn-ghost {
  border: 0.5px dashed var(--border-2); background: none; color: var(--info);
  font-weight: 600; font-size: 14px; padding: 12px;
}

/* ---- Set table ---- */
.set-table { width: 100%; font-size: 14px; border-collapse: collapse; }
.set-table th { color: var(--text-2); font-weight: 600; padding: 6px 4px; text-align: left; border-bottom: 0.5px solid var(--border); font-size: 11px; }
.set-table td { padding: 8px 4px; border-bottom: 0.5px solid var(--border); vertical-align: middle; }
.set-table tr:last-child td { border-bottom: none; }
.set-done { width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1.5px solid var(--border-2); background: none; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.set-done.checked { background: var(--success-bg); border-color: var(--success); }
.set-done.checked i { color: var(--success); }
.set-done i { font-size: 17px; color: var(--text-3); }
.set-input { width: 58px; border: 0.5px solid var(--border-2); border-radius: var(--radius-sm); padding: 8px 6px; font-size: 15px; text-align: center; background: var(--surface-2); color: var(--text); font-family: var(--font); }
.add-set-btn { border: none; background: none; color: var(--info); font-size: 13px; cursor: pointer; padding: 8px 0 2px; display: flex; align-items: center; gap: 4px; font-family: var(--font); font-weight: 600; }
.add-set-btn i { font-size: 16px; }

/* ---- PT tip ---- */
.pt-tip { background: var(--info-bg); border-left: 3px solid var(--info); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: 11px 13px; margin: 0 12px 10px; }
.pt-tip.purple { background: var(--purple-bg); border-left-color: var(--purple-mid); }
.pt-tip.purple .pt-tip-label { color: var(--purple); }
.pt-tip.amber { background: var(--warn-bg); border-left-color: var(--warn); }
.pt-tip.amber .pt-tip-label { color: var(--warn); }
.pt-tip-label { font-size: 11px; font-weight: 700; color: var(--info); margin-bottom: 4px; display: flex; align-items: center; gap: 5px; }
.pt-tip-text { font-size: 13px; line-height: 1.5; }

/* ---- Feel buttons ---- */
.feel-row { display: flex; gap: 8px; margin-top: 4px; }
.feel-btn { flex: 1; border: 0.5px solid var(--border-2); border-radius: var(--radius-sm); padding: 13px 4px; background: var(--surface-2); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 5px; font-family: var(--font); }
.feel-btn i { font-size: 24px; color: var(--text-2); }
.feel-btn span { font-size: 11px; font-weight: 600; color: var(--text-2); }
.feel-btn.sel-easy { border-color: var(--success); background: var(--success-bg); }
.feel-btn.sel-easy i, .feel-btn.sel-easy span { color: var(--success); }
.feel-btn.sel-ok { border-color: var(--info); background: var(--info-bg); }
.feel-btn.sel-ok i, .feel-btn.sel-ok span { color: var(--info); }
.feel-btn.sel-hard { border-color: var(--warn); background: var(--warn-bg); }
.feel-btn.sel-hard i, .feel-btn.sel-hard span { color: var(--warn); }
.feel-btn.sel-max { border-color: var(--danger); background: var(--danger-bg); }
.feel-btn.sel-max i, .feel-btn.sel-max span { color: var(--danger); }
.feel-result { margin-top: 12px; padding: 11px 13px; border-radius: var(--radius-sm); font-size: 13px; line-height: 1.5; display: none; }
.feel-result.show { display: block; }

/* ---- Deload meter ---- */
.deload-meter { display: flex; gap: 4px; margin: 10px 0 4px; }
.deload-seg { flex: 1; height: 9px; border-radius: 3px; background: var(--surface-2); }
.deload-seg.fill { background: var(--info); }
.deload-seg.warn { background: var(--warn); }

/* ---- 1RM / plan rows ---- */
.row-line { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 0.5px solid var(--border); }
.row-line:last-child { border-bottom: none; }
.num-input { width: 76px; border: 0.5px solid var(--border-2); border-radius: var(--radius-sm); padding: 8px; font-size: 15px; text-align: center; background: var(--surface-2); color: var(--text); font-family: var(--font); }
.plan-select { flex: 1; margin-left: 10px; border: 0.5px solid var(--border-2); border-radius: var(--radius-sm); padding: 9px 8px; font-size: 14px; background: var(--surface-2); color: var(--text); font-family: var(--font); }
.plan-day { width: 40px; font-size: 14px; font-weight: 600; color: var(--text-2); flex-shrink: 0; }

/* ---- Toggle ---- */
.toggle { width: 46px; height: 26px; border-radius: 13px; background: var(--success); position: relative; cursor: pointer; flex-shrink: 0; border: none; }
.toggle::after { content: ''; position: absolute; width: 20px; height: 20px; border-radius: 50%; background: #fff; top: 3px; right: 3px; transition: right 0.2s; }
.toggle.off { background: var(--surface-2); }
.toggle.off::after { right: auto; left: 3px; }

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: 30px 24px; color: var(--text-2); }
.empty-state i { font-size: 36px; color: var(--text-3); margin-bottom: 10px; display: block; }
.empty-state .title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-state .sub { font-size: 13px; line-height: 1.5; }

/* ---- Chart bars ---- */
.chart-wrap { display: flex; align-items: flex-end; gap: 6px; height: 100px; margin-top: 8px; }
.bar { flex: 1; border-radius: 4px 4px 0 0; background: var(--info); min-height: 4px; position: relative; }
.bar-val { position: absolute; top: -16px; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 600; color: var(--text); }
.bar-lbl { position: absolute; bottom: -16px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--text-2); }

/* ---- Run log form ---- */
.run-form { display: flex; flex-direction: column; gap: 10px; }
.run-form label { font-size: 12px; color: var(--text-2); margin-bottom: 4px; display: block; }
.run-form input { width: 100%; border: 0.5px solid var(--border-2); border-radius: var(--radius-sm); padding: 10px; font-size: 15px; background: var(--surface-2); color: var(--text); font-family: var(--font); }
.run-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 0.5px solid var(--border); }
.run-row:last-child { border-bottom: none; }
.run-icon { width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--success-bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.run-icon i { font-size: 18px; color: var(--success); }

/* ---- Modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: none; align-items: flex-end; justify-content: center; z-index: 100; }
.modal-bg.open { display: flex; }
.modal { background: var(--surface); width: 100%; max-width: 480px; border-radius: var(--radius) var(--radius) 0 0; padding: 18px 16px; padding-bottom: max(20px, env(safe-area-inset-bottom)); max-height: 80vh; overflow-y: auto; }
.modal h3 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.custom-ex { display: flex; gap: 8px; margin-bottom: 12px; }
.custom-ex input { flex: 1; border: 0.5px solid var(--border-2); border-radius: var(--radius-sm); padding: 10px; font-size: 14px; background: var(--surface-2); color: var(--text); font-family: var(--font); }
.ex-option { display: flex; align-items: center; gap: 10px; padding: 12px; border: 0.5px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; cursor: pointer; }
.ex-option:active { background: var(--surface-2); }
.ex-option i { font-size: 18px; color: var(--info); }
.ex-option .name { font-size: 14px; font-weight: 600; }
.ex-option .grp { font-size: 11px; color: var(--text-2); margin-left: auto; }
.modal-close { width: 100%; padding: 12px; border-radius: var(--radius-sm); border: 0.5px solid var(--border-2); background: none; color: var(--text-2); font-size: 14px; cursor: pointer; margin-top: 4px; font-family: var(--font); }

/* ---- Toast (PR celebration) ---- */
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--success); color: #fff; padding: 14px 20px; border-radius: var(--radius); font-size: 14px; font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,0.2); opacity: 0; transition: all 0.3s; z-index: 200; display: flex; align-items: center; gap: 10px; max-width: 90%; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast i { font-size: 20px; }

/* install hint */
.install-hint { margin: 0 12px 10px; padding: 11px 13px; background: var(--purple-bg); border-radius: var(--radius-sm); font-size: 12px; color: var(--purple); line-height: 1.5; display: flex; gap: 8px; align-items: flex-start; }
.install-hint i { font-size: 16px; margin-top: 1px; }
