/* ─── Reset & Foundation ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-secondary: #f2f2f7;
  --text-primary: #1c1c1e;
  --text-secondary: #8e8e93;
  --text-tertiary: #aeaeb2;
  --separator: rgba(60, 60, 67, 0.1);
  --accent: #34c759;
  --accent-light: #d1f5db;
  --accent-bg: #edfcf2;
  --blue: #007aff;
  --red: #ff3b30;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 0.5px 0 0 rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-elevated: 0 4px 24px rgba(0, 0, 0, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-secondary: #2c2c2e;
    --text-primary: #f5f5f7;
    --text-secondary: #8e8e93;
    --text-tertiary: #636366;
    --separator: rgba(84, 84, 88, 0.36);
    --accent: #30d158;
    --accent-light: #0d3b1a;
    --accent-bg: #0d2917;
    --shadow-card: 0 0.5px 0 0 rgba(0,0,0,0.2), 0 2px 8px rgba(0,0,0,0.2);
    --shadow-elevated: 0 4px 24px rgba(0,0,0,0.4);
  }
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* Prevent iOS zoom on inputs */
input, textarea, select { font-size: 16px !important; }

/* ─── Animations ─── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes checkPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes progressPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ─── Navigation Bar ─── */
.nav-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(242, 242, 247, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
  padding: 12px 16px;
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
}

@media (prefers-color-scheme: dark) {
  .nav-bar {
    background: rgba(0, 0, 0, 0.72);
  }
}

.nav-bar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.2px;
}

.nav-bar__brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
}

.nav-bar__action {
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, opacity 0.15s;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.nav-bar__action:active {
  opacity: 0.6;
}

/* ─── Day Tabs ─── */
.day-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 16px 16px 0;
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
}

.day-tabs::-webkit-scrollbar { display: none; }

.day-tab {
  flex-shrink: 0;
  padding: 8px 18px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 36px;
  background: var(--surface);
  color: var(--text-secondary);
  box-shadow: var(--shadow-card);
}

.day-tab--active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px rgba(52, 199, 89, 0.35);
}

.day-tab:active {
  transform: scale(0.95);
}

/* ─── Content Container ─── */
.content {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  padding-bottom: calc(40px + var(--safe-bottom));
}

.content--centered {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
}

/* ─── Paste Screen ─── */
.paste-screen {
  width: 100%;
  max-width: 520px;
  animation: fadeInUp 0.4s ease;
}

.paste-header {
  text-align: center;
  margin-bottom: 32px;
}

.paste-header__icon {
  width: 96px;
  height: 96px;
  border-radius: 22px;
  margin: 0 auto 16px;
  display: block;
  object-fit: cover;
}

.paste-header__title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.paste-header__subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.paste-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.paste-card__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.paste-card__textarea {
  width: 100%;
  min-height: 200px;
  border: 1px solid var(--separator);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 15px;
  font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, monospace;
  resize: vertical;
  color: var(--text-primary);
  background: var(--surface-secondary);
  line-height: 1.5;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.paste-card__textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.15);
}

.paste-card__textarea::placeholder {
  color: var(--text-tertiary);
}

.paste-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.paste-hint {
  text-align: center;
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 16px;
}

.paste-hint code {
  background: var(--surface);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, monospace;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
  transform: none;
}

.btn--primary {
  flex: 1;
  padding: 16px 24px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 17px;
  min-height: 50px;
  box-shadow: 0 2px 12px rgba(52, 199, 89, 0.3);
}

.btn--primary:disabled {
  background: var(--surface-secondary);
  color: var(--text-tertiary);
  box-shadow: none;
}

.btn--secondary {
  padding: 16px 20px;
  background: var(--surface);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  font-size: 16px;
  min-height: 50px;
  box-shadow: var(--shadow-card);
}

.btn--tertiary {
  width: 100%;
  margin-top: 10px;
  padding: 12px 0;
  background: none;
  color: var(--text-tertiary);
  border-radius: var(--radius-sm);
  font-size: 14px;
  min-height: 44px;
}

