/* ============================================================
   WORKOUT TRACKER — Complete Stylesheet
   Light/Dark/Device theme, mobile-first, premium fitness aesthetic
   ============================================================ */

/* --- CSS Custom Properties (non-color, shared) --- */
:root {
  /* Containers (cards, panels) are see-through: the page and its texture show behind them */
  /* Transparent containers: the page colour at (100% - transparency), so
     0% is opaque and 100% fully see-through (Settings → Containers). */
  --surface-transparency: 100%;
  /* Standard control height: buttons, dropdowns and date fields (.ctl),
     the same as a toggle's selection (47px toggle − 4 border − 6 padding) */
  --control-h: 37px;
  --surface: color-mix(in srgb, var(--bg) calc(100% - var(--surface-transparency)), transparent);
  --radius: 14px;
  --radius-sm: 8px;
  --radius-xs: 6px;

  --sidebar-width: 240px;
  /* The iOS 26/27 status-bar blur fades out ~96pt from the top of the screen
     (62pt inset + 34). Overlay content is placed a little lower. */
  --ios-top-clear: calc(env(safe-area-inset-top, 0px) + 42px);
  --bottomnav-height: 64px;
  /* Floating tab bar: gap between the capsule and the bottom of the screen. */
  --bottomnav-offset: max(12px, calc(env(safe-area-inset-bottom, 0px) - 10px));

  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";

  --transition-fast: 150ms ease;
  --transition: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ============================================================
   THEME: DARK (default)
   ============================================================ */
:root,
[data-theme="dark"] {
  --accent: #00E5FF;
  --accent-rgb: 0, 229, 255;
  --accent-dim: rgba(0, 229, 255, 0.15);
  --accent-hover: rgba(0, 229, 255, 0.9);
  --accent-text: #00E5FF;

  --bg: #000000;
  --bg-card: #111111;
  --bg-input: #1a1a1a;
  --bg-elevated: #161616;
  --bg-hover: #1e1e1e;

  --text: #ffffff;
  --text-muted: #888888;
  --text-dim: #555555;
  /* Summary bar chart: past-month bars, their month labels, the hero year */
  --chart-muted: #888888;

  --border: #333333;
  --border-focus: var(--accent);
  --separator: rgba(255, 255, 255, 0.04);

  --glass-bg: rgba(10, 10, 10, 0.85);
  --glass-bg-heavy: rgba(10, 10, 10, 0.75);
  --shadow-card: none;
  --shadow-dropdown: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-modal: 0 16px 64px rgba(0, 0, 0, 0.5);
  --shadow-toast: 0 4px 24px rgba(0, 0, 0, 0.3);

  --skeleton-shimmer: rgba(255, 255, 255, 0.04);
  --table-stripe: rgba(255, 255, 255, 0.015);
  --btn-google-bg: #ffffff;
  --btn-google-text: #333333;
  --btn-google-shadow: 0 4px 24px rgba(255, 255, 255, 0.1);

  --success-flash: rgba(34, 197, 94, 0.27);
  --bar-bg: #000000;
  --header-bg: #111111;
  --modal-overlay: rgba(0, 0, 0, 0.8);
  --nav-glass: rgba(38, 38, 43, 0.8);
  --nav-glass-solid: #212125;
  --nav-glass-border: rgba(255, 255, 255, 0.12);
  --nav-glass-highlight: rgba(255, 255, 255, 0.28);
  --nav-glass-sheen: rgba(255, 255, 255, 0.1);
  --nav-active-bg: rgba(10, 10, 12, 0.82);
  --nav-lens-bg: rgba(10, 10, 12, 0.7);
  --nav-lens-edge: rgba(0, 0, 0, 0.3);
  --nav-active-fg: var(--nav-accent, var(--accent));
  --nav-active-plain: #fff;
  --color-scheme: dark;
}

/* ============================================================
   THEME: LIGHT
   ============================================================ */
[data-theme="light"] {
  --accent: #00E5FF;
  --accent-rgb: 0, 229, 255;
  --accent-dim: rgba(0, 229, 255, 0.12);
  --accent-hover: rgba(0, 200, 230, 0.95);
  --accent-text: #007a8a;

  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --bg-input: #f0f0f2;
  --bg-elevated: #ffffff;
  --bg-hover: #eeeef0;

  --text: #1c1c1e;
  --text-muted: #6e6e73;
  --text-dim: #aeaeb2;
  --chart-muted: #8e8e92;   /* halfway between --text-muted and --text-dim */

  --border: #d2d2d7;
  --border-focus: var(--accent);
  --separator: rgba(0, 0, 0, 0.06);

  --glass-bg: rgba(245, 245, 247, 0.8);
  --glass-bg-heavy: rgba(245, 245, 247, 0.75);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-dropdown: 0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-modal: 0 16px 64px rgba(0, 0, 0, 0.15);
  --shadow-toast: 0 4px 24px rgba(0, 0, 0, 0.1);

  --skeleton-shimmer: rgba(0, 0, 0, 0.04);
  --table-stripe: rgba(0, 0, 0, 0.02);
  --btn-google-bg: #ffffff;
  --btn-google-text: #333333;
  --btn-google-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);

  --success-flash: rgba(34, 197, 94, 0.2);
  --bar-bg: #ffffff;
  --header-bg: #ffffff;
  --modal-overlay: rgba(255, 255, 255, 0.85);
  --nav-glass: rgba(250, 250, 252, 0.8);
  --nav-glass-solid: #ffffff;
  --nav-glass-border: rgba(0, 0, 0, 0.07);
  --nav-glass-highlight: rgba(255, 255, 255, 0.95);
  --nav-glass-sheen: rgba(255, 255, 255, 0.5);
  --nav-active-bg: rgba(120, 120, 128, 0.16);
  --nav-lens-bg: rgba(120, 120, 128, 0.22);
  --nav-lens-edge: rgba(0, 0, 0, 0.06);
  --nav-active-fg: var(--accent-text);
  --nav-active-plain: var(--text);
  --color-scheme: light;
}

