/*
 * Ella — shared stylesheet (mobile-first, light mode, ~400px viewport).
 * Single file per config.yaml L48 unless size forces a split.
 *
 * Sections in this file:
 *   1. Design tokens (:root)
 *   2. Reset + baseline
 *   3. A11y utilities (.sr-only, :focus-visible, reduced-motion)
 *   4. Layout shell (added in PR2/PR3)
 *
 * --------------------------------------------------------------------------
 * Accessibility baseline (T1.7)
 * --------------------------------------------------------------------------
 * All interactive elements MUST satisfy WCAG 2.1 AA (P3=B). The 8 patterns:
 *
 *   1. Landmarks — every page uses <header>, <main id="main">, and <nav>.
 *      A skip-link <a class="skip-link" href="#main"> sits at the top of
 *      <body> and becomes visible on focus (see .skip-link below).
 *
 *   2. Toggle semantics — the 4 language toggles in player-settings and the
 *      privacy toggle in user-settings use
 *        <button role="switch" aria-checked="true|false">
 *      Space toggles; aria-checked must update on every change.
 *
 *   3. Slider semantics — voice-volume sliders use native
 *        <input type="range" min="70" max="130" step="10"
 *               aria-label="Italian volume">
 *      paired with <output> for live percent.
 *
 *   4. Radio-group semantics — pills and segments use
 *        <div role="radiogroup" aria-label="...">
 *        <button role="radio" aria-checked="...">
 *      ArrowLeft / ArrowRight move the selection.
 *
 *   5. SVG icons — decorative back-chevron is aria-hidden="true"
 *      focusable="false". Meaningful icons (search, FABs, transport)
 *      use <svg role="img" aria-label="..."><title>...</title>.
 *
 *   6. Form labels — every <input> has a paired <label for="..."> — either
 *      visible or .sr-only. Never use placeholder as the label.
 *
 *   7. Focus order — DOM order = tab order. Transport bar reads in PNG
 *      order: rewind -> prev -> PLAY -> next -> forward.
 *
 *   8. Contrast floor — body text #1A1A1A on #FFFFFF = 16.1:1 ✓.
 *      Muted #8A8A8A on white = 4.6:1 ✓. Primary #5C72E0 is for links and
 *      focus rings only; never as a text color over its own light tint.
 *
 * Honor @media (prefers-reduced-motion: reduce) — see reset block below.
 * --------------------------------------------------------------------------
 */

/* 1. Design tokens — palette, spacing, typography, radii, elevation.
 *    Extracted from screens/*.png; matched by eye (P1=B, visual liberties OK).
 *
 *    Also: enforce the W3C-standard behavior of the [hidden] attribute
 *    so that `el.hidden = true` always hides the element. Without this,
 *    author CSS like `.card-list { display: flex }` silently overrides
 *    the UA `[hidden] { display: none }` rule (specificity 0,1,0 == 0,1,0;
 *    later rule wins in cascade). */
[hidden] { display: none !important; }
:root {
  /* Palette */
  --color-primary:        #A4B8FF;
  --color-primary-soft:   #E0E7FF;
  --color-primary-deep:   #5C72E0;
  --color-bg-page:        #FFFFFF;
  --color-bg-card:        #FFFFFF;
  --color-bg-disabled:    #F1F1F4;
  --color-text-primary:   #1A1A1A;
  --color-text-muted:     #8A8A8A;
  --color-text-link:      #5C72E0;
  --color-border:         #E5ECFF;
  --color-toggle-off:     #D9DDE5;
  --color-card-thumb-a:   #DDE6FF;
  --color-card-thumb-b:   #B7C4FF;
  --color-waveform:       #6F4CE8;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Typography */
  --font-family-base: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 18px;
  --fs-2xl: 20px;
  --fs-3xl: 24px;
  --fs-4xl: 28px;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-card: 0 1px 3px rgba(20, 20, 50, 0.04);

  /* Layout */
  --max-content-width: 400px;
  --header-height: 56px;
  --fab-size: 48px;
}

/* 2. Reset + baseline */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-family-base);
  font-size: var(--fs-md);
  color: var(--color-text-primary);
  background: var(--color-bg-page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }

/* 3. A11y utilities — minimal baseline; full patterns documented by T1.7. */

