/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

/* Shake animation for incorrect quiz answers */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
  20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.animate-shake {
  animation: shake 0.5s ease-in-out;
}

/* Quiz option collapse animation - two phases:
   1. Fade out (opacity + scale, GPU-composited, smooth)
   2. Collapse space (after fade completes, via JS) */
.quiz-option-fading {
  overflow: hidden;
  transition: opacity 200ms ease-out, transform 200ms ease-out;
  transform-origin: top center;
  opacity: 0;
  transform: scaleY(0.8);
}

.quiz-option-collapsed {
  display: none !important;
}

/* Character grid expand/collapse animation */
.grid-content {
  transition: max-height 300ms ease-in-out;
  overflow: hidden;
  max-height: 0;
}

/* ===== Landing page styles ===== */

/* Hero headline — letterpress ink with cinnabar accent */
.text-gradient-hero {
  background: linear-gradient(135deg, #1a1410 0%, #a93121 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.dark .text-gradient-hero {
  background: linear-gradient(135deg, #c9d1d9 0%, #8b949e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Floating character animations */
@keyframes float-slow {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-12px); }
}
@keyframes float-medium {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
}
@keyframes float-fast {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-6px); }
}

.animate-float-slow {
  animation: float-slow 6s ease-in-out infinite;
}
.animate-float-medium {
  animation: float-medium 4.5s ease-in-out infinite;
}
.animate-float-fast {
  animation: float-fast 3.5s ease-in-out infinite;
}

/* Scroll-reveal animation */
[data-landing-target="reveal"] {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}
[data-landing-target="reveal"].is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Solid card — no glassmorphism */
.glass-card {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.dark .glass-card {
  background: #252535;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: none;
}

/* Pulsing mastery dot */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}
.animate-pulse-dot {
  animation: pulse-dot 2s ease-in-out infinite;
}

/* Crossfade transition for Turbo Drive body swaps */
@keyframes turbo-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.turbo-body-fade-in {
  animation: turbo-fade-in 150ms ease-in;
}

/* ===== Library / Reader color palette ===== */
:root {
  --ink-900: #1a1612;
  --ink-700: #2d2720;
  --ink-500: #4a4035;
  --parchment-50: #faf6f0;
  --parchment-100: #f2ebe0;
  --parchment-200: #e6d9c8;
  --cinnabar-500: #c23c2a;
  --cinnabar-600: #a93121;
  --jade-500: #2d6b5a;
  --jade-600: #1f5847;
  --gold-400: #c9a84c;
}
.dark {
  --ink-900: #f2ebe0;
  --ink-700: #e6d9c8;
  --ink-500: #b8a898;
  --parchment-50: #1a1612;
  --parchment-100: #2d2720;
  --parchment-200: #3d3428;
  --cinnabar-500: #e05a48;
  --cinnabar-600: #c23c2a;
  --jade-500: #4aad8f;
  --jade-600: #2d6b5a;
  --gold-400: #d4b65e;

  /* ===== Dark mode accent — jade replaces cinnabar for CTAs =====
   * Cinnabar (warm red) is the light-mode primary: works on parchment.
   * In dark mode, jade takes over as the single purposeful accent:
   * cool enough for deep dark, semantically "progress/learning."
   * Text/badge accents (-400) stay muted near-white.
   */
  /* ── Text scale (3 tiers, clearly distinct) ──────────────────────────────
   * Primary ~72% white, secondary ~45%, tertiary ~28% — perceivable jumps. */
  --color-gray-50:  #e0e0ea;   /* highest emphasis only */
  --color-gray-100: #c9d1d9;   /* primary — headings, key numbers */
  --color-gray-200: #a8a8bc;   /* mid */
  --color-gray-300: #8888a0;   /* hover-to state — clearly readable */
  --color-gray-400: #787890;   /* secondary — subordinate but readable */
  --color-gray-500: #565670;   /* tertiary — labels, captions */
  --color-gray-600: #424256;   /* near-surface — muted interactive */
  --color-gray-700: #303042;   /* character tiles (unseen) */
  --color-gray-800: #242434;   /* deep surfaces */
  --color-gray-900: #181826;   /* matches card bg */

  /* ── Surface scale ────────────────────────────────────────────────────────
   * Bold steps — each level visibly distinct without a side-by-side comparison.
   * L0 #0f0f14 → L1 #252535 → L2 #303042 → L3 #3a3a50 */
  --color-cinnabar-50:  #f0f6fc;
  --color-cinnabar-100: #252535;   /* L1 surface (= card) */
  --color-cinnabar-200: #303042;   /* L2 surface */
  --color-cinnabar-300: #3a3a50;   /* L3 hover/active */
  --color-cinnabar-400: #c9a84c;   /* gold — dark mode accent */
  --color-cinnabar-500: #303042;   /* interactive fill */
  --color-cinnabar-600: #3a3a50;   /* hover fill */
  --color-cinnabar-700: #44445e;   /* active/pressed */
  --color-cinnabar-800: #252535;   /* matches card */
  --color-cinnabar-900: #252535;   /* matches card */
  --color-cinnabar-950: #0d0d14;
}