/* ============================================================
   THEME: DEVICE (system preference)
   Defaults to dark, flips to light if OS prefers light
   ============================================================ */
@media (prefers-color-scheme: light) {
  [data-theme="device"] {
    --accent: #00E5FF;
    --accent-rgb: 0, 229, 255;
    --accent-dim: rgba(0, 229, 255, 0.12);
    --accent-hover: rgba(0, 200, 230, 0.95);
    --accent-text: #007a8a;

    --bg: #f5f5f7;
    --bg-card: #ffffff;
    --bg-input: #f0f0f2;
    --bg-elevated: #ffffff;
    --bg-hover: #eeeef0;

    --text: #1c1c1e;
    --text-muted: #6e6e73;
    --text-dim: #aeaeb2;
    --chart-muted: #8e8e92;

    --border: #d2d2d7;
    --border-focus: var(--accent);
    --separator: rgba(0, 0, 0, 0.06);

    --glass-bg: rgba(245, 245, 247, 0.8);
    --glass-bg-heavy: rgba(245, 245, 247, 0.75);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-dropdown: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-modal: 0 16px 64px rgba(0, 0, 0, 0.15);
    --shadow-toast: 0 4px 24px rgba(0, 0, 0, 0.1);

    --skeleton-shimmer: rgba(0, 0, 0, 0.04);
    --table-stripe: rgba(0, 0, 0, 0.02);
    --btn-google-bg: #ffffff;
    --btn-google-text: #333333;
    --btn-google-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);

    --success-flash: rgba(34, 197, 94, 0.2);
    --bar-bg: #ffffff;
    --header-bg: #ffffff;
    --modal-overlay: rgba(255, 255, 255, 0.85);
    --nav-glass: rgba(250, 250, 252, 0.8);
    --nav-glass-solid: #ffffff;
    --nav-glass-border: rgba(0, 0, 0, 0.07);
    --nav-glass-highlight: rgba(255, 255, 255, 0.95);
    --nav-glass-sheen: rgba(255, 255, 255, 0.5);
    --nav-active-bg: rgba(120, 120, 128, 0.16);
    --nav-lens-bg: rgba(120, 120, 128, 0.22);
    --nav-lens-edge: rgba(0, 0, 0, 0.06);
    --nav-active-fg: var(--accent-text);
    --nav-active-plain: var(--text);
    --color-scheme: light;
  }
}

/* ============================================================
   THEME TRANSITION (smooth switch between themes)
   ============================================================ */
html {
  color-scheme: var(--color-scheme, dark);
}

body,
.bottom-nav,
.sidebar,
.card,
.modal,
.toast {
  transition: background-color var(--transition), color var(--transition),
    border-color var(--transition), box-shadow var(--transition);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
  overflow: hidden;
  background: var(--bar-bg);
}

body {
  font-family: var(--font-stack);
  background: var(--bar-bg);
  color: var(--text);
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* The status-bar blur is tinted from the document background (live), so it
   must match what scrolls under it: the page once signed in. */
html.has-top-bar,
html.has-top-bar body {
  background: var(--bg);
}

/* A full-screen overlay covers the header, so the scrim takes its colour. */
html.has-top-bar:has(> body > .fullscreen-overlay),
html.has-top-bar:has(> body > .fullscreen-overlay) body {
  background: var(--bg);
}

/* iPhone home-screen app: the page runs under the status bar
   (black-translucent + viewport-fit=cover) so content scrolls behind it.
   - html/body take 100vh: with black-translucent iOS otherwise starts the web
     view a status-bar height short (100%, dvh and svh all measure short).
   - Content at rest starts below the status-bar blur; it only blurs as it
     scrolls up behind the status bar. */
html.ios-app,
html.ios-app body {
  height: 100vh;
}
html.ios-app .main-content {
  padding-top: calc(env(safe-area-inset-top, 0px) + 34px);
}

img {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input,
select {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent-text);
  text-decoration: none;
}

ul, ol {
  list-style: none;
}

[hidden] {
  display: none !important;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  overflow-y: auto;
  padding: 24px;
  transition: opacity 1s ease;
  /* fixed, like the .app shell: covers the whole screen, home-indicator area
     included (absolute stopped short and showed the tab bar below it). */
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--bg);
}

