/* Weight Room Pro — shared color themes.
   Drive UI with data-theme on <html> ("dark" | "light"). Default is dark.
   Cast / TV views should reuse these variables and the data-theme attribute.
   Accent is always #ff5a1f. Neutrals stay cool gray — no warm paper tints. */

:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0b0d;
  --bg-2: #0f1114;
  --bg-3: #15181c;
  --surface: #16191e;
  --surface-2: #1c2026;
  --line: rgba(255,255,255,0.08);
  --line-2: rgba(255,255,255,0.14);
  --text: #f3f4f6;
  --muted: #a7acb6;
  --faint: #8b919c;
  --accent: #ff5a1f;
  --accent-2: #ff7a45;
  --accent-ink: #0a0b0d;
  --accent-text: #ff8a5c;
  --accent-soft: rgba(255,90,31,0.12);
  --ink: #f3f4f6;
  --ink-soft: #a3a8b3;
  --navy: #0d0f12;
  --navy-2: #13161a;
  --navy-3: #1d2128;
  --paper: #0a0b0d;
  --card: #15181d;
  --card-2: #1b1f25;
  --line-strong: rgba(255,255,255,0.14);
  --teal: #7cc4ff;
  --teal-soft: rgba(124,196,255,0.12);
  --ok: #4ade80;
  --ok-soft: rgba(74,222,128,0.12);
  --warn: #fbbf24;
  --warn-soft: rgba(251,191,36,0.10);
  --danger: #f87171;
  --danger-soft: rgba(248,113,113,0.12);
  --pr: #ff8a5c;
  --pr-soft: rgba(255,90,31,0.14);
  --demo: #a3a8b3;
  --demo-bg: #0d0f12;
  --shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 20px 40px -24px rgba(0,0,0,0.7);
  --header-bg: rgba(10,11,13,.80);
  --strip-bg: #07080a;
  --footer-bg: #07080a;
  --ghost-fill: rgba(255,255,255,.04);
  --ghost-fill-2: rgba(255,255,255,.08);
  --on-media: #f3f4f6;
  --on-media-muted: #c3c7cf;
  --logo-ink: #f3f4f6;
  --theme-color: #0a0b0d;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --bg-2: #eceef2;
  --bg-3: #e4e7ec;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --line: rgba(18,20,23,0.10);
  --line-2: rgba(18,20,23,0.16);
  --text: #121417;
  --muted: #3e4553;
  --faint: #4e5666;
  --accent: #ff5a1f;
  --accent-2: #e04812;
  --accent-ink: #0a0b0d;
  --accent-text: #c2410c;
  --accent-soft: rgba(255,90,31,0.12);
  --ink: #121417;
  --ink-soft: #3e4553;
  --navy: #eef0f3;
  --navy-2: #e7e9ee;
  --navy-3: #dfe2e8;
  --paper: #f4f5f7;
  --card: #ffffff;
  --card-2: #f3f4f6;
  --line-strong: rgba(18,20,23,0.16);
  --teal: #0a5ea8;
  --teal-soft: rgba(10,94,168,0.12);
  --ok: #157a3a;
  --ok-soft: rgba(21,122,58,0.12);
  --warn: #8a5a00;
  --warn-soft: rgba(138,90,0,0.12);
  --danger: #c0272c;
  --danger-soft: rgba(192,39,44,0.12);
  --pr: #c2410c;
  --pr-soft: rgba(255,90,31,0.14);
  --demo: #3e4553;
  --demo-bg: #eef0f3;
  --shadow: 0 1px 0 rgba(255,255,255,0.9) inset, 0 16px 32px -20px rgba(18,20,23,0.18);
  --header-bg: rgba(244,245,247,.90);
  --strip-bg: #e8eaee;
  --footer-bg: #eceef2;
  --ghost-fill: rgba(18,20,23,.04);
  --ghost-fill-2: rgba(18,20,23,.08);
  --on-media: #f3f4f6;
  --on-media-muted: #c3c7cf;
  --logo-ink: #121417;
  --theme-color: #f4f5f7;
}