/* Dark mode base text — off-white (#c9d1d9) instead of near-white reduces
 * halation/glow for astigmatism. Elements with explicit text-color utilities
 * (text-white, text-gray-400, etc.) are unaffected; bare headings inherit this. */
html.dark,
html.dark body {
  color: #c9d1d9;
}

/* Segmented control selected pill — single class used by both ERB and JS so
 * the visual state is identical whether rendered server-side or via Stimulus. */
.segment-pill-selected {
  background-color: var(--color-cinnabar-600);
  color: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}
.dark .segment-pill-selected {
  background-color: rgba(201, 168, 76, 0.20);
  color: #d4b86a;
  box-shadow: 0 0 0 1px rgba(201, 168, 76, 0.40) inset;
}

/* ===== Dark-mode button hover overrides =====
 * Some views use `hover:bg-cinnabar-400` for a "lighten on hover" effect,
 * which assumes cinnabar-400 is a slightly lighter orange. But in dark
 * mode, cinnabar-400 is remapped to near-white for TEXT accents. Without
 * this override, hovering a button would flash the whole button to
 * bright white. Force hover bg to stay in the graphite range.
 */
.dark .hover\:bg-cinnabar-400:hover {
  background-color: rgba(201, 168, 76, 0.12);  /* subtle gold tint on hover */
}



/* Library atmosphere — parchment base with subtle classical gradients */
.bg-library-atmosphere {
  background-color: var(--parchment-50);
  background-image:
    radial-gradient(ellipse 70% 50% at 15% 10%, rgba(194, 60, 42, 0.04) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 85% 85%, rgba(45, 107, 90, 0.03) 0%, transparent 60%);
}