.login-container {
  text-align: center;
  max-width: 360px;
  width: fit-content;
  opacity: 0;
  animation: loginFadeIn 1s ease 0.5s forwards;
}

@keyframes loginFadeIn {
  to { opacity: 1; }
}

.login-container.fade-out {
  animation: none !important;
  transition: opacity 1s ease;
}

.login-logo {
  margin-bottom: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.login-logo svg {
  margin: 0;
}

/* Splash lifter: three poses stacked, one shown at a time, in four equal
   frames (low, mid, high, mid) so it reps up and down on a loop. */
.login-lifter {
  position: relative;
  width: 68px;
  height: 68px;
  margin: 0;
  /* White on the dark theme; dark grey on the light one (below) */
  color: #fff;
}
.lifter-pose {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  animation: 1.6s step-end infinite;
}
.lifter-low { animation-name: lifterLow; }
.lifter-mid { animation-name: lifterMid; }
.lifter-high { animation-name: lifterHigh; }
@keyframes lifterLow {
  0% { opacity: 1; }
  25%, 100% { opacity: 0; }
}
@keyframes lifterMid {
  0%, 50% { opacity: 0; }
  25%, 75% { opacity: 1; }
}
@keyframes lifterHigh {
  0%, 25%, 75%, 100% { opacity: 0; }
  50% { opacity: 1; }
}
/* Solid head; eyes on the low pose (dots) and mid pose (two short lines,
   squinting), a dot mouth on the high pose. Each pose's mask cuts them out
   of the body; on the dark theme (white lifter) they stay holes, so the page
   background shows through; on the light theme (dark grey lifter) they're
   drawn white over the holes. */
.lifter-eye {
  display: none;
  fill: #fff;
  stroke: none;
}
.lifter-eye-line {
  display: none;
  stroke: #fff;
  stroke-width: 0.5;
}
[data-theme="light"] .login-lifter {
  color: #3a3a3a;
}
[data-theme="light"] :is(.lifter-eye, .lifter-eye-line) {
  display: inline;
}
@media (prefers-color-scheme: light) {
  [data-theme="device"] .login-lifter {
    color: #3a3a3a;
  }
  [data-theme="device"] :is(.lifter-eye, .lifter-eye-line) {
    display: inline;
  }
}
@media (prefers-reduced-motion: reduce) {
  .lifter-pose { animation: none; }
  .lifter-high { opacity: 1; }
}
/* The page loading spinner (.page-loading-ring), under the lifter */
.splash-spinner {
  margin-top: 24px;
}

.btn-google-signin {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 28px;
  background: var(--btn-google-bg);
  color: var(--btn-google-text);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.btn-google-signin:hover {
  transform: translateY(-1px);
  box-shadow: var(--btn-google-shadow);
}

.btn-google-signin:active {
  transform: translateY(0);
}

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bar-bg);
  z-index: 1;
}

/* ============================================================
   SIDEBAR NAVIGATION (Desktop)
   ============================================================ */
.sidebar {
  display: none;
}

@media (min-width: 768px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    z-index: 90;
    overflow-y: auto;
  }
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.925rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent-text);
  font-weight: 600;
}

.nav-item.active:hover {
  background: var(--accent-dim);
  color: var(--accent-text);
}

.nav-icon {
  flex-shrink: 0;
}

/* ============================================================
   BOTTOM NAVIGATION (Mobile)
   iOS 27-style Liquid Glass tab bar: a translucent capsule floating just
   above the home indicator, with a glass "lens" that slides (and squishes)
   between tabs. Press-and-drag moves the lens with the finger.
   ============================================================ */
.bottom-nav {
  --nav-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: var(--bottomnav-offset);
  height: var(--bottomnav-height);
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 2px;
  padding: 0 3px;
  border-radius: 999px;
  isolation: isolate;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.1);
  z-index: 100;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: scale 380ms var(--nav-spring);
}

/* Capsule swells slightly while a finger is on it */
.bottom-nav.pressed {
  scale: 1.025;
}

/* The blur lives on a pseudo-element: backdrop-filter directly on a
   position: fixed element glitches its positioning on iOS. */
.bottom-nav::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -2;
  border-radius: inherit;
  border: 1px solid var(--nav-glass-border);
  background: var(--nav-glass);
  -webkit-backdrop-filter: blur(30px) saturate(220%) brightness(1.08);
  backdrop-filter: blur(30px) saturate(220%) brightness(1.08);
  /* Specular rim on the top edge + soft refraction shading on the bottom */
  box-shadow:
    inset 0 1px 0.5px var(--nav-glass-highlight),
    inset 0 -1px 1px rgba(0, 0, 0, 0.06),
    inset 0 0 12px rgba(255, 255, 255, 0.04);
}

/* Glass sheen: a light falloff across the upper half of the capsule */
.bottom-nav::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% -30%, var(--nav-glass-sheen), transparent 60%),
    linear-gradient(180deg, var(--nav-glass-sheen) 0%, transparent 40%);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .bottom-nav::before {
    background: var(--nav-glass-solid);
  }
}

/* --- Workout in progress: accent glow on the tab bar ------------------
   A soft halo that breathes, plus a band of light travelling around the
   capsule's edge, in the accent colour. html.workout-on is set by app.js
   while a workout is active; the animations are paused otherwise. */