/* Visually hidden helper for skip-links and form labels. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Universal focus-visible ring — WCAG 2.1 AA focus indicator. */
:focus-visible {
  outline: 2px solid var(--color-primary-deep);
  outline-offset: 2px;
}

/* Honor OS reduced-motion preference — disables non-essential animations. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* A11y primitives — T1.7. */

/* Skip-link: hidden until keyboard-focused, then slides into the top-left.
   Pair with <a class="skip-link" href="#main"> at the top of <body>. */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary-deep);
  color: #FFFFFF;
  font-weight: var(--fw-semibold);
  text-decoration: none;
  border-radius: var(--radius-sm);
  z-index: 1000;
  transition: top 150ms ease-out;
}
.skip-link:focus,
.skip-link:focus-visible {
  top: var(--space-2);
}

/* Visually-hidden alias for .sr-only — same accessibility pattern, alternate
   name. Prefer .sr-only in new code; .visually-hidden kept for parity with
   common a11y utility libraries. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
 * PR2 — Layout shell + content-feed components (T2.1)
 * --------------------------------------------------------------------------
 * Mobile-first ~400px viewport. Tokens from :root above.
 * Shared shell (.header, .search, .tabs) reused by library.html (T2.2).
 * Page-specific shells for library + player follow in T2.2 and T2.3.
 * -------------------------------------------------------------------------- */

/* Shell — centers content and caps width on tablets. */
.shell, body > .header, body > .main, body > .search, body > .tabs, body > .chip-row {
  max-width: var(--max-content-width);
  margin-left: auto;
  margin-right: auto;
}

/* Header — fixed-height row with logo (left) and avatar (right). */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  height: var(--header-height);
  width: 100%;
}

/* Logo "speech-bubble" wordmark. Decorative; aria-label on the parent <a>. */
.logo { display: inline-flex; text-decoration: none; }
.logo-bubble {
  display: inline-block;
  background: var(--color-primary-deep);
  color: #FFFFFF;
  font-weight: var(--fw-bold);
  font-size: var(--fs-lg);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  border-bottom-left-radius: var(--space-1);
  line-height: 1.2;
}

/* Avatar link + initial badge — T2.5 refactors this to renderAvatar(). */
.avatar-link { text-decoration: none; }
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary-deep);
  color: #FFFFFF;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.02em;
}

/* Search — pill input with leading magnifier icon. */
.search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-2) var(--space-4) 0;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  width: calc(100% - 2 * var(--space-4));
  background: var(--color-bg-page);
}
.search-icon { width: 18px; height: 18px; color: var(--color-text-muted); flex: 0 0 auto; }
.search input {
  flex: 1 1 auto;
  border: none;
  outline: none;
  font-size: var(--fs-md);
  color: var(--color-text-primary);
  background: transparent;
  min-width: 0;
}
.search input::placeholder { color: var(--color-text-muted); }

/* Tabs — two anchors separated by a divider; active = blue underline. */
.tabs {
  display: flex;
  gap: var(--space-6);
  padding: var(--space-3) var(--space-4) 0;
  border-bottom: 1px solid var(--color-border);
  width: 100%;
}
.tab {
  flex: 1 1 0;
  text-align: center;
  text-decoration: none;
  color: var(--color-text-muted);
  font-weight: var(--fw-medium);
  font-size: var(--fs-md);
  padding: var(--space-2) 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.is-active {
  color: var(--color-text-primary);
  border-bottom-color: var(--color-primary-deep);
  font-weight: var(--fw-semibold);
}

/* Chip row — horizontally scrollable filter pills. */
.chip-row {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
  width: 100%;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--color-border);
  background: var(--color-bg-page);
  color: var(--color-text-primary);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
}
.chip.is-active {
  background: var(--color-primary-deep);
  border-color: var(--color-primary-deep);
  color: #FFFFFF;
}

/* Main content area + card list. */
.main { padding: 0 var(--space-4) var(--space-7); width: 100%; }
.card-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.card-item[hidden] { display: none; }
.empty-state { color: var(--color-text-muted); text-align: center; padding: var(--space-6) 0; }

