/* Gym Workout App v1.0.1 — phone-first styles. No build step. */
:root {
  --bg: #ffffff;
  --ink: #141414;
  --ink-soft: #3a3a3a;
  --line: #d8d8d8;
  --accent: #0b5cff;
  --accent-dark: #0846c2;
  --rest: #6b6f76;
  --good: #0a7b3d;
  --warn: #b35400;
  --danger: #c22a1c;
  --chip: #eef2f7;
  --card: #f7f8fa;
  --radius: 12px;
  --tap: 48px; /* min touch target, >=44pt */
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.45;
  min-height: 100dvh;
  max-width: 100%;
  overflow-x: hidden;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
}
body.workout-mode { padding-bottom: 0; }
body.workout-mode #tabbar, body.workout-mode #topbar { display: none; }

/* ---------- top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 56px; padding: 8px 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
#app-title { font-size: 22px; margin: 0; }
.sync-pill {
  font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px;
  background: var(--chip); color: var(--ink-soft); white-space: nowrap;
}
.sync-pill.ok { background: #dff0e5; color: var(--good); }
.sync-pill.busy { background: #fff3d6; color: var(--warn); }
.sync-pill.err { background: #fbe3df; color: var(--danger); }

/* ---------- views ---------- */
main { max-width: 640px; margin: 0 auto; min-width: 0; }
.view { display: none; padding: 12px 16px 24px; min-width: 0; }
.view.active { display: block; }
.view-title { font-size: 24px; margin: 8px 0 12px; }
h3 { font-size: 18px; margin: 0 0 8px; }

