/* ── Speaking overlay styles ── */
/* Adapted from today.atomic.community, scoped under .speaking-overlay */

/* ── Overlay ── */

.speaking-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: transparent;
  pointer-events: none;
  opacity: 0;
}

.speaking-overlay.is-active {
  pointer-events: auto;
  opacity: 1;
}

.speaking-overlay.is-leaving {
  pointer-events: none;
  opacity: 0;
  transition: opacity 360ms ease;
}

body.speaking-open .container {
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms ease;
}

body.speaking-open .promo-pill {
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms ease;
}

/* ── Card (same dimensions as quiz) ── */

.speaking-card {
  position: relative;
  width: min(500px, calc(100vw - 40px));
  height: calc(100dvh - 40px);
  min-height: 0;
  overflow: hidden;
  border-radius: 18px;
  background: radial-gradient(ellipse farthest-side at 25% 20%, #f8f0fa 0%, #eceeff 30%, #eceeff 50%, #f8f0fa 80%);
  box-shadow: 0 4px 24px rgba(8, 0, 138, 0.18), 0 0 0 1px rgba(8, 0, 138, 0.08);
  margin: 20px;
  transform: translateX(calc(100vw + 100px));
  transition: transform 420ms cubic-bezier(0.4, 0, 0.2, 1);
  font-family: 'Newsreader', serif;
  color: #211d18;
}

.speaking-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 18px;
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(170, 180, 195, 0.06) 3px, rgba(170, 180, 195, 0.06) 4px),
    repeating-linear-gradient(90deg, transparent, transparent 3px, rgba(170, 180, 195, 0.06) 3px, rgba(170, 180, 195, 0.06) 4px);
  z-index: 0;
}

.speaking-overlay.is-active .speaking-card {
  transform: translateX(0);
}

.speaking-overlay.is-leaving .speaking-card {
  transform: translateX(calc(100vw + 100px));
}

/* ── Close button ── */

.speaking-close {
  position: fixed;
  top: 12px;
  left: calc(50% - min(500px, calc(100vw - 40px)) / 2 - 8px);
  z-index: 60;
  width: 40px;
  height: 40px;
  border: 1.5px solid rgba(8, 0, 138, 0.15);
  background: #fdfaf6;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: #6f737a;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 150ms ease, border-color 150ms ease, opacity 200ms ease;
  box-shadow: 0 2px 8px rgba(8, 0, 138, 0.1);
}

.speaking-close:hover {
  background: #fff;
  border-color: rgba(8, 0, 138, 0.3);
}

body.speaking-panel-open .speaking-close {
  opacity: 0;
  pointer-events: none;
}

.speaking-back {
  position: fixed;
  top: 12px;
  left: calc(50% - min(500px, calc(100vw - 40px)) / 2 - 8px);
  z-index: 60;
  width: 40px;
  height: 40px;
  border: 1.5px solid rgba(8, 0, 138, 0.15);
  background: #fdfaf6;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  color: #6f737a;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(8, 0, 138, 0.1);
  transition: background 150ms ease, opacity 200ms ease;
  opacity: 0;
  pointer-events: none;
}

.speaking-back:hover {
  background: #fff;
}

body.speaking-panel-open .speaking-back {
  opacity: 1;
  pointer-events: auto;
}

/* ── Hub view (homepage) ── */

.speaking-hub {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px 40px;
}

.speaking-hub::-webkit-scrollbar { display: none; }

.speaking-hub.is-hidden {
  display: none;
}

.speaking-course-label {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 0.85rem;
  font-weight: 400;
  color: #05007A;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.speaking-journal-heading {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #05007A;
  margin: 0 0 48px;
  line-height: 1;
  text-align: center;
}

