@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&family=Fredoka+One&display=swap');

/* =============================================
   ROOT VARIABLES
   ============================================= */
#mathGameRoot {
  --bg1: #0f0c29; --bg2: #302b63; --bg3: #24243e;
  --primary: #f7971e; --secondary: #ffd200;
  --accent: #21d4fd; --accent2: #b721ff;
  --green: #56ab2f; --green2: #a8e063;
  --red: #f7263f; --pink: #ff6fd8;
  --card: rgba(255,255,255,0.08);
  --glass: rgba(255,255,255,0.12);
  --border: rgba(255,255,255,0.18);
  --text: #ffffff; --text2: rgba(255,255,255,0.7);
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --glow: 0 0 20px rgba(247,151,30,0.5);
  --radius: 18px; --radius-sm: 12px;
}

/* =============================================
   GAME ROOT CONTAINER — replaces html/body rules
   All positioning is relative to this container.
   ============================================= */
#mathGameRoot {
  width: 100% !important;
  height: 620px !important;
  min-height: 620px !important;
  max-height: 620px !important;
  position: relative !important;
  overflow: hidden !important;
  font-family: 'Nunito', sans-serif !important;
  background: linear-gradient(135deg, #0f0c29, #302b63, #24243e) !important;
  color: #ffffff !important;
  display: flex !important;
  flex-direction: column !important;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box !important;
  visibility: visible !important;
  opacity: 1 !important;
  padding: 0 !important;
  margin: 0 !important;
}

#mathGameRoot *, #mathGameRoot *::before, #mathGameRoot *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* =============================================
   SCREENS
   position:absolute so they fill #mathGameRoot
   ============================================= */
#mathGameRoot .screen {
  position: absolute !important;
  top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
  display: none;
  flex-direction: column;
  align-items: center;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding-bottom: 80px;
  width: 100% !important;
  height: 100% !important;
}
#mathGameRoot .screen.active { display: flex !important; }

/* Scrollbar inside game */
#mathGameRoot .screen::-webkit-scrollbar { width: 6px; }
#mathGameRoot .screen::-webkit-scrollbar-track { background: transparent; }
#mathGameRoot .screen::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }

/* =============================================
   START SCREEN
   ============================================= */
#mathGameRoot #startScreen {
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
}
#mathGameRoot .start-content {
  text-align: center;
  padding: 40px 30px;
  z-index: 2;
  position: relative;
}
#mathGameRoot .start-logo {
  font-size: 5rem;
  margin-bottom: 20px;
  animation: mgr-logoBounce 2s ease-in-out infinite;
}
@keyframes mgr-logoBounce {
  0%,100% { transform: translateY(0) rotate(-5deg); }
  50%      { transform: translateY(-15px) rotate(5deg); }
}
#mathGameRoot .start-title {
  font-family: 'Fredoka One', cursive;
  font-size: 3rem;
  line-height: 1.3;
  padding: 20px !important;
  background: linear-gradient(90deg, #f7971e, #ffd200, #21d4fd);
  /*background: #03fc0f;*/
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
  display: inline-block;
}
#mathGameRoot .start-sub {
  color: var(--text2);
  font-size: 1.1rem;
  margin-bottom: 12px;
}
#mathGameRoot .start-features {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 32px;
}
#mathGameRoot .feat-chip {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text2);
}
#mathGameRoot .start-btn {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border: none;
  border-radius: 20px;
  padding: 18px 50px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.6rem;
  color: #1a1a1a;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(247,151,30,0.5);
  transition: all 0.3s;
  display: block;
  margin: 0 auto;
}
#mathGameRoot .start-btn:hover  { transform: scale(1.05) translateY(-3px); box-shadow: 0 12px 40px rgba(247,151,30,0.7); }
#mathGameRoot .start-btn:active { transform: scale(0.97); }