.btn--icon-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  flex-shrink: 0;
  font-size: 18px;
  color: var(--text-secondary);
}

.btn--icon-circle.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px rgba(52, 199, 89, 0.3);
}

.btn--copy {
  padding: 12px 24px;
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  font-size: 15px;
  min-height: 48px;
  box-shadow: var(--shadow-card);
}

.btn--copy.copied {
  background: var(--accent-bg);
  color: var(--accent);
}

/* ─── Progress Bar ─── */
.progress-section {
  margin-bottom: 20px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}

.progress-track {
  background: var(--separator);
  border-radius: 100px;
  height: 6px;
  overflow: hidden;
}

.progress-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 100px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Day Title ─── */
.day-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 16px;
}

/* ─── Exercise Card ─── */
.exercise-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
  transition: all 0.25s ease;
  animation: fadeInUp 0.35s ease both;
}

.exercise-card--done {
  background: var(--accent-bg);
  box-shadow: var(--shadow-card), inset 0 0 0 1px var(--accent-light);
}

.exercise-card--skipped {
  opacity: 0.6;
}

.skip-icon {
  color: var(--text-tertiary);
  font-size: 14px;
}

.exercise-card__skipped-tag {
  color: var(--text-tertiary);
  font-style: italic;
}

.btn-skip {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-tertiary);
  background: none;
  border: 1px solid var(--separator);
  border-radius: 8px;
  padding: 4px 12px;
  cursor: pointer;
  min-height: 32px;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  white-space: nowrap;
}

.btn-skip:active {
  transform: scale(0.95);
  opacity: 0.7;
}

.btn-skip--active {
  color: var(--accent);
  border-color: var(--accent);
}

.exercise-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}

.exercise-card__name {
  font-weight: 600;
  font-size: 17px;
  line-height: 1.3;
  letter-spacing: -0.1px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.exercise-card__name .check-icon {
  color: var(--accent);
  font-size: 15px;
}

.exercise-card__meta {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.exercise-card__weight-tag {
  color: var(--blue);
  font-weight: 600;
}

.exercise-card__suggested-tag {
  color: var(--text-tertiary);
  font-weight: 500;
}

.exercise-card__counter {
  font-size: 13px;
  color: var(--text-tertiary);
  font-weight: 500;
  white-space: nowrap;
}

/* ─── Demo Toggle ─── */
.demo-toggle {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface-secondary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  cursor: pointer;
  margin-bottom: 12px;
  transition: all 0.15s;
  min-height: 36px;
  font-weight: 500;
}

.demo-toggle:active {
  opacity: 0.7;
}

.demo-panel {
  border-radius: var(--radius-md);
  background: var(--surface-secondary);
  text-align: center;
  padding: 16px;
  min-height: 80px;
  margin-bottom: 12px;
  animation: scaleIn 0.2s ease;
}

.demo-panel img {
  max-width: 100%;
  max-height: 240px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.demo-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 10px;
}

.demo-nav__btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.demo-nav__btn:active { transform: scale(0.9); }

.demo-nav__counter {
  font-size: 12px;
  color: var(--text-tertiary);
}

.demo-match {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 8px;
}

.demo-match a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

/* ─── Set Buttons ─── */
.sets-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.set-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--separator);
  background: var(--surface);
  color: var(--text-tertiary);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.set-btn:active {
  transform: scale(0.9);
}

.set-btn--done {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  animation: checkPop 0.3s ease;
}

.set-btn--active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── Rest Timer ─── */
.rest-timer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 8px;
  background: var(--accent-bg);
  border-radius: var(--radius-sm);
  animation: scaleIn 0.2s ease;
}

.rest-timer__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}

.rest-timer__skip {
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent-light);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  min-height: 34px;
}

.rest-timer__skip:active { opacity: 0.7; }

