:root {
  --bg: #14161a;
  --bg-elev: #1e2126;
  --bg-elev2: #262a31;
  --border: #33383f;
  --text: #f1f2f4;
  --text-dim: #9aa1ab;
  --accent: #ff5a3c;
  --accent-dim: #7a2c1e;
  --good: #3ecf8e;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

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

input, select {
  font-family: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.5px;
  color: var(--accent);
}

.tabs {
  display: flex;
  gap: 6px;
  flex: 1;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
}

.tab-btn.active {
  background: var(--bg-elev2);
  color: var(--text);
}

.profile-btn {
  background: var(--accent);
  color: #1a0d08;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 14px;
}

#app {
  padding: 16px;
  padding-bottom: calc(90px + var(--safe-bottom));
  max-width: 640px;
  margin: 0 auto;
}

.screen { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 700;
  background: var(--bg-elev2);
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  color: #1a0d08;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn-danger {
  background: transparent;
  border: 1px solid #5c2a24;
  color: #ff6b5e;
}

.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 8px; }

.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--text-dim); font-size: 13px; }
.big-number { font-size: 42px; font-weight: 800; letter-spacing: 1px; font-variant-numeric: tabular-nums; }

.user-pick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.user-pick-btn {
  padding: 24px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
}

.user-pick-btn.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* Session screen */
.session-timer {
  text-align: center;
}

.exercise-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  padding: 14px;
}

.exercise-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.exercise-name {
  font-size: 17px;
  font-weight: 700;
}

.exercise-actions { display: flex; gap: 4px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  padding: 6px 8px;
  line-height: 1;
}

.icon-btn:active { color: var(--text); }

.last-time {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-dim);
}

.set-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.set-index {
  width: 22px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev2);
  border-radius: 10px;
  padding: 4px;
}

.stepper button {
  background: none;
  border: none;
  color: var(--text);
  width: 30px;
  height: 30px;
  font-size: 18px;
  font-weight: 700;
  border-radius: 8px;
}

.stepper button:active { background: var(--border); }

.stepper .val {
  min-width: 44px;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stepper .unit {
  font-size: 10px;
  color: var(--text-dim);
}

.timer-set {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.timer-display {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 16px;
}

.timer-toggle {
  border-radius: 10px;
  border: none;
  padding: 8px 16px;
  font-weight: 700;
  background: var(--good);
  color: #062818;
}

.timer-toggle.running {
  background: var(--accent);
  color: #1a0d08;
}

.add-exercise-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-exercise-form input[type=text],
.text-input {
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px;
  border-radius: 10px;
  font-size: 16px;
  width: 100%;
}

.type-toggle {
  display: flex;
  gap: 8px;
}

.type-toggle button {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev2);
  color: var(--text-dim);
  font-weight: 600;
}

.type-toggle button.selected {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.session-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

/* Calendar */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}

.cal-dow {
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 0;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--bg-elev2);
  font-size: 14px;
  position: relative;
  border: none;
  color: var(--text);
}

.cal-day.empty { background: none; }
.cal-day.has-session { background: var(--accent-dim); color: var(--accent); font-weight: 700; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--accent); }

.exercise-summary-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--text);
}

.exercise-summary-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-tile {
  background: var(--bg-elev2);
  border-radius: 10px;
  padding: 12px;
}

.stat-tile .num { font-size: 22px; font-weight: 800; }
.stat-tile .label { font-size: 12px; color: var(--text-dim); }

.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 50;
  transition: opacity 0.2s;
}

.toast.hidden { opacity: 0; pointer-events: none; }

.demo-banner {
  position: sticky;
  top: 0;
  z-index: 11;
  background: var(--accent-dim);
  color: var(--accent);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
}

.demo-banner.hidden { display: none; }

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
}

.spinner {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
}

datalist { display: none; }
