@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg-base: #000000;
  --glass-bg: #000000;
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --card-bg: #1C1C1E;
  --card-hover: #2C2C2E;
  --text-main: #FFFFFF;
  --text-muted: #8E8E93;
  --accent: #39FF14;
  --accent-glow: rgba(57, 255, 20, 0.25);
  --on-accent: #000000;
  --danger: #FF5D5D;
  /* Fixed white regardless of theme so the exercise GIF's own white
     background blends into its frame instead of showing as a dark box
     in dark mode. */
  --media-bg: #FFFFFF;

  --font-h: -apple-system, BlinkMacSystemFont, 'Inter', sans-serif;
  --font-b: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

:root[data-theme="light"] {
  --bg-base: #F2F2F7;
  --glass-bg: #F2F2F7;
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --card-bg: #FFFFFF;
  --card-hover: #E5E5EA;
  --text-main: #1C1C1E;
  --text-muted: #8E8E93;
  --accent: #34C759;
  --accent-glow: rgba(52, 199, 89, 0.2);
  --on-accent: #000000;
}

::-webkit-scrollbar { display: none; }
* {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
  -ms-overflow-style: none; scrollbar-width: none;
}

html, body { height: 100%; background-color: var(--bg-base); overflow: hidden; }
body {
  color: var(--text-main); font-family: var(--font-b); -webkit-font-smoothing: antialiased;
  display: flex; justify-content: center; align-items: center; transition: background-color 0.5s ease;
}

.ambient-bg {
  position: fixed; inset: -50%; z-index: 0;
  background: radial-gradient(circle at 50% 50%, var(--accent-glow) 0%, transparent 40%);
  animation: pulseGlow 15s ease-in-out infinite alternate; pointer-events: none; opacity: 0.6;
}
@keyframes pulseGlow {
  0% { transform: scale(1) translate(0, 0); }
  50% { transform: scale(1.2) translate(5%, -5%); }
  100% { transform: scale(0.9) translate(-5%, 5%); }
}

h1, h2, h3 { font-family: var(--font-h); font-weight: 800; letter-spacing: -0.02em; }
button { font-family: var(--font-b); cursor: pointer; outline: none; border: none; background: none; }

.app {
  width: 100vw; max-width: 440px; height: 100dvh; position: relative; z-index: 1;
  overflow-y: auto; overflow-x: hidden; background: var(--glass-bg);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (min-width: 720px) {
  .app { height: 88dvh; max-width: 460px; border-radius: 40px; border: 1px solid var(--glass-border); box-shadow: var(--glass-shadow); }
}
/* Small phones (SE-class, ~360px and under): tighten spacing so nothing
   crowds or clips at the narrowest widths. */
@media (max-width: 359px) {
  .scr { padding: 16px; }
  .opt-grid { grid-template-columns: 1fr; }
}

#statsBtn { position: absolute; top: calc(24px + env(safe-area-inset-top, 0px)); right: 24px; z-index: 50; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--card-bg); border: 1px solid var(--glass-border); display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(10px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); transition: all 0.4s var(--spring); color: var(--text-main);
}
.icon-btn:active { transform: scale(0.85); }
.icon-btn svg { width: 20px; height: 20px; }

