:root {
  --color-bg: #f0f7ff;
  --color-surface: #ffffff;
  --color-primary: #4f46e5;
  --color-success: #16a34a;
  --color-error: #dc2626;
  --color-warning: #d97706;
  --color-text: #1e1b4b;
  --color-text-muted: #6b7280;
  
  --font-body: 'Nunito', sans-serif;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

.dark-mode {
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-text: #f8fafc;
  --color-text-muted: #94a3b8;
  --color-primary: #6366f1;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
}

#app-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  transition: max-width 0.3s ease;
}

body.viewing-leaderboard #app-container {
  max-width: 1024px;
}

/* Header & Controls */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.header-controls {
  display: flex;
  gap: 0.5rem;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  border-radius: var(--radius-full);
  transition: all 0.2s;
  font-weight: 700;
}

.btn-icon {
  background: var(--color-surface);
  color: var(--color-text);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.btn-icon:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
}

.btn-primary {
  background: var(--color-primary);
  color: white;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  box-shadow: var(--shadow-md);
}

.btn-primary:active {
  transform: scale(0.95);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Screens */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  animation: fadeInUp 0.25s ease-out;
}

.screen.active {
  display: flex;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Welcome Screen */
.logo-container {
  text-align: center;
  margin-bottom: 2rem;
}

.logo-container h1 {
  font-size: 2rem;
  color: var(--color-primary);
  margin-top: 1rem;
}

.welcome-card {
  background: var(--color-surface);
  padding: 2rem;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.username-list {
  list-style: none;
  margin: 1.5rem 0;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--color-text-muted);
  border-radius: 0.5rem;
  padding: 0.5rem;
}

.username-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  background: var(--color-bg);
  cursor: pointer;
  transition: background 0.2s;
}

.username-item:hover, .username-item.selected {
  background: var(--color-primary);
  color: white;
}

.username-item.selected .btn-icon-small {
  color: white;
}

.btn-icon-small {
  background: transparent;
  color: var(--color-text-muted);
  width: 32px;
  height: 32px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
}
.btn-icon-small:hover {
  background: rgba(0,0,0,0.1);
  color: var(--color-text);
}

.new-user-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

input[type="text"] {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid var(--color-text-muted);
  border-radius: var(--radius-full);
  font-family: var(--font-body);
  font-size: 1rem;
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
}

input[type="text"]:focus {
  border-color: var(--color-primary);
}

/* Menus */
.menu-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 2rem;
}

@media (min-width: 640px) {
  .menu-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.menu-card {
  background: var(--color-surface);
  padding: 1.5rem;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  border: 2px solid transparent;
}

.menu-card:hover {
  transform: scale(1.03);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-primary);
}

.menu-card-emoji {
  font-size: 3rem;
}

.menu-card h3 {
  font-size: 1.25rem;
}
.menu-card p {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* Quiz Screen */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-weight: bold;
}

.progress-container {
  width: 100%;
  height: 12px;
  background: var(--color-surface);
  border-radius: var(--radius-full);
  margin-bottom: 2rem;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.progress-bar {
  height: 100%;
  background: var(--color-primary);
  width: 0%;
  transition: width 0.4s ease;
}

.question-card {
  background: var(--color-surface);
  padding: 2rem;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  text-align: center;
  margin-bottom: 2rem;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.question-text {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  font-weight: 800;
}

.question-subtext {
  font-size: clamp(0.9rem, 2.5vw, 1.2rem);
  font-weight: 600;
  color: var(--color-text-muted);
  margin-top: 0.5rem;
  animation: slideInLeft 0.3s ease-out 0.15s both;
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

.question-illustration {
  margin-top: 1rem;
  font-size: 2rem;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.question-illustration.large-emoji {
  font-size: clamp(4rem, 15vw, 7rem);
  margin-bottom: 1rem;
}

.answers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.answers-grid.grid-3 {
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .answers-grid.grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.answer-btn {
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1.2rem;
  min-height: 60px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  border: 2px solid transparent;
}

.answer-btn:hover:not(:disabled) {
  border-color: var(--color-primary);
  transform: scale(1.02);
}

.answer-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.answer-btn.correct {
  background: var(--color-success);
  color: white;
  animation: pulse 0.5s;
}

.answer-btn.wrong {
  background: var(--color-error);
  color: white;
  animation: shake 0.4s;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.feedback-msg {
  text-align: center;
  font-weight: bold;
  margin-top: 1.5rem;
  font-size: 1.2rem;
  min-height: 1.8rem;
}

.feedback-msg.correct-msg { color: var(--color-success); }
.feedback-msg.wrong-msg { color: var(--color-error); }

.fill-gap {
  font-weight: bold;
  color: var(--color-primary);
}

.hyphen-highlight {
  color: var(--color-primary);
  font-weight: 900;
  margin: 0 0.15rem;
}

/* Results Screen */
.results-card {
  background: var(--color-surface);
  padding: 3rem 2rem;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.results-icon {
  font-size: 5rem;
  margin-bottom: 1rem;
  animation: spinIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes spinIn {
  from { transform: scale(0) rotate(-180deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

.results-score {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--color-primary);
  margin: 1rem 0;
}

.results-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 2rem;
}

/* Leaderboard */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.leaderboard-table th, .leaderboard-table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-text-muted);
}

.leaderboard-table th {
  background: var(--color-primary);
  color: white;
  font-weight: 700;
}

.leaderboard-row.current-user {
  background: rgba(79, 70, 229, 0.1);
  font-weight: bold;
  animation: gentlePulse 2s infinite;
}

.dark-mode .leaderboard-row.current-user {
  background: rgba(99, 102, 241, 0.2);
}

@keyframes gentlePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background: var(--color-surface);
  padding: 2rem;
  border-radius: var(--radius-xl);
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  transform: scale(0.9);
  transition: transform 0.2s;
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 1.5rem;
}

.btn-danger {
  background: var(--color-error);
  color: white;
  padding: 0.5rem 1rem;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}

/* Utilities */
.hidden {
  display: none !important;
}

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 2rem; }
.text-center { text-align: center; }