/* Brush-reveal animation for staggered chapter lists */
@keyframes brush-reveal {
  from {
    opacity: 0;
    transform: scale(0.97);
    filter: blur(2px);
  }
  to {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .animate-brush-reveal {
    animation: brush-reveal 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
  }
}

/* ===== App-wide atmosphere =====
 * Light mode: flat warm paper + subtle SVG grain (1-2% opacity). No aurora.
 * Dark mode: flat near-black. Elevation via tonal surface-ladder only.
 */
.bg-app-atmosphere {
  background-color: #faf6f0;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='matrix' values='0 0 0 0 0.18  0 0 0 0 0.13  0 0 0 0 0.08  0 0 0 0.015 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-attachment: fixed;
}
.dark .bg-app-atmosphere {
  background-color: #0f0f14;
  background-image: none;
}

/* Reader parchment — warm cream for an editorial reading feel */
.bg-reader-parchment {
  background-color: #f8f3ec;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.80' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='matrix' values='0 0 0 0 0.20  0 0 0 0 0.15  0 0 0 0 0.08  0 0 0 0.018 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-attachment: fixed;
}
.dark .bg-reader-parchment {
  background-color: #1a1918;
  background-image: none;
}

/* Navbar — solid background, no glassmorphism */
.navbar-glass {
  background: #faf6f0;
  border-bottom: 1px solid rgba(74, 64, 53, 0.10);
}
.dark .navbar-glass {
  background: #18182a;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

/* CTA banner — cinnabar gradient that stays vibrant in dark mode */
.cta-banner {
  background: linear-gradient(to bottom right, #a93121, #8a271a);
}
.dark .cta-banner {
  background: linear-gradient(to bottom right, #c23c2a, #8a271a);
  box-shadow: 0 0 80px rgba(194, 60, 42, 0.15);
}

/* Elevated card — hairline border + single soft shadow */
.card-elevated {
  position: relative;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.dark .card-elevated {
  background: #252535;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: none;
}

/* Themed inset surface — used for the practice-controls bar inside the hero
 * card so it works in BOTH modes. Replaces the dark-only bg-white/[0.04] hack.
 */
.surface-inset {
  background: linear-gradient(180deg, rgba(74, 64, 53, 0.035), rgba(74, 64, 53, 0.015));
  border: 1px solid rgba(74, 64, 53, 0.10);
  box-shadow: none;
  border-radius: 0.5rem;
}
.dark .surface-inset {
  /* L2 — clearly raised inside card */
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: none;
}

/* Themed form controls inside .surface-inset */
.surface-inset .inset-label { color: #6b5b4a; }
.dark .surface-inset .inset-label { color: #9ca3af; }

.inset-select {
  background: #ffffff;
  color: #2d2720;
  border: 1px solid rgba(74, 64, 53, 0.14);
}
.inset-select:hover { background: #fdfbf6; }
.dark .inset-select {
  background: rgba(255, 255, 255, 0.07);
  color: #e5e7eb;
  border-color: rgba(255, 255, 255, 0.10);
}
.dark .inset-select:hover { background: rgba(255, 255, 255, 0.10); }

/* Exercise toggle track */
.exercise-toggle { background: rgba(74, 64, 53, 0.20); }
.dark .exercise-toggle { background: rgba(255, 255, 255, 0.12); }
.exercise-toggle.active { background: var(--color-cinnabar-500); }
.dark .exercise-toggle.active { background: #c9a84c; }

.inset-divider {
  background: linear-gradient(180deg, transparent, rgba(74, 64, 53, 0.18), transparent);
}
.dark .inset-divider {
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.15), transparent);
}

.inset-secondary-btn {
  color: #4a4035;
  border: 1px solid rgba(74, 64, 53, 0.18);
  background: #ffffff;
}
.inset-secondary-btn:hover {
  background: #fdfbf6;
  border-color: rgba(74, 64, 53, 0.28);
}
.dark .inset-secondary-btn {
  color: #d1d5db;
  border-color: rgba(255, 255, 255, 0.15);
  background: transparent;
}
.dark .inset-secondary-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.25);
}

/* Hero stat number — subtle ink-wash gradient for a delightful focal moment.
 * Falls back to solid color if background-clip:text isn't supported. */
.hero-stat {
  background: linear-gradient(135deg, #1a1612 0%, #2d2720 40%, #6b3a2e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: -0.02em;
}
.dark .hero-stat {
  background: linear-gradient(135deg, #c9d1d9 0%, #b1bac4 40%, #c4a88a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Generic content card (progress bar, block list) with the same warm,
 * hairline-bordered language as the hero. */
.card-soft {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 0.75rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.dark .card-soft {
  background: #252535;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: none;
}

/* Block list row — hairline divider + sliding accent bar on hover */
.block-row {
  position: relative;
  transition: background-color 0.2s ease;
}
.block-row::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10%;
  bottom: 10%;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, #c23c2a, #a93121);
  transform: scaleY(0);
  transform-origin: center;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
.dark .block-row::before {
  background: rgba(255, 255, 255, 0.18);
}
/* Edge bar appears on hover and on the currently-open row */
.block-row:hover::before,
.block-row.is-active::before { transform: scaleY(1); }
.block-row.is-active {
  background: linear-gradient(90deg, rgba(194, 60, 42, 0.07), transparent 65%);
}
.dark .block-row.is-active {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.04), transparent 65%);
}

/* ===== Entrance animations ===== */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .animate-fade-up {
    animation: fade-up 0.5s ease-out both;
  }
  .animate-fade-up-delay-1 {
    animation: fade-up 0.5s ease-out 100ms both;
  }
  .animate-fade-up-delay-2 {
    animation: fade-up 0.5s ease-out 200ms both;
  }
  .animate-fade-up-delay-3 {
    animation: fade-up 0.5s ease-out 300ms both;
  }

  /* Hover lift for interactive cards */
  .hover-lift {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }
  .hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  }
  .dark .hover-lift:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

/* Thin scrollbar for horizontal scroll rows */
.scrollbar-thin {
  scrollbar-width: thin;
  scrollbar-color: rgba(156, 163, 175, 0.3) transparent;
}
.scrollbar-thin:hover {
  scrollbar-color: rgba(156, 163, 175, 0.5) transparent;
}
.scrollbar-thin::-webkit-scrollbar {
  height: 6px;
}
.scrollbar-thin::-webkit-scrollbar-track {
  background: transparent;
}
.scrollbar-thin::-webkit-scrollbar-thumb {
  background: rgba(156, 163, 175, 0.3);
  border-radius: 3px;
}
.scrollbar-thin::-webkit-scrollbar-thumb:hover {
  background: rgba(156, 163, 175, 0.5);
}
.dark .scrollbar-thin {
  scrollbar-color: rgba(107, 114, 128, 0.3) transparent;
}
.dark .scrollbar-thin:hover {
  scrollbar-color: rgba(107, 114, 128, 0.5) transparent;
}
.dark .scrollbar-thin::-webkit-scrollbar-thumb {
  background: rgba(107, 114, 128, 0.3);
}
.dark .scrollbar-thin::-webkit-scrollbar-thumb:hover {
  background: rgba(107, 114, 128, 0.5);
}

/* Safe area padding for iOS bottom bar */
.safe-area-bottom {
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ===== Pagy pagination nav ===== */
nav.pagy {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
  justify-content: center;
}

nav.pagy a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 0.625rem;
  border-radius: 9999px;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
  background: rgba(255, 255, 255, 0.6);
  color: #374151;
  text-decoration: none;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

nav.pagy a:hover:not([aria-disabled]) {
  background: rgba(194, 60, 42, 0.1);
  color: #a93121;
}

nav.pagy a[aria-current="page"] {
  background: #a93121;
  color: white;
  border-color: transparent;
}

nav.pagy a[role="separator"] {
  color: #6b7280;
  min-width: auto;
  background: transparent;
  border-color: transparent;
}

.dark nav.pagy a {
  background: rgba(30, 41, 59, 0.6);
  color: #d1d5db;
  border-color: rgba(255, 255, 255, 0.08);
}

.dark nav.pagy a:hover:not([aria-disabled]) {
  background: rgba(255, 255, 255, 0.08);
  color: #c9d1d9;
}

.dark nav.pagy a[aria-current="page"] {
  background: #21262d;
  color: #f0f6fc;
  border-color: #30363d;
}

.dark nav.pagy a[role="separator"] {
  color: #9ca3af;
  background: transparent;
  border-color: transparent;
}

/* ===== Word bank tiles (dialogue roleplay) ===== */

.word-tile {
  display: inline-flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  background: rgba(139, 92, 246, 0.1);
  border: 1.5px solid rgba(139, 92, 246, 0.25);
  color: #1f2937;
  font-size: 1.375rem;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}
.word-tile:active {
  transform: scale(0.95);
}
.word-tile.placed {
  opacity: 0.35;
  background: transparent;
  border-style: dashed;
  border-color: rgba(139, 92, 246, 0.2);
  color: transparent;
  pointer-events: none;
}
.word-tile.placed ruby rt,
.word-tile.placed span {
  color: transparent;
}

.dark .word-tile {
  background: rgba(139, 92, 246, 0.15);
  border-color: rgba(139, 92, 246, 0.35);
  color: #e5e7eb;
}

.word-tile-answer {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  background: rgba(139, 92, 246, 0.22);
  border: 2px solid rgba(139, 92, 246, 0.5);
  color: #1f2937;
  font-size: 1.375rem;
  cursor: grab;
  transition: background 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 1px 3px rgba(139, 92, 246, 0.15);
}
.word-tile-answer .tile-content {
  display: inline;
}
.word-tile-answer:hover {
  background: rgba(139, 92, 246, 0.3);
  border-color: rgba(139, 92, 246, 0.6);
}
.word-tile-answer:active {
  transform: scale(0.95);
}
/* SortableJS drag states — compound selectors beat .word-tile-answer base rules */
.word-tile-answer.word-tile-chosen {
  position: relative;
  transform: none;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.3), 0 2px 8px rgba(0, 0, 0, 0.1);
  cursor: grabbing;
}
.dark .word-tile-answer.word-tile-chosen {
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.45), 0 2px 8px rgba(0, 0, 0, 0.25);
}
.word-tile-answer.word-tile-ghost {
  opacity: 0.35;
  background: rgba(139, 92, 246, 0.1);
  border-style: dashed;
  border-color: rgba(139, 92, 246, 0.3);
  box-shadow: none;
  transition: none;
}
.dark .word-tile-answer.word-tile-ghost {
  background: rgba(139, 92, 246, 0.15);
  border-color: rgba(139, 92, 246, 0.4);
}
.word-tile-drag {
  opacity: 0.95;
  z-index: 9999;
}
.word-tile-answer .tile-remove {
  font-size: 0.8rem;
  opacity: 0.35;
  cursor: pointer;
  padding: 0 0.125rem;
  border-radius: 0.25rem;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.word-tile-answer:hover .tile-remove {
  opacity: 0.7;
}
.word-tile-answer .tile-remove:hover {
  opacity: 1;
  color: #ef4444;
}
.dark .word-tile-answer {
  background: rgba(139, 92, 246, 0.3);
  border-color: rgba(139, 92, 246, 0.55);
  color: #e5e7eb;
  box-shadow: 0 1px 3px rgba(139, 92, 246, 0.25);
}
.dark .word-tile-answer:hover {
  background: rgba(139, 92, 246, 0.4);
  border-color: rgba(139, 92, 246, 0.65);
}

.word-tile-correct {
  background: rgba(16, 185, 129, 0.15) !important;
  border-color: rgba(16, 185, 129, 0.5) !important;
  color: #065f46 !important;
}
.dark .word-tile-correct {
  background: rgba(16, 185, 129, 0.2) !important;
  color: #6ee7b7 !important;
}

.word-tile-incorrect {
  background: rgba(245, 158, 11, 0.15) !important;
  border-color: rgba(245, 158, 11, 0.5) !important;
  color: #92400e !important;
}
.dark .word-tile-incorrect {
  background: rgba(245, 158, 11, 0.2) !important;
  color: #fcd34d !important;
}

@keyframes tile-pop {
  0% { transform: scale(0.8); opacity: 0; }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  .animate-tile-pop {
    animation: tile-pop 0.2s ease-out both;
  }
}

/* Ruby text (pinyin above characters) */
ruby { ruby-align: center; }
rt {
  font-size: 0.55em;
  letter-spacing: 0.02em;
  font-family: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
}
rt.hidden-pinyin { visibility: hidden; height: 0; overflow: hidden; }
.hide-pinyin rt { visibility: hidden; height: 0; overflow: hidden; }

/* Reading view — optimized typography for annotated Chinese text */
.reading-segment-chinese {
  font-size: var(--reader-font-size, 1.625rem);  /* 26px mobile default */
  line-height: var(--reader-line-height, 2.8);  /* generous room for ruby pinyin */
  letter-spacing: 0.02em;
  transition: font-size 0.2s ease;
}
@media (min-width: 640px) {
  .reading-segment-chinese {
    font-size: var(--reader-font-size-desktop, 1.75rem);  /* 28px desktop default */
    line-height: var(--reader-line-height, 2.8);
  }
}

.reading-segment-english {
  font-size: 0.9375rem;  /* 15px — readable for older users */
  line-height: 1.6;
  margin-top: 0.375rem;
}

/* ===== Read-along TTS highlighting ===== */

/* Active segment background — warm tint, progress semantic */
.read-along-active-segment {
  background: rgba(45, 107, 90, 0.06);
  border-radius: 0.5rem;
  margin: -0.5rem;
  padding: 0.5rem;
  transition: background 0.3s ease;
}
.dark .read-along-active-segment {
  background: rgba(255, 255, 255, 0.06);
}

/* Already-spoken words — cinnabar fading, "completed" */
.read-along-word-spoken {
  background: rgba(194, 60, 42, 0.08);
  border-radius: 0.25rem;
  transition: background 0.15s ease;
}
.dark .read-along-word-spoken {
  background: rgba(139, 148, 158, 0.12);
}

/* Currently-active word — jade, "progress / focus" */
.read-along-word-active {
  background: rgba(45, 107, 90, 0.22);
  border-radius: 0.25rem;
  transition: background 0.1s ease;
}
.dark .read-along-word-active {
  background: rgba(255, 255, 255, 0.15);
}

/* Already-spoken English words (proportional sync) */
.read-along-english-spoken {
  background: rgba(194, 60, 42, 0.06);
  border-radius: 0.15rem;
  transition: background 0.15s ease;
}
.dark .read-along-english-spoken {
  background: rgba(139, 148, 158, 0.10);
}

/* Currently-active English word — jade */
.read-along-english-active {
  background: rgba(45, 107, 90, 0.18);
  color: rgb(31, 88, 71);
  border-radius: 0.15rem;
  transition: background 0.1s ease;
}
.dark .read-along-english-active {
  background: rgba(255, 255, 255, 0.12);
  color: #c9d1d9;
}

/* Sticky player bar */
.read-along-player {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}
/* Offset player bar above mobile bottom tabs (h-14 = 3.5rem + safe area) */
@media (max-width: 767px) {
  .read-along-player {
    bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px));
  }
}
.dark .read-along-player {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
/* Extra bottom padding when player bar is active on mobile */
@media (max-width: 767px) {
  .player-bar-active {
    padding-bottom: 10rem;
  }
}

/* ===== Kindle-style page navigation ===== */
.reader-page-btn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 5rem;
  color: rgba(156, 163, 175, 0.5);
  transition: color 0.2s, background-color 0.2s;
  border-radius: 0.375rem;
}
.reader-page-btn:hover {
  color: rgba(156, 163, 175, 0.9);
  background-color: rgba(156, 163, 175, 0.1);
}
.reader-page-btn-prev { left: 0.5rem; }
.reader-page-btn-next { right: 0.5rem; }
@media (max-width: 767px) {
  .reader-page-btn { display: none; }
}

/* ===== Word definition bottom sheet ===== */
.word-bottom-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 49;
  background: rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.word-bottom-sheet-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}
.dark .word-bottom-sheet-backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.word-bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  min-height: 40vh;
  max-height: 60vh;
  overflow-y: auto;
  border-top-left-radius: 1rem;
  border-top-right-radius: 1rem;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.1);
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.word-bottom-sheet.active {
  transform: translateY(0);
}
.dark .word-bottom-sheet {
  background: rgba(15, 23, 42, 0.95);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
}

.word-bottom-sheet-handle {
  width: 2.5rem;
  height: 0.3rem;
  border-radius: 0.15rem;
  background: rgba(0, 0, 0, 0.15);
  margin: 0.625rem auto 0;
}
.dark .word-bottom-sheet-handle {
  background: rgba(255, 255, 255, 0.2);
}

/* Saved word indicator in reading text */
.word-saved {
  border-bottom: 1.5px dotted #059669;
}
.dark .word-saved {
  border-bottom-color: #34d399;
}

/* Save toast notification */
.word-save-toast {
  position: fixed;
  bottom: 65vh;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: rgba(5, 150, 105, 0.95);
  color: white;
  padding: 0.5rem 1.25rem;
  border-radius: 2rem;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.word-save-toast.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Reader settings sheet ===== */
.reader-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 49;
  background: rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.reader-sheet-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}
.dark .reader-sheet-backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.reader-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  border-top-left-radius: 1rem;
  border-top-right-radius: 1rem;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.08);
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.reader-sheet.active {
  transform: translateY(0);
}
.dark .reader-sheet {
  background: rgba(15, 23, 42, 0.97);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25);
}

