/* ==========================================================================
   Design tokens — "Stained-glass energetic"
   Dark navy canvas (church interior at dusk) + luminous cream cards (glass
   panels catching light) + gold/sapphire/ruby jewel accents.
   ========================================================================== */
:root {
  /* Color: dark canvas */
  --color-canvas: oklch(20% 0.03 264);
  --color-canvas-2: oklch(25% 0.035 264);
  --color-canvas-3: oklch(30% 0.045 264);

  /* Color: cream surfaces (elevated content) */
  --color-surface: oklch(97% 0.012 85);
  --color-surface-2: oklch(92% 0.018 85);

  /* Color: text */
  --color-ink: oklch(22% 0.02 264);
  --color-ink-soft: oklch(42% 0.02 264);
  --color-cream-text: oklch(95% 0.01 85);
  --color-cream-text-soft: oklch(75% 0.03 90);

  /* Color: jewel accents */
  --color-gold: oklch(76% 0.13 80);
  --color-gold-deep: oklch(58% 0.12 65);
  --color-sapphire: oklch(50% 0.12 258);
  --color-sapphire-soft: oklch(68% 0.08 258);
  --color-ruby: oklch(52% 0.16 25);
  --color-ruby-soft: oklch(38% 0.11 25);
  --color-ruby-bg: oklch(30% 0.06 25);
  --color-gold-bg: oklch(34% 0.06 80);

  /* Radius scale (concentric: lg card -> md button -> sm chip -> pill) */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-pill: 999px;

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

  /* Typography */
  --font-display: 'Baloo 2', system-ui, sans-serif;
  --font-body: 'Hind', system-ui, sans-serif;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-canvas);
  color: var(--color-cream-text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  overflow-x: hidden;
  max-width: 100vw;
  /* Devanagari conjunct clusters aren't always exposed as break
     opportunities by every font/renderer combo; force a wrap rather
     than let long words overflow the viewport. */
  overflow-wrap: anywhere;
}

body {
  min-height: 100dvh;
  line-height: 1.5;
}

button {
  font-family: inherit;
  touch-action: manipulation;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-gold);
  color: var(--color-ink);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus {
  left: var(--space-3);
  top: var(--space-3);
}

:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 2px;
}

/* ==========================================================================
   App shell
   ========================================================================== */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: max(var(--space-3), env(safe-area-inset-top)) var(--space-4) var(--space-3);
  background: var(--color-canvas-2);
  border-bottom: 1px solid oklch(100% 0 0 / 0.06);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--color-cream-text);
  cursor: pointer;
  transition: background-color 150ms ease, transform 150ms ease;
}
.icon-btn:active { transform: scale(0.94); background: oklch(100% 0 0 / 0.08); }
@media (hover: hover) {
  .icon-btn:hover { background: oklch(100% 0 0 / 0.06); }
}

.topbar-title {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar-title-ne {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-title-en {
  font-size: 11px;
  color: var(--color-cream-text-soft);
  letter-spacing: 0.02em;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-4) max(var(--space-6), calc(env(safe-area-inset-bottom) + var(--space-4)));
  max-width: 640px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
}

.view { min-width: 0; }
.view[hidden] { display: none; }

/* ==========================================================================
   Home view
   ========================================================================== */
.home-hero {
  padding: var(--space-6) var(--space-2) var(--space-5);
  text-align: center;
}
.home-eyebrow {
  margin: 0 0 var(--space-2);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-gold);
}
.home-title {
  margin: 0 0 var(--space-3);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(32px, 8vw, 44px);
  line-height: 1.15;
  text-wrap: balance;
  overflow-wrap: break-word;
}
.home-sub {
  margin: 0 auto var(--space-5);
  max-width: 46ch;
  color: var(--color-cream-text-soft);
  font-size: 16px;
  line-height: 1.75;
  text-wrap: pretty;
}

.home-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-top: var(--space-4);
}
.home-stat {
  background: oklch(100% 0 0 / 0.04);
  border: 1px solid oklch(100% 0 0 / 0.07);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-2);
  text-align: center;
}
.home-stat-num {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  color: var(--color-gold);
  font-variant-numeric: tabular-nums;
}
.home-stat-label {
  display: block;
  font-size: 12px;
  color: var(--color-cream-text-soft);
  margin-top: 2px;
}

.home-footer {
  margin: var(--space-6) 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--color-cream-text-soft);
}
.home-footer a {
  color: var(--color-gold);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 150ms ease;
}
@media (hover: hover) {
  .home-footer a:hover { color: var(--color-cream-text); }
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-5);
  border-radius: var(--radius-pill);
  border: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: transform 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--color-gold);
  color: var(--color-ink);
  box-shadow: 0 2px 0 var(--color-gold-deep);
}
@media (hover: hover) {
  .btn-primary:hover { background: oklch(80% 0.13 82); }
}

.btn-ghost {
  background: oklch(100% 0 0 / 0.06);
  color: var(--color-cream-text);
  border: 1px solid oklch(100% 0 0 / 0.14);
}
@media (hover: hover) {
  .btn-ghost:hover { background: oklch(100% 0 0 / 0.1); }
}

