/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #1a1a2e;
  --surface:   #16213e;
  --card:      #0f3460;
  --accent:    #e94560;
  --accent2:   #f5a623;
  --accent3:   #4db8ff;
  --text:      #eaeaea;
  --text-dim:  #8a8a9a;
  --radius:    10px;
  --font-jp:   'Noto Serif JP', Georgia, serif;
  --font-ui:   'Segoe UI', system-ui, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Header ── */
header {
  width: 100%;
  background: var(--surface);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--accent3);
}

header h1 {
  font-family: var(--font-jp);
  font-size: 1.6rem;
  color: var(--accent3);
  letter-spacing: 0.05em;
}

header .subtitle {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 2px;
}

header .header-site-link {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-decoration: none;
  opacity: 0.7;
  transition: opacity 0.15s;
}
header .header-site-link:hover { opacity: 1; color: var(--accent3); }

/* ── Volume slider ── */
.volume-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.volume-control label {
  font-size: 1rem;
  line-height: 1;
}

.volume-control input[type="range"] {
  -webkit-appearance: none;
  width: 120px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent3);
  outline: none;
  opacity: 0.7;
  transition: opacity 0.15s;
  cursor: pointer;
}

.volume-control input[type="range"]:hover { opacity: 1; }

.volume-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent3);
  cursor: pointer;
}

.volume-control input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent3);
  border: none;
  cursor: pointer;
}

/* ── Main container ── */
main {
  width: 100%;
  max-width: 760px;
  padding: 2rem 1.5rem;
  flex: 1;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.8rem;
  margin-bottom: 1.5rem;
  border: 1px solid rgba(255,255,255,0.06);
}

/* ── Intro section ── */
.intro-section {
  margin-bottom: 1.5rem;
  text-align: center;
}

.intro-blurb {
  font-size: 1rem;
  color: var(--text-dim);
  line-height: 1.7;
  max-width: 580px;
  margin: 0 auto 1rem;
}

.feature-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.pill {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ── How it works ── */
.how-it-works {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.4rem 1.8rem;
  margin-bottom: 1.5rem;
  border: 1px solid rgba(255,255,255,0.06);
}

.how-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

.steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.step {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.step-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  background: var(--accent3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  margin-top: 1px;
}

.step-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.step-body strong {
  font-size: 0.95rem;
  color: var(--text);
}

.step-body span {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ── Form elements ── */
.form-group {
  margin-bottom: 1.4rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

select, input[type="text"], input[type="number"] {
  width: 100%;
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
  padding: 0.6rem 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

select:focus, input:focus {
  border-color: var(--accent3);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1.4rem;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent3);
  color: #0a0a1a;
  font-weight: 700;
}

.btn-secondary {
  background: var(--card);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.15);
}

.btn-primary:hover:not(:disabled) { opacity: 0.88; }
.btn-secondary:hover:not(:disabled) { opacity: 0.85; }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: rgba(255,255,255,0.4); }

/* ── Big play button ── */
.btn-play {
  background: var(--accent3);
  color: #0a0a1a;
  font-weight: 700;
  font-size: 1.25rem;
  padding: 1rem 2.5rem;
  border-radius: 50px;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 0 24px rgba(77, 184, 255, 0.3);
  min-width: 160px;
  justify-content: center;
}

.btn-play:hover:not(:disabled) {
  opacity: 0.9;
  box-shadow: 0 0 36px rgba(77, 184, 255, 0.5);
}

.btn-play:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

.btn-play.playing {
  background: var(--accent2);
  box-shadow: 0 0 24px rgba(245, 166, 35, 0.4);
}

.player-nav {
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
}

/* ── Loading spinner ── */
#loading {
  display: none;
  text-align: center;
  padding: 3rem 0;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(77, 184, 255, 0.2);
  border-top-color: var(--accent3);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error / warning ── */
.error-msg {
  background: rgba(233,69,96,0.15);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.8rem 1rem;
  color: #ff8fa0;
  font-size: 0.9rem;
  margin-top: 1rem;
  display: none;
}

.tts-warning {
  background: rgba(245,166,35,0.12);
  border: 1px solid var(--accent2);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  color: var(--accent2);
  font-size: 0.9rem;
  margin-bottom: 1.2rem;
}

/* ══════════════════════════════════
   LISTEN PAGE
══════════════════════════════════ */

.story-title {
  font-family: var(--font-jp);
  font-size: 1.5rem;
  color: var(--accent3);
  margin-bottom: 0.3rem;
}

.story-title-en {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 1.8rem;
}

/* ── Progress bar ── */
.progress-bar-wrap {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  margin-bottom: 0.5rem;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent3);
  border-radius: 2px;
  transition: width 0.4s ease;
  width: 0%;
}

.sentence-counter {
  font-size: 0.78rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 1.5rem;
  text-align: center;
}

/* ── Waveform animation ── */
.audio-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 60px;
  margin-bottom: 1.5rem;
}

.wave-bar {
  width: 5px;
  background: var(--accent3);
  border-radius: 3px;
  height: 8px;
  opacity: 0.35;
  transition: height 0.1s ease, opacity 0.2s;
}

.audio-visual.playing .wave-bar {
  opacity: 1;
  animation: wave 0.8s ease-in-out infinite alternate;
}

