/* ===== 2-2-2 Workout — dark theme ===== */
:root {
  --bg: #000000;
  --surface: #121414;
  --surface-2: #1d2020;
  --line: #2a2e2e;
  --text: #ffffff;
  --muted: #8a9090;
  --accent: #ff8000;
  --accent-dim: #cc6600;
  --danger: #ff5a5a;
  --good: #ff8000;
  --nav-h: 64px;
  --top-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ===== Top bar ===== */
#topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: calc(var(--top-h) + var(--safe-t));
  padding-top: var(--safe-t);
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: space-between;
  padding-left: 18px; padding-right: 18px;
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
#topbar-title { font-size: 20px; font-weight: 700; margin: 0; }
#topbar-extra { font-size: 14px; color: var(--accent); font-variant-numeric: tabular-nums; }
#topbar-extra.tappable { padding: 8px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; }
#topbar-extra.tappable:active { transform: scale(0.96); }
#topbar-extra.paused { color: #3b9eff; border-color: rgba(59,158,255,0.45); background: rgba(59,158,255,0.08); }

/* ===== Main view ===== */
#view {
  padding: calc(var(--top-h) + var(--safe-t) + 12px) 16px calc(var(--nav-h) + var(--safe-b) + 24px);
  min-height: 100vh;
  max-width: 640px; margin: 0 auto;
}

/* ===== Bottom nav ===== */
#nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(10,12,12,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex; z-index: 20;
}
.nav-btn {
  flex: 1; background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 6px 0; min-height: 44px;
}
.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 20px; line-height: 1; filter: grayscale(0.2); }
.nav-btn.active .nav-icon { filter: none; }
.nav-label { font-size: 11px; font-weight: 600; }

/* ===== Generic blocks ===== */
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 22px 4px 10px; font-weight: 700; }
.section-title:first-child { margin-top: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}