/* Floating emojis — contained inside #mathGameRoot via overflow:hidden */
#mathGameRoot .floating-emoji {
  position: absolute;
  font-size: 2rem;
  animation: mgr-floatAround linear infinite;
  pointer-events: none;
  opacity: 0.4;
}
@keyframes mgr-floatAround {
  0%   { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(-700px) rotate(360deg); }
}

/* =============================================
   HOME SCREEN
   ============================================= */
#mathGameRoot #homeScreen {
  justify-content: flex-start;
  background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
}
#mathGameRoot .home-header {
  text-align: center;
  padding: 40px 20px 20px;
  width: 100%;
}
#mathGameRoot .home-title {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  line-height: 1.3;
  padding: 4px 8px;
  display: inline-block;
  background: linear-gradient(90deg, #f7971e, #ffd200, #21d4fd, #b721ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: mgr-titlePulse 3s ease-in-out infinite;
}
@keyframes mgr-titlePulse {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.85; }
}
#mathGameRoot .home-subtitle { font-size: 1.1rem; color: var(--text2); margin-top: 8px; font-weight: 600; }
#mathGameRoot .stars-display  { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
#mathGameRoot .star-icon       { font-size: 1.8rem; animation: mgr-starSpin 4s linear infinite; }
@keyframes mgr-starSpin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

#mathGameRoot .stats-bar {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 12px 20px;
  width: 100%;
}
#mathGameRoot .stat-chip {
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  border-radius: 50px;
  padding: 8px 18px;
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

#mathGameRoot .modes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  padding: 16px 20px;
  width: 100%;
  max-width: 700px;
}
#mathGameRoot .mode-card {
  background: var(--card);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}
#mathGameRoot .mode-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.05));
  opacity: 0;
  transition: opacity 0.3s;
}
#mathGameRoot .mode-card:hover::before,
#mathGameRoot .mode-card:active::before { opacity: 1; }
#mathGameRoot .mode-card:hover  { transform: translateY(-4px) scale(1.03); box-shadow: var(--shadow); }
#mathGameRoot .mode-card:active { transform: scale(0.97); }
#mathGameRoot .mode-icon          { font-size: 2.5rem; margin-bottom: 10px; display: block; }
#mathGameRoot .mode-name          { font-weight: 800; font-size: 0.85rem; margin-bottom: 6px; }
#mathGameRoot .mode-progress      { font-size: 0.75rem; color: var(--text2); }
#mathGameRoot .mode-progress-bar  { height: 4px; background: rgba(255,255,255,0.15); border-radius: 10px; margin-top: 8px; overflow: hidden; }
#mathGameRoot .mode-progress-fill { height: 100%; border-radius: 10px; transition: width 0.5s ease; }

/* =============================================
   TIER BADGES
   ============================================= */
#mathGameRoot .tier-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 20px;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
#mathGameRoot .tier-1 { background: rgba(86,171,47,0.4);  color: #a8e063; }
#mathGameRoot .tier-2 { background: rgba(33,212,253,0.3); color: #21d4fd; }
#mathGameRoot .tier-3 { background: rgba(247,151,30,0.4); color: #ffd200; }
#mathGameRoot .tier-4 { background: rgba(183,33,255,0.4); color: #e879f9; }
#mathGameRoot .tier-5 { background: rgba(247,38,63,0.4);  color: #ff6b6b; }

/* =============================================
   LEVEL SELECT SCREEN
   ============================================= */
#mathGameRoot #levelScreen { background: inherit; }
#mathGameRoot .level-header {
  width: 100%;
  padding: 20px 20px 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
#mathGameRoot .back-btn {
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.2s;
  color: var(--text);
}
#mathGameRoot .back-btn:hover { background: rgba(255,255,255,0.2); transform: scale(1.05); }
#mathGameRoot .level-title { font-family: 'Fredoka One', cursive; font-size: 1.8rem; }