.scr { display: none; padding: 24px; min-height: 100%; flex-direction: column; position: relative; }
.scr.active { display: flex; animation: springFadeUp 0.6s var(--spring) forwards; }
@keyframes springFadeUp { from { opacity: 0; transform: translateY(30px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@media (prefers-reduced-motion: reduce) { .scr.active { animation: none; } }

h1 { font-size: 38px; line-height: 1.1; margin-bottom: 16px; text-transform: uppercase; }
h2 { font-size: 28px; line-height: 1.2; }
p { color: var(--text-muted); font-size: 16px; line-height: 1.5; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 999px; padding: 18px 32px; font-weight: 800; font-size: 16px; transition: all 0.3s var(--spring); position: relative; overflow: hidden; z-index: 2; }
.btn:active { transform: scale(0.92); }
.btn-accent { background: var(--accent); color: var(--on-accent); box-shadow: 0 8px 24px var(--accent-glow); }
.btn-accent:hover { box-shadow: 0 12px 32px var(--accent-glow); transform: translateY(-2px); }
.btn-ghost { background: var(--card-bg); color: var(--text-main); border: 1px solid var(--glass-border); }
.btn-ghost:hover { background: var(--card-hover); }
.btn-block { width: 100%; }
.link-btn { background: none; color: var(--text-muted); font-size: 14px; font-weight: 700; padding: 12px; transition: color 0.2s; }
.link-btn:active { color: var(--text-main); }
.btn:disabled { opacity: 0.4; pointer-events: none; }

/* ---------- Welcome ---------- */
#scr-welcome { justify-content: center; align-items: center; text-align: center; overflow: hidden; }
.welcome-bg {
  position: absolute; inset: 0;
  background-image: url('https://images.unsplash.com/photo-1517836357463-d25dfeac3438?q=80&w=1470&auto=format&fit=crop');
  background-size: cover; background-position: center; opacity: 0.15; z-index: 0; pointer-events: none;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 40%, rgba(0,0,0,0) 100%);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 40%, rgba(0,0,0,0) 100%);
}
:root[data-theme="light"] .welcome-bg { opacity: 0.25; }

.welcome-logo { width: 84px; height: 84px; margin-bottom: 24px; z-index: 2; border-radius: 22px; box-shadow: 0 8px 24px var(--accent-glow); }

.quote-loop-container { position: relative; height: 60px; width: 100%; margin-bottom: 32px; display: flex; justify-content: center; align-items: center; z-index: 2; }
.splash-quote { position: absolute; opacity: 0; width: 100%; text-align: center; font-size: 32px; line-height: 1.1; font-family: var(--font-h); font-weight: 800; text-transform: uppercase; animation: loopFade 9s infinite; text-shadow: 0 2px 10px rgba(0,0,0,0.5); }
.splash-quote:nth-child(1) { animation-delay: 0s; }
.splash-quote:nth-child(2) { animation-delay: 3s; }
.splash-quote:nth-child(3) { animation-delay: 6s; }

@keyframes loopFade {
  0%, 5% { opacity: 0; transform: translateY(15px); }
  10%, 25% { opacity: 1; transform: translateY(0); }
  30%, 100% { opacity: 0; transform: translateY(-15px); }
}

.splash-enter { animation: popIn 0.8s var(--spring) forwards; opacity: 0; }
@keyframes popIn { from { opacity: 0; transform: translateY(20px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ---------- Auth ---------- */
#scr-auth { justify-content: center; }
.auth-head { text-align: center; margin-bottom: 28px; }
.tabs { display: flex; gap: 8px; margin-bottom: 24px; background: var(--card-bg); border: 1px solid var(--glass-border); border-radius: 16px; padding: 4px; }
.tab-btn { flex: 1; padding: 12px; border-radius: 12px; color: var(--text-muted); font-weight: 700; font-size: 14px; transition: all 0.3s var(--spring); }
.tab-btn.active { color: var(--on-accent); background: var(--accent); }

.form { display: flex; flex-direction: column; gap: 14px; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--text-muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--glass-border); }
#auth-google-btn { gap: 10px; }
.field { display: flex; flex-direction: column; gap: 8px; font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.field input {
  padding: 18px; border-radius: 16px; border: 1px solid var(--glass-border); background: var(--card-bg);
  color: var(--text-main); font-size: 16px; font-family: var(--font-b); transition: all 0.3s var(--ease-out);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-glow); }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin-top: 14px; text-align: center; font-weight: 600; }
.confirm-msg {
  color: var(--accent); font-size: 14px; margin-top: 14px; text-align: center; font-weight: 600;
  background: var(--accent-glow); border: 1px solid var(--accent); border-radius: 16px; padding: 14px 16px;
  animation: popIn 0.4s var(--spring);
}

/* ---------- Onboarding Slider ---------- */
.step-head { display: flex; align-items: center; gap: 16px; margin-bottom: 32px; margin-top: 40px; }
.back-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--card-bg); border: 1px solid var(--glass-border); display: flex; align-items: center; justify-content: center; transition: all 0.3s var(--spring); }
.back-btn:active { transform: scale(0.85); background: var(--card-hover); }
.back-btn svg { width: 18px; height: 18px; color: var(--text-main); }
.dots { display: flex; gap: 8px; flex: 1; }
.dot { flex: 1; height: 6px; border-radius: 999px; background: var(--glass-border); transition: all 0.4s var(--ease-out); }
.dot.on { background: var(--accent); box-shadow: 0 0 10px var(--accent-glow); }