@property --nav-glow-angle {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}
.bottom-nav-glow {
  position: absolute;
  inset: -1px;
  z-index: 1;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 700ms ease;
}
.bottom-nav-glow::before,
.bottom-nav-glow::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  animation-play-state: paused;
}
/* Halo outside the capsule */
.bottom-nav-glow::before {
  box-shadow:
    0 0 24px 2px rgba(var(--accent-rgb), 0.5),
    0 0 8px rgba(var(--accent-rgb), 0.45);
  animation: navGlowBreathe 2.8s ease-in-out infinite;
}
/* Light travelling around the edge: a rotating conic gradient, masked to a ring */
.bottom-nav-glow::after {
  padding: 1.5px;
  background: conic-gradient(
    from var(--nav-glow-angle),
    transparent 0deg,
    rgba(var(--accent-rgb), 0) 30deg,
    rgb(var(--accent-rgb)) 90deg,
    rgba(var(--accent-rgb), 0) 150deg,
    transparent 180deg,
    rgba(var(--accent-rgb), 0) 210deg,
    rgb(var(--accent-rgb)) 270deg,
    rgba(var(--accent-rgb), 0) 330deg
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  animation: navGlowSpin 4.5s linear infinite;
}
html.workout-on .bottom-nav-glow {
  opacity: 1;
}
html.workout-on .bottom-nav-glow::before,
html.workout-on .bottom-nav-glow::after {
  animation-play-state: running;
}
@keyframes navGlowSpin {
  to { --nav-glow-angle: 360deg; }
}
@keyframes navGlowBreathe {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .bottom-nav-glow::before,
  .bottom-nav-glow::after {
    animation: none;
  }
}

@media (min-width: 768px) {
  .bottom-nav {
    display: none;
  }
}

/* Sliding selection lens (positioned by JS via --lens-x / --lens-w) */
.bottom-nav-lens {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  width: var(--lens-w, 0px);
  transform: translateX(var(--lens-x, 0px));
  border-radius: 999px;
  background: var(--nav-active-bg);
  box-shadow:
    inset 0 1px 0.5px rgba(255, 255, 255, 0.2),
    inset 0 -0.5px 1px var(--nav-lens-edge),
    0 1px 3px rgba(0, 0, 0, 0.12);
  pointer-events: none;
  z-index: 0;
  transition:
    transform 560ms var(--nav-spring),
    width 560ms var(--nav-spring),
    scale 420ms var(--nav-spring),
    background-color 250ms ease,
    box-shadow 250ms ease;
}

.bottom-nav-lens.no-anim {
  transition: none;
}

/* Liquid stretch while travelling between tabs */
.bottom-nav-lens.moving {
  scale: 1.14 0.84;
  transition:
    transform 560ms var(--nav-spring),
    width 560ms var(--nav-spring),
    scale 160ms ease-out;
}

/* Magnified glass lens while the finger is down / dragging */
.bottom-nav.pressed .bottom-nav-lens {
  scale: 1.16 1.22;
  background: var(--nav-lens-bg);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.28),
    inset 0 -1px 2px var(--nav-lens-edge),
    0 4px 14px rgba(0, 0, 0, 0.22);
}

.bottom-nav.dragging .bottom-nav-lens {
  transition:
    width 300ms var(--nav-spring),
    scale 420ms var(--nav-spring),
    background-color 250ms ease,
    box-shadow 250ms ease;
}

.bottom-nav-item {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  height: calc(100% - 6px);
  border-radius: 999px;
  font-size: 0.625rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: color 300ms ease;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item .nav-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  transition: scale 380ms var(--nav-spring);
}

.bottom-nav-item:active .nav-icon {
  scale: 0.88;
}

.bottom-nav-item.active {
  color: var(--nav-active-fg);
  font-weight: 600;
}

.bottom-nav-item.active .nav-icon {
  animation: navIconPop 520ms var(--nav-spring);
}

/* Item under the finger while dragging the lens */
.bottom-nav-item.drag-target {
  color: var(--text);
}

@keyframes navIconPop {
  0% { scale: 0.82; }
  55% { scale: 1.12; }
  100% { scale: 1; }
}

/* Hover only for real pointers: iOS keeps :hover on the last tapped tab,
   which left a page that was no longer active highlighted. */