.btn-lg { width: 100%; min-height: 56px; font-size: 16px; }

.btn-text {
  background: none;
  border: none;
  color: var(--color-cream-text-soft);
  font-size: 14px;
  font-weight: 600;
  padding: var(--space-2) var(--space-1);
  cursor: pointer;
  min-height: 44px;
  transition: color 150ms ease;
}
.btn-text:active { transform: scale(0.97); }
@media (hover: hover) {
  .btn-text:hover { color: var(--color-cream-text); }
}

/* ==========================================================================
   Drawer navigation
   ========================================================================== */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: oklch(10% 0.02 264 / 0.6);
  z-index: 30;
  opacity: 0;
  transition: opacity 200ms ease;
}
.drawer-overlay.is-visible { opacity: 1; }
.drawer-overlay[hidden] { display: none; }

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(340px, 86vw);
  background: var(--color-canvas-2);
  z-index: 31;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 4px 0 24px oklch(0% 0 0 / 0.3);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer.is-open { transform: translateX(0); }

@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer-overlay { transition-duration: 1ms; }
}

.drawer-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4) var(--space-4);
  border-bottom: 1px solid oklch(100% 0 0 / 0.08);
}
.drawer-book-ne {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  color: var(--color-gold);
}
.drawer-book-en {
  font-size: 12px;
  color: var(--color-cream-text-soft);
  flex: 1;
}
.drawer-close { margin-left: auto; }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  overscroll-behavior: contain;
}

.drawer-section + .drawer-section { margin-top: var(--space-5); }

.drawer-heading {
  margin: 0 0 var(--space-3);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-cream-text-soft);
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
}
.drawer-heading-en { font-weight: 500; text-transform: none; opacity: 0.7; }

.drawer-progress {
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.drawer-progress .progress-track {
  flex: none;
}
.drawer-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.drawer-progress-label {
  font-size: 11px;
  font-family: var(--font-body);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-cream-text-soft);
  font-variant-numeric: tabular-nums;
}
.drawer-progress-reset {
  font-size: 11px;
  font-family: var(--font-body);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-ruby-soft);
  background: none;
  border: none;
  padding: var(--space-1);
  margin: calc(var(--space-1) * -1);
  cursor: pointer;
  flex-shrink: 0;
}
@media (hover: hover) {
  .drawer-progress-reset:hover { color: var(--color-ruby); text-decoration: underline; }
}