/* ─── Timer Panel ─── */
.timer-panel {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  margin-top: 12px;
  animation: scaleIn 0.2s ease;
}

.timer-panel--running {
  background: var(--accent-bg);
}

.timer-panel--paused {
  background: var(--surface-secondary);
}

.timer-panel__info {
  flex: 1;
}

.timer-panel__set-label {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
}

.timer-panel__controls {
  display: flex;
  gap: 12px;
}

/* ─── Weight Input ─── */
.weight-input {
  padding: 14px 16px;
  background: var(--accent-bg);
  border-radius: var(--radius-md);
  margin-top: 12px;
  animation: scaleIn 0.2s ease;
}

.weight-input__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 10px;
}

.weight-input__row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.weight-input__field {
  width: 80px;
  padding: 10px 12px;
  border: 1px solid var(--accent-light);
  border-radius: var(--radius-sm);
  font-size: 16px;
  text-align: right;
  background: var(--surface);
  color: var(--text-primary);
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}

.weight-input__field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.15);
}

.weight-input__unit {
  font-size: 14px;
  color: var(--accent);
  font-weight: 500;
  flex-shrink: 0;
}

.weight-input__effort-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.effort-btn {
  font-size: 22px;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--separator);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.effort-btn:active { transform: scale(0.9); }

.effort-btn--selected {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.weight-input__save {
  flex: 1;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  min-height: 44px;
  transition: all 0.15s;
}

.weight-input__save:disabled {
  background: var(--surface-secondary);
  color: var(--text-tertiary);
  cursor: not-allowed;
}

.weight-input__save:active:not(:disabled) {
  transform: scale(0.97);
}

/* ─── Completion Banner ─── */
.completion-banner {
  text-align: center;
  padding: 24px 0 8px;
  animation: fadeInUp 0.4s ease;
}

.completion-banner__emoji {
  font-size: 40px;
  margin-bottom: 8px;
}

.completion-banner__text {
  color: var(--accent);
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 16px;
}

/* ─── Spinner ─── */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--separator);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 80px;
}

.loading-state__text {
  font-size: 13px;
  color: var(--text-tertiary);
}

.error-text {
  font-size: 13px;
  color: var(--red);
}

.empty-text {
  font-size: 13px;
  color: var(--text-tertiary);
}

/* ─── Responsive ─── */
@media (min-width: 480px) {
  .paste-header__title { font-size: 34px; }
  .paste-card { padding: 24px; }
  .paste-card__textarea { min-height: 240px; }
  .content { padding: 20px; }
}

@media (min-width: 768px) {
  .content { max-width: 620px; }
}

/* ─── Dashboard (RPG home) ─── */
/*  All dashboard rules are scoped under .rpg so the always-dark palette
 *  never leaks into the existing light/auto-dark workout screens.
 *
 *  Colour rule: --theme (deep violet) owns every piece of chrome,
 *  including the ambient glow behind the avatar. Green/amber/red appear
 *  ONLY on the score rings, their status labels, the overall badge and
 *  the light disc the character stands on. BODY is never graded. */