@media (hover: hover) and (pointer: fine) {
  .bottom-nav-item:hover {
    color: var(--text);
  }

  .bottom-nav-item.active:hover {
    color: var(--nav-active-fg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bottom-nav,
  .bottom-nav-lens,
  .bottom-nav-lens.moving,
  .bottom-nav-item .nav-icon {
    transition: none;
    animation: none;
  }
  .bottom-nav.pressed,
  .bottom-nav-lens.moving,
  .bottom-nav.pressed .bottom-nav-lens {
    scale: none;
  }
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.main-content {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* contain, not none: iOS rubber-bands this scroller at both ends, but the
     bounce doesn't chain to the page (tab bar and status bar stay put). */
  overscroll-behavior-y: contain;
  padding: 16px 12px;
  max-width: 960px;
  width: 100%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  margin: 0 auto;
  background: var(--bg);
}

/* Content scrolls under the floating tab bar; the last item comes to rest
   just above it. */
@media (max-width: 767px) {
  .main-content {
    padding-bottom: calc(var(--bottomnav-height) + var(--bottomnav-offset) + 24px);
  }
}

@media (min-width: 768px) {
  .main-content {
    margin-left: var(--sidebar-width);
    padding: 24px 32px 32px;
    width: calc(100% - var(--sidebar-width));
    max-width: none;
  }
}

/* --- Calendar Day Circles --- */
.cal-day {
  width: 41px;
  height: 41px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  color: var(--text-muted);
  cursor: default;
  transition: all 0.2s;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

.cal-day.cal-workout {
  border: 1px solid var(--text);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.cal-day.cal-today.cal-workout {
  border: 1px solid var(--text);
}

.cal-day.cal-today {
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
}

/* --- Views --- */
/* Every page is at least 1px taller than the scroller, so even a short page
   can be scrolled and therefore rubber-bands, like a native app. */
.main-content > .view.active {
  min-height: calc(100% + 1px);
}
/* Every page ends the same distance above the tab bar (or Summary's month
   picker): the scroller's bottom padding (… + 24px) is the only gap, so the
   last item on a page drops its own bottom margin. Three levels deep: page →
   wrapper / sub-page → wrapper → last card. !important over inline margins. */
.view > :last-child,
.view > :last-child > :last-child,
.view > :last-child > :last-child > :last-child {
  margin-bottom: 0 !important;
}

.view {
  display: none;
  animation: viewFadeIn var(--transition-slow) ease forwards;
}

.view.active {
  display: block;
}

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

@keyframes setRowSlideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.set-row-new > td {
  animation: setRowSlideIn 0.5s ease-out both;
}

/* --- Summary month carousel: ‹ Today › ---------------------------------
   Sits just above the floating tab bar. Hidden, it is tucked behind the tab
   bar (lower z-index, shifted down by the bar's height); on Summary it slides
   up from behind it with a little overshoot. */
.month-nav {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-offset) + var(--bottomnav-height) + 10px);
  z-index: 99;                       /* the tab bar is 100: hidden behind it */
  display: flex;
  align-items: center;
  gap: 2px;
  height: 44px;
  padding: 0 4px;
  border-radius: 999px;
  isolation: isolate;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16), 0 1px 3px rgba(0, 0, 0, 0.1);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(var(--bottomnav-height) + 10px)) scale(0.92);
  /* Hiding (leaving Summary): slides down behind the tab bar, staying opaque
     until it is almost behind it, then fades. */
  transition: transform 420ms cubic-bezier(0.4, 0, 0.6, 1), opacity 140ms ease 300ms;
}
.month-nav::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  border: 1px solid var(--nav-glass-border);
  background: var(--nav-glass);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
}
.month-nav.show {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
  /* Showing: springs up from behind the tab bar */
  transition: transform 520ms cubic-bezier(0.2, 0.9, 0.25, 1.15), opacity 200ms ease;
}
.month-nav-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--text);
}
.month-nav-today {
  padding: 0 14px;
  height: 36px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
}
/* Same colour as the tab bar's active item: accent, or plain with the
   "Default" nav bar setting (html.nav-plain, set by applyNavBarStyle). */
.month-nav-today.active {
  color: var(--nav-active-fg);
}
html.nav-plain .month-nav-today.active {
  color: var(--nav-active-plain);
}
.month-nav button:disabled {
  opacity: 0.3;
  cursor: default;
}
.month-nav-today:disabled {
  opacity: 0.55;
}
.month-nav button:not(:disabled):active {
  background: var(--nav-active-bg);
}
@media (min-width: 768px) {
  .month-nav { display: none; }
}
@media (max-width: 767px) {
  html.month-nav-on .main-content {
    padding-bottom: calc(var(--bottomnav-height) + var(--bottomnav-offset) + 24px + 54px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .month-nav,
  .month-nav.show { transition: opacity 200ms ease; }
}

/* --- Workout in progress: timer + Save above the log ------------------
   Opens by animating its row height from 0, so the log moves down to make
   room; closes the same way. .no-anim shows/hides it instantly (switching
   to Log mid-workout, app launch). */
/* Page controls (History sub-tabs, Exercises toolbar) stay pinned while the
   page scrolls behind them, like the workout card: sticky top 0 rests them at
   their place below the status-bar blur (WebKit counts the scroller padding). */
.pinned-controls {
  position: sticky;
  top: 0;
  z-index: 20;
}
.pinned-controls > *,
.pinned-controls > button {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.1);
}

.workout-banner {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 420ms cubic-bezier(0.2, 0.8, 0.2, 1);
  /* Pinned while the log scrolls: content scrolls up behind the card. In the
     home-screen app it sticks at the edge of the status-bar blur (~96pt), so
     it stays sharp while content continues up under the clock. WebKit
     measures sticky top from inside the scroller's top padding, and that
     padding (.main-content: inset + 34px) already puts it below the blur,
     so top is 0 there (measured: 96pt at rest and while scrolled). */
  position: sticky;
  top: 0;
  z-index: 20;
}
.workout-banner.open {
  grid-template-rows: 1fr;
}
.workout-banner.no-anim,
.workout-banner.no-anim .workout-banner-card {
  transition: none;
}
.workout-banner-inner {
  min-height: 0;
  overflow: hidden;
}
.workout-banner.settled .workout-banner-inner {
  overflow: visible;
}
.workout-banner-card {
  width: 98%;
  max-width: 700px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 12px 16px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  transition: opacity 320ms ease, transform 420ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
/* Mesh gradient behind the timer card's content while a workout runs: the
   iOS app's "Groovy" header (LavaLampView). Eight blurred blobs in shades of
   the accent drift over it; app.js colours and moves them. */
.workout-banner-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  /* Subtle lift so the pinned card reads as floating over the content */
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.1);
}
/* The card's background (mesh + texture) under its content, clipped to the
   card's rounded shape with clip-path: WebKit lets composited children (the
   moving blobs, the blended texture) escape overflow:hidden + border-radius
   and square the corners. On this layer, not the card, so the card's shadow
   isn't clipped. */