.hidden { display: none !important; }

/* .ob-window no longer owns the scroll — with all question slides laid
   out side-by-side, a single shared scrollTop meant scrolling down on
   one question carried over to the next. Each .ob-slide now scrolls
   independently instead. */
.ob-window { width: 100%; overflow: hidden; flex: 1; position: relative; }
.ob-track { display: flex; height: 100%; transition: transform 0.5s var(--spring); width: 100%; align-items: stretch; }
.ob-track.dragging { transition: none; }
.ob-slide { flex: 0 0 100%; width: 100%; min-width: 100%; height: 100%; overflow-y: auto; overflow-x: hidden; }

.q-title { font-size: clamp(24px, 7vw, 32px); margin-bottom: 32px; max-width: 14ch; }
.opt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.opt { background: var(--card-bg); border: 2px solid transparent; border-radius: 24px; padding: 24px 20px; font-weight: 700; font-size: 16px; color: var(--text-main); text-align: left; display: flex; flex-direction: column; gap: 12px; transition: all 0.3s var(--spring); box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.opt:active { transform: scale(0.94); }
.opt.wide { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
.opt.sel { border-color: var(--accent); background: var(--card-bg); box-shadow: 0 8px 24px var(--accent-glow); transform: scale(0.98); }
.opt.sel::after { content: "\2713"; display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; background: var(--accent); color: var(--on-accent); border-radius: 50%; font-size: 12px; }

/* ---------- Generating ---------- */
#scr-generating { align-items: center; justify-content: center; text-align: center; }
/* Bouncing-dot loader — used by the generating screen, the payment
   overlay, and the boot session-check screen. Kept as a single reusable
   component (.loader-pulse) so all three stay visually consistent. */
.loader-pulse { display: flex; align-items: center; justify-content: center; gap: 12px; width: 80px; height: 80px; margin: 0 auto 32px; }
.loader-pulse span { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); box-shadow: 0 4px 14px var(--accent-glow); animation: dotBounce 1.1s ease-in-out infinite; }
.loader-pulse span:nth-child(1) { animation-delay: -0.32s; }
.loader-pulse span:nth-child(2) { animation-delay: -0.16s; }
.loader-pulse span:nth-child(3) { animation-delay: 0s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.5) translateY(0); opacity: 0.5; }
  40% { transform: scale(1) translateY(-20px); opacity: 1; }
}
#genText { font-size: 18px; font-weight: 600; color: var(--text-main); letter-spacing: 0.5px; transition: opacity 0.45s ease, filter 0.45s ease, transform 0.45s ease; display: inline-block; }
/* Completion state: the dots + text drift apart, blur and fade — a
   "dispersing" exit instead of an abrupt cut to the exercise screen. */
.loader-pulse.disperse span { animation: none; transform: scale(1.4); opacity: 0; filter: blur(4px); transition: all 0.5s var(--ease-out); }
#genText.disperse { opacity: 0; filter: blur(4px); transform: translateY(-10px) scale(1.05); letter-spacing: 2px; transition: all 0.5s var(--ease-out); }

/* ---------- Boot (session check) ---------- */
#scr-boot { align-items: center; justify-content: center; }
.boot-loading-wrap { display: flex; align-items: center; justify-content: center; }