.rpg {
  /* Section palettes. Fixed, so a ring can always draw its own hue
     no matter which section is selected. */
  --vitality: #2DD4BF;
  --vitality-bright: #5EEAD4;
  --vitality-deep: #14A89A;
  --power: #F43F6E;
  --power-bright: #FB7196;
  --power-deep: #BE2950;
  --recovery: #7C6CF0;
  --recovery-bright: #A594FF;
  --recovery-deep: #5B4FD6;

  /* The active theme. Swapped by [data-theme] below; Vitality is the
     default when no ring is selected. */
  --theme: var(--vitality);
  --theme-bright: var(--vitality-bright);
  --theme-deep: var(--vitality-deep);
  --theme-soft: rgba(45, 212, 191, 0.16);
  --theme-glow: rgba(45, 212, 191, 0.65);

  /* Constant in every section. */
  --bg: #0B0E1A;
  --bg-lift: #161C33;
  --surface: #151A2E;
  --surface-lift: #1E2440;
  --surface-veil: rgba(11, 14, 26, 0.84);
  --track: #252B45;
  --accent: #F0A830;
  --neutral: #3A3F5C;
  --text: #F2F4FA;
  --text-muted: #9BA2BC;
  --border: rgba(255, 255, 255, 0.07);
  --edge: rgba(255, 255, 255, 0.11);
  --core: rgba(255, 255, 255, 0.78);
  --tick: rgba(255, 255, 255, 0.8);
  --cast: #000000;
  --shade: var(--shade);
  --shade-deep: var(--shade-deep);

  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(85% 42% at 50% 24%, var(--bg-lift) 0%, transparent 72%),
    radial-gradient(120% 80% at 50% 100%, var(--surface) 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  overflow-x: hidden;
  /*  body adds both safe-area insets as padding, and the scroll
   *  container below adds them again. These negative margins cancel
   *  body's copy so each inset is counted exactly once, and they let the
   *  dashboard background paint behind the Dynamic Island and the home
   *  indicator rather than leaving body's darker strip showing at either
   *  edge. Scoped to .rpg, so the workout screens are unaffected. */
  margin-top: calc(var(--safe-top) * -1);
  margin-bottom: calc(var(--safe-bottom) * -1);
}

.rpg__scroll {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 480px;
  margin: 0 auto;
  /* Top: the inset itself, plus breathing room so the first card is
     not flush against the Dynamic Island. */
  padding: calc(var(--safe-top) + 0.75rem) calc(14px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(14px + var(--safe-left));
}

/* Band colours — set once, inherited by ring stroke, status text and disc. */
/* Rings are a fixed legend: each always draws its own section hue, at
   every score, selected or not. Hue encodes identity, never score. */
.rpg-ring--vitality { --ring: var(--vitality); --ring-bright: var(--vitality-bright); }
.rpg-ring--power { --ring: var(--power); --ring-bright: var(--power-bright); }
.rpg-ring--recovery { --ring: var(--recovery); --ring-bright: var(--recovery-bright); }

/* Theme switching. The page background is deliberately left alone —
   the ambient glow carries the hue shift. */
.rpg[data-theme="power"] {
  --theme: var(--power);
  --theme-bright: var(--power-bright);
  --theme-deep: var(--power-deep);
  --theme-soft: rgba(244, 63, 110, 0.16);
  --theme-glow: rgba(244, 63, 110, 0.65);
}

.rpg[data-theme="recovery"] {
  --theme: var(--recovery);
  --theme-bright: var(--recovery-bright);
  --theme-deep: var(--recovery-deep);
  --theme-soft: rgba(124, 108, 245, 0.16);
  --theme-glow: rgba(124, 108, 245, 0.65);
}

/* ─── Dashboard: cards ─── */
.rpg-card {
  position: relative;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--surface-lift) 0%, var(--surface) 100%);
  box-shadow: 0 10px 26px var(--shade);
}

/* 1px top edge highlight — lifts the card off the page. */
.rpg-card::before,
.rpg-hero::before {
  content: "";
  position: absolute;
  top: 0;
  left: 12px;
  right: 12px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--edge), transparent);
  pointer-events: none;
}

.rpg-card__title {
  margin-bottom: 10px;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--theme-bright);
  transition: color 350ms ease-in-out;
}

/* ─── Dashboard: hero ─── */
.rpg-hero {
  position: relative;
  padding: 4px 12px 14px;
  border: 1px solid var(--border);
  border-radius: 26px;
  background: linear-gradient(180deg, var(--surface-lift) 0%, var(--surface) 100%);
  box-shadow: 0 24px 54px var(--shade-deep);
  overflow: hidden;
}

.rpg-hero__stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/*  The bottom padding is the room the disc and badge sit in — both are
 *  positioned against the stack's bottom edge, which is the floor line. */
