:root {
  --bg: #f4f7fe;
  --surface: #ffffff;
  --surface-soft: #f8faff;
  --ink: #1e293b;
  --muted: #5b6b82;
  --border: #dbe4f3;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --accent: #f59e0b;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --shadow: 0 8px 24px rgba(30, 41, 59, 0.07);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #eff6ff 0%, var(--bg) 280px);
  color: var(--ink);
  min-height: 100vh;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  font-size: 2rem;
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: #1d4ed8;
}

.brand-sub {
  font-size: 0.82rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.stat-pill {
  padding: 7px 14px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  font-weight: 700;
  font-size: 0.88rem;
  border: 1px solid #fde68a;
}

.primary-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 10px;
  transition: transform 0.12s ease, background 0.15s ease;
}

.primary-btn:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.primary-btn.large {
  padding: 12px 22px;
  font-size: 1rem;
}

.secondary-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 10px;
}

.secondary-btn:hover:not(:disabled) {
  background: #eff6ff;
  border-color: #93c5fd;
}

.secondary-btn.large {
  padding: 12px 20px;
  font-size: 1rem;
}

button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.hub-main,
.player-main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 20px 56px;
}

.badges-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.badge-chip {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  border: 1px solid var(--border);
}

.badge-chip.unlocked {
  background: #dcfce7;
  color: #166534;
  border-color: #86efac;
}

.badge-chip.locked {
  background: #f1f5f9;
  color: #64748b;
  opacity: 0.72;
}

.module-matrix {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.matrix-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 10px;
}

.matrix-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mod-pill {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.83rem;
  font-weight: 700;
}

.mod-pill.active {
  background: #1d4ed8;
  color: #fff;
  border-color: #1d4ed8;
}

.filters-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.subject-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.88rem;
}

.tab-btn.active {
  background: #0f172a;
  color: #fff;
  border-color: #0f172a;
}

.search-grade-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-select,
.search-input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 0.9rem;
  color: var(--ink);
}

.search-input {
  min-width: 260px;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 5px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.game-card.subject-math {
  border-top-color: #3b82f6;
}
.game-card.subject-literacy {
  border-top-color: #ec4899;
}
.game-card.subject-science {
  border-top-color: #10b981;
}
.game-card.subject-social-studies {
  border-top-color: #f59e0b;
}
.game-card.subject-logic-life {
  border-top-color: #8b5cf6;
}

.card-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--muted);
}

.card-grade {
  background: #eef2ff;
  color: #3730a3;
  padding: 2px 8px;
  border-radius: 999px;
}

.card-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-icon {
  font-size: 2rem;
}

.card-title {
  margin: 0;
  font-size: 1.05rem;
}

.card-inspired {
  font-size: 0.77rem;
  color: var(--muted);
}

.card-desc {
  margin: 0;
  font-size: 0.89rem;
  line-height: 1.45;
  color: #334155;
  flex: 1;
}

.card-meta-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-tag {
  font-size: 0.75rem;
  font-weight: 700;
  background: #f1f5f9;
  color: #334155;
  padding: 3px 9px;
  border-radius: 999px;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid #f1f5f9;
}

.card-stars {
  font-size: 1rem;
  letter-spacing: 2px;
}

/* ================= GAME PLAYER VIEW ================= */
.player-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.player-title-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.player-icon {
  font-size: 2.3rem;
}

.player-title-group h2 {
  margin: 0 0 3px;
  font-size: 1.3rem;
}

.player-subtitle {
  font-size: 0.85rem;
  color: var(--muted);
}

.diff-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.diff-btn {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  padding: 7px 12px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.84rem;
}

.diff-btn.active {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.player-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.hud-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.9rem;
}

.hud-pill.streak {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #c2410c;
}

.challenge-stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.challenge-prompt {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 16px;
}

.hint-banner {
  background: #fefce8;
  border: 1px solid #fde047;
  color: #854d0e;
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-weight: 600;
}

.module-instruction {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 12px;
}

/* Multiple Choice */
.mc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.mc-option {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
  font-size: 1rem;
  font-weight: 700;
}

.mc-option.selected {
  border-color: var(--primary);
  background: #eff6ff;
}