/* Card — 2-column grid: thumb (left) + content (right). */
.card {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
.card-thumb {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--color-card-thumb-a), var(--color-card-thumb-b));
  overflow: hidden;
}
.card-duration {
  position: absolute;
  bottom: var(--space-1);
  right: var(--space-1);
  background: rgba(0, 0, 0, 0.65);
  color: #FFFFFF;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  padding: 2px var(--space-1);
  border-radius: var(--radius-sm);
}
.card-content { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}
.card-tag {
  display: inline-block;
  background: var(--color-primary-deep);
  color: #FFFFFF;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
}
.card-icons { display: flex; gap: var(--space-1); }
.icon-btn {
  background: transparent;
  border: none;
  padding: var(--space-1);
  cursor: pointer;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
}
.icon-btn:hover { color: var(--color-text-primary); background: var(--color-primary-soft); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.is-active { color: var(--color-primary-deep); }
/* REQ-LIB-9 — "Add to library" affordance rendered on feed-saved cards under
   the Saved chip. Lives inside .card-icons next to bookmark + overflow. */
.btn-add-to-library {
  background: transparent;
  border: 1px solid var(--color-primary-deep);
  color: var(--color-primary-deep);
  padding: 4px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
}
.btn-add-to-library:hover { background: var(--color-primary-soft); }
.btn-add-to-library:focus-visible {
  outline: 2px solid var(--color-primary-deep);
  outline-offset: 2px;
}
.btn-add-to-library[hidden] { display: none; }
.card-title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--color-text-primary);
  text-decoration: none;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-creator { margin: 0; color: var(--color-text-muted); font-size: var(--fs-sm); }
.card-genres { display: flex; flex-wrap: wrap; gap: var(--space-1); align-items: center; margin-top: var(--space-1); }
.card-genre-label { color: var(--color-text-muted); font-size: var(--fs-xs); margin-right: var(--space-1); }
.card-genre {
  background: var(--color-primary-soft);
  color: var(--color-primary-deep);
  font-size: var(--fs-xs);
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
}
.card-details {
  align-self: flex-end;
  color: var(--color-primary-deep);
  font-size: var(--fs-sm);
  text-decoration: none;
  margin-top: var(--space-1);
}
.card-details[aria-disabled="true"] { cursor: default; opacity: 0.85; }

/* Library document-thumb + add-content FAB (T2.2). */
/* .card-thumb-doc + .doc-thumb are retired in EXT.4 — every card now uses
   the procedural cover SVG from app.js#generateCoverSVG (C3=B). */
.card-cover { width: 100%; height: 100%; display: block; }
.card-cover svg { width: 100%; height: 100%; display: block; }
.fab {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: var(--color-primary-deep);
  color: #FFFFFF;
  border: none;
  box-shadow: 0 4px 12px rgba(20, 20, 50, 0.18);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.fab svg { width: 24px; height: 24px; }
.fab:hover { background: #4A60CC; }

/* Action sheet — full impl in T3.7.
   Renders overlay + bottom panel with header (title + close X) + list of
   action buttons. Closes on outside-click, Escape key, or close icon.
   z-index (200) sits above the FAB stack (z-index implicit / 0). */
.action-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 50, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  animation: ella-overlay-in 150ms ease-out;
}
@keyframes ella-overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ella-sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }
.action-sheet {
  width: 100%;
  max-width: var(--max-content-width);
  background: var(--color-bg-page);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4) var(--space-6);
  box-shadow: 0 -4px 16px rgba(20, 20, 50, 0.12);
  animation: ella-sheet-in 200ms ease-out;
}
.action-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) 0 var(--space-3);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-3);
}
.action-sheet-title {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  color: var(--color-text-primary);
}
.action-sheet-close {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.action-sheet-close svg { width: 18px; height: 18px; }
.action-sheet-close:hover { background: var(--color-primary-soft); color: var(--color-text-primary); }
.action-sheet-list { display: flex; flex-direction: column; gap: var(--space-2); }
.action-sheet-action {
  display: block;
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  background: var(--color-bg-page);
  color: var(--color-text-primary);
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.action-sheet-action:hover { background: var(--color-primary-soft); }
.action-sheet-action.is-disabled {
  background: var(--color-bg-disabled);
  color: var(--color-text-muted);
  cursor: not-allowed;
}
.action-sheet-action.is-disabled:hover { background: var(--color-bg-disabled); }

/* Player page shell (T2.3). */
.header-player { justify-content: space-between; gap: var(--space-2); }
.header-player .logo-bubble { margin: 0 auto; }
.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: var(--color-text-primary);
  text-decoration: none;
  border-radius: var(--radius-sm);
}
.back-link:hover { background: var(--color-primary-soft); }
.back-link svg { width: 22px; height: 22px; }
.header-spacer { width: 36px; height: 36px; display: inline-block; }
.main-player {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4) var(--space-5);
}