/* ---------- Exercise & Timer ---------- */
.ex-card { background: var(--card-bg); border: 1px solid var(--glass-border); border-radius: 32px; padding: 32px; margin-top: 40px; box-shadow: var(--glass-shadow); backdrop-filter: blur(16px); }
.ex-media-frame { width: 100%; height: clamp(150px, 26vh, 220px); border-radius: 20px; background: var(--media-bg); display: flex; align-items: center; justify-content: center; margin-bottom: 20px; box-shadow: inset 0 2px 10px rgba(255,255,255,0.05); overflow: hidden; transition: height 0.2s ease, margin-bottom 0.2s ease; }
.ex-media-frame img { width: 100%; height: 100%; object-fit: contain; }
/* No text fallback: when there's no gif, the frame collapses to nothing
   instead of showing a "Preview unavailable" placeholder. The gif is the
   only visual this card ever shows. */
.ex-media-frame.no-media { height: 0; margin-bottom: 0; box-shadow: none; }
.ex-name { font-size: 28px; line-height: 1.1; }
.ex-meta { color: var(--accent); font-size: 14px; margin-top: 8px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }
.ex-cue-list { margin-top: 20px; padding-left: 18px; }
.ex-cue-list li { font-size: 16px; line-height: 1.6; color: var(--text-main); opacity: 0.9; margin-bottom: 6px; }

.timer-box { margin-top: 24px; background: var(--card-bg); border: 1px solid var(--glass-border); border-radius: 28px; padding: 20px; text-align: center; }

.timer-scroller { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--glass-border); }
.t-opt { scroll-snap-align: center; flex: 0 0 auto; padding: 10px 20px; background: var(--bg-base); border-radius: 12px; font-size: 18px; font-weight: 800; font-family: var(--font-h); color: var(--text-muted); border: 2px solid transparent; transition: all 0.3s; }
.t-opt.active { border-color: var(--accent); color: var(--accent); background: var(--card-hover); transform: scale(1.05); }

.timer-num { font-family: var(--font-h); font-size: 56px; font-weight: 900; letter-spacing: -2px; transition: all 0.5s var(--spring); }
.timer-ctrls { display: flex; gap: 12px; justify-content: center; }
.timer-ctrls .btn { padding: 14px 28px; font-size: 15px; flex: 1; }
.timer-ctrls .btn:only-child { flex: 0 1 240px; }

.active-timer-ctrls { display: none; margin-top: 16px; justify-content: center; }
.is-running .active-timer-ctrls { display: flex; }
.is-running.is-paused-rep .active-timer-ctrls { display: none; }

.ex-actions { display: flex; flex-direction: column; gap: 12px; padding-top: 24px; }

.hide-on-run {
  transition: max-height 0.6s var(--spring), opacity 0.4s ease, padding 0.6s var(--spring), margin 0.6s var(--spring);
  max-height: 320px; opacity: 1; overflow: hidden;
}
.is-running .hide-on-run { max-height: 0; opacity: 0; padding-top: 0 !important; padding-bottom: 0 !important; margin-top: 0 !important; margin-bottom: 0 !important; border: none !important; }

.rep-actions { display: none; opacity: 0; transform: translateY(10px); transition: all 0.4s var(--spring); flex-direction: column; gap: 12px; margin-top: 24px; }
.rep-actions.show { opacity: 1; transform: translateY(0); }
/* Forced rest countdown between sets — vividly yellow even while
   disabled, so it reads as "wait" rather than "greyed out/broken". */
.btn-rest, .btn-rest:disabled { background: #FFD60A; color: #1C1C1E; opacity: 1; }

/* ---------- Goodbye ---------- */
#scr-goodbye { justify-content: center; align-items: center; text-align: center; }
.goodbye-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; }
.goodbye-thumb { width: 96px; height: 96px; margin-bottom: 24px; border-radius: 22px; animation: popIn 0.8s var(--spring) forwards; }