#mathGameRoot .tier-section { width: 100%; max-width: 700px; padding: 0 20px; margin-bottom: 16px; }
#mathGameRoot .tier-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 8px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}
#mathGameRoot .tier-header:hover       { background: rgba(255,255,255,0.05); }
#mathGameRoot .tier-header-title       { font-weight: 800; font-size: 0.95rem; }
#mathGameRoot .tier-header-sub         { font-size: 0.75rem; color: var(--text2); margin-left: auto; }
#mathGameRoot .tier-levels             { display: grid; grid-template-columns: repeat(auto-fill, minmax(65px, 1fr)); gap: 8px; }

#mathGameRoot .level-btn {
  aspect-ratio: 1;
  border-radius: 14px;
  border: none;
  font-family: 'Fredoka One', cursive;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.25s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
  overflow: hidden;
}
#mathGameRoot .level-btn.locked    { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.3); cursor: not-allowed; }
#mathGameRoot .level-btn.unlocked  { background: var(--glass); border: 1px solid var(--border); color: var(--text); }
#mathGameRoot .level-btn.unlocked:hover { transform: scale(1.08); box-shadow: 0 4px 20px rgba(247,151,30,0.4); }
#mathGameRoot .level-btn.completed { background: linear-gradient(135deg, var(--green), var(--green2)); color: #fff; box-shadow: 0 4px 15px rgba(86,171,47,0.5); }
#mathGameRoot .level-btn.perfect   { background: linear-gradient(135deg, #f7971e, #ffd200); color: #1a1a1a; box-shadow: 0 4px 15px rgba(255,210,0,0.6); }
#mathGameRoot .level-stars         { font-size: 0.45rem; letter-spacing: 1px; }

/* =============================================
   GAME SCREEN
   ============================================= */
#mathGameRoot #gameScreen {
  justify-content: flex-start;
  background: linear-gradient(135deg, var(--bg1), var(--bg2), var(--bg3));
}
#mathGameRoot .game-topbar {
  width: 100%;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.2);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#mathGameRoot .game-info { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
#mathGameRoot .info-chip {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
}
#mathGameRoot .info-chip.tier-chip { font-size: 0.7rem; }
#mathGameRoot .streak-chip {
  background: linear-gradient(135deg, rgba(247,151,30,0.3), rgba(255,210,0,0.2));
  border-color: rgba(255,210,0,0.5);
}

/* Timer */
#mathGameRoot .timer-wrap   { width: 100%; padding: 0 16px 6px; flex-shrink: 0; }
#mathGameRoot .timer-track  { height: 5px; background: rgba(255,255,255,0.1); border-radius: 10px; overflow: hidden; }
#mathGameRoot .timer-fill   { height: 100%; border-radius: 10px; background: linear-gradient(90deg, #21d4fd, #b721ff); transition: width 0.1s linear; }
#mathGameRoot .timer-fill.warning { background: linear-gradient(90deg, #f7971e, #f7263f); }

/* Progress */
#mathGameRoot .progress-wrap  { width: 100%; padding: 10px 16px; flex-shrink: 0; }
#mathGameRoot .progress-track { height: 8px; background: rgba(255,255,255,0.1); border-radius: 10px; overflow: hidden; }
#mathGameRoot .progress-fill  { height: 100%; border-radius: 10px; background: linear-gradient(90deg, var(--primary), var(--secondary)); transition: width 0.5s ease; }

/* Question area */
#mathGameRoot .question-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  overflow-y: auto;
}
#mathGameRoot .question-card {
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 28px 24px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  animation: mgr-cardIn 0.4s ease;
}
@keyframes mgr-cardIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to   { opacity: 1; transform: none; }
}
#mathGameRoot .question-label {
  font-size: 0.85rem;
  color: var(--text2);
  margin-bottom: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}