.workout-banner-bg {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  border-radius: inherit;
  overflow: hidden;
  clip-path: inset(0 round var(--radius));
  -webkit-clip-path: inset(0 round var(--radius));
}
.workout-banner-mesh {
  position: absolute;
  inset: 0;
}
/* The page's background texture over the mesh (under the text), drawn by
   app.js: specks and chips as light dots at the page's strength; grain in
   black and white, blended so it roughens the colours without changing them. */
.workout-banner-texture {
  position: absolute;
  inset: 0;
  background-size: 128px 128px;
  background-repeat: repeat;
}
.workout-banner-texture.blend {
  mix-blend-mode: overlay;
}
/* As strong as the texture looks through the sets container (Settings →
   Containers): Transparent shows it at the transparency set there; Diffused
   lays a ~40% tint over it. */
html:not(.containers-diffused) .workout-banner-texture {
  opacity: var(--surface-see-through, 1);
}
html.containers-diffused .workout-banner-texture {
  opacity: 0.6;
}
.workout-banner-mesh span {
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  will-change: transform;
}

.workout-banner.open .workout-banner-card {
  opacity: 1;
  transform: none;
}
.workout-banner-label {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.8;
}
.workout-banner-time {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.workout-banner-save {
  padding: 10px 22px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}
.workout-banner-save:active {
  opacity: 0.7;
}
@media (prefers-reduced-motion: reduce) {
  .workout-banner,
  .workout-banner-card {
    transition: none;
  }
}

/* Standard controls (.ctl): text buttons, dropdowns and date fields all
   --control-h tall, matching a toggle's selection. !important because most
   of these carry inline padding / heights from their markup. */
.ctl {
  height: var(--control-h) !important;
  box-sizing: border-box !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}
button.ctl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Log page Date / Start Time row. Before a workout starts the labels are
   hidden and the start button is an accent "Start"; once one is in progress
   (.started) the labels show and the button shows the clock + start time. */
.log-meta-label {
  display: none;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 4px;
}
.log-meta.started .log-meta-label {
  display: block;
}
.log-start-btn {
  width: 100%;
  height: var(--control-h);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 2px solid var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.log-start-clock,
.log-start-time {
  display: none;
}
.log-start-time {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.log-meta.started .log-start-btn {
  border-color: var(--border);
  background: var(--bg-hover);
  color: var(--text);
  font-weight: 400;
}
.log-meta.started .log-start-idle {
  display: none;
}
.log-meta.started .log-start-clock,
.log-meta.started .log-start-time {
  display: inline;
}

/* Log page Reset: red (the remove-set colour) on the Add Set fill while a
   workout is in progress; faded and inert until then. */
.log-reset-btn {
  flex: 1;
  padding: 8px;
  background: var(--bg-hover);
  color: #ef4444;
  border: 2px solid #ef4444;   /* the Settings buttons' border width */
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.log-reset-btn:disabled {
  background: var(--bg-input);
  color: var(--text-dim);
  border-color: var(--border);
  cursor: default;
}

/* Summary month bar chart: scrolls sideways, 12 months to the width
   (--bar-cols is the number of months). The top padding is room for a tapped
   bar's value / jump pop-up, which a scroller would otherwise clip; the
   negative margin keeps the chart in place. */
.bar-scroller {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  padding-top: 64px;
  margin-top: -44px;
}
.bar-scroller::-webkit-scrollbar {
  display: none;
}
.bar-scroller .bar-track {
  width: calc((100% + 4px) * var(--bar-cols, 12) / 12 - 4px);
}

/* Summary bar chart: a tapped bar's value, just above the bar (app.js
   showBarValue), fading in and out. Centred on the bar; the first and last
   bars align it to their outer edge so it isn't clipped. */
.bar-value {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
  animation: barValueIn 150ms ease-out;
  transition: opacity 1000ms ease;
}
.bar-value.bar-value-start {
  left: 0;
  transform: none;
}
.bar-value.bar-value-end {
  left: auto;
  right: 0;
  transform: none;
}
.bar-value.leaving {
  opacity: 0;
}
@keyframes barValueIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
/* Second tap on a bar: "View <Month Year> ›", above its value (app.js) */
.bar-jump {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 6px 10px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.1);
  animation: barValueIn 150ms ease-out;
  transition: opacity 1000ms ease;
}
.bar-jump.bar-edge-start {
  left: 0;
  transform: none;
}
.bar-jump.bar-edge-end {
  left: auto;
  right: 0;
  transform: none;
}
.bar-jump.leaving {
  opacity: 0;
  pointer-events: none;
}

/* Summary This Week / This Month: a ring around the count (app.js
   progressRing). The arc starts at 12 o'clock and fills in when drawn. */
.progress-ring {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 0 auto;
}
.progress-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.progress-ring circle {
  fill: none;
  stroke-width: 9;
}
.progress-ring-track {
  stroke: var(--bg-hover);
}
/* Light theme: --bg-hover nearly vanishes on the page; a visible grey */
[data-theme="light"] .progress-ring-track {
  stroke: var(--border);
}
@media (prefers-color-scheme: light) {
  [data-theme="device"] .progress-ring-track {
    stroke: var(--border);
  }
}
.progress-ring-arc {
  stroke: var(--accent);
  stroke-linecap: round;
  animation: ringFill 700ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes ringFill {
  from { stroke-dashoffset: var(--ring-c); }
}
@media (prefers-reduced-motion: reduce) {
  .progress-ring-arc { animation: none; }
}
.progress-ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}
.progress-ring-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}
.progress-ring-goal {
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================
   SEGMENTED TOGGLE (History / Stats / PRs)
   Any .seg-toggle with .seg-btn buttons: a thumb behind them slides to the
   .active one. app.js (watchSegToggles) adds the thumb and sets
   --seg-count / --seg-index automatically; .seg-ready turns the slide on
   after the first placement.
   ============================================================ */
.seg-toggle {
  position: relative;
  display: flex;
  background: var(--bg-input);
  border: 2px solid var(--border);   /* outside border, like the buttons */
  border-radius: 12px;
  padding: 3px;
}
.seg-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / var(--seg-count, 3));
  transform: translateX(calc(100% * var(--seg-index, 0)));
  border-radius: 8px;
  background: var(--accent);   /* the active selection in the accent colour */
  box-shadow: var(--shadow-card);
  pointer-events: none;
}
.seg-toggle.seg-ready .seg-thumb {
  transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
/* Equal widths always (min-width 0, so a long label like "Workouts" can't
   widen its button and throw the evenly spaced thumb off) */
.seg-btn {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 21px;   /* fixed, so every toggle is the same height (8 + 21 + 8) */
  cursor: pointer;
  transition: color 200ms ease;
}
.seg-btn.active {
  color: var(--accent-contrast);
}
/* Icon options (Settings → Theme): 22px icon + 7.5px padding = the text
   options' 37px, so icon toggles match the others' height */
.seg-btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7.5px 6px;
}
.seg-btn-icon svg {
  display: block;
}
@media (prefers-reduced-motion: reduce) {
  .seg-toggle.seg-ready .seg-thumb { transition: none; }
}

/* ============================================================
   PAGE LOADING COVER
   Shown while a page or a Summary month loads: a light veil of the page
   colour over the content (under the month picker and tab bar; on a
   sub-page change app.js starts it below the History tabs) with the
   DS Customer Health spinner: a ring chasing its own tail (solid head, tail
   easing to ~20%, small gap), a conic gradient masked to a ring.
   ============================================================ */
.page-loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: color-mix(in srgb, var(--bg) 35%, transparent);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 300ms ease, visibility 0s linear 300ms;
}
.page-loading.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 300ms ease;
}
@media (min-width: 768px) {
  .page-loading {
    left: var(--sidebar-width);
  }
}
.page-loading-ring {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--text-muted);
  background: conic-gradient(from 0deg, currentColor 0deg, currentColor 130deg, color-mix(in srgb, currentColor 20%, transparent) 334deg, transparent 335deg 360deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3.5px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3.5px), #000 calc(100% - 3px));
  animation: pageLoadingSpin 1s linear infinite;
}
.page-loading-label {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}
@keyframes pageLoadingSpin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