.rpg-hero__figure {
  position: relative;
  padding-bottom: 44px;
}

/*  Fixed aspect ratio, matching the PNGs (393x760), so swapping variants
 *  can never reflow the page. */
.rpg-hero__stack {
  position: relative;
  z-index: 3;
  height: clamp(230px, 44vh, 400px);
  aspect-ratio: 393 / 760;
}

/*  Every variant is stacked and always present — that is the preload.
 *  Only opacity animates: the character is identically posed in all three,
 *  so any movement would break the morph. */
.rpg-hero__avatar {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  filter: drop-shadow(0 14px 22px var(--shade));
  transition: opacity 350ms ease-in-out;
}

.rpg-hero__avatar--on { opacity: 1; }

/* Violet ambient glow — brand accent, sits furthest back. */
.rpg-hero__aura {
  position: absolute;
  z-index: 0;
  left: 50%;
  top: 46%;
  width: 150%;
  max-width: 430px;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  color: var(--theme);
  background: radial-gradient(circle, currentColor 0%, transparent 62%);
  opacity: 0.24;
  filter: blur(46px);
  animation: rpgAura 6s ease-in-out infinite;
  transition: color 350ms ease-in-out;
  pointer-events: none;
}

/*  The lit disc: a filled, blurred glow tinted by the overall band, with a
 *  near-white core falling off to transparent. Centred on the floor line
 *  by translateY(50%), so it reads as light on a surface. */
.rpg-hero__disc {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 44px;
  width: 82%;
  max-width: 300px;
  height: 94px;
  transform: translate(-50%, 50%);
  border-radius: 50%;
  color: var(--theme);
  background:
    radial-gradient(ellipse 40% 44% at 50% 50%, var(--core), transparent 100%),
    radial-gradient(ellipse 74% 80% at 50% 50%, currentColor, transparent 72%);
  opacity: 0.95;
  filter: blur(11px);
  transition: color 350ms ease-in-out;
  pointer-events: none;
}

/* Contact shadow, tight under the soles. */
.rpg-hero__shadow {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 44px;
  width: 30%;
  height: 11px;
  transform: translate(-50%, 20%);
  border-radius: 50%;
  background: var(--cast);
  opacity: 0.5;
  filter: blur(6px);
  pointer-events: none;
}

/* Overall score, resting on the disc. */
.rpg-hero__badge {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 13px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: var(--surface-veil);
  box-shadow: 0 6px 18px var(--shade);
}

