:root {
  --bg: #160d28;
  --bg2: #1f1438;
  --card: #271a44;
  --card2: #32245a;
  --line: #3d2c64;
  --txt: #f3eefb;
  --muted: #b3a3d4;
  --pri: #ff5fa2;
  --pri2: #b96bff;
  --accent: #36d6e0;
  --win: #34d399;
  --warn: #fbbf24;
  --hot: #fb7185;
  --radius: 18px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: linear-gradient(170deg, #1f1438 0%, var(--bg) 60%);
  background-attachment: fixed;
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
h2 { font-size: 1.5rem; margin: .3em 0 .3em; }
h3 { font-size: 1.05rem; margin: 1.3em 0 .5em; color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.win { color: var(--win); font-weight: 700; }
b { color: #fff; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(var(--safe-t) + 12px) 16px 10px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  backdrop-filter: blur(8px);
}
.brand { font-weight: 800; font-size: 1.2rem; letter-spacing: .2px; }
.brand span { background: linear-gradient(90deg, var(--pri), var(--pri2)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

#app { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 24px); }
.container { padding: 4px 16px 8px; max-width: 640px; margin: 0 auto; }

.hello { font-size: 1.3rem; font-weight: 800; margin: 8px 0 6px; }
.streak-chip { display: inline-block; background: linear-gradient(90deg, rgba(255,95,162,.2), rgba(185,107,255,.2)); border: 1px solid var(--line); color: var(--txt); border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: .9rem; margin-bottom: 4px; }

/* tabbar */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: rgba(22,13,40,.92); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
#tabbar button { background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .7rem; font-family: inherit; cursor: pointer; }
#tabbar button .ico { font-size: 1.3rem; opacity: .8; }
#tabbar button.active { color: var(--pri); }
#tabbar button.active .ico { opacity: 1; }
body.runner-open #tabbar, body.runner-open .topbar, body.runner-open #app { display: none; }

/* exercise cards */
.ex-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 6px; }
.ex-card { display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.ex-emoji { font-size: 1.9rem; width: 44px; text-align: center; flex: none; }
.ex-thumb { width: 56px; height: 56px; border-radius: 12px; object-fit: contain; background: #f3eefb; flex: none; }
.ex-info { flex: 1; min-width: 0; }
.ex-name { font-weight: 700; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--card2); color: var(--txt); font: inherit; font-weight: 700; border-radius: 16px; padding: 13px 16px; cursor: pointer; width: 100%; margin: 8px 0; text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(120deg, var(--pri), var(--pri2)); color: #fff; border: 0; box-shadow: 0 8px 24px rgba(185,107,255,.32); }
.btn.big { padding: 20px; font-size: 1.3rem; border-radius: 20px; }
.btn.ghost { background: transparent; }
.btn.sm { width: auto; padding: 9px 14px; font-size: .85rem; margin: 0; }
.btn.danger { color: var(--hot); border-color: rgba(251,113,133,.4); }
.safe { margin-top: 14px; }

/* stats */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin: 6px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 6px; text-align: center; }
.stat-n { font-size: 1.5rem; font-weight: 800; color: var(--pri); }
.stat-l { font-size: .74rem; color: var(--muted); }

/* progress bars */
.prog-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin: 10px 0; }
.prog-top { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 8px; }
.bartrack { height: 14px; background: var(--bg2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--pri)); transition: width .3s ease; border-radius: 999px; }

/* achievements */
.ach-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ach { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; text-align: center; }
.ach.off { opacity: .5; }
.ach.on { border-color: var(--pri); box-shadow: 0 4px 16px rgba(255,95,162,.18); }
.ach-emoji { font-size: 2.2rem; }
.ach-name { font-weight: 800; font-size: .95rem; margin-top: 4px; }

/* settings */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--card2); border: 1px solid var(--line); border-radius: 999px; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 24px; height: 24px; left: 3px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--pri); border-color: var(--pri); }
.switch input:checked + span::before { transform: translateX(20px); }
.steps { padding-left: 1.2em; } .steps li { margin: 4px 0; }

/* =========================== RUNNER =========================== */
.runner:not([hidden]) {
  position: fixed; inset: 0; z-index: 20;
  background: radial-gradient(120% 70% at 50% 0%, #2a1a52 0%, var(--bg) 60%);
  display: flex; flex-direction: column; padding-top: var(--safe-t);
}
.runner-top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.runner-title { flex: 1; text-align: center; font-size: .85rem; color: var(--muted); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--card2); border: 1px solid var(--line); color: var(--txt); font-size: 1rem; cursor: pointer; flex: none; }
.runner-scroll { flex: 1; overflow-y: auto; padding: 8px 18px 24px; -webkit-overflow-scrolling: touch; }
.runner-scroll.center { text-align: center; }
.phase-emoji { font-size: 5rem; line-height: 1.1; margin: 10px 0 4px; }
.phase-img { width: 240px; max-width: 72%; border-radius: 16px; background: #f3eefb; display: block; margin: 10px auto 4px; }
.ex-h { font-size: 1.7rem; margin: 4px 0 6px; }
.side-tag { display: inline-block; background: var(--card2); border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; padding: 4px 14px; font-weight: 700; font-size: .9rem; margin-bottom: 6px; }
.timer { font-size: 5rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.05; margin: 8px 0 6px; }
.timer.paused { opacity: .5; }
.controls { display: flex; gap: 10px; margin-top: 14px; }
.controls .btn { margin: 0; }
.demo-actions { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.cues { text-align: left; max-width: 420px; margin: 6px auto; padding-left: 1.2em; color: var(--muted); }
.cues li { margin: 4px 0; }
.big-emoji { font-size: 4rem; margin: 14px 0 4px; }

/* measure + done */
.measure { max-width: 360px; margin: 14px auto; display: flex; flex-direction: column; gap: 12px; }
.measure label { text-align: left; font-weight: 700; }
.mrow { display: flex; align-items: center; gap: 8px; margin-top: 4px; color: var(--muted); font-weight: 400; }
.measure input { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 12px; color: var(--txt); font-size: 1.4rem; text-align: center; padding: 10px; font-variant-numeric: tabular-nums; }
.new-ach { margin: 14px auto; max-width: 360px; }
.ach-pop { background: linear-gradient(120deg, rgba(255,95,162,.2), rgba(185,107,255,.2)); border: 1px solid var(--pri); border-radius: 14px; padding: 10px 14px; margin: 8px 0; font-weight: 800; font-size: 1.05rem; }
