/* exer — mobile-first, auto dark/light. Dependency-free. */
:root {
  --bg: #0b0d10;
  --surface: #14181d;
  --surface-2: #1b2129;
  --border: #262d36;
  --text: #e7ecf2;
  --muted: #8b97a6;
  --accent: #4f8cff;
  --accent-fg: #fff;
  --danger: #ff5c5c;
  --good: #36d399;
  --radius: 14px;
  --tabbar-h: 64px;
  --maxw: 560px;
  color-scheme: dark light;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --border: #e3e7ee;
    --text: #16191d;
    --muted: #66717f;
    --accent: #2f6fed;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
input, select, button { font-family: inherit; font-size: 1rem; color: inherit; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100%;
  position: relative;
}
#main {
  padding: max(env(safe-area-inset-top), 12px) 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

/* ---- screen scaffolding ---- */
.screen { display: flex; flex-direction: column; gap: 14px; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.screen-head { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.screen-head h1 { flex: 0 0 auto; }
.screen-head .grow { flex: 1; }
.section { display: flex; flex-direction: column; gap: 10px; }
.section-title { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-s { display: flex; flex-direction: column; gap: 8px; }
.empty { text-align: center; padding: 30px 10px; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.empty .muted { max-width: 36ch; }

/* ---- generic ---- */
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.center { text-align: center; }
.pad { padding: 18px 0; }
.right { text-align: right; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 10px; }
.row.end { justify-content: flex-end; }
.row.gap { gap: 12px; }
.row.gap-s { gap: 6px; }

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.link-card { width: 100%; text-align: left; cursor: pointer; color: inherit; }
.link-card:active { background: var(--surface-2); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 11px; padding: 11px 16px; font-weight: 600; cursor: pointer;
  transition: transform .06s, filter .15s; line-height: 1;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 12px; font-size: .9rem; border-radius: 9px; }
.btn.big { padding: 16px; font-size: 1.1rem; border-radius: 13px; }
.btn.full { width: 100%; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px; border: none; background: transparent;
  color: var(--muted); cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); color: var(--text); }

/* ---- chips ---- */
.chips { display: flex; gap: 8px; }
.scroll-x { overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); border-radius: 999px; padding: 6px 13px; font-size: .85rem; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.chip.ghost { background: var(--surface-2); }

/* ---- forms ---- */
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 11px 12px; outline: none;
}
.input:focus { border-color: var(--accent); }
.input.compact { padding: 8px 10px; }
.input.tiny { width: 52px; padding: 7px 6px; text-align: center; }

/* ---- workout logger ---- */
.logger-head { align-items: flex-start; }
.logger-title { font-size: 1.25rem; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entries { display: flex; flex-direction: column; gap: 14px; }
.entry-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.sets { display: flex; flex-direction: column; gap: 7px; margin-bottom: 8px; }
.set-row {
  display: grid; grid-template-columns: 34px 56px 1fr 1fr 48px; gap: 7px; align-items: center;
}
.set-row.head { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.set-row.head .set-col { text-align: center; }
.set-col { text-align: center; font-size: .9rem; }
.set-col.idx { color: var(--muted); }
.set-col.idx.tap { background: var(--surface-2); border: none; border-radius: 8px; height: 38px; cursor: pointer; }
.set-col.prev { font-size: .8rem; }
.set-input {
  width: 100%; height: 40px; text-align: center; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 9px; color: var(--text); outline: none;
  -moz-appearance: textfield;
}
.set-input::-webkit-outer-spin-button, .set-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.set-input:focus { border-color: var(--accent); }
.set-done {
  height: 40px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.set-done.on { background: var(--good); color: #06231a; border-color: transparent; }
.set-row.done .set-input { border-color: color-mix(in srgb, var(--good) 40%, var(--border)); }

/* ---- history detail ---- */
.set-lines { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.set-line { display: flex; gap: 10px; align-items: baseline; font-size: .95rem; }
.set-line .muted { width: 14px; }

/* ---- stats ---- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 10px; text-align: center; }
.stat-value { font-size: 1.25rem; font-weight: 700; }
.stat-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-top: 3px; }

/* ---- muscle balance bars ---- */
.bar-row { display: grid; grid-template-columns: 90px 1fr 32px; align-items: center; gap: 10px; padding: 5px 0; }
.bar-label { font-size: .85rem; }
.bar-track { background: var(--surface-2); border-radius: 999px; height: 9px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar-val { text-align: right; font-size: .85rem; color: var(--muted); }

/* ---- chart ---- */
.chart { width: 100%; height: auto; margin-top: 8px; display: block; }
.chart-empty { fill: var(--muted); font-size: 11px; }
.pr-badge { display: inline-flex; align-items: center; gap: 4px; color: var(--good); font-size: .82rem; font-weight: 600; }

/* ---- routine editor ---- */
.routine-ex { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.routine-ex:last-child { border-bottom: none; }
.sticky-actions { position: sticky; bottom: calc(var(--tabbar-h) + 8px); padding-top: 8px; }

/* ---- picker ---- */
.picker { display: flex; flex-direction: column; gap: 12px; }
.picker-list { display: flex; flex-direction: column; gap: 7px; max-height: 48vh; overflow-y: auto; }
.picker-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 11px 13px; cursor: pointer; color: inherit;
}
.picker-item:active { border-color: var(--accent); }

/* ---- plate calc ---- */
.plate-out { background: var(--surface-2); border-radius: 11px; padding: 14px; }
.plate-stack { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.plate {
  display: inline-flex; align-items: center; justify-content: center; min-width: 38px; height: 38px;
  border-radius: 8px; background: var(--accent); color: var(--accent-fg); font-weight: 700; font-size: .9rem; padding: 0 6px;
}

/* ---- modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center;
  z-index: 60; animation: fade .15s ease; backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); width: 100%; max-width: var(--maxw); border-radius: 18px 18px 0 0;
  border: 1px solid var(--border); max-height: 88vh; display: flex; flex-direction: column;
  animation: slideup .2s ease; padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 600px) { .modal { border-radius: 18px; margin-bottom: 5vh; } .modal-overlay { align-items: center; } }
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 8px; }
.modal-head h2 { font-size: 1.15rem; }
.modal-body { padding: 4px 16px 18px; overflow-y: auto; }

/* ---- toast ---- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-weight: 600; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 80; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.success { background: var(--good); color: #06231a; }
#toast.warn { background: var(--danger); color: #fff; }

/* ---- rest timer bar ---- */
#timerbar {
  position: fixed; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--maxw); padding: 0 10px 8px; z-index: 50;
}
#timerbar.hidden { display: none; }
.timer-inner {
  display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--accent);
  border-radius: 13px; padding: 9px 12px; box-shadow: 0 6px 24px rgba(0,0,0,.3);
}
.timer-label { font-size: 1.1rem; font-weight: 700; min-width: 46px; }
.timer-track { flex: 1; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.timer-progress { display: block; height: 100%; background: var(--accent); width: 100%; transition: width .25s linear; }
.timer-btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 8px; padding: 6px 9px; font-size: .8rem; font-weight: 600; cursor: pointer; }
.timer-btn.solid { background: var(--accent); color: var(--accent-fg); border-color: transparent; }

/* ---- bottom tab bar ---- */
#tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--maxw); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--border); z-index: 40;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px 2px; min-width: 0;
}
.tab.active { color: var(--accent); }
.tab-label { font-size: .62rem; font-weight: 600; letter-spacing: .01em; }
