:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #15171c;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #e0e9ff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d24;
    --text: #f2f3f5;
    --muted: #9aa1ad;
    --line: #2a2f39;
    --accent: #5b8cff;
    --accent-soft: #1e2a47;
    --ok: #34d399;
    --ok-soft: #12352a;
    --warn: #fbbf24;
    --warn-soft: #3a2e10;
    --bad: #f87171;
    --bad-soft: #3d1a1a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
main { max-width: 640px; margin: 0 auto; padding: 16px; }
h1 { font-size: 28px; margin: 8px 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 20px; margin: 20px 0 8px; }
h3 { font-size: 17px; margin: 0 0 6px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
a { color: var(--accent); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
  border: 1px solid var(--line);
}
.card.accent { background: var(--accent-soft); border-color: transparent; }
.card.ok { background: var(--ok-soft); border-color: transparent; }
.card.warn { background: var(--warn-soft); border-color: transparent; }
.card.bad { background: var(--bad-soft); border-color: transparent; }

.btn {
  display: block; width: 100%;
  border: 0; border-radius: 14px;
  padding: 15px 16px; font-size: 17px; font-weight: 600;
  background: var(--accent); color: #fff;
  text-align: center; text-decoration: none; cursor: pointer;
  margin: 8px 0;
}
.btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--bad); }
.btn.okb { background: var(--ok); }
.btn.small { padding: 10px 12px; font-size: 15px; width: auto; display: inline-block; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .btn { flex: 1; }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a { color: inherit; text-decoration: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.chev { color: var(--muted); }

ul.cues { padding-left: 20px; margin: 6px 0; }
ul.cues li { margin: 4px 0; }

.video {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #000; border-radius: var(--radius); overflow: hidden; margin: 8px 0;
}
.video.vertical { aspect-ratio: 9 / 14; max-height: 60vh; margin-left: auto; margin-right: auto; }
.video iframe, .video video, .video > div { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video .ph {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: #ccc; text-align: center; padding: 16px; background: #22252c;
}
.video .ph .btn { width: auto; }
.video-tools { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.video-tools button { background: none; border: 0; color: var(--accent); font-size: 14px; padding: 4px 0; cursor: pointer; }

.dose { font-size: 22px; font-weight: 700; margin: 4px 0; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 8px 0 12px; }
.progress > i { display: block; height: 100%; background: var(--accent); }

.timer {
  text-align: center; font-size: 64px; font-weight: 700; font-variant-numeric: tabular-nums;
  margin: 8px 0; letter-spacing: -0.02em;
}
.timer-label { text-align: center; color: var(--muted); font-weight: 600; }

.scale { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 8px 0; }
.scale button {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 10px 0; font-size: 16px; font-weight: 600; cursor: pointer;
}
.scale button.sel { background: var(--accent); color: #fff; border-color: var(--accent); }

.choice { display: grid; gap: 8px; }
.choice button {
  text-align: left; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 14px; padding: 14px; font-size: 16px; cursor: pointer;
}
.choice button.sel { border-color: var(--accent); background: var(--accent-soft); }

textarea, input[type=text], input[type=url] {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
}
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 10;
}
.tabbar a {
  flex: 1; text-align: center; color: var(--muted); text-decoration: none;
  font-size: 11px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbar a .ti { font-size: 20px; line-height: 1.2; }
.tabbar a.active { color: var(--accent); }
body.workout .tabbar { display: none; }
body.workout { padding-bottom: env(safe-area-inset-bottom); }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.topbar button { background: none; border: 0; color: var(--accent); font-size: 16px; padding: 6px 0; cursor: pointer; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal.hidden { display: none; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto;
}

.stat { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 8px 0; }
.week div { text-align: center; font-size: 12px; color: var(--muted); padding: 6px 0; border-radius: 10px; background: var(--card); border: 1px solid var(--line); }
.week div.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; font-weight: 700; }
.week div.today { outline: 2px solid var(--accent); }
.week div.plan { color: var(--accent); }

.video .tap-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  background: rgba(0,0,0,.7); color: #fff; padding: 6px 12px; border-radius: 999px;
  font-size: 14px; pointer-events: none; display: none; width: auto; height: auto; inset: auto auto 12px 50%;
}
.video.needs-tap .tap-hint { display: block; }