/* ============================================================
   SKELETON / LOADING STATE
   ============================================================ */

@keyframes shimmer {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(100%);
  }
}

/* ============================================================
   CALENDAR (Dashboard & History)
   ============================================================ */
.calendar {
  width: 100%;
}

/* ============================================================
   FORMS & INPUTS
   ============================================================ */

/* Date input — constrain iOS native picker width */
input[type="date"] {
  color-scheme: var(--color-scheme, dark);
  max-width: 100%;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}

input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  padding: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
  overflow: hidden;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: 2px solid var(--border);
  border-radius: 50%;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  /* Every button: a 2px border, as on Settings (filled ones in their fill) */
  border: 2px solid var(--border);
  transition: background var(--transition-fast), transform var(--transition-fast),
    box-shadow var(--transition-fast), opacity var(--transition-fast);
}

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

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ============================================================
   HISTORY VIEW
   ============================================================ */

/* Data-editable cells */
[data-editable] {
  text-decoration: underline;
  text-decoration-style: dashed;
  text-decoration-color: var(--text-dim);
  text-underline-offset: 3px;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  border-radius: 3px;
  padding: 2px 4px;
  margin: -2px -4px;
}

[data-editable]:hover {
  background: var(--accent-dim);
  color: var(--accent-text);
  text-decoration-color: var(--accent-text);
}

