@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  --font-main: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  
  /* Color Palette */
  --bg-dark: #090d16;
  --bg-gradient: radial-gradient(circle at 50% 0%, #1e1b4b 0%, #0c1021 55%, #070913 100%);
  --surface-card: rgba(22, 28, 45, 0.75);
  --surface-glass: rgba(255, 255, 255, 0.05);
  --surface-glass-hover: rgba(255, 255, 255, 0.1);
  --border-glass: rgba(255, 255, 255, 0.1);
  --border-glow: rgba(99, 102, 241, 0.4);
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #818cf8;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dark: #0f172a;
  
  /* Shadows & Radii */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-card: 0 12px 32px -4px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--border-glass);
  --shadow-glow: 0 0 24px -2px rgba(99, 102, 241, 0.45);
  --shadow-emerald: 0 0 24px -2px rgba(16, 185, 129, 0.45);
  
  /* Transitions */
  --transition-fast: 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-smooth: 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

body {
  font-family: var(--font-main);
  background: var(--bg-dark);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  position: relative;
  line-height: 1.5;
}

/* Background floating decorative ambient lights */
.ambient-glow {
  position: fixed;
  width: 550px;
  height: 550px;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(120px);
  z-index: 0;
  opacity: 0.35;
  animation: floatAmbient 18s ease-in-out infinite alternate;
}

.ambient-1 {
  top: -150px;
  left: -100px;
  background: #6366f1;
}

.ambient-2 {
  bottom: -150px;
  right: -100px;
  background: #06b6d4;
  animation-delay: -9s;
}

@keyframes floatAmbient {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(60px, 40px) scale(1.15); }
}

/* Canvas confetti on top */
#confettiCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

/* App Wrapper */
.app-container {
  width: 100%;
  max-width: 860px;
  padding: 1.5rem 1.25rem 3rem;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Header */
.app-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

.brand-text h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, #ffffff, #c7d2fe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-text p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  background: var(--surface-glass);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all var(--transition-fast);
  backdrop-filter: blur(8px);
}

.icon-btn:hover {
  background: var(--surface-glass-hover);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}

.icon-btn.active-sound {
  color: var(--accent-emerald);
}

/* Topic Selector Bar */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  background: var(--surface-card);
  backdrop-filter: blur(16px);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.topic-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topic-selector-wrapper label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.topic-select {
  background: rgba(15, 23, 42, 0.8);
  color: var(--text-main);
  border: 1px solid var(--border-glass);
  padding: 0.45rem 1rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast);
}

.topic-select:focus {
  border-color: var(--primary-light);
}

/* Stats Badges Header */
.stats-badge-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-glass);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 700;
}

.stat-chip.score-chip {
  color: var(--accent-amber);
}

.stat-chip.streak-chip {
  color: var(--accent-rose);
  animation: none;
}

.stat-chip.streak-chip.on-fire {
  animation: firePulse 1.2s infinite alternate;
  background: rgba(244, 63, 94, 0.15);
  border-color: rgba(244, 63, 94, 0.4);
}

@keyframes firePulse {
  0% { transform: scale(1); box-shadow: 0 0 6px rgba(244, 63, 94, 0.3); }
  100% { transform: scale(1.06); box-shadow: 0 0 16px rgba(244, 63, 94, 0.6); }
}

/* Navigation Mode Tabs */
.mode-tabs-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}

.mode-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 0.6rem;
  background: var(--surface-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mode-tab:hover {
  background: var(--surface-glass-hover);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.2);
}

.mode-tab.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(6, 182, 212, 0.2));
  border-color: var(--primary-light);
  color: #ffffff;
  box-shadow: 0 4px 18px rgba(99, 102, 241, 0.35);
}