/* Phrase list — vertical scrollable cards. */
.phrase-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.phrase {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  align-items: center;
}
.phrase.is-active {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-deep);
}
.phrase-native {
  grid-column: 1 / -1;
  font-weight: var(--fw-semibold);
  color: var(--color-text-primary);
  font-size: var(--fs-md);
}
.phrase-translation {
  grid-column: 1 / -1;
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
}
.phrase-overflow {
  grid-column: 2;
  grid-row: 1 / span 2;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  align-self: start;
}
.phrase-overflow:hover { background: var(--color-primary-soft); }
.phrase-overflow svg { width: 18px; height: 18px; }

/* FAB stack — settings (top) + bookmark (bottom), right edge. */
.fab-stack {
  position: fixed;
  right: var(--space-3);
  bottom: 110px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.fab-bookmark[aria-pressed="true"] { background: #4A60CC; }
.fab-bookmark[aria-pressed="true"] svg path { fill: currentColor; }

/* Progress bar — thin fill above the FABs. */
.progress-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4) 0;
}
.progress-time { color: var(--color-text-muted); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.progress {
  flex: 1 1 auto;
  height: 4px;
  background: var(--color-border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--color-primary-deep);
  transition: width 250ms linear;
}

/* Transport bar — 5 buttons in a row; PLAY = big blue square (T2.3 PR2 minimal). */
.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-3) 0 var(--space-5);
}
.transport-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-primary);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.transport-btn svg { width: 22px; height: 22px; }
.transport-btn:hover { background: var(--color-primary-soft); }
.transport-play {
  width: 64px;
  height: 64px;
  background: var(--color-primary-deep);
  color: #FFFFFF;
  border-radius: var(--radius-md);
}
.transport-play svg { width: 28px; height: 28px; }
.transport-play:hover { background: #4A60CC; }
.transport-play .icon-pause { display: none; }
.transport-play[aria-pressed="true"] .icon-play { display: none; }
.transport-play[aria-pressed="true"] .icon-pause { display: inline; }

/* --------------------------------------------------------------------------
 * PR3 — Settings page shell + form widget primitives (T3.2)
 * --------------------------------------------------------------------------
 * Wires up the 4 widget roles called out in design.md §"Accessibility Patterns":
 *   - <button class="switch" role="switch" aria-checked>  (REQ-PLY-14 toggle)
 *   - <div class="segment" role="radiogroup"> + <button role="radio">  (pills)
 *   - <input class="range" type="range" aria-label> + <output>  (slider)
 * Interactive behavior is owned by app.js helpers; this file owns the visuals.
 * -------------------------------------------------------------------------- */

/* Settings page shell — vertical rhythm + bottom padding for Save button. */
.main-settings {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-3) var(--space-4) var(--space-7);
}
.page-title {
  margin: 0;
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  color: var(--color-text-primary);
  letter-spacing: -0.01em;
}
.settings-section { display: flex; flex-direction: column; gap: var(--space-3); }
.settings-section-label {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  color: var(--color-text-primary);
}
.settings-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}
.settings-row:last-child { border-bottom: none; }
.settings-row-col { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-3) 0; }
.settings-row-col .settings-row-label { color: var(--color-text-muted); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.settings-row-label { color: var(--color-text-primary); font-size: var(--fs-md); font-weight: var(--fw-medium); }

/* Switch — pill-shaped toggle. Color flips via aria-checked attribute. */
.switch {
  position: relative;
  width: 48px;
  height: 26px;
  padding: 0;
  border: none;
  background: var(--color-toggle-off);
  border-radius: var(--radius-pill);
  cursor: pointer;
  flex: 0 0 auto;
  transition: background-color 150ms ease-out;
}
.switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 2px rgba(20, 20, 50, 0.18);
  transition: transform 150ms ease-out;
}
.switch[aria-checked="true"] { background: var(--color-primary); }
.switch[aria-checked="true"]::before { transform: translateX(22px); }
.switch:hover { filter: brightness(0.97); }