.reader-sheet-handle {
  width: 2.5rem;
  height: 0.25rem;
  border-radius: 0.15rem;
  background: rgba(0, 0, 0, 0.12);
  margin: 0.625rem auto 0;
}
.dark .reader-sheet-handle {
  background: rgba(255, 255, 255, 0.18);
}

/* Density radio buttons */
.density-active {
  background: rgba(45, 107, 90, 0.12);
  color: rgb(31, 88, 71);
  border: 1px solid rgba(45, 107, 90, 0.3);
}
.dark .density-active {
  background: rgba(45, 107, 90, 0.2);
  color: rgb(134, 197, 171);
  border-color: rgba(45, 107, 90, 0.4);
}
.density-inactive {
  background: rgba(0, 0, 0, 0.03);
  color: rgb(107, 114, 128);
  border: 1px solid rgba(0, 0, 0, 0.06);
}
.dark .density-inactive {
  background: rgba(255, 255, 255, 0.05);
  color: rgb(156, 163, 175);
  border-color: rgba(255, 255, 255, 0.08);
}

/* Font size option buttons */
.font-size-active {
  background: rgba(45, 107, 90, 0.12);
  color: rgb(31, 88, 71);
  border: 1px solid rgba(45, 107, 90, 0.3);
}
.dark .font-size-active {
  background: rgba(45, 107, 90, 0.2);
  color: rgb(134, 197, 171);
  border-color: rgba(45, 107, 90, 0.4);
}
.font-size-inactive {
  background: rgba(0, 0, 0, 0.03);
  color: rgb(107, 114, 128);
  border: 1px solid rgba(0, 0, 0, 0.06);
}
.dark .font-size-inactive {
  background: rgba(255, 255, 255, 0.05);
  color: rgb(156, 163, 175);
  border-color: rgba(255, 255, 255, 0.08);
}