/* ---------- Congrats & Rank Badge ---------- */
#scr-congrats { align-items: center; text-align: center; justify-content: center; }
.rank-badge-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; background: transparent; border: 2px solid transparent; border-radius: 40px; padding: 10px; cursor: pointer; transition: all 0.5s var(--spring); margin-bottom: 16px; width: 100%; max-width: 260px; margin-inline: auto; }
.rank-badge-wrap.expanded { background: var(--card-bg); border-color: var(--glass-border); box-shadow: var(--glass-shadow); padding: 32px 20px; }
.rank-badge { width: 110px; height: 110px; border-radius: 50%; background: radial-gradient(circle at top left, var(--card-hover), var(--card-bg)); border: 3px solid var(--accent); display: flex; align-items: center; justify-content: center; font-size: 50px; box-shadow: 0 0 40px var(--accent-glow); transition: all 0.4s var(--spring); overflow: hidden; }
.rank-badge img { width: 100%; height: 100%; object-fit: cover; -webkit-mask-image: radial-gradient(circle, black 55%, transparent 78%); mask-image: radial-gradient(circle, black 55%, transparent 78%); }
.rank-badge-wrap.expanded .rank-badge { transform: scale(0.85); box-shadow: 0 0 20px var(--accent-glow); }
.rank-details { display: flex; flex-direction: column; align-items: center; height: 0; opacity: 0; overflow: hidden; transition: all 0.5s var(--spring); transform: translateY(-10px); }
.rank-badge-wrap.expanded .rank-details { height: 64px; opacity: 1; transform: translateY(0); margin-top: 16px; }
.rank-detail-name { font-weight: 900; font-size: 24px; color: var(--text-main); text-transform: uppercase; letter-spacing: 1px; }
.rank-detail-xp { font-weight: 800; font-size: 16px; color: var(--accent); margin-top: 4px; }
.progress-track { width: 100%; max-width: 260px; height: 12px; border-radius: 999px; background: var(--glass-border); margin: 24px auto 0; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,0.2); }
.progress-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width 1s var(--spring); box-shadow: 0 0 10px var(--accent-glow); }
.progress-label { font-size: 13px; color: var(--text-muted); margin-top: 12px; font-weight: 600; }
.quote { margin-top: 32px; font-size: 16px; color: var(--text-main); font-style: italic; max-width: 28ch; font-weight: 500; opacity: 0.8; }
.congrats-actions { margin-top: 40px; display: flex; flex-direction: column; gap: 12px; width: 100%; }

/* ---------- Paywall ---------- */
#scr-paywall { justify-content: safe center; }
.pw-head { text-align: center; margin-bottom: 32px; }
.pw-icon { width: 60px; height: 60px; margin: 0 auto 16px; border-radius: 16px; background: var(--accent-glow); display: flex; align-items: center; justify-content: center; animation: popIn 0.5s var(--spring) both; }
.pw-icon svg { width: 28px; height: 28px; color: var(--accent); }
.pw-head h2 { font-size: 32px; margin-bottom: 12px; }
.plan { position: relative; border: 2px solid var(--glass-border); background: var(--card-bg); border-radius: 24px; padding: 24px; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; transition: all 0.3s var(--spring); }
.plan:active { transform: scale(0.96); }
.plan.feat { border-color: var(--accent); background: linear-gradient(145deg, var(--card-bg), rgba(212, 255, 0, 0.05)); box-shadow: 0 8px 24px var(--accent-glow); margin-top: 4px; }
.plan.feat::before {
  content: "MOST POPULAR"; position: absolute; top: -11px; left: 20px;
  background: var(--accent); color: var(--on-accent); font-size: 10px; font-weight: 900;
  letter-spacing: 0.06em; padding: 4px 10px; border-radius: 999px;
}
.plan.best { border-color: var(--accent); margin-top: 12px; }
.plan.best::before {
  content: "BEST VALUE \00B7  SAVE 17%"; position: absolute; top: -11px; left: 20px;
  background: var(--accent); color: var(--on-accent); font-size: 10px; font-weight: 900;
  letter-spacing: 0.06em; padding: 4px 10px; border-radius: 999px;
}
.plan-name { font-size: 14px; color: var(--text-muted); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }
.plan-price { font-family: var(--font-h); font-size: 24px; margin-top: 6px; color: var(--text-main); }
.plan-usd { font-size: 14px; color: var(--text-muted); font-weight: 600; }
.plan-buy { padding: 12px 24px; font-size: 14px; flex-shrink: 0; }
.plan-note { font-size: 12px; margin-top: 2px; }

/* ---------- Payment success ---------- */
#scr-payment-success { justify-content: center; align-items: center; text-align: center; }