#mathGameRoot .question-text {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1.6rem, 6vw, 3rem);
  line-height: 1.4;
  padding: 20px;
  display: block;
  margin-bottom: 20px;
  background: linear-gradient(90deg, #f7971e, #ffd200);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#mathGameRoot .question-hint { font-size: 0.8rem; color: var(--text2); margin-bottom: 12px; font-style: italic; }

/* =============================================
   ANSWER OPTIONS
   ============================================= */
#mathGameRoot .options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
}
#mathGameRoot .options-grid.three-col { grid-template-columns: 1fr 1fr 1fr; }
#mathGameRoot .option-btn {
  background: var(--glass);
  border: 2px solid var(--border);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 18px 12px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
  color: var(--text);
  cursor: pointer;
  transition: all 0.25s;
  text-align: center;
  line-height: 1.2;
}
#mathGameRoot .option-btn:hover  { transform: scale(1.05); border-color: var(--primary); box-shadow: 0 0 20px rgba(247,151,30,0.4); }
#mathGameRoot .option-btn:active { transform: scale(0.97); }
#mathGameRoot .option-btn.correct { background: linear-gradient(135deg, #56ab2f, #a8e063); border-color: #56ab2f; animation: mgr-correctPulse 0.5s ease; }
#mathGameRoot .option-btn.wrong   { background: linear-gradient(135deg, #f7263f, #ff6b6b); border-color: #f7263f; animation: mgr-wrongShake 0.4s ease; }
@keyframes mgr-correctPulse { 0%{transform:scale(1)} 50%{transform:scale(1.1)} 100%{transform:scale(1)} }
@keyframes mgr-wrongShake   { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-8px)} 75%{transform:translateX(8px)} }

/* =============================================
   INPUT ANSWER
   ============================================= */
#mathGameRoot .input-answer-wrap {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}
#mathGameRoot .answer-input {
  flex: 1;
  background: var(--glass);
  border: 2px solid var(--border);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 16px 20px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.6rem;
  color: var(--text);
  text-align: center;
  outline: none;
  transition: border-color 0.3s;
}
#mathGameRoot .answer-input:focus       { border-color: var(--primary); box-shadow: 0 0 20px rgba(247,151,30,0.3); }
#mathGameRoot .answer-input::placeholder { color: rgba(255,255,255,0.3); }
#mathGameRoot .submit-btn {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border: none;
  border-radius: 16px;
  padding: 16px 20px;
  font-size: 1.4rem;
  cursor: pointer;
  transition: all 0.25s;
}
#mathGameRoot .submit-btn:hover  { transform: scale(1.08); box-shadow: var(--glow); }
#mathGameRoot .submit-btn:active { transform: scale(0.95); }

/* =============================================
   DRAG & DROP
   ============================================= */
#mathGameRoot .drag-options { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
#mathGameRoot .drag-item {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  border-radius: 12px;
  padding: 14px 20px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
  cursor: grab;
  transition: all 0.25s;
  user-select: none;
  box-shadow: 0 4px 15px rgba(183,33,255,0.4);
}
#mathGameRoot .drag-item:active { cursor: grabbing; transform: scale(1.1) rotate(3deg); }

#mathGameRoot .drop-zone {
  min-width: 120px;
  min-height: 60px;
  border: 3px dashed var(--border);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-family: 'Fredoka One', cursive;
  transition: all 0.3s;
  margin: 16px auto;
}
#mathGameRoot .drop-zone.drag-over { border-color: var(--primary); background: rgba(247,151,30,0.1); }
#mathGameRoot .drop-zone.filled    { border-style: solid; border-color: var(--green); background: rgba(86,171,47,0.15); }

#mathGameRoot .multi-drop-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 12px 0; }
#mathGameRoot .drop-slot {
  min-width: 70px;
  min-height: 55px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-family: 'Fredoka One', cursive;
  transition: all 0.3s;
  cursor: pointer;
  padding: 4px;
  background: rgba(255,255,255,0.04);
}
#mathGameRoot .drop-slot.drag-over { border-color: var(--primary); background: rgba(247,151,30,0.1); }
#mathGameRoot .drop-slot.filled    { border-style: solid; border-color: var(--green); background: rgba(86,171,47,0.1); }
#mathGameRoot .drop-slot .slot-label { font-size: 0.6rem; color: var(--text2); margin-top: 2px; }