.speaking-sticky-board {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.speaking-sticky-note {
  position: relative;
  width: min(300px, calc(100vw - 48px));
  padding: 36px 32px 32px;
  background: rgba(253, 250, 246, 0.6);
  border: none;
  border-radius: 3px;
  box-shadow: 2px 3px 14px rgba(0, 0, 0, 0.06);
  cursor: pointer;
  transition: transform 280ms ease, box-shadow 280ms ease, border 300ms ease, background 300ms ease;
  user-select: none;
  text-align: center;
}

.speaking-sticky-note.is-done {
  background: rgba(253, 250, 246, 0.85);
  border: 1px solid rgba(5, 0, 122, 0.3);
  box-shadow: 0 0 0 2px rgba(5, 0, 122, 0.12), 0 3px 14px rgba(0, 0, 0, 0.06);
}

.speaking-sticky-note:first-child { transform: rotate(-1.2deg); }
.speaking-sticky-note:nth-child(3) { transform: rotate(0.6deg); }
.speaking-sticky-note:last-child { transform: rotate(-0.8deg); }
.speaking-sticky-note:hover { transform: rotate(0deg) translateY(-4px); box-shadow: 3px 6px 22px rgba(0, 0, 0, 0.1); }

.speaking-sticky-icon {
  display: block;
  font-size: 1.4rem;
  color: #05007A;
  text-align: center;
  margin-bottom: 4px;
}

.speaking-sticky-title {
  font-family: 'Archivo Black', sans-serif;
  font-size: 1.1rem;
  font-weight: 400;
  color: #05007A;
  margin: 10px 0 0;
  letter-spacing: -0.01em;
  text-align: center;
}

.speaking-sticky-label {
  position: absolute;
  top: -12px;
  right: -16px;
  z-index: 2;
  padding: 6px 12px;
  background: #fff;
  border: 1.5px solid #d8d1f5;
  border-radius: 8px;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: #05007A;
  transform: rotate(3deg);
  box-shadow: 2px 3px 0 rgba(94, 76, 190, 0.10);
  white-space: nowrap;
}

.speaking-sticky-label.pulse {
  animation: speakingLabelPulse 700ms ease;
}

@keyframes speakingLabelPulse {
  0%, 100% { opacity: 0.5; transform: rotate(3deg) scale(1); }
  50% { opacity: 1; transform: rotate(3deg) scale(1.15); }
}

.speaking-schedule-btn {
  margin-top: 32px;
  padding: 14px 28px;
  background: var(--purple, #05007A);
  border: none;
  border-radius: 10px;
  font-family: 'Archivo Black', sans-serif;
  font-size: 0.95rem;
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 500ms ease, transform 500ms ease;
}

.speaking-schedule-btn.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.speaking-schedule-btn:hover {
  opacity: 0.9;
}

.speaking-sticky-connector {
  width: 2px;
  height: 36px;
  background: repeating-linear-gradient(to bottom, #6f737a 0px, #6f737a 4px, transparent 4px, transparent 9px);
  opacity: 0.3;
  margin: -2px 0;
}

/* ── Task panels (flex column, slide in from right) ── */

.speaking-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 18px;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 380ms cubic-bezier(0.4, 0, 0.2, 1), visibility 0s 380ms;
  will-change: transform;
}

.speaking-panel.is-open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 380ms cubic-bezier(0.4, 0, 0.2, 1), visibility 0s 0s;
  z-index: 5;
}

.speaking-panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  position: relative;
}

.speaking-panel-body::-webkit-scrollbar { display: none; }

/* ── Voice panel ── */