/* Segment / radiogroup — shows / play-first style: outlined pills. */
.segment {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.segment-item {
  flex: 1 1 auto;
  min-width: 90px;
  padding: var(--space-2) var(--space-4);
  border: 1.5px solid var(--color-primary);
  background: var(--color-bg-page);
  color: var(--color-primary-deep);
  border-radius: var(--radius-pill);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: background-color 120ms ease-out, color 120ms ease-out;
}
.segment-item[aria-checked="true"] {
  background: var(--color-primary-soft);
  color: var(--color-primary-deep);
}
/* Pill (segment-pill) — filled when selected, used inside Other Settings card. */
.segment-pill .segment-item {
  flex: 0 0 auto;
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}
.segment-pill .segment-item[aria-checked="true"] {
  background: var(--color-primary-deep);
  color: #FFFFFF;
  border-radius: var(--radius-sm);
}
.segment-item:hover { background: var(--color-primary-soft); }
.segment-pill .segment-item[aria-checked="true"]:hover { background: #4A60CC; }
.segment-pill .segment-item:hover { background: transparent; color: var(--color-text-primary); }

/* Range slider — native <input type=range> styled with primary thumb/track. */
.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--color-border);
  border-radius: var(--radius-pill);
  outline: none;
  margin: var(--space-2) 0;
  overflow: visible;
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid var(--color-primary-deep);
  cursor: pointer;
}
.range::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid var(--color-primary-deep);
  cursor: pointer;
}
.range:focus-visible { outline: 2px solid var(--color-primary-deep); outline-offset: 4px; }

.volume-row { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border); }
.volume-row:last-child { border-bottom: none; }
.range-output {
  align-self: flex-end;
  color: var(--color-text-primary);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
}

/* Primary CTA — full-width Save button, muted when disabled (REQ-PLY-12). */
.btn-save {
  width: 100%;
  padding: var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-primary-soft);
  color: var(--color-text-muted);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  cursor: not-allowed;
  margin-top: var(--space-3);
  transition: background-color 120ms ease-out, color 120ms ease-out;
}
.btn-save:not(:disabled) {
  background: var(--color-primary-deep);
  color: #FFFFFF;
  cursor: pointer;
}
.btn-save:not(:disabled):hover { background: #4A60CC; }

/* --------------------------------------------------------------------------
 * PR3 — User settings page (T3.3)
 * --------------------------------------------------------------------------
 * Account name row, language cards, privacy toggle row, sign-out button,
 * delete + version footer. Visual primitives (.switch, .settings-section)
 * are reused from the T3.2 block above.
 * -------------------------------------------------------------------------- */

.account-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}
.account-name {
  font-size: var(--fs-lg);
  font-weight: var(--fw-medium);
  color: var(--color-text-primary);
}
.account-name-input:not(.sr-only) {
  flex: 1 1 auto;
  padding: var(--space-2) var(--space-3);
  border: 1.5px solid var(--color-primary-deep);
  border-radius: var(--radius-sm);
  font-size: var(--fs-lg);
  font-family: var(--font-family-base);
  color: var(--color-text-primary);
  outline: none;
}
.icon-pencil { color: var(--color-text-muted); }
.icon-pencil svg { width: 20px; height: 20px; }
.icon-pencil:hover { color: var(--color-primary-deep); background: var(--color-primary-soft); }

.lang-cards { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.lang-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
.lang-card-label { color: var(--color-text-muted); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.lang-card-value {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--color-text-primary);
}
.lang-card-flag { font-size: var(--fs-xl); line-height: 1; }

.privacy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0;
}
.privacy-row-text {
  flex: 1 1 auto;
  margin: 0;
  font-size: var(--fs-md);
  color: var(--color-text-primary);
  line-height: 1.4;
}
.privacy-row-text a { color: var(--color-text-link); text-decoration: underline; }

.btn-signout {
  align-self: flex-start;
  padding: var(--space-3) var(--space-5);
  border: 1.5px solid var(--color-primary);
  border-radius: var(--radius-pill);
  background: var(--color-bg-page);
  color: var(--color-primary-deep);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  margin-top: var(--space-4);
}
.btn-signout:hover { background: var(--color-primary-soft); }

.account-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-7);
  padding-bottom: var(--space-5);
}
.link-delete {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
  text-decoration: underline;
  cursor: pointer;
  padding: var(--space-2);
}
.link-delete:hover { color: var(--color-text-primary); }