/* Main Arena Container */
.game-arena {
  background: var(--surface-card);
  backdrop-filter: blur(20px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  min-height: 420px;
  position: relative;
  overflow: hidden;
}

/* Arena Progress & Timer */
.arena-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.round-info {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

.timer-wrapper {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  max-width: 280px;
}

.timer-bar-bg {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.timer-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(to right, var(--accent-emerald), var(--accent-cyan));
  border-radius: var(--radius-full);
  transition: width 0.1s linear, background-color 0.3s ease;
}

.timer-bar-fill.danger {
  background: var(--accent-rose);
}

.timer-text {
  font-size: 0.85rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
  min-width: 24px;
}

/* ======================================================== */
/* MODE 1: SPEED QUIZ STYLES                                */
/* ======================================================== */
.quiz-mode-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1.25rem;
  width: 100%;
}

.clue-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.25rem;
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.clue-emoji {
  font-size: 3.5rem;
  line-height: 1;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
  margin-bottom: 0.25rem;
  animation: floatEmoji 3s ease-in-out infinite alternate;
}

@keyframes floatEmoji {
  0% { transform: translateY(0px) rotate(0deg); }
  100% { transform: translateY(-6px) rotate(2deg); }
}

.clue-meaning {
  font-size: 1.4rem;
  font-weight: 800;
  color: #ffffff;
}

.clue-hint {
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 500px;
}

.audio-hint-btn {
  margin-top: 0.5rem;
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: var(--primary-light);
  padding: 0.45rem 1.1rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all var(--transition-fast);
}

.audio-hint-btn:hover {
  background: rgba(99, 102, 241, 0.35);
  transform: translateY(-2px);
  color: #ffffff;
}

.quiz-options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
  width: 100%;
}

.quiz-opt-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 1.1rem 1rem;
  color: var(--text-main);
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.quiz-opt-btn:hover:not(:disabled) {
  background: var(--surface-glass-hover);
  border-color: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 18px rgba(99, 102, 241, 0.25);
}

.quiz-opt-btn.correct {
  background: rgba(16, 185, 129, 0.25) !important;
  border-color: var(--accent-emerald) !important;
  color: #34d399 !important;
  box-shadow: var(--shadow-emerald);
  animation: correctBounce 0.4s ease;
}

.quiz-opt-btn.wrong {
  background: rgba(244, 63, 94, 0.25) !important;
  border-color: var(--accent-rose) !important;
  color: #fb7185 !important;
  animation: shakeAnim 0.4s ease;
}

/* ======================================================== */
/* MODE 2: WORD SCRAMBLE STYLES                             */
/* ======================================================== */
.scramble-mode-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  width: 100%;
}

.word-meaning-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 1rem 1.5rem;
  width: 100%;
  text-align: center;
}

.scramble-emoji {
  font-size: 2.2rem;
}

.meaning-detail h3 {
  font-size: 1.25rem;
  font-weight: 800;
}

.meaning-detail p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Answer Slots */
.answer-slots-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  min-height: 58px;
  padding: 0.5rem;
  margin-top: 0.5rem;
}

.slot-box {
  width: 48px;
  height: 54px;
  border-bottom: 3px solid var(--primary-light);
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: #ffffff;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.slot-box:hover {
  background: rgba(255, 255, 255, 0.1);
}

.slot-box.filled {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--accent-cyan);
}

/* Letter Bank Tiles */
.letter-bank-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-lg);
  width: 100%;
}

.tile-btn {
  width: 48px;
  height: 52px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  color: #ffffff;
  font-family: inherit;
  font-size: 1.35rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.tile-btn:hover:not(:disabled) {
  transform: translateY(-3px) scale(1.05);
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  box-shadow: var(--shadow-glow);
}

.tile-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  transform: none;
}

.scramble-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 0.5rem;
}

.action-btn {
  background: var(--surface-glass);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all var(--transition-fast);
}

.action-btn:hover {
  background: var(--surface-glass-hover);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.action-btn.submit-btn {
  background: linear-gradient(135deg, var(--accent-emerald), #059669);
  border: none;
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
}

.action-btn.submit-btn:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
}

/* ======================================================== */
/* MODE 3: MEMORY MATCH STYLES                              */
/* ======================================================== */
.memory-mode-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 1rem;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  width: 100%;
  perspective: 1000px;
}