/* =============================================
   SHAPE COUNTING
   ============================================= */
#mathGameRoot .shapes-area {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 16px;
  background: rgba(0,0,0,0.1);
  border-radius: 16px;
  margin-bottom: 20px;
  max-height: 160px;
  overflow-y: auto;
}
#mathGameRoot .shape-item { font-size: 2rem; animation: mgr-shapeBounce 2s ease-in-out infinite; }
@keyframes mgr-shapeBounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* =============================================
   NUMBER MATCHING
   ============================================= */
#mathGameRoot .matching-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; max-width: 440px; }
#mathGameRoot .match-col     { display: flex; flex-direction: column; gap: 8px; }
#mathGameRoot .match-item {
  background: var(--glass);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  text-align: center;
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.25s;
  word-break: break-all;
}
#mathGameRoot .match-item:hover       { border-color: var(--primary); }
#mathGameRoot .match-item.selected    { border-color: var(--accent); background: rgba(33,212,253,0.2); }
#mathGameRoot .match-item.matched     { border-color: var(--green); background: rgba(86,171,47,0.2); pointer-events: none; }
#mathGameRoot .match-item.wrong-match { border-color: var(--red); background: rgba(247,38,63,0.2); animation: mgr-wrongShake 0.4s ease; }

/* =============================================
   SEQUENCE
   ============================================= */
#mathGameRoot .sequence-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 12px 0;
  align-items: center;
}
#mathGameRoot .seq-num {
  background: var(--glass);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
  min-width: 55px;
  text-align: center;
}
#mathGameRoot .seq-blank {
  min-width: 55px;
  min-height: 50px;
  border: 3px dashed var(--primary);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-family: 'Fredoka One', cursive;
  animation: mgr-blinkBorder 1.5s ease-in-out infinite;
  background: rgba(247,151,30,0.1);
}
@keyframes mgr-blinkBorder {
  0%,100% { border-color: var(--primary); }
  50%     { border-color: var(--secondary); }
}

/* =============================================
   WORD PROBLEM
   ============================================= */
#mathGameRoot .word-problem-text {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 16px;
  background: rgba(255,255,255,0.05);
  border-radius: 14px;
  padding: 16px 18px;
  border: 1px solid var(--border);
}
#mathGameRoot .word-problem-text strong { color: var(--secondary); }

/* MISSING NUMBER */
#mathGameRoot .blank-box {
  display: inline-block;
  min-width: 60px;
  height: 50px;
  border: 3px solid var(--primary);
  border-radius: 12px;
  background: rgba(247,151,30,0.15);
  vertical-align: middle;
  line-height: 50px;
  text-align: center;
  animation: mgr-blinkBorder 1.5s ease-in-out infinite;
}

/* =============================================
   FEEDBACK OVERLAY
   position:absolute — stays inside #mathGameRoot
   ============================================= */
#mathGameRoot .feedback-overlay {
  position: absolute !important;
  inset: 0 !important;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
}
#mathGameRoot .feedback-overlay.show { display: flex !important; }
#mathGameRoot .feedback-card {
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  border: 2px solid var(--border);
  border-radius: 28px;
  padding: 40px 32px;
  text-align: center;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  animation: mgr-cardIn 0.4s ease;
}
#mathGameRoot .feedback-icon    { font-size: 4rem; margin-bottom: 16px; }
#mathGameRoot .feedback-title   { font-family: 'Fredoka One', cursive; font-size: 2rem; margin-bottom: 8px; }
#mathGameRoot .feedback-rewards { display: flex; gap: 16px; justify-content: center; margin: 16px 0; flex-wrap: wrap; }
#mathGameRoot .reward-chip {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 8px 16px;
  font-weight: 800;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 4px;
}
#mathGameRoot .feedback-btn {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border: none;
  border-radius: 16px;
  padding: 14px 32px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.2rem;
  color: #1a1a1a;
  cursor: pointer;
  width: 100%;
  transition: all 0.25s;
  margin-top: 8px;
}
#mathGameRoot .feedback-btn:hover  { transform: scale(1.05); box-shadow: var(--glow); }
#mathGameRoot .feedback-accuracy   { margin-top: 8px; font-size: 0.85rem; color: var(--text2); }

