:root {
  --bg: #0d0d1a;
  --surface: #15152e;
  --raised: #1e1e3f;
  --border: #2e2e5e;
  --primary: #a78bfa;
  --primary-d: #7c5cf6;
  --correct: #34d399;
  --wrong: #f87171;
  --text: #e2e8f0;
  --muted: #8892a4;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  min-height: 100dvh;
  line-height: 1.4;
}

/* ── Shell ──────────────────────────────────────────────────────────────── */
.game-shell {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header rules live in header.css (shared across all games). */

.btn-sm {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-sm.ghost {
  background: var(--raised);
  color: var(--muted);
  border: 1.5px solid var(--border);
}
.btn-sm.ghost:hover { color: var(--primary); border-color: var(--primary); }

/* ── Phases ─────────────────────────────────────────────────────────────── */
.phase { display: flex; flex-direction: column; gap: 20px; }
.hidden { display: none !important; }

/* ── Level picker phase ─────────────────────────────────────────────────── */
.level-cards {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.level-card {
  flex: 1;
  min-width: 140px;
  max-width: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 28px 20px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.level-card:hover {
  border-color: var(--primary);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(124, 92, 246, 0.25);
}
.level-card:active {
  transform: translateY(0);
}

.level-card-num {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}
.level-card-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
}
.level-card-desc {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

/* ── Arrange phase ──────────────────────────────────────────────────────── */
.phase-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
  padding: 0 8px;
}

.record-intro {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 16px 20px;
  color: var(--text);
}
.record-intro-title {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--primary);
}
.record-intro-steps {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--muted);
}
.record-intro-steps strong { color: var(--text); }

.word-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  padding: 4px 0;
}

.word-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 14px 18px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.word-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(124, 92, 246, 0.25);
}
.word-card:active { cursor: grabbing; }
.word-card.dragging { opacity: 0.25; }
.word-card.drag-over {
  border-color: var(--correct);
  transform: translateY(-4px) scale(1.04);
  box-shadow: 0 8px 24px rgba(52, 211, 153, 0.3);
}

.card-num {
  width: 24px;
  height: 24px;
  background: var(--raised);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--muted);
  flex-shrink: 0;
}
.card-word {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 0.02em;
}
.card-drag {
  font-size: 1rem;
  color: var(--border);
  flex-shrink: 0;
  letter-spacing: -1px;
}

/* ── Primary / Stop buttons ──────────────────────────────────────────────── */
.btn-primary,
.btn-stop {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary {
  background: var(--primary-d);
  color: #fff;
  box-shadow: 0 4px 18px rgba(124, 92, 246, 0.4);
}
.btn-primary:hover {
  background: var(--primary);
  box-shadow: 0 6px 26px rgba(124, 92, 246, 0.55);
  transform: translateY(-1px);
}
.btn-stop {
  background: var(--wrong);
  color: #fff;
  box-shadow: 0 4px 16px rgba(248, 113, 113, 0.4);
  animation: pulse-red 1.6s ease-in-out infinite;
}
.btn-stop:hover {
  background: #ef4444;
  transform: translateY(-1px);
  animation: none;
}

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 4px 16px rgba(248, 113, 113, 0.35); }
  50%       { box-shadow: 0 4px 28px rgba(248, 113, 113, 0.7); }
}

/* ── Recording phase ─────────────────────────────────────────────────────── */
.words-mini {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.word-chip {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  color: var(--muted);
  background: var(--raised);
  transition: all 0.25s;
}
.word-chip.used {
  background: rgba(52, 211, 153, 0.12);
  border-color: var(--correct);
  color: var(--correct);
}

.rec-status {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  align-self: flex-start;
}
.rec-status.idle  { color: var(--muted); }
.rec-status.error { color: var(--wrong); border-color: var(--wrong); }

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--wrong);
  box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.7);
  animation: rec-pulse 1.4s ease-out infinite;
}
.rec-status.idle  .rec-dot { background: var(--muted); animation: none; box-shadow: none; }
.rec-status.error .rec-dot { animation: none; }

@keyframes rec-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.6); }
  70%  { box-shadow: 0 0 0 10px rgba(248, 113, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
}

.transcript-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 130px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.box-label {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.transcript-text {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text);
  flex: 1;
}
.transcript-text mark {
  background: rgba(167, 139, 250, 0.22);
  color: var(--primary);
  border-radius: 4px;
  padding: 0 2px;
}
.transcript-interim {
  font-size: 0.92rem;
  color: var(--muted);
  font-style: italic;
  min-height: 1.4em;
}

/* Fallback textarea (browsers without SpeechRecognition) */
.fallback-textarea {
  width: 100%;
  background: var(--raised);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 12px;
  resize: vertical;
  line-height: 1.65;
  outline: none;
  transition: border-color 0.15s;
  margin-top: 4px;
}
.fallback-textarea:focus { border-color: var(--primary); }

/* ── Processing phase ────────────────────────────────────────────────────── */
.processing-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 56px 0;
  color: var(--muted);
  font-weight: 700;
  font-size: 1rem;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result phase ────────────────────────────────────────────────────────── */
.score-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.score-badge {
  font-size: 0.88rem;
  font-weight: 800;
  padding: 5px 14px;
  border-radius: 999px;
  margin-right: 4px;
}
.score-perfect { background: rgba(52, 211, 153, 0.18); color: var(--correct); }
.score-good    { background: rgba(167, 139, 250, 0.18); color: var(--primary); }
.score-ok      { background: rgba(248, 113, 113, 0.18); color: var(--wrong); }

.score-word {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1.5px solid;
}
.score-word.hit  { color: var(--correct); border-color: var(--correct); background: rgba(52, 211, 153, 0.08); }
.score-word.miss { color: var(--wrong);   border-color: var(--wrong);   background: rgba(248, 113, 113, 0.08); }

.story-image-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}
.story-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.final-transcript {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .word-card { padding: 12px 14px; }
  .card-word { font-size: 1.05rem; }
  .btn-primary, .btn-stop { font-size: 0.97rem; padding: 14px; }
}