.drawer-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid oklch(68% 0.08 258 / 0.25);
  background: oklch(100% 0 0 / 0.03);
  color: var(--color-cream-text);
  cursor: pointer;
  min-height: 56px;
  text-align: left;
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}
.drawer-item:active { transform: scale(0.98); }
@media (hover: hover) {
  .drawer-item:hover { background: oklch(100% 0 0 / 0.06); border-color: var(--color-sapphire-soft); }
}
.drawer-item.is-active {
  background: var(--color-gold-bg);
  border-color: var(--color-gold);
}
.drawer-item.progress-started { border-color: var(--color-sapphire); }
.drawer-item.progress-mistakes { border-color: var(--color-ruby-soft); }
.drawer-item.progress-perfect { border-color: var(--color-gold); }
.drawer-item-icon {
  font-size: 18px;
  color: var(--color-gold);
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}
.drawer-item-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.drawer-item-ne { font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.drawer-item-en { font-size: 11px; color: var(--color-cream-text-soft); }
.drawer-item-count {
  font-size: 11px;
  color: var(--color-cream-text-soft);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}
@media (min-width: 360px) {
  .chapter-grid { grid-template-columns: repeat(5, 1fr); }
}
.chapter-pill {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid oklch(68% 0.08 258 / 0.25);
  background: oklch(100% 0 0 / 0.03);
  color: var(--color-cream-text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  min-height: 44px;
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}
.chapter-pill:active { transform: scale(0.94); }
@media (hover: hover) {
  .chapter-pill:hover { border-color: var(--color-sapphire-soft); }
}
.chapter-pill.is-active {
  background: var(--color-gold);
  color: var(--color-ink);
  border-color: var(--color-gold);
}
.chapter-pill.progress-started { border-color: var(--color-sapphire); }
.chapter-pill.progress-mistakes { border-color: var(--color-ruby-soft); }
.chapter-pill.progress-perfect { border-color: var(--color-gold); }

/* ==========================================================================
   Quiz view
   ========================================================================== */
.quiz-progress-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.progress-track {
  flex: 1;
  height: 8px;
  border-radius: var(--radius-pill);
  background: oklch(100% 0 0 / 0.1);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--color-gold);
  width: 0%;
  transition: width 300ms cubic-bezier(0.16, 1, 0.3, 1);
}
.progress-count {
  font-size: 13px;
  color: var(--color-cream-text-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.quiz-card {
  background: var(--color-surface);
  color: var(--color-ink);
  border: 1px solid var(--color-sapphire-soft);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: 0 8px 24px oklch(0% 0 0 / 0.25);
}

.quiz-set-label {
  margin: 0 0 var(--space-2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-sapphire);
}

.quiz-question {
  margin: 0 0 var(--space-4);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(19px, 5vw, 22px);
  line-height: 1.5;
  text-wrap: balance;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.option-btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 56px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1.5px solid oklch(30% 0.02 264 / 0.2);
  background: var(--color-surface-2);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 15px;
  line-height: 1.5;
  text-align: left;
  cursor: pointer;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease;
}
.option-btn:active:not(:disabled) { transform: scale(0.98); }
@media (hover: hover) {
  .option-btn:not(:disabled):hover { border-color: var(--color-sapphire); }
}
.option-btn:disabled { cursor: default; }

.option-letter {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: oklch(100% 0 0 / 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
}

.option-btn.is-correct {
  background: var(--color-gold);
  border-color: var(--color-gold-deep);
  animation: glow-pulse 600ms ease-out;
}
.option-btn.is-correct .option-letter { background: oklch(100% 0 0 / 0.4); }

.option-btn.is-incorrect {
  background: oklch(88% 0.05 25);
  border-color: var(--color-ruby);
  animation: shake 320ms ease-in-out;
}

@keyframes glow-pulse {
  0% { box-shadow: 0 0 0 0 oklch(76% 0.13 80 / 0.6); }
  100% { box-shadow: 0 0 0 14px oklch(76% 0.13 80 / 0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
@media (prefers-reduced-motion: reduce) {
  .option-btn.is-correct, .option-btn.is-incorrect { animation: none; }
}

.quiz-feedback {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid oklch(30% 0.02 264 / 0.15);
}
.quiz-feedback-status {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
}
.quiz-feedback[data-result="correct"] .quiz-feedback-status { color: var(--color-gold-deep); }
.quiz-feedback[data-result="incorrect"] .quiz-feedback-status { color: var(--color-ruby); }

.quiz-feedback-ref {
  display: inline-block;
  margin: 0 0 var(--space-3);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--color-gold-bg);
  color: var(--color-gold);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
}
.quiz-feedback-explain {
  margin: 0;
  color: var(--color-ink-soft);
  font-size: 15px;
  line-height: 1.75;
  text-wrap: pretty;
}

/* ==========================================================================
   Score view
   ========================================================================== */
.score-card {
  margin-top: var(--space-6);
  text-align: center;
  background: var(--color-surface);
  color: var(--color-ink);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-5);
  border: 1px solid var(--color-sapphire-soft);
}
.score-eyebrow {
  margin: 0 0 var(--space-3);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-sapphire);
}
.score-big {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 52px;
  color: var(--color-gold-deep);
  font-variant-numeric: tabular-nums;
}
.score-sub {
  margin: 0 0 var(--space-5);
  color: var(--color-ink-soft);
  font-size: 15px;
}
.score-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.score-card .btn-ghost {
  background: var(--color-surface-2);
  color: var(--color-ink);
  border-color: oklch(30% 0.02 264 / 0.2);
}
@media (hover: hover) {
  .score-card .btn-ghost:hover { background: oklch(92% 0.018 85 / 0.6); }
}

/* ==========================================================================
   Flashcard view (Popular Verses)
   ========================================================================== */
.flash-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.flashcard {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 60vh;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  perspective: 1200px;
  margin-bottom: var(--space-5);
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 500ms cubic-bezier(0.16, 1, 0.3, 1);
  transform-style: preserve-3d;
}
.flashcard.is-flipped .flashcard-inner { transform: rotateY(180deg); }
@media (prefers-reduced-motion: reduce) {
  .flashcard-inner { transition-duration: 1ms; }
}

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-sapphire-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-5);
  text-align: center;
  box-shadow: 0 8px 24px oklch(0% 0 0 / 0.25);
}
.flashcard-front {
  background: var(--color-surface);
  color: var(--color-ink);
}
.flashcard-back {
  background: var(--color-canvas-3);
  color: var(--color-cream-text);
  transform: rotateY(180deg);
  overflow-y: auto;
}
.flashcard-hint {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-sapphire);
  margin-bottom: var(--space-4);
}
.flashcard-ref {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(24px, 7vw, 32px);
  margin: 0;
}
.flashcard-text {
  font-size: 18px;
  line-height: 1.8;
  margin: 0 0 var(--space-4);
  text-wrap: pretty;
}
.flashcard-note {
  font-size: 13px;
  color: var(--color-gold);
  margin: 0;
}

.flash-nav-row {
  display: flex;
  gap: var(--space-3);
}
.flash-nav-row .btn { flex: 1; }

/* ==========================================================================
   Confetti (correct-answer celebration)
   ========================================================================== */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  opacity: 0.9;
  animation: confetti-fall 900ms ease-in forwards;
}
@keyframes confetti-fall {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 0.9; }
  100% { transform: translate(var(--drift, 0px), 70vh) rotate(360deg); opacity: 0; }
}

/* ==========================================================================
   Responsive: tablet and up
   ========================================================================== */
@media (min-width: 720px) {
  .chapter-grid { grid-template-columns: repeat(6, 1fr); }
  .home-title { font-size: 48px; }
}