/* ---------- Modals & Overlays ---------- */
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(12px); z-index: 60; display: none; align-items: center; justify-content: center; padding: 24px; }
.modal-overlay.show { display: flex; animation: fadeIn 0.3s ease; }
.modal-card { width: 100%; max-width: 340px; background: var(--card-bg); border: 1px solid var(--glass-border); border-radius: 32px; padding: 32px; box-shadow: var(--glass-shadow); text-align: center; transform: scale(0.95); transition: all 0.4s var(--spring); }
.modal-overlay.show .modal-card { transform: scale(1); }
.modal-stat-row { display: flex; justify-content: space-between; align-items: center; font-size: 18px; font-weight: 700; padding: 16px 0; border-bottom: 1px solid var(--glass-border); }
.modal-stat-row:last-of-type { border-bottom: none; }
.accent-text { color: var(--accent); font-family: var(--font-h); font-weight: 900; }

/* ---------- Install prompt (Add to Home Screen) ---------- */
.install-logo { width: 64px; height: 64px; border-radius: 16px; object-fit: cover; }
.install-steps { list-style: none; margin: 0 0 20px; padding: 0; text-align: left; display: flex; flex-direction: column; gap: 14px; }
.install-steps li { display: flex; align-items: flex-start; gap: 12px; font-size: 14px; line-height: 1.4; }
.install-step-icon { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--card-hover); display: flex; align-items: center; justify-content: center; font-size: 13px; color: var(--accent); }

.theme-switch { width: 56px; height: 32px; border-radius: 999px; background: var(--glass-border); border: 1px solid var(--glass-border); cursor: pointer; position: relative; padding: 3px; transition: all 0.3s var(--spring); }
.theme-switch:active { transform: scale(0.92); }
.theme-switch-thumb { width: 24px; height: 24px; border-radius: 50%; background: var(--text-main); color: var(--bg-base); display: flex; align-items: center; justify-content: center; transition: transform 0.4s var(--spring); position: relative; overflow: hidden; }
.theme-switch-thumb svg { width: 14px; height: 14px; position: absolute; transition: all 0.4s var(--spring); }
#icon-sun { opacity: 0; transform: translateY(15px) rotate(-45deg); }
#icon-moon { opacity: 1; transform: translateY(0) rotate(0); }
:root[data-theme="light"] .theme-switch-thumb { transform: translateX(24px); }
:root[data-theme="light"] #icon-moon { opacity: 0; transform: translateY(-15px) rotate(45deg); }
:root[data-theme="light"] #icon-sun { opacity: 1; transform: translateY(0) rotate(0); }

.overlay-spin { position: absolute; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(10px); z-index: 60; display: none; align-items: center; justify-content: center; flex-direction: column; }
.overlay-spin.show { display: flex; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: calc(16px + env(safe-area-inset-top, 0px)); left: 50%;
  transform: translateX(-50%) translateY(-120%); background: var(--card-bg); border: 1px solid var(--glass-border);
  color: var(--text-main); padding: 14px 20px; border-radius: 16px; font-size: 14px; font-weight: 600; z-index: 999;
  transition: transform 0.4s var(--spring); max-width: 90vw; text-align: center; backdrop-filter: blur(12px);
  box-shadow: var(--glass-shadow);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.toast-success { border-color: var(--accent); color: var(--accent); }
.toast.toast-error { border-color: var(--danger); color: var(--danger); }


/* ==================================================================
   iOS layer — flat surfaces, system font, spring/push transitions,
   bottom sheet, segmented control, dashboard, GHXP
   ================================================================== */
:root { --ios: cubic-bezier(0.32, 0.72, 0, 1); }
.ambient-bg, .welcome-bg { display: none !important; }
.app { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg-base); }

@keyframes iosPush { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }
.scr.active { animation: iosPush 0.5s var(--ios) forwards; }