.audio-visual.playing .wave-bar:nth-child(1) { animation-delay: 0s;    animation-duration: 0.7s; }
.audio-visual.playing .wave-bar:nth-child(2) { animation-delay: 0.1s;  animation-duration: 0.9s; }
.audio-visual.playing .wave-bar:nth-child(3) { animation-delay: 0.05s; animation-duration: 0.6s; }
.audio-visual.playing .wave-bar:nth-child(4) { animation-delay: 0.15s; animation-duration: 1.0s; }
.audio-visual.playing .wave-bar:nth-child(5) { animation-delay: 0.08s; animation-duration: 0.75s;}
.audio-visual.playing .wave-bar:nth-child(6) { animation-delay: 0.2s;  animation-duration: 0.85s;}
.audio-visual.playing .wave-bar:nth-child(7) { animation-delay: 0.03s; animation-duration: 0.65s;}

@keyframes wave {
  from { height: 8px; }
  to   { height: 44px; }
}

/* ── Player controls ── */
.player-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.8rem;
}

/* ── Reveal area ── */
.reveal-area {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  margin-bottom: 1rem;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.6rem;
}

.sentence-en-reveal {
  font-size: 0.95rem;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.5;
}

.reveal-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.3rem;
}

.reveal-btn {
  font-size: 0.82rem;
  padding: 0.35rem 0.85rem;
}

.listen-hint {
  font-size: 0.82rem;
  color: var(--text-dim);
  text-align: center;
  font-style: italic;
  margin-bottom: 0.5rem;
}

/* ── Nav buttons ── */
.story-nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

/* ══════════════════════════════════
   QUIZ SECTION
══════════════════════════════════ */

#quiz-section {
  margin-top: 2rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 1.5rem;
  display: none;
}

#quiz-section.visible { display: block; }

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.quiz-header h3 {
  font-family: var(--font-jp);
  font-size: 1.1rem;
  color: var(--accent2);
}

.quiz-score {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.quiz-score span {
  color: var(--accent2);
  font-weight: 700;
}

.session-score {
  font-size: 0.78rem;
  color: var(--text-dim);
  text-align: right;
}

/* Question */
.quiz-question {
  margin-bottom: 1rem;
}

.quiz-question-text {
  font-family: var(--font-jp);
  font-size: 1.15rem;
  line-height: 1.7;
  margin-bottom: 0.9rem;
  color: var(--text);
}

.quiz-question-num {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.4rem;
}

/* Choice buttons */
.quiz-choices {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.choice-btn {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-jp);
  font-size: 1rem;
  padding: 0.7rem 1rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  line-height: 1.5;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--accent3);
  background: rgba(77,184,255,0.1);
}

.choice-btn.correct {
  border-color: #4caf50;
  background: rgba(76,175,80,0.15);
  color: #a5d6a7;
}

.choice-btn.wrong {
  border-color: var(--accent);
  background: rgba(233,69,96,0.15);
  color: #ff8fa0;
}

.choice-btn:disabled { cursor: default; }

/* Explanation */
.quiz-explanation {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 0.7rem;
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--accent2);
  display: none;
}

.quiz-explanation.visible { display: block; }

/* Next / result buttons */
.quiz-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Final result */
.quiz-result {
  text-align: center;
  padding: 1.2rem 0 0.5rem;
  display: none;
}

.quiz-result.visible { display: block; }

.quiz-result-score {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent3);
  line-height: 1;
  margin-bottom: 0.4rem;
}

.quiz-result-label {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

/* Footer */
footer {
  width: 100%;
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  border-top: 1px solid rgba(255,255,255,0.05);
  margin-top: auto;
}

/* ══════════════════════════════════
   CLICKABLE TOKENS (revealed text)
══════════════════════════════════ */

/* Revealed sentence renders as flex token row */
.sentence-jp-reveal {
  display: none;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 2px;
  line-height: 2.4;
}

.sentence-jp-reveal.visible { display: flex; }

/* Individual word token */
.token {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 2px 3px;
  border-radius: 4px;
  transition: background 0.15s;
  position: relative;
}

.token:hover  { background: rgba(77,184,255,0.18); }
.token.active { background: rgba(77,184,255,0.30); }

.token-furigana {
  font-size: 0.72rem;
  color: var(--accent2);
  min-height: 0.85rem;
  line-height: 1;
  margin-bottom: -2px;
  /* always visible once text is revealed */
  transition: opacity 0.2s;
}

/* Furigana hidden state */
.furigana-hidden .token-furigana {
  opacity: 0;
  pointer-events: none;
}

.token-word {
  font-family: var(--font-jp);
  font-size: 1.4rem;
}

/* Word popup tooltip */
.word-popup {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--accent3);
  border-radius: 6px;
  padding: 0.45rem 0.75rem;
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--text);
  font-family: var(--font-ui);
  z-index: 20;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.word-popup::after {
  content: '';
  position: absolute;
  top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--accent3);
}

.word-popup .pop-reading {
  color: var(--accent2);
  font-size: 0.75rem;
  margin-bottom: 2px;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  header h1 { font-size: 1.2rem; }
  .token-word { font-size: 1.15rem; }
  .btn-play { font-size: 1.1rem; padding: 0.85rem 1.8rem; }
}