.rpg-hero__badge-score {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.6px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.rpg-hero__badge-label {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ─── Dashboard: ring tabs ─── */
/*  Three identical cards in one row with one visibly active. Both states
 *  share the same box — same padding, same 1px border — so selecting
 *  cannot shift or resize anything. */
.rpg-tabs {
  display: flex;
  align-items: stretch;
  gap: 6px;
  width: 100%;
}

.rpg-ring {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  min-height: 56px;
  padding: 8px 2px 10px;
  border: 1px solid var(--track);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: inherit;
  font-family: inherit;
  /* iOS would otherwise flash its own grey overlay over our press state. */
  -webkit-tap-highlight-color: transparent;
  /* Press feedback has to land on touchdown, so transform and border run
     well under 100ms and cannot linger during a scroll. The theme hue
     shift keeps its own slower curve. */
  transition: transform 90ms ease-out,
              border-color 90ms ease-out,
              background-color 350ms ease-in-out,
              box-shadow 350ms ease-in-out;
}

/* The only instant confirmation a touch user gets. */
.rpg-ring:active {
  transform: scale(0.96);
  border-color: var(--theme);
}

.rpg-ring--active {
  background: var(--surface-lift);
  border-color: var(--theme);
  box-shadow: 0 0 16px -4px var(--theme-glow);
}

/* Connector notch: what ties the selected tab to the panel below it. */
.rpg-ring--active::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 14px;
  height: 7px;
  transform: translateX(-50%);
  background: var(--surface-lift);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

/* Distinct from both the selected and the pressed state, and an outline
   costs no layout. */
.rpg-ring:focus-visible {
  outline: 2px solid var(--theme);
  outline-offset: 2px;
}

/* Hover is desktop-only. Left unwrapped it sticks after a tap and makes
   the wrong card look selected; cursor belongs in here too. */
@media (hover: hover) and (pointer: fine) {
  .rpg-ring { cursor: pointer; }
  .rpg-ring:not(.rpg-ring--active):hover { background: var(--surface-lift); }
}

.rpg-ring__dial {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Stroke is set here rather than on the SVG attribute so it can
   transition and so --ring resolves per ring. */
.rpg-ring__track { stroke: var(--track); }

.rpg-ring__progress {
  stroke: var(--ring);
  opacity: 1;
  transition: stroke-dashoffset 700ms cubic-bezier(0.22, 1, 0.36, 1),
              stroke 350ms ease-in-out, filter 350ms ease-in-out,
              opacity 350ms ease-in-out;
}

/* 85+ : brightest tone, full opacity, soft glow. */
.rpg-ring--optimal .rpg-ring__progress {
  stroke: var(--ring-bright);
  filter: drop-shadow(0 0 5px var(--ring-bright));
}

/* 70-84 : base tone, full opacity, no glow. */
.rpg-ring--good .rpg-ring__progress {
  stroke: var(--ring);
}

/* Below 70 : same hue, visibly dimmer and desaturated. The arc dims,
   never the number. */
.rpg-ring--attention .rpg-ring__progress {
  stroke: var(--ring);
  opacity: 0.55;
  filter: saturate(0.6);
}

.rpg-ring__score {
  position: absolute;
  font-size: 1.4375rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.8px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.rpg-ring__label {
  margin-top: -5px;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.9px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.rpg-ring__status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: 0.2px;
  text-align: center;
  color: var(--text-muted);
  transition: color 350ms ease-in-out;
}

/* The only two places --accent is permitted in the whole app: this
   label's text and the dot beside it. */
.rpg-ring--attention .rpg-ring__status { color: var(--accent); }

.rpg-ring__alert {
  flex: none;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

/* ─── Dashboard: category narrative ─── */
.rpg-detail__text {
  margin-bottom: 14px;
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--text-muted);
}

/* ─── Dashboard: contextual panel ─── */
/*  One card, swapping contents with the selected ring. The outgoing
 *  layer is stacked over the incoming one so they genuinely cross-fade,
 *  and the wrapper height is driven by a measured inline value so the
 *  transition below can animate between differently-sized panels. */
.rpg-panel {
  position: relative;
  overflow: hidden;
  transition: height 340ms cubic-bezier(0.22, 1, 0.36, 1);
}

.rpg-panel__layer { animation: rpgPanelIn 300ms ease both; }

.rpg-panel__layer--out {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  animation: rpgPanelOut 280ms ease both;
  pointer-events: none;
}

@keyframes rpgPanelIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rpgPanelOut { from { opacity: 1; } to { opacity: 0; } }

/* ─── Dashboard: metric row ─── */
/*  Shared by BODY markers, sleep vitals and training figures. */
.rpg-metrics {
  display: flex;
  gap: 4px;
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.rpg-metric {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}

.rpg-metric__value {
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.3px;
  font-variant-numeric: tabular-nums;
}


/* Absent readings show a muted em-dash — never a zero, never red. */
.rpg-metric__value--empty {
  font-weight: 600;
  color: var(--text-muted);
  opacity: 0.7;
}

.rpg-metric__label {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ─── Dashboard: body section ─── */
/*  No bands, no colour grading — chrome accent only. */
.rpg-body__track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--track);
}

.rpg-body__fill {
  height: 100%;
  border-radius: 999px;
  background-color: var(--theme);
  transition: background-color 350ms ease-in-out;
}

.rpg-body__pin {
  position: absolute;
  top: 50%;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--theme);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 12px var(--theme-glow);
  transition: border-color 350ms ease-in-out, box-shadow 350ms ease-in-out;
}

.rpg-body__scale {
  display: flex;
  justify-content: space-between;
  margin-top: 9px;
  font-size: 0.8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.rpg-body__now {
  font-weight: 800;
  color: var(--text);
}

/* ─── Dashboard: sleep section ─── */
.rpg-sleep__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
}

.rpg-sleep__total {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.9px;
  font-variant-numeric: tabular-nums;
}

/*  Caption and coverage merged into one line. The selected segment
 *  already names the range, so it is not repeated here. */
.rpg-sleep__meta {
  margin-top: 0.125rem;
  font-size: 0.8125rem;
  font-weight: 400;
  line-height: 1.35;
  color: var(--text-muted);
}

/*  Main bar. The top margin is room for the target tick's label.
 *  The fill carries the Recovery band colour. */
.rpg-sleep__bar {
  position: relative;
  height: 14px;
  margin-top: 1.125rem;
  border-radius: 999px;
  background: var(--track);
}

.rpg-sleep__fill {
  height: 100%;
  border-radius: 999px;
  background-color: var(--theme);
  box-shadow: 0 0 12px -2px var(--theme-glow);
  transition: width 200ms ease,
              background-color 350ms ease-in-out,
              box-shadow 350ms ease-in-out;
}

.rpg-sleep__target {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 2px;
  border-radius: 1px;
  background: var(--tick);
}

.rpg-sleep__target-label {
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

/* Stage composition, proportional to time in bed. */
.rpg-sleep__stages {
  display: flex;
  height: 8px;
  margin-top: 16px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--track);
}

.rpg-sleep__stage { height: 100%; }

/* Awake sits outside the theme family on purpose: it is the absence of
   sleep, not a stage of it. */
.rpg-sleep__stage, .rpg-sleep__dot {
  transition: width 200ms ease, background-color 350ms ease-in-out;
}

.rpg-sleep__stage--deep, .rpg-sleep__dot--deep { background-color: var(--theme-deep); }
.rpg-sleep__stage--rem, .rpg-sleep__dot--rem { background-color: var(--theme); }
.rpg-sleep__stage--light, .rpg-sleep__dot--light { background-color: var(--theme-bright); }
.rpg-sleep__stage--awake, .rpg-sleep__dot--awake { background-color: var(--neutral); }

.rpg-metrics--legend {
  margin-top: 9px;
  padding-top: 0;
  border-top: none;
}

.rpg-metric__stage {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.rpg-sleep__dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 2px;
}

/* ─── Dashboard: range control ─── */
/*  Generic segmented control. Full width on its own row — at 390px there
 *  is no room to sit it beside the header and still let it breathe. */
.rpg-range {
  display: flex;
  gap: 2px;
  width: 100%;
  margin-bottom: 0.75rem;
  padding: 2px;
  border: 1px solid var(--track);
  border-radius: 0.625rem;
  background: var(--surface);
}

.rpg-range__seg {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
  /* 38 + 4px padding + 2px border = 44pt for the control as a whole. */
  min-height: 38px;
  padding: 0 4px;
  border: none;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: 0.4px;
  -webkit-tap-highlight-color: transparent;
  transition: transform 90ms ease-out,
              background-color 180ms ease,
              color 180ms ease;
}

/*  Extends each segment's touch target to the full 44pt without
 *  changing its visual height. Vertical only, so neighbours cannot
 *  overlap each other. */
.rpg-range__seg::before {
  content: "";
  position: absolute;
  inset: -3px 0;
}

.rpg-range__seg:active { transform: scale(0.96); }

.rpg-range__seg--on {
  background: var(--surface-lift);
  /* --theme itself only reaches 3.8:1 on --surface-lift; the bright
     tone of the same hue clears AA without leaving the palette. */
  color: var(--theme-bright);
}

.rpg-range__seg:focus-visible {
  outline: 2px solid var(--theme);
  outline-offset: -2px;
}

@media (hover: hover) and (pointer: fine) {
  .rpg-range__seg { cursor: pointer; }
  .rpg-range__seg:not(.rpg-range__seg--on):hover { color: var(--text); }
}

/* ─── Dashboard: range figures ─── */
/*  Values cross-fade on range change; the bars above are not keyed, so
 *  they animate their widths instead. */
.rpg-sleep__fade { animation: rpgValueIn 200ms ease both; }

@keyframes rpgValueIn { from { opacity: 0; } to { opacity: 1; } }

.rpg-sleep__delta {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  transition: color 350ms ease-in-out;
}

/* Up is the theme hue. --accent is never used here — it belongs to the
   Pay Attention label alone. */
.rpg-sleep__delta--up { color: var(--theme); }

/*  Under 60% coverage the figures dim. The caption and the coverage line
 *  stay at full strength — they are what explain the dimming. */
.rpg-sleep--thin .rpg-sleep__total,
.rpg-sleep--thin .rpg-sleep__delta,
.rpg-sleep--thin .rpg-sleep__bar,
.rpg-sleep--thin .rpg-sleep__stages,
.rpg-sleep--thin .rpg-metrics {
  opacity: 0.45;
}

/* ─── Dashboard: training section ─── */
.rpg-train__slots {
  display: flex;
  gap: 6px;
  margin-top: 20px;
}

.rpg-train__slot {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: var(--track);
}

.rpg-train__slot--done {
  background-color: var(--theme);
  box-shadow: 0 0 12px -2px var(--theme-glow);
  transition: background-color 350ms ease-in-out, box-shadow 350ms ease-in-out;
}

/* ─── Dashboard: workout link ─── */
.rpg-link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--surface-lift) 0%, var(--surface) 100%);
  box-shadow: 0 10px 26px var(--shade);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 140ms ease;
}

