:root {
  --primary: #4F46E5;
  --primary-dark: #3730A3;
  --secondary: #06B6D4;
  --accent: #F59E0B;
  --math-color: #059669;
  --english-color: #7C3AED;
  --mixed-color: #EC4899;
  --bg-main: #F8FAFC;
  --card-bg: #FFFFFF;
  --text-main: #0F172A;
  --text-muted: #475569;
  --success: #10B981;
  --danger: #EF4444;
  --border-color: #E2E8F0;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', sans-serif;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* App Header */
header {
  background: var(--card-bg);
  border-bottom: 2px solid var(--border-color);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.03);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Nunito', sans-serif;
  font-weight: 900;
  font-size: 1.4rem;
  color: var(--primary);
  cursor: pointer;
}

.brand-badge {
  background: #EEF2FF;
  color: var(--primary);
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 8px;
  font-weight: 700;
}

/* Screen Management */
.screen {
  display: none;
  flex: 1;
  padding: 20px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* UI Cards & Buttons */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.08);
  border: 1px solid var(--border-color);
  margin-bottom: 16px;
}

h1, h2, h3 {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
}

.btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px 24px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--primary-dark);
  transition: all 0.1s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--primary-dark);
}

.btn-secondary {
  background: #F1F5F9;
  color: var(--text-main);
  box-shadow: 0 4px 0 #CBD5E1;
}

.btn-secondary:active {
  box-shadow: 0 1px 0 #CBD5E1;
}

/* Intro Screen */
.intro-hero {
  text-align: center;
  padding: 30px 10px;
}

.intro-title {
  font-size: 2.8rem;
  color: var(--primary);
  margin-bottom: 10px;
}

.intro-sub {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-bottom: 24px;
}

.mode-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.mode-card {
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.mode-card:hover, .mode-card.selected {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.mode-card.math { border-top: 6px solid var(--math-color); }
.mode-card.english { border-top: 6px solid var(--english-color); }
.mode-card.mixed { border-top: 6px solid var(--mixed-color); }

.difficulty-group {
  display: flex;
  gap: 8px;
  margin-top: 15px;
}

.diff-chip {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.diff-chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* How to Play Section Styles */
.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin: 16px 0;
}

.guide-item {
  background: #F8FAFC;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.guide-icon {
  font-size: 1.8rem;
  background: white;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

/* Board & HUD */
.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  margin-bottom: 16px;
  gap: 10px;
  flex-wrap: wrap;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.95rem;
}

.board-container {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  aspect-ratio: 1;
  max-width: 550px;
  margin: 0 auto 20px auto;
  width: 100%;
}

.tile {
  background: white;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  position: relative;
  font-weight: 800;
  transition: all 0.2s;
}

.tile.path { border-color: #A5B4FC; background: #EEF2FF; }
.tile.start { background: #D1FAE5; border-color: var(--math-color); }
.tile.finish { background: #FCE7F3; border-color: var(--mixed-color); }

.player-token {
  position: absolute;
  width: 28px;
  height: 28px;
  background: var(--accent);
  border: 2px solid white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  box-shadow: 0 4px 6px rgba(0,0,0,0.2);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 10;
}

.controls-panel {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
}

.dice-box {
  font-size: 2rem;
  width: 60px;
  height: 60px;
  background: white;
  border: 2px solid var(--border-color);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 0 #CBD5E1;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.2);
  animation: popIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.answers-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 16px;
}

.answer-btn {
  background: #F8FAFC;
  border: 2px solid var(--border-color);
  padding: 14px;
  border-radius: var(--radius-md);
  text-align: left;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.answer-btn:hover {
  border-color: var(--primary);
  background: #EEF2FF;
}

/* Leaderboard Table */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

.leaderboard-table th, .leaderboard-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.leaderboard-table th {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Mobile Tweaks */
@media (max-width: 480px) {
  .intro-title { font-size: 2.1rem; }
  .board-container { gap: 4px; }
  .tile { font-size: 0.9rem; border-radius: 8px; }
  .hud { font-size: 0.8rem; }
  .btn { width: 100%; }
}