.speaking-voice-panel {
  background: linear-gradient(160deg, #f5f0eb 0%, #ede8f5 50%, #e8f0f2 100%);
}

.speaking-voice-section {
  max-width: 640px;
  margin: 0 auto;
  padding: 40px 32px 200px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.speaking-transcript {
  font-size: clamp(1.35rem, 3.2vw, 1.65rem);
  line-height: 1.55;
  margin-bottom: 40px;
  letter-spacing: -0.005em;
  font-weight: 400;
}

.speaking-word {
  color: rgba(33, 29, 24, 0.24);
  transition: color 180ms ease;
  cursor: default;
}

.speaking-word.spoken { color: rgba(33, 29, 24, 0.95); }
.speaking-word.current { color: #211d18; }
.speaking-word.is-target {
  background: linear-gradient(to top, rgba(8, 0, 138, 0.15) 0 45%, transparent 45%);
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 500;
}

.speaking-word.is-target.spoken {
  background: linear-gradient(to top, rgba(8, 0, 138, 0.25) 0 45%, transparent 45%);
}

.speaking-voice-back-link {
  display: block;
  margin: 0 auto;
  border: 0;
  background: transparent;
  color: #6f737a;
  font-family: 'Newsreader', serif;
  font-size: 0.95rem;
  font-style: italic;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(23, 24, 25, 0.15);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.25em;
  padding: 0 12px;
  opacity: 0;
  pointer-events: none;
  max-height: 0;
  overflow: hidden;
  transition: opacity 400ms ease 0.5s, max-height 400ms ease 0.5s, padding 400ms ease 0.5s, margin 400ms ease 0.5s;
}

.speaking-voice-back-link.is-visible {
  opacity: 1;
  pointer-events: auto;
  max-height: 60px;
  padding: 8px 12px;
  margin: 40px auto 20px;
}

/* ── Player bar (outside scroll area, absolute at bottom) ── */

.speaking-player-bar {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: none;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  width: min(460px, calc(100vw - 80px));
  padding: 12px 18px;
  background: #fdfaf6;
  border: 1px solid rgba(170, 180, 195, 0.2);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  z-index: 10;
}

.speaking-player-bar.is-visible {
  display: grid;
}

.speaking-play-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid rgba(40, 45, 52, 0.72);
  background: transparent;
  color: #211d18;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.speaking-play-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.speaking-timeline {
  height: 2px;
  background: rgba(60, 65, 72, 0.18);
  overflow: hidden;
  opacity: 0.3;
}

.speaking-timeline-progress {
  height: 100%;
  background: #211d18;
  width: 0;
  transition: width 100ms linear;
}

.speaking-time {
  font-family: 'Poppins', sans-serif;
  font-size: 0.7rem;
  font-weight: 500;
  color: #6f737a;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
}

/* ── Story panel ── */

.speaking-story-panel {
  background: linear-gradient(160deg, #f5f0eb 0%, #ede8f5 50%, #e8f0f2 100%);
}

.speaking-story-fade-top {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(to bottom, #f5f0eb, transparent);
  z-index: 10;
  pointer-events: none;
  margin-bottom: -40px;
  flex-shrink: 0;
}

.speaking-story-chat {
  width: 100%;
  padding: 20px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.speaking-chat-bubble {
  padding: 12px 16px;
  border-radius: 20px;
  font-family: 'Albert Sans', sans-serif;
  font-size: 16px;
  line-height: 1.55;
  letter-spacing: -0.01em;
  word-break: break-word;
  animation: speakingBubbleIn 300ms ease both;
}

.speaking-chat-bubble.teacher {
  align-self: flex-start;
  max-width: 80%;
  background: #F3F0FF;
  color: #211d18;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 14px 18px;
}

.speaking-chat-bubble.user {
  align-self: flex-end;
  max-width: 65%;
  background: #2c3e50;
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 10px 16px;
}

.speaking-chat-bubble img {
  display: block;
  max-width: 100%;
  max-height: 50vh;
  object-fit: contain;
  border-radius: 12px;
  margin-top: 4px;
}

.speaking-chat-bubble.image-only { padding: 4px !important; }
.speaking-chat-bubble.image-only img { margin-top: 0; border-radius: 12px; }

.speaking-chat-bubble.celeb-gif {
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  padding: 4px !important;
  width: 30%;
  align-self: flex-start;
}

.speaking-chat-bubble.celeb-gif img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  margin-top: 0;
}

/* ── Answer bar (outside scroll area, fixed at bottom) ── */

.speaking-answer-bar {
  position: relative;
  padding: 0 16px;
  background: rgba(245, 240, 235, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(170, 180, 195, 0.15);
  border-radius: 0 0 18px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  flex-shrink: 0;
  height: 72px;
}

.speaking-answer-btn {
  padding: 12px 24px;
  border: 1.5px solid rgba(44, 62, 80, 0.25);
  border-radius: 28px;
  background: white;
  font-family: 'Albert Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: #211d18;
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, transform 120ms ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.speaking-answer-btn:hover {
  border-color: #2c3e50;
  background: rgba(44, 62, 80, 0.04);
}

.speaking-answer-btn:active { transform: scale(0.97); }
.speaking-answer-btn.is-correct { background: #2c3e50; color: white; border-color: #2c3e50; }
.speaking-answer-btn.is-wrong { animation: speakingShake 400ms ease; }
.speaking-answer-btn.is-single { background: #2c3e50; color: white; border-color: #2c3e50; }

.speaking-refresh-btn {
  width: 36px;
  height: 36px;
  border: 1.5px solid rgba(44, 62, 80, 0.25);
  border-radius: 50%;
  background: white;
  color: #211d18;
  font-size: 16px;
  cursor: pointer;
  display: none;
  place-items: center;
  flex-shrink: 0;
}

.speaking-refresh-btn.is-visible { display: grid; }

/* ── Animations ── */

body:not(.ready) .speaking-sticky-check { transition: none !important; }

.speaking-sticky-note.just-done {
  animation: speakingDoneReveal 500ms ease both;
}

@keyframes speakingDoneReveal {
  0% { box-shadow: 2px 3px 14px rgba(0, 0, 0, 0.06); }
  100% { box-shadow: 0 0 0 2px rgba(5, 0, 122, 0.12), 0 3px 14px rgba(0, 0, 0, 0.06); }
}

@keyframes speakingBubbleIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes speakingShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes speakingGentleFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Reduced motion ── */

@media (prefers-reduced-motion: reduce) {
  .speaking-card,
  .speaking-panel,
  .speaking-chat-bubble {
    transition: none !important;
    animation: none !important;
  }
}