/* English density states */
.english-muted {
  opacity: 0.5;
  transition: opacity 0.2s ease;
}
.english-muted:hover,
.group:hover .english-muted {
  opacity: 1;
}
.english-full {
  opacity: 1;
}

/* Auto-hide top bar on scroll */
.reader-topbar {
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.reader-topbar-hidden {
  opacity: 0;
  transform: translateY(-100%);
  pointer-events: none;
}

/* ===== Goal urgency: empty state warm tint ===== */
.goal-cell-empty {
  background: linear-gradient(180deg, rgba(201, 168, 76, 0.08), rgba(201, 168, 76, 0.03));
  border-color: rgba(201, 168, 76, 0.22);
}
.dark .goal-cell-empty {
  background: linear-gradient(180deg, rgba(201, 168, 76, 0.10), rgba(201, 168, 76, 0.04));
  border-color: rgba(201, 168, 76, 0.18);
}

/* ===== Goal completion celebration ===== */
@keyframes goal-celebrate {
  0%   { transform: scale(0.95); opacity: 0.7; }
  50%  { transform: scale(1.05); }
  100% { transform: scale(1);    opacity: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  .animate-goal-celebrate {
    animation: goal-celebrate 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
  }
}

/* Disable all landing animations for reduced motion */
@media (prefers-reduced-motion: reduce) {
  .animate-float-slow,
  .animate-float-medium,
  .animate-float-fast,
  .animate-pulse-dot,
  .turbo-body-fade-in,
  .animate-fade-up,
  .animate-fade-up-delay-1,
  .animate-fade-up-delay-2,
  .animate-fade-up-delay-3,
  .animate-tile-pop,
  .animate-brush-reveal,
  .animate-goal-celebrate {
    animation: none;
  }
  .hover-lift {
    transition: none;
  }
  .hover-lift:hover {
    transform: none;
    box-shadow: none;
  }
  [data-landing-target="reveal"] {
    opacity: 1;
    transform: none;
    transition: none;
  }
  .read-along-word-spoken,
  .read-along-word-active,
  .read-along-active-segment,
  .read-along-english-spoken,
  .read-along-english-active {
    transition: none;
  }
  .word-bottom-sheet,
  .word-bottom-sheet-backdrop,
  .reader-sheet,
  .reader-sheet-backdrop,
  .reading-segment-chinese,
  .reader-topbar {
    transition: none;
  }
}