.btn { border-radius: 16px; font-weight: 700; transition: transform 0.12s ease, opacity 0.2s ease; }
.btn:active { transform: scale(0.97); }
.btn-accent, .btn-accent:hover { box-shadow: none; transform: none; }
.btn-accent:active { transform: scale(0.97); }
.icon-btn, .back-btn { background: var(--card-bg); border: none; }
.opt { border-radius: 16px; background: var(--card-bg); border: 1.5px solid transparent; box-shadow: none; }
.opt:active { transform: scale(0.97); }
.opt.sel { border-color: var(--accent); box-shadow: none; }
.ex-card, .timer-box, .plan, .db-card, .hist-row { border-radius: 20px; box-shadow: none; }
.loader-pulse span { box-shadow: none; }
.rank-badge, .rank-badge-wrap.expanded .rank-badge { box-shadow: none; }

/* Segmented control (Body Part | Muscle) */
.seg { display: flex; padding: 3px; margin: -12px 0 20px; background: var(--card-hover); border-radius: 12px; }
.seg-btn { flex: 1; padding: 9px 0; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--text-muted); transition: background 0.25s var(--ios), color 0.25s var(--ios); }
.seg-btn.active { background: var(--card-bg); color: var(--text-main); box-shadow: 0 1px 4px rgba(0,0,0,0.25); }

/* Stats sheet's internal panels (Profile root + More Settings). Only one
   panel is ever un-hidden at a time — this is one modal-overlay/sheet,
   not two stacked ones, so the existing focus-trap (which already
   filters out display:none elements via offsetParent) keeps working
   without any changes. */
.sheet-panel-head { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.sheet-panel-head h2 { flex: 1; }
@keyframes panelPushIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }
@keyframes panelPushBack { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: translateX(0); } }
.panel-push-in { animation: panelPushIn 0.32s var(--ios) both; }
.panel-push-back { animation: panelPushBack 0.32s var(--ios) both; }
@media (prefers-reduced-motion: reduce) { .panel-push-in, .panel-push-back { animation: none; } }

/* Directional screen navigation: show() defaults to the existing forward
   iosPush; screens explicitly navigated "back" to (paywall exit, history
   close) get the mirrored pop instead of replaying the same forward
   animation, matching iOS's own back-navigation feel. */
@keyframes iosPop { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: translateX(0); } }
.scr.active.screen-pop { animation: iosPop 0.5s var(--ios) forwards; }
@media (prefers-reduced-motion: reduce) { .scr.active.screen-pop { animation: none; } }