.mc-option.eliminated {
  text-decoration: line-through;
  opacity: 0.35;
}

.mc-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #dbeafe;
  color: #1d4ed8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* True / False */
.tf-statement-card {
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  padding: 20px;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
}

.tf-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.tf-btn {
  padding: 16px;
  font-size: 1.08rem;
  font-weight: 800;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--surface-soft);
}

.tf-btn.selected {
  border-color: var(--primary);
  background: #eff6ff;
}

/* Cloze */
.cloze-sentence {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  font-size: 1.15rem;
  line-height: 2;
  margin-bottom: 16px;
}

.cloze-slot {
  display: inline-block;
  margin: 0 5px;
  padding: 4px 14px;
  border-radius: 10px;
  border: 2px dashed #3b82f6;
  background: #eff6ff;
  font-weight: 800;
  color: #1d4ed8;
}

.cloze-slot.active {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.cloze-slot.filled {
  border-style: solid;
  background: #dbeafe;
}

.cloze-banks {
  display: grid;
  gap: 12px;
}

.cloze-bank-title {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-chip {
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--surface);
  font-weight: 700;
}

.choice-chip.selected {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

/* Drag and Drop */
.dnd-tray {
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 16px;
}

.dnd-tray-label {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 8px;
}

.dnd-items-row,
.dnd-bin-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 42px;
}

.dnd-item {
  padding: 8px 14px;
  border-radius: 10px;
  border: 2px solid #93c5fd;
  background: #eff6ff;
  font-weight: 800;
}

.dnd-item.selected {
  background: #2563eb;
  color: #fff;
  border-color: #1d4ed8;
}

.dnd-bins {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.dnd-bin {
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: var(--surface-soft);
  min-height: 115px;
}

.dnd-bin.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}

.dnd-bin-title {
  font-weight: 800;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.empty-note {
  color: #94a3b8;
  font-size: 0.85rem;
  font-style: italic;
}

/* Ordering */
.order-list {
  display: grid;
  gap: 10px;
}

.order-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
}

.order-card.selected {
  border-color: var(--primary);
  background: #eff6ff;
}

.order-card.drag-over {
  border-style: dashed;
  border-color: var(--accent);
}

.order-pos {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #e2e8f0;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.order-label {
  flex: 1;
  font-weight: 700;
}

.order-controls {
  display: flex;
  gap: 6px;
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 5px 10px;
  font-weight: 800;
}

/* Matching Pairs */
.match-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.match-col {
  display: grid;
  gap: 8px;
  align-content: start;
}

.match-col-header {
  font-weight: 800;
  font-size: 0.86rem;
  color: var(--muted);
  text-transform: uppercase;
}

.match-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
  font-weight: 700;
  text-align: left;
}

.match-card.selected {
  border-color: var(--primary);
  background: #eff6ff;
}

.match-num {
  background: #e2e8f0;
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 0.78rem;
}

.match-tag {
  margin-left: auto;
  font-size: 0.82rem;
  color: #1d4ed8;
}

