:root {
  --bg: #0f1115;
  --card: #191c23;
  --card2: #22262f;
  --line: #2e333d;
  --text: #eef0f4;
  --muted: #9aa3b2;
  --accent: #4ade80;
  --accent-ink: #062b13;
  --warn: #fbbf24;
  --bad: #f87171;
  --info: #60a5fa;
  --radius: 16px;
  --tap: 56px;
  --nav-h: 64px;
  font-size: 17px;
}
html.light {
  --bg: #f5f6f8;
  --card: #ffffff;
  --card2: #eceef2;
  --line: #d6d9e0;
  --text: #14171c;
  --muted: #5b6474;
  --accent: #16a34a;
  --accent-ink: #ffffff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
body.playing { padding-bottom: 0; }
body.playing #tabs { display: none; }
main { max-width: 640px; margin: 0 auto; padding: 16px 16px 24px; padding-top: calc(12px + env(safe-area-inset-top)); }
h1 { font-size: 1.6rem; margin: 8px 0 12px; }
h2 { font-size: 1.15rem; margin: 20px 0 8px; }
h3 { font-size: 1rem; margin: 12px 0 6px; }
p { margin: 6px 0; }
a { color: var(--info); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 10px; }
.hidden { display: none !important; }

/* Bottom navigation, reachable with the thumb. */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs a {
  flex: 1; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; gap: 2px;
}
#tabs a span { font-size: 1.3rem; }
#tabs a.active { color: var(--accent); }

/* Cards and lists */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; display: block; color: inherit; text-decoration: none;
}
a.card:active, button.card:active { background: var(--card2); }
.list { display: grid; gap: 10px; }
.card.row { display: flex; }
.card .title { font-weight: 650; font-size: 1.05rem; }
.card .meta { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.75rem;
  background: var(--card2); color: var(--muted); border: 1px solid var(--line);
}
.pill.ok { color: var(--accent); border-color: currentColor; }
.pill.warn { color: var(--warn); border-color: currentColor; }
.pill.bad { color: var(--bad); border-color: currentColor; }

/* Buttons: big tap targets */
button, .btn {
  font: inherit; min-height: var(--tap); padding: 0 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card2); color: var(--text); font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  touch-action: manipulation; user-select: none;
}
button:active, .btn:active { transform: scale(0.98); }
button:disabled { opacity: 0.4; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.danger { color: var(--bad); }
.block { width: 100%; }
.ghost { background: transparent; }
.icon-btn { min-width: var(--tap); padding: 0; }
.btn-row { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; }

/* Forms */
label { display: block; font-size: 0.9rem; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card2); color: var(--text);
}
textarea { min-height: 80px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); }
.switch input { width: 52px; height: 30px; min-height: 0; accent-color: var(--accent); }

/* Session player */
.player { display: flex; flex-direction: column; min-height: calc(100dvh - 40px); }
.player-top { display: flex; align-items: center; gap: 8px; }
.progress { height: 6px; background: var(--card2); border-radius: 3px; overflow: hidden; flex: 1; }
.progress > div { height: 100%; background: var(--accent); transition: width 0.3s; }
.phase { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.ex-img {
  width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: #fff; border-radius: var(--radius);
  display: block; margin: 10px 0;
}
.ex-img.svg { background: var(--card2); }
.ex-name { font-size: 1.45rem; font-weight: 700; margin: 4px 0; }
.target { font-size: 1.1rem; font-weight: 600; }
.cues { margin: 8px 0; padding-left: 20px; }
.cues li { margin: 4px 0; }
.counter {
  width: 100%; min-height: 140px; font-size: 2.4rem; font-weight: 800; border-radius: 22px;
  background: var(--accent); color: var(--accent-ink); border: none; flex-direction: column; gap: 0;
}
.counter small { font-size: 1rem; font-weight: 600; opacity: 0.8; }
.dots { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.dots span { width: 14px; height: 14px; border-radius: 50%; background: var(--card2); border: 2px solid var(--line); }
.dots span.done { background: var(--accent); border-color: var(--accent); }
.big-timer { font-size: 5.5rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; line-height: 1.05; }
.huge-timer { font-size: 7rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; line-height: 1; }
.rest-screen { text-align: center; padding: 20px 0; }
.ring { width: 240px; height: 240px; margin: 10px auto; display: block; }
.stepper { display: grid; grid-template-columns: var(--tap) 1fr var(--tap); align-items: center; gap: 8px; }
.stepper output { text-align: center; font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }
.bottom-actions { position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 25%); }

/* Cardio */
.block-now { font-size: 1.4rem; font-weight: 700; text-align: center; }
.block-now.work { color: var(--warn); }
.block-now.rest, .block-now.easy { color: var(--accent); }
.block-next { text-align: center; color: var(--muted); }
.level { font-size: 2rem; font-weight: 800; text-align: center; }
.blocks-list .blk { display: grid; grid-template-columns: minmax(0, 1fr) 72px 56px 44px; gap: 6px; align-items: center; margin-bottom: 6px; }
.blocks-list .blk .icon-btn { min-width: 44px; min-height: 44px; }
.blocks-list .blk input, .blocks-list .blk select { min-height: 44px; padding: 6px 8px; }
.timeline { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; margin: 10px 0; }
.timeline div { background: var(--card2); }
.timeline div.work { background: var(--warn); }
.timeline div.rest, .timeline div.easy { background: var(--accent); opacity: 0.6; }
.timeline div.current { outline: 2px solid var(--text); }

/* History */
.hist-day { font-weight: 600; }
details summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 50; font-weight: 600;
}
.cite { font-size: 0.85rem; }
.ev { font-size: 0.75rem; }
.thumb { width: 72px; height: 54px; object-fit: contain; background: #fff; border-radius: 8px; display: block; }
.thumb.svg { background: var(--card2); }
.ring-wrap .big-timer { font-size: 4rem; }
.timing .ex-img { max-height: 26vh; }
