:root {
  --bg: #0b0f1a;
  --bg-raised: #131a2a;
  --fg: #f4f6fb;
  --fg-dim: #93a0bd;
  --accent: #22d3ee;
  --accent-dim: #0e7490;
  --danger: #f87171;
  --good: #4ade80;
  --ring-track: #1e2740;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

#app.booting main { visibility: hidden; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}
.brand .accent { color: var(--accent); }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-raised);
  border-radius: 999px;
  padding: 4px;
}

.tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--fg-dim);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
}

.tab.active {
  background: var(--accent);
  color: #04222a;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 0 16px 16px;
  min-height: 0;
}
.screen.active { display: flex; }

/* --- Count mode --- */

.today-strip {
  text-align: center;
  color: var(--fg-dim);
  font-size: 0.9rem;
  margin-bottom: 8px;
}
.today-strip #today-total { color: var(--fg); font-weight: 700; }

.tap-area {
  flex: 1;
  min-height: 40vh;
  border: 2px solid var(--ring-track);
  border-radius: 24px;
  background: radial-gradient(circle at 50% 40%, var(--bg-raised), var(--bg));
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  touch-action: none;
  transition: background 80ms ease, border-color 80ms ease;
}

.tap-area.pulse {
  border-color: var(--accent);
  background: radial-gradient(circle at 50% 40%, var(--accent-dim), var(--bg));
}

.rep-display { text-align: center; }

.rep-count {
  font-size: min(28vw, 8rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.rep-label {
  color: var(--fg-dim);
  font-size: 1rem;
  margin-top: 4px;
}

.tap-hint {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--fg-dim);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.set-controls {
  display: flex;
  gap: 12px;
  margin: 16px 0 8px;
}

.btn {
  flex: 1;
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 16px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary { background: var(--accent); color: #04222a; }
.btn-ghost { background: var(--bg-raised); color: var(--fg); }

.sets-today {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 1.5rem;
}

.set-chip {
  background: var(--bg-raised);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  color: var(--fg-dim);
}
.set-chip.pending { color: var(--accent); }

.sync-indicator {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--accent);
  text-align: center;
}

/* --- Stats mode --- */

.goal-ring-wrap {
  position: relative;
  width: min(60vw, 240px);
  margin: 24px auto;
}
.goal-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track, .ring-progress {
  fill: none;
  stroke-width: 10;
}
.ring-track { stroke: var(--ring-track); }
.ring-progress {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 300ms ease;
}
.goal-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.goal-ring-total { font-size: 2.4rem; font-weight: 800; }
.goal-ring-goal { color: var(--fg-dim); font-size: 0.9rem; }

.stat-row {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}
.stat-tile {
  flex: 1;
  background: var(--bg-raised);
  border-radius: 14px;
  padding: 12px;
  text-align: center;
}
.stat-value { font-size: 1.4rem; font-weight: 700; }
.stat-label { color: var(--fg-dim); font-size: 0.75rem; margin-top: 2px; }

.history-title {
  font-size: 0.9rem;
  color: var(--fg-dim);
  font-weight: 600;
  margin: 0 0 12px;
}

.history-chart {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding-bottom: 4px;
  overflow-x: auto;
}

.history-bar-wrap {
  flex: 1;
  min-width: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}
.history-bar {
  width: 100%;
  border-radius: 6px 6px 2px 2px;
  background: var(--ring-track);
  min-height: 3px;
}
.history-bar.met { background: var(--good); }
.history-bar.miss { background: var(--accent-dim); }
.history-date {
  color: var(--fg-dim);
  font-size: 0.6rem;
  margin-top: 4px;
}