/* =============================================
   CONFETTI — absolute, clipped by #mathGameRoot
   ============================================= */
#mathGameRoot .confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  z-index: 200;
  pointer-events: none;
  animation: mgr-confettiFall linear forwards;
}
@keyframes mgr-confettiFall {
  0%   { transform: translateY(-20px) rotate(0deg);   opacity: 1; }
  100% { transform: translateY(700px) rotate(720deg); opacity: 0; }
}

/* =============================================
   ACHIEVEMENT TOAST — absolute inside container
   ============================================= */
#mathGameRoot .achievement-toast {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-200px);
  background: linear-gradient(135deg, #f7971e, #ffd200);
  color: #1a1a1a;
  border-radius: 50px;
  padding: 12px 24px;
  font-weight: 800;
  font-size: 0.95rem;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 30px rgba(247,151,30,0.6);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
}
#mathGameRoot .achievement-toast.show { transform: translateX(-50%) translateY(0); }

/* =============================================
   TIME BONUS FLASH — absolute inside container
   ============================================= */
#mathGameRoot .time-bonus-flash {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Fredoka One', cursive;
  font-size: 2rem;
  font-weight: 900;
  z-index: 250;
  pointer-events: none;
  animation: mgr-bonusFlash 0.8s ease forwards;
}
@keyframes mgr-bonusFlash {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(1.5); }
}

/* =============================================
   CONTROL BAR — absolute, sticks to bottom of container
   ============================================= */
#mathGameRoot #controlBar {
  position: absolute !important;
  bottom: 0 !important; left: 0 !important; right: 0 !important;
  height: 70px !important;
  z-index: 50;
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(15,12,41,0.85);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  width: 100% !important;
  box-sizing: border-box !important;
}
#mathGameRoot .ctrl-btn {
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  border-radius: 14px;
  padding: 10px 18px;
  cursor: pointer;
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.25s;
  white-space: nowrap;
}
#mathGameRoot .ctrl-btn:hover  { transform: scale(1.05); border-color: var(--primary); box-shadow: 0 0 15px rgba(247,151,30,0.4); }
#mathGameRoot .ctrl-btn:active { transform: scale(0.95); }
#mathGameRoot .ctrl-btn.music-on  { border-color: var(--accent); box-shadow: 0 0 12px rgba(33,212,253,0.3); }
#mathGameRoot .ctrl-btn.close-btn { background: linear-gradient(135deg, rgba(247,38,63,0.3), rgba(255,107,107,0.2)); border-color: var(--red); }
#mathGameRoot .ctrl-btn.close-btn:hover { box-shadow: 0 0 15px rgba(247,38,63,0.5); }
#mathGameRoot .home-ctrl { background: linear-gradient(135deg, rgba(247,151,30,0.2), rgba(255,210,0,0.1)); }

#mathGameRoot .music-icon { font-size: 1.2rem; }
#mathGameRoot .music-icon.playing { animation: mgr-musicBounce 0.6s ease-in-out infinite alternate; }
@keyframes mgr-musicBounce { from { transform: scale(1); } to { transform: scale(1.2); } }

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 400px) {
  #mathGameRoot .modes-grid        { grid-template-columns: repeat(2, 1fr); }
  #mathGameRoot .question-text     { font-size: 1.6rem; }
  #mathGameRoot .options-grid      { gap: 8px; }
  #mathGameRoot .option-btn        { padding: 14px 8px; font-size: 1.1rem; }
  #mathGameRoot .tier-levels       { grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); }
}