.memory-card {
  aspect-ratio: 1 / 1;
  cursor: pointer;
  position: relative;
  border: none;
  background: transparent;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
}

.memory-card.flipped,
.memory-card.matched {
  transform: rotateY(180deg);
}

.memory-card-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  text-align: center;
  box-shadow: var(--shadow-card);
  user-select: none;
}

.card-back {
  background: linear-gradient(135deg, #1e1b4b, #0f172a);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: var(--primary-light);
  font-size: 1.8rem;
  font-weight: 800;
  transition: all var(--transition-fast);
}

.memory-card:hover .card-back {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-glow);
}

.card-front {
  background: rgba(30, 41, 59, 0.9);
  border: 2px solid var(--primary-light);
  transform: rotateY(180deg);
  color: #ffffff;
}

.memory-card.matched .card-front {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--accent-emerald);
  box-shadow: var(--shadow-emerald);
}

.card-content-icon {
  font-size: 1.6rem;
  margin-bottom: 0.2rem;
}

.card-content-text {
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.2;
  word-break: break-word;
}

/* Feedback & Shake Animations */
@keyframes correctBounce {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes shakeAnim {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.shake {
  animation: shakeAnim 0.4s ease;
}

/* ======================================================== */
/* MODAL DIALOGS (Modern @starting-style)                  */
/* ======================================================== */
dialog {
  margin: auto;
  padding: 2rem;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  color: var(--text-main);
  max-width: 480px;
  width: 90%;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  outline: none;
  
  /* Modern Top Layer Animation Transitions */
  opacity: 0;
  transform: scale(0.92);
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.28s;
  transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  transition-behavior: allow-discrete;
}

dialog[open] {
  opacity: 1;
  transform: scale(1);
  
  @starting-style {
    opacity: 0;
    transform: scale(0.92);
  }
}

dialog::backdrop {
  background-color: rgba(0, 0, 0, 0);
  transition: display 0.28s allow-discrete, overlay 0.28s allow-discrete, background-color 0.28s ease;
}

dialog[open]::backdrop {
  background-color: rgba(5, 8, 18, 0.75);
  backdrop-filter: blur(8px);
  
  @starting-style {
    background-color: rgba(0, 0, 0, 0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-header h2 {
  font-size: 1.35rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  transition: color var(--transition-fast);
}

.modal-close-btn:hover {
  color: #ffffff;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.game-over-icon {
  font-size: 3.5rem;
  text-align: center;
  margin-bottom: 0.5rem;
}

.results-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
}

.res-stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.res-stat-val {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent-cyan);
}

.res-stat-lbl {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.btn-primary {
  flex: 1;
  background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
  border: none;
  color: #ffffff;
  padding: 0.8rem 1.25rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
  transition: all var(--transition-fast);
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
}

.btn-secondary {
  background: var(--surface-glass);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  padding: 0.8rem 1.25rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-secondary:hover {
  background: var(--surface-glass-hover);
}

/* Word Pronounce Card in Feedback */
.word-detail-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin-top: 0.5rem;
}

.w-info h4 {
  font-size: 1rem;
  font-weight: 800;
  color: #ffffff;
}

.w-info span {
  font-size: 0.82rem;
  color: var(--primary-light);
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .app-container {
    padding: 1rem 0.75rem 2rem;
  }
  .quiz-options-grid {
    grid-template-columns: 1fr;
  }
  .memory-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .mode-tab {
    padding: 0.6rem 0.3rem;
    font-size: 0.78rem;
    flex-direction: column;
    gap: 0.2rem;
  }
  .slot-box {
    width: 38px;
    height: 44px;
    font-size: 1.15rem;
  }
  .tile-btn {
    width: 40px;
    height: 44px;
    font-size: 1.15rem;
  }
}
