/* ── Celebration overlay ── */

.celebration-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #1D9E75 0%, #0d6e50 100%);
  animation: celebFadeIn 0.5s ease;
}

@keyframes celebFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

#confettiCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.celebration-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px 32px;
  text-align: center;
}

.celebration-badr {
  width: 140px;
  height: 140px;
  object-fit: contain;
  animation: celebBadr 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: 0.2s;
}

@keyframes celebBadr {
  from { opacity: 0; transform: scale(0.5) translateY(30px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.celebration-title {
  font-family: 'Amiri', serif;
  font-size: 52px;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  animation: celebSlideUp 0.5s ease both;
  animation-delay: 0.4s;
}

.celebration-surah-arabic {
  font-family: 'Amiri', serif;
  font-size: 36px;
  font-weight: 700;
  color: #fff;
  direction: rtl;
  animation: celebSlideUp 0.5s ease both;
  animation-delay: 0.5s;
}

.celebration-surah-names {
  font-size: 18px;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
  animation: celebSlideUp 0.5s ease both;
  animation-delay: 0.55s;
}

.celebration-msg {
  font-size: 15px;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  line-height: 1.6;
  max-width: 280px;
  animation: celebSlideUp 0.5s ease both;
  animation-delay: 0.6s;
}

.celebration-score {
  font-size: 17px;
  font-weight: 600;
  color: rgba(255,255,255,0.8);
  background: rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 8px 20px;
  animation: celebSlideUp 0.5s ease both;
  animation-delay: 0.6s;
}

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

.celebration-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  animation: celebSlideUp 0.5s ease both;
  animation-delay: 0.7s;
}

.celebration-btn {
  padding: 14px 28px;
  border-radius: 20px;
  border: none;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.celebration-btn.primary {
  background: #fff;
  color: #1D9E75;
  box-shadow: 0 4px 0 rgba(0,0,0,0.2);
}
.celebration-btn.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.2); }

.celebration-btn.secondary {
  background: rgba(255,255,255,0.2);
  color: #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
}
.celebration-btn.secondary:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }

/* ── Learn page layout ── */

.learn-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.learn-page .topbar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.learn-page .topbar .back-btn {
  flex: 1;
  text-align: left;
}

.learn-page .topbar .learn-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