/* ============================================================
   EXERCISES VIEW
   ============================================================ */

.exercise-category {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: modalOverlayIn var(--transition) ease;
}

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

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
  animation: modalSlideIn var(--transition) ease;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  color: var(--text-dim);
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 0 20px 20px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  top: var(--ios-top-clear);
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 360px;
  width: calc(100% - 32px);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-toast);
  font-size: 0.9rem;
  pointer-events: auto;
  animation: toastIn var(--transition) ease forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* ============================================================
   RESPONSIVE FINE-TUNING
   ============================================================ */
@media (max-width: 480px) {

  .card {
    padding: 16px;
  }

}

/* ============================================================
   PRINT (hidden for now, no printing needed)
   ============================================================ */
@media print {
  .sidebar,
.bottom-nav,
.toast-container {
    display: none !important;
  }

  .main-content {
    padding: 0;
    margin: 0;
  }

  body {
    background: #fff;
    color: #000;
  }
}

/* ============================================================
   PAGE BACKGROUND TEXTURE (Settings → Background)
   The layers sit in one fixed root at the start of <body>, under both the
   app shell (z-index 1) and the splash (z-index 10000). While a texture is
   on, the page background moves to <html>/<body> and the shell, scroller
   and splash go transparent, so the same texture runs from the loading
   screen into the app.
   ============================================================ */
.bg-texture-root {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}
.bg-texture-canvas,
.bg-texture-grain,
.bg-texture-lava {
  position: absolute;
  pointer-events: none;
}
.bg-texture-canvas {
  inset: 0;
  width: 100%;
  height: 100%;
}
/* Repeating noise tiles, one tile wider each side, slid sideways on scroll */
.bg-texture-grain {
  top: 0;
  bottom: 0;
  left: -256px;
  right: -256px;
  background-size: 256px 256px;
  background-repeat: repeat;
  will-change: transform, opacity;
}
/* Lava blobs: centred spans moved with transform from scroll position */
.bg-texture-lava {
  inset: 0;
  overflow: hidden;
}
.bg-texture-lava span {
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  will-change: transform;
}
/* On load the page is the plain theme colour; the texture fades in together
   with the splash title and bar (same 1s fade from 0.5s, see .login-container). */
html.splashing .bg-texture-root {
  animation: splashFadeIn 1s ease 0.5s both;
}
@keyframes splashFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
html.bg-texture,
html.bg-texture body {
  background: var(--bg);
}
html.bg-texture .app,
html.bg-texture .main-content,
html.bg-texture .login-screen {
  background: transparent;
}
/* Full-screen overlays (workout detail, charts) are a container the size of
   the screen: the same fill as the page's containers (Settings → Containers)
   over the page background and texture. The app fades out underneath as an
   overlay fades in (html.overlay-open, set by watchFullscreenOverlays). */
:root {
  --overlay-bg: var(--surface);
}
html.containers-diffused {
  --overlay-bg: var(--surface-diffuse);
}
html.containers-diffused .fullscreen-overlay {
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
  backdrop-filter: blur(18px) saturate(1.1);
}
html.overlay-open .app {
  opacity: 0;
}
html.overlay-open .app,
html.overlay-fading .app {
  transition: opacity 0.25s ease;
}

/* Settings → Containers → Diffused: bordered containers frost what's behind
   them (blur + a light tint of the page) instead of letting the background
   show straight through. Only containers with a visible border; one inside
   another doesn't frost twice. */
:root {
  --surface-diffuse: rgba(18, 18, 20, 0.38);
}
[data-theme="light"] {
  --surface-diffuse: rgba(255, 255, 255, 0.45);
}
@media (prefers-color-scheme: light) {
  [data-theme="device"] {
    --surface-diffuse: rgba(255, 255, 255, 0.45);
  }
}
html.containers-diffused .card,
html.containers-diffused .exercise-category,
html.containers-diffused [style*="var(--surface)"][style*="solid"] {
  background: var(--surface-diffuse);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
  backdrop-filter: blur(18px) saturate(1.1);
}
html.containers-diffused :is(.card, .exercise-category, [style*="var(--surface)"][style*="solid"])
  :is(.card, .exercise-category, [style*="var(--surface)"][style*="solid"]) {
  background: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* The splash no longer hides the app behind an opaque fill: keep the app
   invisible until the splash lifts, then fade it in over the texture. */
.app {
  transition: opacity 1s ease;
}
html.bg-texture.splashing .app {
  opacity: 0;
}

.tex-sliders {
  display: grid;
  gap: 4px;
  margin-top: 12px;
}
.tex-slider {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.tex-slider span {
  width: 64px;
}
.tex-slider input {
  flex: 1;
  accent-color: var(--accent);
  height: 32px;
}
.tex-slider output {
  width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