.muted { color: var(--muted); }
.accent { color: var(--accent); }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap-gap { display: flex; flex-wrap: wrap; gap: 8px; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty-state .big { font-size: 40px; margin-bottom: 8px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font-size: 16px; font-weight: 600;
}
.btn.full { width: 100%; }
.btn.primary { background: var(--accent); color: #2a1400; border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(255,90,90,0.35); }
.btn.sm { min-height: 38px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.btn:active { transform: scale(0.98); }
.btn-stack { display: flex; flex-direction: column; gap: 10px; }

/* ===== Log: start buttons ===== */
.start-grid { display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }
.start-btn {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 64px; padding: 0 20px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 18px; font-weight: 700;
}
.start-btn .sub { font-size: 13px; color: var(--muted); font-weight: 500; }
.start-btn.suggested { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.suggest-tag { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; }

/* ===== History list ===== */
.hist-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.hist-item:last-child { border-bottom: none; }
.hist-right { display: flex; align-items: center; gap: 8px; }
.hist-del { background: none; border: none; color: var(--muted); font-size: 16px; min-width: 44px; min-height: 44px; border-radius: 10px; opacity: 0.6; }
.hist-del:active { background: var(--surface-2); opacity: 1; }
.hist-main { font-weight: 600; }
.hist-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 8px; background: var(--surface-2); color: var(--muted); }
.badge.A { color: var(--accent); }
.badge.B { color: #3b9eff; }
.scheme-tag { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 6px; vertical-align: middle; letter-spacing: 0.03em; }
.scheme-tag.v1 { background: rgba(255,128,0,0.15); color: var(--accent); }
.scheme-tag.v2 { background: rgba(160,140,255,0.18); color: #b3a4ff; }
.badge.activity { color: var(--accent); background: rgba(255,128,0,0.15); }

/* Quick Log */
.quicklog-btn { margin-top: 12px; border-color: var(--accent-dim); color: var(--accent); }
.ql-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.ql-chip { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); border-radius: 20px; padding: 9px 13px; font-size: 13px; font-weight: 600; min-height: 40px; }
.ql-chip.sel { background: var(--accent); color: #2a1400; border-color: var(--accent); }

/* ===== Active workout ===== */
.ex-block { margin-bottom: 14px; }
.ex-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; padding: 0 4px; }
.ex-name { font-size: 17px; font-weight: 700; }
.type-badge { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 3px 7px; border-radius: 6px; }
.type-badge.compound { background: rgba(255,128,0,0.15); color: var(--accent); }
.type-badge.isolation { background: rgba(59,158,255,0.15); color: #3b9eff; }

.rest-hint { font-size: 12px; color: var(--muted); margin: 2px 4px 8px; }

.set-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; margin: 6px 4px 4px; }

.warmups { border-left: 2px solid var(--line); margin-left: 4px; padding-left: 8px; }
.warmups.collapsed .set-row { display: none; }
.warmup-toggle { background: none; border: none; color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 4px; display: flex; align-items: center; gap: 6px; }

.goal-pill { display: inline-flex; align-items: center; gap: 5px; background: rgba(255,128,0,0.12); color: var(--accent); font-size: 13px; font-weight: 700; padding: 5px 10px; border-radius: 20px; margin: 0 4px 8px; }

.set-row {
  display: grid;
  grid-template-columns: 26px 1fr 1fr 48px;
  gap: 8px; align-items: center;
  padding: 7px 6px; border-radius: 12px;
}
.set-row.done { opacity: 0.5; }
.set-row.flash { animation: flash 0.5s ease; }
@keyframes flash { 0% { background: rgba(255,128,0,0.35); } 100% { background: transparent; } }
.set-row.warmup { font-size: 14px; }
.set-num { font-size: 13px; font-weight: 700; color: var(--muted); text-align: center; }

.input-wrap { position: relative; }
.input-wrap .unit { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--muted); pointer-events: none; }
.field {
  width: 100%; min-height: 44px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font-size: 16px; text-align: center; padding: 0 8px;
  font-variant-numeric: tabular-nums;
}
.field:focus { outline: none; border-color: var(--accent); }
.field.suggested::placeholder { color: var(--accent-dim); }

.done-btn {
  min-height: 44px; min-width: 44px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--muted); font-size: 20px; display: flex; align-items: center; justify-content: center;
}
.done-btn.checked { background: var(--accent); color: #2a1400; border-color: var(--accent); }

.col-head { display: grid; grid-template-columns: 26px 1fr 1fr 48px; gap: 8px; padding: 0 6px 2px; }
.col-head span { font-size: 11px; color: var(--muted); text-align: center; font-weight: 600; }

.add-set-btn { background: none; border: 1px dashed var(--line); color: var(--muted); width: 100%; min-height: 40px; border-radius: 10px; font-size: 13px; font-weight: 600; margin-top: 6px; }

.finish-bar { margin-top: 18px; }

/* ===== Routines ===== */
.routine-row { display: flex; align-items: center; justify-content: space-between; padding: 16px; }
.routine-row .meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.chev { color: var(--muted); font-size: 20px; }

.ex-edit-row { display: flex; align-items: center; gap: 10px; padding: 12px 6px; border-bottom: 1px solid var(--line); }
.ex-edit-row:last-child { border-bottom: none; }
.ex-edit-main { flex: 1; min-width: 0; }
.ex-edit-name { font-weight: 600; }
.ex-edit-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.reorder-btns { display: flex; flex-direction: column; gap: 2px; }
.icon-btn { min-width: 36px; min-height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 14px; display: flex; align-items: center; justify-content: center; }
.icon-btn.danger { color: var(--danger); }

.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.field-row:last-child { border-bottom: none; }
.field-row label { font-size: 15px; }
.field-row .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.field-sm { width: 90px; min-height: 44px; text-align: center; }
.range-inputs { display: flex; align-items: center; gap: 6px; }
.range-inputs .field-sm { width: 64px; }
.range-inputs span { color: var(--muted); }

select.field { -webkit-appearance: none; appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) center, calc(100% - 11px) center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

/* ===== Stats ===== */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.stat-box { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 10px; text-align: center; }
.stat-num { font-size: 26px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 11px; color: var(--muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.04em; }

.ex-link { display: flex; align-items: center; justify-content: space-between; padding: 14px; border-bottom: 1px solid var(--line); }
.ex-link:last-child { border-bottom: none; }
.ex-link .pr { font-size: 12px; color: var(--muted); }

.range-tabs { display: flex; gap: 6px; margin: 4px 0 14px; }
.range-tab { flex: 1; min-height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600; }
.range-tab.active { background: var(--accent); color: #2a1400; border-color: var(--accent); }

.chart-wrap { position: relative; height: 230px; margin-bottom: 6px; }
.chart-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 16px 4px 8px; text-transform: uppercase; letter-spacing: 0.04em; }

.pr-grid { display: flex; gap: 10px; }
.pr-box { flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; text-align: center; }
.pr-num { font-size: 20px; font-weight: 800; color: var(--accent); }
.pr-lbl { font-size: 11px; color: var(--muted); margin-top: 3px; }

.session-row { padding: 12px 4px; border-bottom: 1px solid var(--line); }
.session-row:last-child { border-bottom: none; }
.session-date { font-size: 13px; color: var(--muted); }
.session-sets { margin-top: 4px; font-weight: 600; font-variant-numeric: tabular-nums; }

.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-weight: 600; font-size: 15px; background: none; border: none; padding: 4px 0 12px; }

/* ===== Settings ===== */
.set-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--line); }
.set-item:last-child { border-bottom: none; }
.set-item .lbl { font-size: 15px; }
.set-item .desc { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ===== Rest timer overlay ===== */
#rest-timer {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-b));
  z-index: 30; padding: 12px 16px;
  transform: translateY(0); transition: transform 0.25s ease;
}
#rest-timer.hidden { transform: translateY(140%); }
.rest-card {
  max-width: 640px; margin: 0 auto;
  background: var(--surface-2); border: 1px solid var(--accent);
  border-radius: 18px; padding: 14px 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.rest-label { font-size: 12px; color: var(--muted); text-align: center; }
.rest-time { font-size: 44px; font-weight: 800; text-align: center; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.1; }
.rest-time.done { color: var(--danger); }
.rest-adjust { display: flex; gap: 10px; justify-content: center; margin: 8px 0; }
.rest-adj-btn { flex: 1; max-width: 120px; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 15px; font-weight: 700; }
.rest-presets { display: flex; gap: 8px; margin-bottom: 8px; }
.rest-preset { flex: 1; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 14px; font-weight: 600; }
.rest-skip { width: 100%; min-height: 42px; border-radius: 10px; border: none; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; }

/* ===== Modal ===== */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 20px; max-height: 80vh; overflow-y: auto; }
.modal-card h3 { margin: 0 0 8px; font-size: 18px; }
.modal-card p { color: var(--muted); margin: 0 0 16px; font-size: 14px; line-height: 1.4; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
.search-input { width: 100%; min-height: 46px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; color: var(--text); font-size: 16px; padding: 0 14px; margin-bottom: 12px; }
.pick-list { max-height: 320px; overflow-y: auto; }
.pick-item { padding: 13px 10px; border-bottom: 1px solid var(--line); font-size: 15px; }
.pick-item:active { background: var(--surface-2); }

/* ===== Toast ===== */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  background: var(--surface-2); border: 1px solid var(--accent);
  color: var(--text); padding: 12px 20px; border-radius: 12px;
  font-size: 14px; font-weight: 600; z-index: 50;
  box-shadow: 0 6px 30px rgba(0,0,0,0.6);
  transition: opacity 0.2s ease; max-width: 90vw; text-align: center;
}

.hidden { display: none !important; }
.banner { background: rgba(255,128,0,0.12); border: 1px solid var(--accent-dim); color: var(--accent); border-radius: 12px; padding: 12px 14px; font-size: 14px; font-weight: 600; margin-bottom: 14px; }
