:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #7d8590;
  --accent: #22d3a1;
  --accent-ink: #042b1e;
  --warn: #8b5cf6;
  --danger: #f85149;

  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-6: 24px; --s-8: 32px; --s-12: 48px; --s-16: 64px;

  --radius: 12px;
  --radius-lg: 16px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--s-4) var(--s-4) var(--s-16);
  min-height: 100dvh;
}

h1, h2, h3, p { margin: 0; }

.h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
.caption { font-size: 0.85rem; font-weight: 500; color: var(--muted); }
.muted { color: var(--muted); }

a { color: var(--accent); text-decoration: none; }

/* ── Top bar ──────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) 0 var(--s-6);
}
.topbar .title { flex: 1; font-size: 1.15rem; font-weight: 700; }
.topbar .back, .topbar .logout {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.9rem;
  min-height: 40px;
  cursor: pointer;
}

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 56px;
  padding: 0 var(--s-4);
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font: 600 1.05rem/1 inherit;
  cursor: pointer;
  transition: transform 150ms var(--ease), filter 150ms var(--ease);
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { filter: grayscale(0.4) opacity(0.6); cursor: not-allowed; }
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-xl {
  min-height: 120px;
  font-size: 1.5rem;
  font-weight: 800;
}

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s-4);
  margin-bottom: var(--s-4);
}
.card-link { cursor: pointer; }
.card-link:active { transform: scale(0.99); }

.session-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--s-3);
}
.session-header .session-title {
  font-size: 1.1rem;
  font-weight: 700;
}
.session-header .session-score {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
}

/* ── Exercise row ─────────────────────────────────────────────── */
.exercise-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.exercise-row:first-child { border-top: none; }
.exercise-row .emoji { font-size: 1.6rem; width: 2rem; text-align: center; }
.exercise-row .name { flex: 1; font-weight: 600; }
.exercise-row .score {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
  min-width: 3.5rem;
  text-align: right;
}
.exercise-row.done .score { color: var(--accent); }
.exercise-row .chev { color: var(--muted); font-size: 1.2rem; }

/* ── Progress ─────────────────────────────────────────────────── */
.progress {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  margin-top: var(--s-2);
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, white));
  transition: width 300ms var(--ease);
}
.progress.warn .progress-fill {
  background: linear-gradient(90deg, var(--warn), color-mix(in srgb, var(--warn) 55%, white));
}

/* ── Stat tiles ───────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-3);
  margin-bottom: var(--s-6);
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-3) var(--s-2);
  text-align: center;
}
.stat .num {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.stat .lbl { color: var(--muted); font-size: 0.8rem; font-weight: 500; }

/* ── Chart ─────────────────────────────────────────────────────── */
.chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--s-2);
  align-items: end;
  height: 180px;
  margin-bottom: var(--s-3);
}
.bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-1);
}
.bar .fill {
  width: 100%;
  max-width: 28px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 40%, black));
  transition: height 400ms var(--ease);
}
.bar .lbl { color: var(--muted); font-size: 0.7rem; }

/* ── Counter screen ───────────────────────────────────────────── */
.counter {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--s-16));
  padding: 0 var(--s-4) calc(var(--s-4) + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
}
.counter-header {
  padding: var(--s-4) 0;
  text-align: center;
}
.counter-header .emoji { font-size: 3rem; }
.counter-header .name { font-size: 1.2rem; font-weight: 700; margin-top: var(--s-2); }
.counter-header .target { color: var(--muted); margin-top: var(--s-1); font-size: 0.95rem; }
.counter-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-4);
}
.counter-display {
  font-size: clamp(6rem, 22vw, 12rem);
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: transform 150ms var(--ease), color 200ms var(--ease);
}
.counter-display.bump { transform: scale(1.05); }
.counter-display.done { color: var(--accent); }
.counter-points {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.15rem;
}
.counter-actions {
  display: flex;
  gap: var(--s-3);
  padding-top: var(--s-3);
}
.counter-actions[hidden] { display: none; }
.counter-actions .btn-secondary { flex: 0 0 35%; }
.counter-actions .btn { flex: 1; }

/* ── Form ─────────────────────────────────────────────────────── */
.form-field { display: flex; flex-direction: column; gap: var(--s-2); margin-bottom: var(--s-4); }
.form-field label { font-size: 0.9rem; color: var(--muted); font-weight: 500; }
.form-field input {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0 var(--s-3);
  min-height: 48px;
  font-size: 1rem;
}
.form-field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

.error {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  border: 1px solid var(--danger);
  color: #ffd7d4;
  padding: var(--s-3);
  border-radius: 10px;
  margin-bottom: var(--s-4);
  font-size: 0.9rem;
}

.hero {
  text-align: center;
  padding: var(--s-8) 0 var(--s-6);
}
.hero .logo { font-size: 3rem; }
.hero h1 { font-size: 1.8rem; margin-top: var(--s-3); }
.hero p { color: var(--muted); margin-top: var(--s-2); }

/* ── Utilities ────────────────────────────────────────────────── */
.row { display: flex; gap: var(--s-3); }
.row > * { flex: 1; }
.spacer { height: var(--s-4); }
.skeleton { opacity: 0.5; animation: skel 1.2s var(--ease) infinite; }
@keyframes skel { 0%,100%{opacity:0.5} 50%{opacity:0.8} }

/* Respect reduced-motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