html { background: var(--bg, var(--paper, #0a0b0d)); }

/* Lockup: two <img> assets; CSS picks the one that matches data-theme (no flash).
   Selectors must beat .logo img / .sidebar .brand img { display: block }. */
.logo img.lockup-light,
.brand-mark img.lockup-light,
.sidebar .brand img.lockup-light { display: none; }
html[data-theme="light"] .logo img.lockup-dark,
html[data-theme="light"] .brand-mark img.lockup-dark,
html[data-theme="light"] .sidebar .brand img.lockup-dark { display: none; }
html[data-theme="light"] .logo img.lockup-light,
html[data-theme="light"] .brand-mark img.lockup-light,
html[data-theme="light"] .sidebar .brand img.lockup-light { display: block; }

/* ---------- Theme switch: fixed bottom-left, above safe area, never a control overlay ---------- */
.theme-switch {
  position: fixed;
  z-index: 50;
  left: max(12px, env(safe-area-inset-left, 0px));
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line-2, var(--line-strong));
  background: var(--surface, var(--card));
  color: var(--text, var(--ink));
  font-family: var(--sans, Inter, system-ui, sans-serif);
  font-weight: 600;
  font-size: 13px;
  line-height: 1;
  letter-spacing: .01em;
  box-shadow: var(--shadow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.theme-switch:hover { background: var(--surface-2, var(--card-2)); }
.theme-switch-icon { display: block; width: 16px; height: 16px; flex: none; }
.theme-switch-icon svg { display: block; width: 16px; height: 16px; }
/* Muscle-map legend already occupies the bottom-left; sit just above it */
body.mm .theme-switch {
  bottom: max(96px, calc(84px + env(safe-area-inset-bottom, 0px)));
}

/* Marketing: the switch lives in the footer, not fixed over the hero CTA */
body.mk .theme-switch {
  position: static;
  margin: 0;
  box-shadow: none;
}
.site-footer .foot-theme {
  margin-top: var(--s4, 24px);
  display: flex;
  justify-content: flex-start;
}

/*
 * App dock: a reserved bottom strip so the chip never sits on top of
 * check-in keys, session-type buttons, or the sticky save / rest bars.
 */
body:has(.app)::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(56px + env(safe-area-inset-bottom, 0px));
  background: var(--paper, var(--bg));
  border-top: 1px solid var(--line, var(--line-strong));
  z-index: 49;
  pointer-events: none;
}
body:has(.app) .theme-switch {
  bottom: max(6px, env(safe-area-inset-bottom, 0px));
  box-shadow: none;
}
body:has(.app) .main {
  padding-bottom: calc(96px + 56px + env(safe-area-inset-bottom, 0px));
}
@media (max-width: 899px) {
  body:has(.app) .bd-save {
    bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: 10px;
  }
}
body:has(.app):has(.rest-bar) .rest-bar {
  bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  padding-bottom: 12px;
}
@media (min-width: 1024px) {
  body:has(.app)::after {
    left: 256px;
    height: 56px;
  }
  body:has(.sidebar) .theme-switch {
    left: calc(256px + 16px);
    bottom: 6px;
  }
}

/* Auth: the chip sits under the card, in flow, so it never covers form actions */
body.auth-shell {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body.auth-shell .theme-switch {
  position: static;
  margin: 8px 16px 16px;
  align-self: flex-start;
  box-shadow: none;
}

body.station .theme-switch { /* keep a small chip off the main board */
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
}

/* Grain is a dark-theme texture; keep it subtle in light mode */
html[data-theme="light"] body.mk::after { opacity: .025; mix-blend-mode: multiply; }

/* Light-mode overrides for hardcoded dark surfaces in feature CSS we prefer not to rewrite */
html[data-theme="light"] .rest-bar { background: rgba(244,245,247,.96); }
html[data-theme="light"] .portal-chrome { background: var(--header-bg); }
html[data-theme="light"] .unit-toggle button.on,
html[data-theme="light"] .level-switch button.on { background: var(--ink); color: var(--paper); box-shadow: none; }
html[data-theme="light"] .auth-card h1,
html[data-theme="light"] .login-card h1,
html[data-theme="light"] .lift-grid .cell strong,
html[data-theme="light"] .portal-nav-toggle { color: var(--ink); }
html[data-theme="light"] .lift-grid tbody tr:hover td:first-child { background: var(--card-2); }
html[data-theme="light"] .callout.privacy { color: var(--teal); }
html[data-theme="light"] .callout.danger { color: var(--danger); }
html[data-theme="light"] .mm-top { background: var(--header-bg); }
html[data-theme="light"] .mm-legend { background: rgba(244,245,247,.92); }
html[data-theme="light"] .mm-tip { background: var(--card); color: var(--ink); }
html[data-theme="light"] .mm-bar-t { background: var(--bg-3); }
html[data-theme="light"] .ex-picker-menu [data-ex-other] { background: var(--paper); }

/* App chrome that was hardcoded for the dark shell */
html[data-theme="light"] .app {
  background: linear-gradient(90deg, var(--strip-bg) 0 255px, var(--line) 255px 256px, transparent 256px);
}
html[data-theme="light"] .nav-link:hover { background: rgba(18,20,23,.04); }
html[data-theme="light"] .nav-link.active { color: var(--ink); }
html[data-theme="light"] .stat .num,
html[data-theme="light"] .chart .chart-big { color: var(--ink); fill: var(--ink); }
html[data-theme="light"] .btn.secondary,
html[data-theme="light"] .btn.ghost:hover,
html[data-theme="light"] .btn.secondary:hover { background: var(--ghost-fill-2); }
html[data-theme="light"] .unit-toggle,
html[data-theme="light"] .level-switch { background: var(--ghost-fill); }
html[data-theme="light"] .field input,
html[data-theme="light"] .field select,
html[data-theme="light"] .field textarea,
html[data-theme="light"] .toolbar input,
html[data-theme="light"] .toolbar select { background-color: var(--ghost-fill); }

/* ------------------------------------------------------------------
 * Light-mode contrast (WCAG AA). Dark theme is left unchanged.
 * Text 4.5:1, large text / UI borders 3:1. Orange-as-text uses
 * --accent-text (#c2410c). Do not recolor type that sits on a photo.
 * ------------------------------------------------------------------ */
html[data-theme="light"] .jc-code { color: var(--ink); }
html[data-theme="light"] .jc-code.closed {
  text-decoration-color: color-mix(in srgb, var(--ink) 45%, transparent);
}

html[data-theme="light"] .lb-value { color: var(--ink); }
html[data-theme="light"] .lb-you { color: var(--accent-text); }
html[data-theme="light"] .lb-table tr.lb-row-1 td:first-child,
html[data-theme="light"] .lb-card.lb-row-1 {
  box-shadow: inset 3px 0 0 var(--accent-text);
  border-color: color-mix(in srgb, var(--accent-text) 35%, var(--line));
}

/* Default callout was #fcd877 (pale yellow). privacy/danger already mapped. */
html[data-theme="light"] .callout {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 40%, var(--line));
}

html[data-theme="light"] .notice.block { color: var(--danger); }
html[data-theme="light"] .notice.block b { color: var(--ink); }

html[data-theme="light"] .demo-banner {
  background: var(--demo-bg);
  color: var(--demo);
}

html[data-theme="light"] .info-btn[aria-expanded="true"] { color: var(--accent-text); }

html[data-theme="light"] .bb { color: var(--ink); }

html[data-theme="light"] .mm-chip.sec,
html[data-theme="light"] .mm-tag { color: var(--accent-text); }
/* Flip control sits on the dark 3D stage; do not use --accent-text (dark rust) or inherited --text. */
html[data-theme="light"] .mm-flip { color: var(--on-media); }

html[data-theme="light"] .plate.p45,
html[data-theme="light"] .plate.p25 { color: var(--accent-ink, #0a0b0d); }

html[data-theme="light"] .badge.neutral { background: var(--ghost-fill-2); }

html[data-theme="light"] .chart .grid line { stroke: var(--line); }
html[data-theme="light"] .chart .axis { stroke: var(--line-strong); }
html[data-theme="light"] .chart circle.pr-dot,
html[data-theme="light"] .spark circle { stroke: var(--card); }

/* Marketing / chrome type that used --accent-2 (#e04812, 4.11:1 on white).
   Leave .img-card .go and other on-photo type on the bright accent. */
html[data-theme="light"] .eyebrow,
html[data-theme="light"] .tag.live,
html[data-theme="light"] .ico,
html[data-theme="light"] .portal .go,
html[data-theme="light"] .mock-sub,
html[data-theme="light"] .board .pr,
html[data-theme="light"] .ph-copy::before,
html[data-theme="light"] .step .num,
html[data-theme="light"] .mock-action,
html[data-theme="light"] .hold .label,
html[data-theme="light"] a.card .go,
html[data-theme="light"] .site-footer a:hover,
html[data-theme="light"] p a:not(.btn):hover {
  color: var(--accent-text);
}
/* #c2410c is 4.30:1 on --strip-bg / 4.46:1 on the footer; use a darker rust (AA). */
html[data-theme="light"] .ph-strip b,
html[data-theme="light"] .site-footer a:hover {
  color: #9a3412;
}

html[data-theme="light"] .field input:hover,
html[data-theme="light"] .field select:hover,
html[data-theme="light"] .field textarea:hover,
html[data-theme="light"] .toolbar input:hover,
html[data-theme="light"] .toolbar select:hover {
  border-color: var(--line-strong);
}