/* --------------------------------------------------------------------------
 * PR2 — Recommendation page (T2.2)
 * --------------------------------------------------------------------------
 * Page-specific styles for src/recommendation.html. Reuses the existing
 * .header, .logo-bubble, .card-list, .card, .empty-state, and back-link
 * primitives from PR2 shell; adds page-only rules for the page title and
 * the "why this?" caption injected into each card by bootstrapRecommendation().
 * Light mode + ~400px viewport per design.md §11 (WCAG AA, contrast ≥ 4.5:1
 * via --color-text-muted).
 * -------------------------------------------------------------------------- */

/* Page heading — sits above the card list, ~400px viewport, 20px top margin. */
.rec-title {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  color: var(--color-text-primary);
  margin: var(--space-5) 0 var(--space-3);
  line-height: 1.25;
}

/* "Why this?" caption injected by bootstrapRecommendation() into each
 * card root after renderCard returns (RP-3, D-RP-18=A). One short sentence,
 * muted, ~14px so it does not compete with the card title. Linked to the
 * card root via aria-describedby so screen readers announce it after the
 * title (RP-14, design.md §11). */
.rec-why {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
  line-height: 1.35;
  font-style: italic;
}

/* Recommendation empty-state — same visual language as .empty-state on
 * content-feed/library but tone-shifted to encourage "finish more content"
 * (the cold-start recovery path). */
.rec-empty {
  color: var(--color-text-muted);
  text-align: center;
  padding: var(--space-6) var(--space-4);
  font-size: var(--fs-md);
  line-height: 1.4;
}
.account-version { color: var(--color-text-muted); font-size: var(--fs-sm); }

/* The rec-view section. The HTML uses the `hidden` attribute for the
   default hidden state; the [hidden] !important rule at the top of
   the file ensures `el.hidden = true` always hides it. */
.rec-view-feed[hidden] { display: none !important; }
.rec-view-feed:not([hidden]) { display: block; }

/* Hero recommendation cards — the top 3 picks on the recommendation
   page. Larger cover, prominent title, caption shown inline below the
   card content. Built by reusing the existing renderCard() with
   thumbStyle "rec-hero" plus the .rec-card-hero modifier class. */
.rec-card-hero .card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-primary-soft);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}
.rec-card-hero .card-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 160px;
  border-radius: var(--radius-md);
  overflow: hidden;
}
.rec-card-hero .card-thumb .card-cover {
  width: 100%;
  height: 100%;
}
.rec-card-hero .card-cover svg {
  width: 100%;
  height: 100%;
  display: block;
}
.rec-card-hero .card-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  line-height: 1.25;
}
.rec-card-hero .rec-why-hero {
  font-size: var(--fs-sm);
  color: var(--color-primary-deep);
  font-weight: var(--fw-semibold);
  font-style: italic;
  padding: var(--space-2) var(--space-3);
  background: var(--color-primary-soft);
  border-radius: var(--radius-sm);
  margin: 0;
  line-height: 1.4;
}

/* Compact list items for the "More suggestions" section — items 4..N
   after the first 3 hero cards. Horizontal layout: small cover +
   title/meta/caption stack. */