/* ---------- buttons ---------- */
button { font: inherit; color: inherit; }
.btn-primary, .btn-big, .btn-ghost, .btn-icon, .link-btn, .tab, .day-tab {
  min-height: var(--tap); touch-action: manipulation; cursor: pointer;
}
.btn-primary {
  background: var(--accent); color: #fff; border: 0; border-radius: var(--radius);
  padding: 12px 20px; font-weight: 700; font-size: 17px;
}
.btn-primary:active { background: var(--accent-dark); }
.btn-ghost {
  background: #fff; color: var(--ink); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 10px 18px; font-weight: 600;
}
.btn-big {
  display: block; width: 100%;
  background: var(--accent); color: #fff; border: 0; border-radius: 14px;
  padding: 18px; font-size: 21px; font-weight: 800;
}
.btn-big:active { background: var(--accent-dark); }
.btn-sm { min-height: 44px; padding: 8px 16px; font-size: 16px; }
.btn-icon {
  background: var(--chip); border: 0; border-radius: 10px;
  width: var(--tap); font-size: 28px; line-height: 1; font-weight: 700;
}
.link-btn {
  background: none; border: 0; color: var(--accent); font-weight: 600;
  padding: 10px 12px; font-size: 16px; text-decoration: underline;
}
.link-btn.danger { color: var(--danger); }
.link-btn.back { padding-left: 0; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; }
.hidden-file { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-label { display: inline-flex; align-items: center; }
.hint { color: var(--ink-soft); font-size: 14px; margin: 6px 0; }
.hidden { display: none !important; }

/* ---------- week view ---------- */
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 8px; min-width: 0; }
.week-nav h2 { font-size: 19px; margin: 0; text-align: center; flex: 1 1 auto; min-width: 0; }
.home-actions { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.day-row {
  border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 8px; background: #fff; min-width: 0;
}
.day-row.today { border: 2px solid var(--accent); }
.day-main { display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 12px; min-width: 0; }
.day-name { flex: 1 1 auto; min-width: 0; background: none; border: 0; text-align: left; padding: 8px 0; }
.day-name strong { display: block; font-size: 17px; }
.day-name small { color: var(--ink-soft); font-size: 13px; }
.badge {
  border: 0; border-radius: 999px; min-width: 64px; min-height: 44px;
  font-weight: 800; font-size: 16px; padding: 8px 14px; flex: 0 0 auto;
}
.badge.a { background: #dce9ff; color: #0b3fa8; }
.badge.b { background: #e6f6e6; color: #0a6b2e; }
.badge.rest { background: var(--chip); color: var(--rest); }
.start-mini {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  min-height: 44px; padding: 8px 16px; font-weight: 700; flex: 0 0 auto;
}
.day-exercises { border-top: 1px dashed var(--line); padding: 8px 12px 12px; }
.day-exercises .ex-line {
  display: flex; justify-content: space-between; gap: 8px; padding: 7px 0;
  border-bottom: 1px solid #eee; font-size: 15px; min-width: 0;
}
.day-exercises .ex-line:last-child { border-bottom: 0; }
.ex-line .nm { flex: 1 1 auto; min-width: 0; color: var(--ink); }
.ex-line .tg { flex: 0 0 auto; color: var(--ink-soft); text-align: right; }
.start-bar {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px);
  margin-top: 16px; z-index: 10;
}
.banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #fff3d6; border: 1px solid #e8c96a; border-radius: var(--radius);
  padding: 10px 12px; margin: 12px 0; font-weight: 600;
}

/* ---------- workout view ---------- */
#view-workout.active { display: flex; flex-direction: column; height: 100dvh; padding: 0; }
.wo-head { padding: 12px 16px 8px; border-bottom: 1px solid var(--line); background: #fff; flex: 0 0 auto; }
.wo-title-row { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
.wo-title { flex: 1 1 auto; min-width: 0; }
.wo-title h2 { font-size: 21px; margin: 0 0 2px; }
.wo-target { margin: 0; color: var(--ink-soft); font-size: 15px; font-weight: 600; }
.video-icon {
  flex: 0 0 auto; min-width: 48px; min-height: 48px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 24px;
  background: var(--chip); border-radius: 10px; text-decoration: none; color: var(--ink);
}
.wo-counter { margin: 8px 0 4px; font-size: 15px; font-weight: 700; color: var(--ink-soft); }
.wo-progress {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px;
  -webkit-overflow-scrolling: touch;
}
.prog-chip {
  flex: 0 0 auto; border: 2px solid var(--line); background: #fff; border-radius: 10px;
  padding: 8px 10px; font-size: 13px; min-height: 44px; min-width: 120px; max-width: 230px;
  text-align: left; line-height: 1.35;
}
.prog-chip.done { border-color: var(--good); background: #eef7f0; }
.prog-chip.now { border-color: var(--accent); background: #eef3ff; font-weight: 700; }
.wo-body { flex: 1 1 auto; overflow-y: auto; padding: 16px; min-width: 0; }
.stepper-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 18px; min-width: 0; }
.stepper-label { font-size: 18px; font-weight: 700; flex: 0 1 auto; min-width: 0; }
.stepper { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.step-btn {
  width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--accent);
  background: #fff; color: var(--accent); font-size: 32px; font-weight: 800; line-height: 1;
}
.step-btn:active { background: var(--accent); color: #fff; }
.step-value { min-width: 96px; text-align: center; }
.step-value span { display: block; font-size: 44px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.step-value small { color: var(--ink-soft); font-size: 14px; }
.wo-links { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.wo-foot {
  flex: 0 0 auto; padding: 8px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line); background: #fff;
}
.rest-pill {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #eef3ff; border: 1px solid var(--accent); border-radius: 999px;
  padding: 6px 8px 6px 16px; margin-bottom: 8px; font-weight: 800; font-size: 18px;
}
.rest-x {
  width: 48px; height: 48px; border-radius: 50%; border: 0; background: #fff;
  color: var(--ink); font-size: 26px; line-height: 1;
}
.wo-foot-links {
  display: flex; justify-content: center; align-items: stretch;
  gap: 20px; margin-top: 4px;
}
.foot-sep { width: 1px; background: var(--line); margin: 10px 0; }
.wo-finish-row {
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line);
}
.btn-finish {
  width: 100%; color: var(--danger); border-color: #e5a49d; font-size: 17px;
}

/* ---------- per-set note (QA-2) ---------- */
.wo-note { margin-top: 2px; }
#note-box { margin-top: 4px; }
#wo-note {
  width: 100%; min-height: 48px; font-size: 16px; padding: 10px 12px;
  border: 2px solid var(--line); border-radius: 10px;
}
.set-note { font-size: 14px; color: var(--ink-soft); font-style: italic; margin: 0 0 8px; }
.wo-head .back { margin-bottom: 2px; }

/* ---------- history ---------- */
.sess-row {
  display: block; width: 100%; text-align: left; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; min-width: 0;
}
.sess-row .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 800; font-size: 17px; min-width: 0; }
.sess-row .sub { color: var(--ink-soft); font-size: 14px; margin-top: 2px; }
.sess-day { flex: 0 0 auto; background: var(--chip); border-radius: 8px; padding: 2px 10px; font-size: 14px; }
.sess-ex { border-bottom: 1px solid #eee; padding: 10px 0; min-width: 0; }
.sess-ex:last-child { border-bottom: 0; }
.sess-ex h4 { margin: 0 0 4px; font-size: 17px; }
.set-line { font-size: 15px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.set-line.skipped { text-decoration: line-through; }

/* ---------- progression cards ---------- */
.prog-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; background: #fff; }
.prog-card .pc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.prog-card .pc-date { font-weight: 800; font-size: 17px; }
.trend { font-size: 22px; font-weight: 800; }
.trend.up { color: var(--good); } .trend.flat { color: var(--ink-soft); } .trend.down { color: var(--danger); }
.set-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.set-chip {
  background: var(--chip); border-radius: 8px; padding: 8px 12px;
  font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.pc-vol { color: var(--ink-soft); font-size: 14px; margin: 4px 0 8px; }
.spark { display: flex; align-items: flex-end; gap: 6px; height: 44px; margin-top: 4px; }
.spark .bar { flex: 1 1 0; min-width: 0; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 4px; opacity: 0.85; }
.spark .bar.max { background: var(--accent-dark); opacity: 1; }

/* ---------- library ---------- */
#lib-search, #add-search {
  width: 100%; min-height: var(--tap); font-size: 17px; padding: 10px 14px;
  border: 2px solid var(--line); border-radius: var(--radius); margin-bottom: 10px;
}
.lib-row { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; background: #fff; min-width: 0; }
.lib-row .lr-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lib-row .lr-name { flex: 1 1 auto; min-width: 0; font-weight: 700; font-size: 17px; background: none; border: 0; text-align: left; padding: 6px 0; }
.lib-row .lr-target { color: var(--ink-soft); font-size: 14px; margin: 2px 0 6px; }
.vid-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.vid-add { display: flex; gap: 8px; width: 100%; min-width: 0; margin-top: 4px; }
.vid-add input {
  flex: 1 1 auto; min-width: 0; min-height: var(--tap); font-size: 16px;
  border: 2px solid var(--line); border-radius: 10px; padding: 8px 12px;
}
.vid-err { color: var(--danger); font-size: 14px; font-weight: 600; }

/* ---------- editor ---------- */
.day-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.day-tab {
  flex: 1 1 0; min-width: 0; border: 2px solid var(--line); background: #fff;
  border-radius: var(--radius); font-weight: 800; font-size: 18px; padding: 10px;
}
.day-tab.active { border-color: var(--accent); color: var(--accent); background: #eef3ff; }
.ed-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; background: #fff; min-width: 0; }
.ed-name { font-weight: 800; font-size: 17px; margin: 0 0 8px; }
.ed-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-bottom: 8px; }
.ed-grid label { font-size: 13px; font-weight: 700; color: var(--ink-soft); display: block; min-width: 0; }
.ed-grid input, .ed-grid select {
  width: 100%; min-height: 48px; font-size: 17px; margin-top: 2px;
  border: 2px solid var(--line); border-radius: 10px; padding: 8px 10px; color: var(--ink);
  min-width: 0;
}
.ed-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ed-actions .btn-icon { width: 48px; font-size: 22px; }
.ed-del { margin-left: auto; }
.editor-add { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
#add-list .lib-row { cursor: pointer; }

/* ---------- settings cards ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; background: #fff; min-width: 0; }
.row-label { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 600; min-width: 0; }
.row-label input {
  width: 110px; min-height: var(--tap); font-size: 19px; text-align: center;
  border: 2px solid var(--line); border-radius: 10px; padding: 8px;
}
.kv { display: flex; justify-content: space-between; gap: 8px; margin: 6px 0; min-width: 0; }
.kv span { color: var(--ink-soft); }
.kv strong { text-align: right; overflow-wrap: anywhere; }
.pair-code {
  font-size: 40px; font-weight: 800; letter-spacing: 8px; text-align: center;
  background: var(--card); border-radius: var(--radius); padding: 16px; margin: 8px 0;
  font-variant-numeric: tabular-nums;
}
.code-row { display: flex; gap: 8px; min-width: 0; margin-top: 8px; }
.code-row input {
  flex: 1 1 auto; min-width: 0; min-height: var(--tap); font-size: 22px; text-align: center;
  letter-spacing: 4px; border: 2px solid var(--line); border-radius: 10px; text-transform: uppercase;
}

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); min-height: var(--tabbar-h);
}
.tab {
  flex: 1 1 0; min-width: 0; border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 12px; font-weight: 700; color: var(--ink-soft); padding: 6px 0;
}
.tab-icon { font-size: 22px; }
.tab.active { color: var(--accent); }

@media (prefers-color-scheme: dark) {
  /* Keep light theme: gym glare needs max contrast, and dark-mode grey text fails load-bearing readability. */
}