.rpg-link:active { transform: scale(0.99); }

/* Appears alongside the Power detail panel, so it fades in with it. */
.rpg-link--reveal { animation: fadeInUp 260ms ease both; }

.rpg-link span { color: var(--theme-bright); }

@keyframes rpgAura {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.3; }
}

/* ─── Dashboard: larger screens ─── */
/*  Capped at 480px — this is a phone app and must not sprawl. */
@media (min-width: 600px) {
  .rpg__scroll { padding-top: 14px; gap: 14px; }
  .rpg-hero { padding: 8px 16px 18px; }
  .rpg-tabs { gap: 10px; }
}

/* ─── Dashboard: reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
  /* Variants swap instantly — no cross-fade. */
  .rpg-hero__avatar { transition: none; }
  .rpg-hero__aura { animation: none; }
  .rpg-ring__progress { transition: none; }
  .rpg-link--reveal { animation: none; }
  .rpg-panel { transition: none; }
  .rpg-panel__layer { animation: none; }
  .rpg-panel__layer--out { display: none; }
  .rpg-ring, .rpg-link { transition: none; }
  /* Hue shifts apply instantly. */
  .rpg-card__title,
  .rpg-hero__aura, .rpg-hero__disc, .rpg-ring__status,
  .rpg-ring__progress, .rpg-body__fill, .rpg-body__pin,
  .rpg-sleep__fill, .rpg-sleep__stage, .rpg-sleep__dot,
  .rpg-train__slot { transition: none; }
  .rpg-sleep__fade { animation: none; }
  .rpg-range__seg { transition: none; }
}

/* ─── Route: back to dashboard ─── */
.route-back {
  display: flex;
  padding: 8px calc(16px + var(--safe-right)) 0 calc(16px + var(--safe-left));
  background: var(--bg);
}

.route-back__btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
  border: none;
  background: none;
  color: var(--blue);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