.rec-list-section {
  list-style: none;
  margin-top: var(--space-5);
  padding: 0;
}
.rec-list-section-title {
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 var(--space-3);
  padding: 0 var(--space-1);
}
.rec-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.rec-list-item {
  list-style: none;
}
.rec-list-link {
  display: flex;
  align-items: stretch;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  text-decoration: none;
  color: inherit;
  transition: border-color 120ms ease, background-color 120ms ease;
}
.rec-list-link:hover,
.rec-list-link:focus-visible {
  border-color: var(--color-primary-deep);
  background: var(--color-primary-soft);
  outline: none;
}
.rec-list-cover {
  flex: 0 0 80px;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  align-self: flex-start;
}
.rec-list-cover svg {
  width: 100%;
  height: 100%;
  display: block;
}
.rec-list-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.rec-list-title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--color-text-primary);
  margin: 0;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.rec-list-meta {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  margin: 0;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.rec-list-type {
  font-weight: var(--fw-semibold);
  color: var(--color-primary-deep);
}
.rec-list-creator::before {
  content: "· ";
}
.rec-list-why {
  font-size: var(--fs-xs);
  color: var(--color-text-secondary);
  margin: 2px 0 0;
  font-style: italic;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
   Mirrors .rec-header / .rec-title from recommendation.html but adapts to
   the smaller viewport context where the section header sits inline above
   the card list. */
.rec-section-title {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  color: var(--color-text-primary);
  margin: var(--space-4) 0 var(--space-3);
}

/* Recommendation filter chip — sits in position 2 of the chip-row (right
   after "All"). Styled like a regular filter chip with a star icon prefix
   and a slightly bolder styling when active so it reads as the primary
   "personalized" filter, not just another type chip. */
.chip-rec {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.chip-rec .chip-icon {
  width: 12px;
  height: 12px;
  color: var(--color-primary-deep);
  flex: 0 0 auto;
}
.chip-rec.is-active {
  background: var(--color-primary-deep);
  color: var(--color-surface);
  border-color: var(--color-primary-deep);
}
.chip-rec.is-active .chip-icon {
  color: var(--color-surface);
}
.chip-rec:hover:not(.is-active) {
  border-color: var(--color-primary-deep);
}
/* When rec-view is active, fade the OTHER filter chips so the Recommended
   chip is the focal point of the chip-row. Chips remain visible/clickable
   so the user can return to the feed by clicking one. */
.chip-row.is-rec-mode .chip:not(.chip-rec) {
  opacity: 0.45;
}

/* --------------------------------------------------------------------------
 * Up-next modal + pill — at 80% / 90% playback band (REQ-PLY-16..18)
 * --------------------------------------------------------------------------
 * Modal: centered floating panel (transport bar must stay reachable).
 * Pill: anchored at bottom: 130px above the FAB stack (bottom: 110px);
 * safe-area-inset scoped to pill + modal positioning only.
 * Reuses ella-overlay-in / ella-sheet-in keyframes from .action-sheet-overlay.
 * -------------------------------------------------------------------------- */
.up-next-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 50, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--space-4);
  animation: ella-overlay-in 150ms ease-out;
}
.up-next-modal-panel {
  width: 100%;
  max-width: var(--max-content-width);
  background: var(--color-bg-page);
  border-radius: var(--radius-lg);
  box-shadow: 0 -4px 16px rgba(20, 20, 50, 0.12);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  animation: ella-sheet-in 200ms ease-out;
  position: relative;
}
.up-next-modal-cover {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-primary-soft);
}
.up-next-modal-cover svg { width: 100%; height: 100%; display: block; }
.up-next-modal-label {
  margin: 0;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--color-primary-deep);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.up-next-modal-title {
  margin: 0;
  font-size: var(--fs-2xl);
  font-weight: var(--fw-semibold);
  color: var(--color-text-primary);
}
.up-next-modal-caption {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  font-style: italic;
}
.up-next-modal-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.up-next-modal-play {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  border: none;
  background: var(--color-primary-deep);
  color: #FFFFFF;
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--fs-md);
  cursor: pointer;
}
.up-next-modal-play:hover { background: #4A60CC; }
.up-next-modal-cancel {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  background: var(--color-bg-page);
  color: var(--color-text-primary);
  font-weight: var(--fw-medium);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--fs-md);
  cursor: pointer;
}
.up-next-modal-cancel:hover { background: var(--color-primary-soft); }
.up-next-modal-panel .action-sheet-close { position: absolute; top: var(--space-2); right: var(--space-2); }

/* Pill — anchored at bottom: 130px (above FAB stack at bottom: 110px).
   Safe-area-inset scoped to this rule only (no app-wide retrofit). */
.up-next-pill {
  position: fixed;
  right: calc(var(--space-3) + env(safe-area-inset-right, 0));
  bottom: calc(130px + env(safe-area-inset-bottom, 0));
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-2);
  background: var(--color-bg-page);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  box-shadow: 0 4px 12px rgba(20, 20, 50, 0.18);
  font-family: inherit;
  cursor: pointer;
  z-index: 50;
  max-width: calc(100vw - var(--space-3) * 2);
}
.up-next-pill-cover {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  overflow: hidden;
  flex: 0 0 auto;
}
.up-next-pill-cover svg { width: 100%; height: 100%; display: block; }
.up-next-pill-title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.up-next-pill-play {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--color-primary-deep);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}
.up-next-pill-play:hover { background: #4A60CC; }
.up-next-pill-play svg { width: 16px; height: 16px; }

/* FAB auto-hide while up-next modal is open — single body-attr rule,
   does not touch .fab-stack styles. */
body[data-modal-open="true"] .fab-stack {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 150ms ease-out, transform 150ms ease-out;
}