.learn-page .topbar .right-bar {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.learn-page .topbar .tts-map-btn {
  display: none;
}

.back-btn {
  background: none;
  border: none;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
.back-btn:hover { color: var(--text-muted); }

.learn-eye-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.learn-eye-icon {
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

.learn-eye-toggle {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: #C8C6BE;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.learn-eye-toggle.on {
  background: var(--green);
}

.learn-eye-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: left 0.2s;
}

.learn-eye-toggle.on .learn-eye-knob {
  left: 19px;
}

.card-back-btn {
  background: none;
  border: none;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.card-back-btn:hover { color: var(--text); }

.learn-title {
  flex: 1;
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  text-align: center;
}

/* ── Surah scroll area ── */

.surah-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 12px;
}

.surah-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ayah-block {
  padding: 12px 14px;
  border-radius: 14px;
  transition: background 0.25s;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.ayah-block:last-child { border-bottom: none; }
.ayah-block:hover { background: rgba(0,0,0,0.03); }
.ayah-block.active-segment { background: rgba(29, 158, 117, 0.07); }

.ayah-arabic {
  font-family: 'Amiri', serif;
  font-size: clamp(22px, 5vw, 30px);
  line-height: 2;
  color: var(--text);
  text-align: right;
  margin-bottom: 4px;
}

.ayah-translit {
  font-size: 13px;
  color: #2C2C2A;
  line-height: 1.6;
  margin-bottom: 4px;
  word-spacing: 4px;
}

.ayah-meaning {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.5;
}

.surah-scroll.test-mode .ayah-meaning {
  display: none;
}

/* override placement.css: .hidden must not nuke ayah blocks */
.ayah-block.hidden { display: block !important; }

/* hide everything in the block except markers */
.ayah-block.chunk-hidden .word-span,
.ayah-block.chunk-hidden .tword-span,
.ayah-block.chunk-hidden .ayah-meaning { visibility: hidden; }

/* reciting overrides: corrected spans become visible */
.ayah-block.chunk-hidden.reciting .word-span.correct,
.ayah-block.chunk-hidden.reciting .word-span.close,
.ayah-block.chunk-hidden.reciting .word-span.wrong,
.ayah-block.chunk-hidden.reciting .tword-span.correct,
.ayah-block.chunk-hidden.reciting .tword-span.close,
.ayah-block.chunk-hidden.reciting .tword-span.wrong { visibility: visible; }

.word-span {
  display: inline;
  transition: color 0.25s, opacity 0.25s, background 0.15s;
  border-radius: 4px;
  padding: 0 1px;
}
.word-span.word-hidden, .tword-span.word-hidden { opacity: 0; }
.word-span.omitted     { opacity: 1; color: transparent; border-bottom: 2px solid #c0392b; }
.word-span.correct     { color: #1D9E75; }
.word-span.close       { color: #b07800; }
.word-span.wrong       { color: #c0392b; }
.tword-span.correct    { color: #1D9E75; }
.tword-span.close      { color: #b07800; }
.tword-span.wrong      { color: #c0392b; }
.tword-span.omitted    { opacity: 1; color: transparent; border-bottom: 2px solid #c0392b; }
.word-span.playing     { background: rgba(29,158,117,0.15); color: var(--green); }

.tword-span {
  display: inline;
  transition: color 0.15s;
}
.tword-span.playing { color: var(--green); font-weight: 700; }

.ayah-marker {
  display: inline-block;
  position: relative;
  margin-right: 4px;
  vertical-align: middle;
}
.ayah-marker-ornament {
  display: inline-block;
  font-size: 0.9em;
  color: var(--text-muted);
  line-height: 1;
  position: relative;
  top: -0.1em;
}
.ayah-marker-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 0.1em;
  font-size: 0.3em;
  color: #000;
  font-weight: 700;
  font-family: system-ui, sans-serif;
  line-height: 1;
}

/* ── Bottom card ── */

.learn-card {
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.10);
  padding: 20px 20px 32px;
  min-height: 140px;
  position: relative;
}

.learn-card.flow-processing::before {
  content: '';
  position: absolute; inset: 0;
  background: rgba(247, 245, 240, 0.6);
  border-radius: 28px 28px 0 0;
  z-index: 1000;
}

.learn-card.flow-processing::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 28px; height: 28px;
  border: 3px solid #ddd9d0;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: app-spin 0.8s linear infinite;
  z-index: 1001;
}

.card-state {
  animation: cardFadeIn 0.18s ease;
}

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

/* ── Badr card layout ── */

.learn-badr-card {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.learn-badr-col {
  width: clamp(90px, 26vw, 120px);
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.learn-badr-col .badr {
  display: block;
  width: clamp(90px, 26vw, 120px);
  height: clamp(99px, 28vw, 132px);
}

.learn-badr-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.learn-badr-header {
  display: flex;
  align-items: center;
}

.learn-badr-msg {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
  background: #f0ece4;
  border-radius: 14px;
  padding: 10px 12px;
  animation: badrPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes badrPop {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

.learn-badr-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Preset select ── */

.preset-label {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 16px;
}

.preset-pills {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.preset-pill {
  flex: 1;
  padding: 10px 6px;
  border-radius: 14px;
  border: none;
  background: #f0ece4;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  text-align: center;
  line-height: 1.3;
  box-shadow: 0 4px 0 #ddd9d0;
  transition: transform 0.1s, box-shadow 0.1s;
}
.preset-pill:active { transform: translateY(3px); box-shadow: 0 1px 0 #ddd9d0; }

.preset-pill .pill-icon {
  display: block;
  font-size: 18px;
  margin-bottom: 4px;
}

/* ── Card header row ── */

.card-back-row {
  display: flex;
  align-items: center;
  margin-bottom: 18px;
}


.card-title {
  flex: 1;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ── Playback controls ── */

.ctrl-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
  color: var(--text);
  background: #f0ece4;
  width: 42px;
  height: 42px;
  box-shadow: 0 3px 0 #ddd9d0;
  transition: transform 0.1s, box-shadow 0.1s;
}
.ctrl-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #ddd9d0; }
.ctrl-btn:disabled { opacity: 0.3; pointer-events: none; }

.ctrl-btn.primary {
  width: 52px;
  height: 52px;
  background: var(--green);
  color: #fff;
  font-size: 18px;
  box-shadow: 0 4px 0 var(--green-dark);
}
.ctrl-btn.primary:active { box-shadow: 0 1px 0 var(--green-dark); }

/* ── Chunk config ── */

.chunk-label {
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

.chunk-pills {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.chunk-pill {
  flex: 1;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: #f0ece4;
  color: var(--text);
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 #ddd9d0;
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s, color 0.15s;
}
.chunk-pill:active { transform: translateY(2px); box-shadow: 0 1px 0 #ddd9d0; }

.chunk-pill.selected {
  background: var(--green);
  color: #fff;
  box-shadow: 0 3px 0 var(--green-dark);
}

.start-learn-btn {
  display: block;
  width: 100%;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 16px;
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--green-dark);
  transition: transform 0.1s, box-shadow 0.1s;
}
.start-learn-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--green-dark); }

/* ── Mic button ── */

.mic-wrap {
  text-align: center;
  margin-bottom: 12px;
}

.mic-ring-wrap {
  position: relative;
  width: 88px;
  height: 88px;
  margin: 0 auto 12px;
  cursor: pointer;
}

.mic-ring {
  position: absolute;
  top: 0; left: 0;
  width: 88px;
  height: 88px;
  transform: rotate(-90deg);
  filter: drop-shadow(0 0 4px rgba(245, 166, 35, 0.5));
  transition: filter 0.3s;
}

.mic-ring:has(.recording-ring) {
  filter: drop-shadow(0 0 4px rgba(224, 80, 80, 0.5));
}

.mic-ring-track {
  fill: none;
  stroke: rgba(0,0,0,0.08);
  stroke-width: 10;
}

.mic-ring-fill {
  fill: none;
  stroke: #f5a623;
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 226;
  stroke-dashoffset: 226;
}

.mic-pulse {
  position: absolute;
  top: 4px; left: 4px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: #fff;
  box-shadow: 0 5px 0 var(--green-dark);
  animation: micPulse 1.5s ease-in-out infinite;
  transition: transform 0.1s, box-shadow 0.1s;
}
.mic-ring-wrap:active .mic-pulse { transform: translateY(3px); box-shadow: 0 2px 0 var(--green-dark); }

@keyframes micPulse {
  0%, 100% { box-shadow: 0 5px 0 var(--green-dark), 0 0 0 0 rgba(29,158,117,0.35); }
  50%       { box-shadow: 0 5px 0 var(--green-dark), 0 0 0 16px rgba(29,158,117,0); }
}

.mic-pulse.peeking {
  background: #C8C6BE;
  box-shadow: 0 5px 0 #aaa89f;
  animation: none;
}

.mic-pulse.recording-pulse {
  background: #e05050;
  box-shadow: 0 5px 0 #a03030;
  animation: micRecording 0.8s ease-in-out infinite;
}

@keyframes micRecording {
  0%, 100% { box-shadow: 0 5px 0 #a03030, 0 0 0 0 rgba(224,80,80,0.4); }
  50%       { box-shadow: 0 5px 0 #a03030, 0 0 0 14px rgba(224,80,80,0); }
}

.mic-ring-fill.recording-ring {
  stroke: #e05050;
}

/* ── Secondary action buttons ── */

.recite-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.recite-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 9px 10px;
  white-space: nowrap;
  border-radius: 20px;
  border: none;
  background: #f0ece4;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 #ddd9d0;
  transition: transform 0.1s, box-shadow 0.1s;
}
.recite-action-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.recite-action-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #ddd9d0; }
.recite-action-btn:disabled { opacity: 0.35; cursor: default; pointer-events: none; }

.recite-now-btn {
  background: var(--green);
  color: #fff;
  box-shadow: 0 3px 0 var(--green-dark);
  font-size: 16px;
}

/* ── Feedback ── */

.feedback-actions {
  display: flex;
  gap: 10px;
}

.feedback-btn {
  flex: 1;
  padding: 10px 8px;
  border-radius: 16px;
  border: none;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}

.feedback-btn svg { flex-shrink: 0; width: 16px; height: 16px; }

.feedback-btn.next {
  background: var(--green);
  color: #fff;
  box-shadow: 0 4px 0 var(--green-dark);
}
.feedback-btn.next:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--green-dark); }

.feedback-btn.retry {
  background: #f0ece4;
  color: var(--text);
  box-shadow: 0 4px 0 #ddd9d0;
}
.feedback-btn.retry:active { transform: translateY(3px); box-shadow: 0 1px 0 #ddd9d0; }