.paired-1 { border-color: #3b82f6; background: #eff6ff; }
.paired-2 { border-color: #ec4899; background: #fdf2f8; }
.paired-3 { border-color: #10b981; background: #ecfdf5; }
.paired-4 { border-color: #f59e0b; background: #fffbeb; }

/* Word Builder */
.wb-clue {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  color: #075985;
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 700;
  margin-bottom: 14px;
}

.wb-answer-tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  min-height: 58px;
  padding: 12px;
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  margin-bottom: 12px;
}

.wb-tools {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}

.wb-pool {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.wb-tile {
  min-width: 46px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 2px solid #93c5fd;
  background: #eff6ff;
  font-size: 1.15rem;
  font-weight: 800;
}

.wb-tile.placed {
  background: #2563eb;
  color: #fff;
  border-color: #1d4ed8;
}

.wb-tile.used {
  opacity: 0.3;
}

.snowman-meter {
  text-align: center;
  font-weight: 800;
  margin-bottom: 12px;
}

.wb-guess-slots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

.wb-letter-box {
  width: 42px;
  height: 48px;
  border-bottom: 3px solid #1e293b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
}

.wb-keyboard {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.kb-key {
  width: 38px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  font-weight: 800;
}

.kb-key.hit {
  background: #dcfce7;
  border-color: #16a34a;
  color: #166534;
}

.kb-key.miss {
  background: #fee2e2;
  color: #991b1b;
  opacity: 0.65;
}

/* Grid Muncher */
.munch-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.munch-rule-badge {
  background: #ede9fe;
  color: #5b21b6;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 800;
}

.munch-count {
  font-weight: 800;
  color: var(--muted);
}

.munch-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.munch-cell {
  position: relative;
  min-height: 60px;
  padding: 8px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface-soft);
  font-weight: 800;
  font-size: 0.96rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.munch-cell.player-here {
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

.munch-cell.munched {
  background: #dcfce7;
  border-color: #16a34a;
  color: #166534;
}

.munch-cell.mistake {
  background: #fee2e2;
  border-color: #dc2626;
  color: #991b1b;
}

.munch-cell.missed-target {
  border-color: #f59e0b;
  background: #fef3c7;
}

.munch-avatar {
  font-size: 1.05rem;
}

.munch-dpad {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.dpad-btns {
  display: flex;
  gap: 6px;
}

/* Number Target Builder */
.target-gauge {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

.target-readout {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  font-size: 1.1rem;
  margin-bottom: 10px;
}

.target-stat.goal {
  color: #1d4ed8;
}

.target-bar-track {
  height: 14px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.target-bar-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.2s ease;
}

.target-bar-fill.exact {
  background: var(--success);
}

.target-bar-fill.over {
  background: var(--danger);
}

.target-parts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.target-part-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: var(--surface-soft);
  text-align: center;
}

.target-part-label {
  font-weight: 800;
  margin-bottom: 10px;
}

.target-part-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.qty-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.2rem;
  font-weight: 800;
}

.qty-val {
  min-width: 24px;
  font-size: 1.15rem;
  font-weight: 800;
}

/* Catcher Arcade */
.catcher-arena {
  background: linear-gradient(180deg, #e0f2fe 0%, #f0fdf4 100%);
  border: 2px solid #bae6fd;
  border-radius: 16px;
  padding: 16px;
}

.catcher-items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

@keyframes bob {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-6px);
  }
}

.catcher-orb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 10px;
  border-radius: 16px;
  border: 2px solid #7dd3fc;
  background: #fff;
  font-weight: 800;
  animation: bob 2.2s ease-in-out infinite;
}

.catcher-orb.caught {
  animation: none;
  background: #dcfce7;
  border-color: #16a34a;
}

.catcher-orb.wrong {
  animation: none;
  background: #fee2e2;
  border-color: #dc2626;
}

.orb-emoji {
  font-size: 1.6rem;
}

/* Feedback & Controls */
.is-correct {
  border-color: #16a34a !important;
  background: var(--success-bg) !important;
}

.is-wrong {
  border-color: #dc2626 !important;
  background: var(--danger-bg) !important;
}

.feedback-banner {
  margin-top: 18px;
  padding: 14px 18px;
  border-radius: 14px;
  border: 2px solid;
}

.feedback-banner.success {
  background: var(--success-bg);
  border-color: #86efac;
  color: #14532d;
}

.feedback-banner.retry {
  background: #fff7ed;
  border-color: #fdba74;
  color: #7c2d12;
}

.feedback-headline {
  font-weight: 800;
  margin-bottom: 4px;
}

.feedback-explanation {
  font-size: 0.94rem;
}

.stage-controls {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}

.summary-stars {
  font-size: 3rem;
  margin-bottom: 10px;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 24px 0;
}

.sum-stat {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sum-stat span {
  font-size: 0.82rem;
  color: var(--muted);
}

.sum-stat strong {
  font-size: 1.35rem;
}

.summary-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.empty-state {
  grid-column: 1 / -1;
  background: var(--surface);
  padding: 32px;
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
}

@media (max-width: 680px) {
  .tf-actions,
  .match-columns {
    grid-template-columns: 1fr;
  }
  .search-input {
    min-width: 100%;
  }
}
