:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #21252e;
  --border: #2c313c;
  --text: #eef0f4;
  --muted: #8b93a3;
  --accent: #4f8cff;
  --accent-dim: #2f5cb3;
  --good: #3ec97b;
  --bad: #e5584f;
  --warn: #e5b84f;
  font-size: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: 3rem;
}

.topbar {
  position: sticky;
  top: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  padding: 0.75rem 1rem 0;
}

.topbar h1 {
  margin: 0 0 0.5rem;
  font-size: 1.3rem;
}

#logout-btn {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.6rem 0.9rem;
  font-size: 0.95rem;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

main {
  padding: 1rem;
  max-width: 640px;
  margin: 0 auto;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.muted { color: var(--muted); font-size: 0.9rem; }

.session-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.workout-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 8px;
  padding: 0.3rem 0.75rem;
  margin-right: 0.6rem;
  font-size: 1.1rem;
}

.rest-timer {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
  margin-bottom: 1.2rem;
}

.rest-display {
  font-size: 2.6rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  margin-bottom: 0.6rem;
}

.rest-timer.running .rest-display { color: var(--accent); }
.rest-timer.done .rest-display { color: var(--bad); }

.rest-controls {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  cursor: pointer;
}

.btn.small { padding: 0.5rem 0.7rem; font-size: 0.9rem; }
.btn.big { width: 100%; padding: 1rem; font-size: 1.1rem; margin-top: 1rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.toggle.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.exercise-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.exercise-card h3 {
  margin: 0 0 0.6rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.weight-stepper {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.weight-stepper .weight-value {
  font-size: 1.4rem;
  font-weight: 700;
  min-width: 5.5rem;
  text-align: center;
}

.sets-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: clamp(0.25rem, 1.5vw, 0.5rem);
}

.set-pill {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: clamp(0.3rem, 1.5vw, 0.5rem) 0.2rem;
  text-align: center;
  flex: 1 1 0;
  min-width: 0;
  background: var(--panel-2);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.set-pill .set-label {
  font-size: clamp(0.6rem, 2.4vw, 0.75rem);
  color: var(--muted);
  margin-bottom: 0.2rem;
  cursor: default;
  white-space: nowrap;
}

.set-pill.editing .set-label { color: var(--accent); }

.set-view {
  touch-action: manipulation;
  cursor: pointer;
  padding: 0.35rem 0;
  border-radius: 6px;
}

.set-view:active { background: rgba(255,255,255,0.06); }

.set-num {
  font-size: clamp(1.05rem, 5vw, 1.5rem);
  font-weight: 700;
  color: var(--text);
}

.set-pill.pending .set-num { color: var(--muted); font-weight: 400; }

.set-pill.hit { border-color: var(--good); background: rgba(62,201,123,0.12); }
.set-pill.hit .set-num { color: var(--good); }
.set-pill.miss { border-color: var(--bad); background: rgba(229,88,79,0.12); }
.set-pill.miss .set-num { color: var(--bad); }
.set-pill.editing { border-color: var(--accent); background: rgba(79,140,255,0.1); }

.set-edit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.set-edit .step-btn {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  font-size: clamp(0.95rem, 4vw, 1.2rem);
  line-height: 1;
  padding: clamp(0.2rem, 1.5vw, 0.3rem) 0;
  touch-action: manipulation;
}

.set-edit .step-btn:active { background: var(--accent-dim); }

.edit-num {
  font-size: clamp(1rem, 4vw, 1.3rem);
  font-weight: 700;
}

.edit-done {
  width: 100%;
  border: 1px solid var(--good);
  background: rgba(62,201,123,0.15);
  color: var(--good);
  border-radius: 6px;
  font-size: clamp(0.8rem, 3vw, 1rem);
  font-weight: 700;
  padding: clamp(0.2rem, 1.5vw, 0.3rem) 0;
  touch-action: manipulation;
}

.finish-summary {
  margin-top: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.finish-summary .row { display: flex; justify-content: space-between; padding: 0.3rem 0; }
.finish-summary .increase { color: var(--good); }
.finish-summary .deload { color: var(--bad); }
.finish-summary .retry { color: var(--warn); }

.hidden { display: none !important; }

.progress-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.progress-controls select {
  flex: 1;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  font-size: 1rem;
}

.chart-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 1rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  font-size: 0.9rem;
}

.data-table th, .data-table td {
  padding: 0.55rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th { color: var(--muted); font-weight: 600; }

.history-hint {
  margin: 0 0 1rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.history-card h3 {
  margin-bottom: 0.9rem;
}

.workout-badge.small {
  font-size: 0.85rem;
  padding: 0.2rem 0.6rem;
  margin-right: 0;
}

.history-exercise {
  margin-bottom: 0.9rem;
}

.history-exercise:last-child {
  margin-bottom: 0;
}

.history-exercise-name {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.weight-pill {
  margin-bottom: 0.8rem;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.weight-view {
  display: inline-block;
  touch-action: manipulation;
  cursor: pointer;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.weight-view:active { background: rgba(255,255,255,0.06); }

.weight-num {
  font-size: 1.2rem;
  font-weight: 700;
}

.weight-edit {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.weight-edit .step-btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
  font-size: 1rem;
  touch-action: manipulation;
}

.weight-edit .step-btn:active { background: var(--accent-dim); }

.weight-edit-num {
  font-size: 1.1rem;
  font-weight: 700;
  min-width: 4.5rem;
  text-align: center;
}

.weight-edit .edit-done {
  border: 1px solid var(--good);
  background: rgba(62,201,123,0.15);
  color: var(--good);
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
  font-weight: 700;
  touch-action: manipulation;
}

.history-note {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--good);
}

.history-note.warn {
  color: var(--warn);
}

.settings-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.settings-block h2 { margin: 0 0 0.7rem; font-size: 1rem; color: var(--muted); }

.unit-toggle { display: flex; gap: 0.5rem; }

.stepper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.weight-settings .weight-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.weight-settings .weight-row:last-child { border-bottom: none; }

.weight-settings .stepper .weight-value { min-width: 4.5rem; text-align: center; font-weight: 700; }

/* ---- exercise name + form-help button ---- */

.exercise-name-group {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.form-help-btn {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.form-help-btn:active { background: var(--accent-dim); color: #fff; }

/* ---- form-guide modal ---- */

.form-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.form-modal.hidden { display: none; }

.form-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}

.form-modal-card {
  position: relative;
  z-index: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.2rem;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.form-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.7rem;
}

.form-modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.form-figure {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem;
  margin-bottom: 0.9rem;
}

.form-svg {
  width: 100%;
  height: auto;
  display: block;
}

.form-svg .body { stroke: var(--text); stroke-width: 4; fill: none; stroke-linecap: round; }
.form-svg .head { stroke: var(--text); stroke-width: 4; fill: none; }
.form-svg .bar { stroke: var(--accent); stroke-width: 5; stroke-linecap: round; }
.form-svg .plate { fill: var(--accent); stroke: var(--accent-dim); stroke-width: 2; }
.form-svg .ground { stroke: var(--border); stroke-width: 3; }
.form-svg .bench { fill: var(--panel-2); stroke: var(--border); stroke-width: 2; }

.form-cue {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.45;
}