/* Stats modal -> bottom sheet */
.modal-overlay { align-items: flex-end; padding: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.modal-card { max-width: none; border: none; border-radius: 24px 24px 0 0; padding: 28px 24px calc(24px + env(safe-area-inset-bottom, 0px)); box-shadow: none; text-align: left; transform: translateY(100%); }
.modal-overlay.show .modal-card { transform: translateY(0); animation: sheetUp 0.5s var(--ios); }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* GHXP */
.ghxp-earned { font-size: 44px; font-weight: 900; color: var(--accent); letter-spacing: -0.02em; margin: 4px 0 8px; animation: ghxpPop 0.9s var(--spring) both; }
@keyframes ghxpPop { 0% { opacity: 0; transform: translateY(16px) scale(0.85); } 100% { opacity: 1; transform: none; } }

/* Dashboard */
#scr-dashboard { padding-bottom: 0; }
.db-head { padding-right: 56px; margin-bottom: 20px; }
.db-head h2 { font-size: 26px; }

/* Badge + streak-progress stack, sits above the GHXP hero */
.db-badge-stack { display: flex; flex-direction: column; align-items: center; margin-bottom: 8px; }
.db-badge-stack .rank-badge { width: 84px; height: 84px; font-size: 36px; margin-bottom: 8px; }
.db-badge-stack .rank-detail-name { font-size: 16px; margin-bottom: 4px; }
.db-badge-stack .progress-track { max-width: 220px; height: 8px; }
.db-badge-stack .progress-label { margin-top: 8px; }

.db-hero { text-align: center; padding: 24px 0 20px; }
.db-label { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.db-ghxp { font-size: 64px; font-weight: 900; color: var(--accent); letter-spacing: -0.03em; line-height: 1.1; }
.db-today { font-size: 15px; font-weight: 600; color: var(--text-muted); margin-top: 4px; }
.db-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.db-card { background: var(--card-bg); padding: 16px; }
.db-val { font-size: 22px; font-weight: 800; margin-top: 4px; }
.db-sub { font-size: 20px; margin-bottom: 12px; }
.db-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 110px; }
.hist-row { background: var(--card-bg); padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hist-name { font-weight: 700; text-transform: capitalize; }
.hist-sub { font-size: 13px; color: var(--text-muted); font-weight: 500; text-transform: capitalize; margin-top: 2px; }
.hist-pts { font-weight: 900; color: var(--accent); white-space: nowrap; }
.hist-empty { color: var(--text-muted); font-weight: 500; text-align: center; margin-top: 40px; }
.hist-empty svg { width: 40px; height: 40px; color: var(--text-muted); opacity: 0.5; margin-bottom: 12px; }
/* History cards fade out the further back they are (--fade-i set inline
   per row, clamped to 6 in app.js so a 10-row list never fades past ~40%
   opacity / never hits 0 and disappears). */
.hist-card { opacity: calc(1 - (var(--fade-i, 0) * 0.1)); }

/* ---------- History (standalone page) ---------- */
#scr-history { padding-bottom: 0; }
.history-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.history-head h2 { font-size: 26px; }
#historyList.db-list { padding-bottom: 24px; }

/* GHXP award popup */
.ghxp-popup-badge { font-size: 40px; animation: ghxpPop 0.6s var(--spring) both; }
.db-cta { position: absolute; left: 0; right: 0; bottom: 0; padding: 24px 24px calc(24px + env(safe-area-inset-bottom, 0px)); background: linear-gradient(to top, var(--bg-base) 60%, transparent); }

/* "Remember why you came" highlight — briefly pulses the dashboard's
   Start Workout button when a returning (already-logged-in) user is
   auto-routed here on app open, mirroring iOS's button-highlight cue. */
.highlight-pulse { animation: highlightPulse 0.7s var(--ios) 2; }
@keyframes highlightPulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { transform: scale(1.04); box-shadow: 0 0 0 10px var(--accent-glow); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 transparent; }
}

/* ==================================================================
   Selective glass — reserved for elements that float ABOVE content
   (Apple's own current direction: translucency on chrome, not cards).
   Everything else stays flat, matching the iOS layer above.
   ================================================================== */
:root { --glass-surface: rgba(28, 28, 30, 0.72); }
:root[data-theme="light"] { --glass-surface: rgba(242, 242, 247, 0.72); }

#statsBtn.icon-btn {
  background: var(--glass-surface);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}
.toast {
  background: var(--glass-surface);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}
.db-cta {
  background: linear-gradient(to top, var(--glass-surface) 45%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* ==================================================================
   Bottom-sheet drag handle + swipe-to-dismiss
   ================================================================== */
.sheet-handle {
  width: 36px; height: 5px; border-radius: 999px; background: var(--glass-border);
  margin: 0 auto 16px; touch-action: none; cursor: grab;
}
/* Dragging state: disable the spring transition so the sheet tracks the
   finger 1:1, and disable the backdrop's own transition so it isn't
   fighting the drag either. Re-enabled the instant the drag ends. */
.modal-card.dragging { transition: none !important; }
.modal-overlay.dragging { transition: none !important; }

/* ==================================================================
   Focus visibility — only shows a ring for keyboard/VoiceOver
   navigation, never on a touch tap.
   ================================================================== */
.btn:focus-visible, .opt:focus-visible, .icon-btn:focus-visible,
.back-btn:focus-visible, .seg-btn:focus-visible, .t-opt:focus-visible,
.field input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Selection checkmark pops in rather than just appearing */
.opt.sel::after { animation: checkPop 0.35s var(--spring) both; }
@keyframes checkPop { from { opacity: 0; transform: scale(0.4); } to { opacity: 1; transform: scale(1); } }

/* Edge-swipe-back affordance: a faint hint strip on the left edge of the
   onboarding slider, mirroring iOS's interactive-pop-gesture zone. Purely
   cosmetic — the gesture itself works with or without it. */
.ob-window { position: relative; }
.ob-window::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--glass-border); border-radius: 0 4px 4px 0; opacity: 0.6; pointer-events: none;
}
