:root {
  /* Primary colors (neutral marble/ghost marble blue) */
  --primary-blue-lightest: #e6f3ff;
  --primary-blue-light: #4a90e2;
  --primary-blue-dark: #2e5c8a;
  --primary-blue-bright: #3498db;
  --primary-blue-hover: #357abd;

  /* Background colors */
  --bg-body: #f0f8ff;
  --bg-container: white;
  --bg-grid: #f9f9f9;
  --bg-light-blue: #e8f4f8;
  --bg-light-blue: #e8f4f8;

  /* Text colors */
  --text-primary: #333;
  --text-secondary: #555;
  --text-dark: #2c3e50;
  --text-light: white;
  --text-tooltip: rgba(255, 255, 255, 0.8);

  /* Tooltip colors */
  --tooltip-bg: rgba(44, 62, 80, 0.95);
  --tooltip-shadow: rgba(0, 0, 0, 0.3);

  /* Accent colors */
  --accent-red: #e74c3c;
  --accent-green: #27ae60;

  /* Purple colors */
  --purple-lightest: #ecdfff;
  --purple-lighter: #c5abec;
  --purple-light: #a569bd;
  --purple-medium: #9b59b6;
  --purple: #8e44ad;
  --purple-dark: #6c3483;

  /* Yellow colors */
  --yellow-lightest: #fff9e6;
  --yellow-light: #ffe680;
  --yellow: #ffb700;
  --yellow-dark: #b8860b;
  --yellow-darker: #cc9900;

  /* Blue text colors */
  --blue-text-dark: #1a4d7a;
  --blue-text-medium: #2e5c8a;

  /* State colors */
  --disabled-gray: #95a5a6;

  /* Transparency values */
  --marble-count-bg: rgba(74, 144, 226, 0.1);
  --split-second-bg: rgba(231, 76, 60, 0.1);
  --purple-bg-light: rgba(155, 89, 182, 0.1);

  /* Opaque feedback colors (calculated to match previous 0.2 opacity over white) */
  --feedback-preview-bg: rgb(235, 222, 240); /* Light purple */
  --feedback-correct-bg: rgb(213, 245, 227); /* Light green */
  --feedback-incorrect-bg: rgb(250, 219, 216); /* Light red */
  --purple-shadow: rgba(155, 89, 182, 0.4);
  --blue-shadow: rgba(74, 144, 226, 0.4);
  --blue-progress-bg: rgba(46, 92, 138, 0.2);
  --purple-progress-bg: rgba(108, 52, 131, 0.2);
  --yellow-shadow: rgba(255, 183, 0, 0.3);
  --yellow-progress-bg: rgba(255, 183, 0, 0.2);

  /* Shadows */
  --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 6px 12px rgba(0, 0, 0, 0.2);
  --shadow-hundred: 0 4px 8px rgba(0, 0, 0, 0.2);
  --shadow-thousand: 0 4px 8px rgba(0, 0, 0, 0.3);
  --shadow-marble: 2px 2px 4px rgba(0, 0, 0, 0.3);
  --text-shadow-marble: 1px 1px 2px rgba(0, 0, 0, 0.5);
  --text-shadow-box: 2px 2px 4px rgba(0, 0, 0, 0.5);

  /* Health shadow (dynamically updated based on lives) */
  --health-shadow-color: rgba(39, 174, 96, 0.15); /* Default: subtle green */
}

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

/* MOBILE FIRST - Default styles for mobile */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body {
  font-family: Arial, sans-serif;
  background-color: var(--bg-body);
  display: flex;
  flex-direction: column;
}

.game-container {
  flex: 1;
  max-width: 100%;
  margin: 0;
  padding: 5px;
  background-color: var(--bg-container);
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: inset 0 -60px 80px -30px var(--health-shadow-color);
  transition: box-shadow 0.5s ease;
}

.mode-controls {
  flex-shrink: 0;
  margin-top: auto;
  display: flex;
  justify-content: center;
  margin-bottom: 15px;
  position: relative;
  height: 70px;
  transition: none; /* No transition when showing */
  pointer-events: auto;
}

.mode-controls.hidden {
  height: 0;
  transition: height 0.5s ease-out 0.2s; /* Only transition when hiding */
  pointer-events: none; /* Disable clicks after hiding */
}

.mode-toggle-btn {
  padding: 12px 24px;
  margin-top: 20px;
  font-size: 18px;
  font-weight: bold;
  background: linear-gradient(135deg, var(--purple-medium), var(--purple));
  color: var(--text-light);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease-in-out;
  box-shadow: var(--shadow-sm);
  transform: translateY(0);
}

.mode-controls.hidden .mode-toggle-btn {
  opacity: 0;
  transition: opacity 0.2s ease-out;
}

.mode-toggle-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  background: linear-gradient(
    135deg,
    var(--purple-light),
    var(--purple-medium)
  );
}

.mode-toggle-btn:disabled {
  background: var(--disabled-gray);
  cursor: not-allowed;
  opacity: 0.6;
}

.mode-toggle-btn:active:not(:disabled) {
  transform: translateY(0);
}

.target-number-container {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding: 5px 0;
  transition: all 0.3s ease-out;
}

/* Dim target display when mini-game modal is about to appear or is active */
.target-number-container.disabled-for-minigame {
  opacity: 0.3;
  pointer-events: none;
  filter: grayscale(0.8);
  transition: opacity 0.3s ease-out, filter 0.3s ease-out;
}

.target-number-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  background-color: var(--marble-count-bg);
  padding: 10px 20px;
  margin: 15px 0 3px 0;
  border-radius: 5px;
  border: 2px solid var(--primary-blue-light);
  box-sizing: border-box;
}

.target-plus {
  font-size: 6vw;
  font-weight: bold;
  color: var(--primary-blue-light);
}

.target-number {
  font-size: 6vw;
  font-weight: bold;
  color: var(--primary-blue-light);
}

.target-number-display .marble-icon {
  width: 7vw;
  height: 7vw;
}

.grid-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 5px;
  padding: 5px;
  background-color: var(--bg-grid);
  border-radius: 8px;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Challenge mode with visual feedback - pointer cursor */
.grid-container.challenge-mode.visual-feedback .box:not(:has(.marble)) {
  cursor: pointer;
}

/* Challenge mode without visual feedback - crosshair cursor for precise aiming */
.grid-container.challenge-mode.no-visual-feedback .box:not(:has(.marble)) {
  cursor: crosshair;
}

.grid-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50px;
  background: linear-gradient(to bottom, var(--bg-grid), transparent);
  pointer-events: none;
  z-index: 1;
  border-radius: 8px 8px 0 0;
}

.row-wrapper {
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  gap: 15px;
  position: relative;
}

.row-label {
  display: none;
}

.row-wrapper > .row,
.row-wrapper > .hundred-box,
.row-wrapper > .thousand-box {
  justify-self: center;
}

.collapsed-row {
  /* No extra styling needed, use the standard row-wrapper layout */
}

/* Animation for rows being removed during collapse */
@keyframes collapseOut {
  0% {
    opacity: 1;
    transform: scale(1);
    max-height: 100px;
  }
  50% {
    opacity: 1;
    transform: scale(0.95);
  }
  100% {
    opacity: 0;
    transform: scale(0.8);
    max-height: 0;
    margin: 0;
    padding: 0;
  }
}

.collapsing-out {
  animation: collapseOut 0.5s ease-out forwards;
}

/* Animation for collapsed bar appearing */
@keyframes collapseIn {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.05);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.collapsing-in {
  animation: collapseIn 0.6s ease-out forwards;
}

.hundred-box {
  width: calc(90vw + 18px); /* 10 boxes * 9vw + 9 gaps * 2px */
  height: 9vw;
  border: 2px solid var(--primary-blue-dark);
  border-radius: 5px;
  background: linear-gradient(
    135deg,
    var(--primary-blue-bright),
    var(--primary-blue-dark)
  );
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 5vw;
  font-weight: bold;
  color: var(--text-light);
  text-shadow: var(--text-shadow-box);
  box-shadow: var(--shadow-hundred);
}

.thousand-box {
  width: calc(90vw + 18px); /* 10 boxes * 9vw + 9 gaps * 2px */
  height: 9vw;
  border: 3px solid var(--purple);
  border-radius: 5px;
  background: linear-gradient(
    135deg,
    var(--purple-medium),
    var(--purple)
  );
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 5vw;
  font-weight: bold;
  color: var(--text-light);
  text-shadow: var(--text-shadow-box);
  box-shadow: var(--shadow-thousand);
}

.row-label {
  min-width: 40px;
  text-align: right;
  font-size: 18px;
  font-weight: bold;
}

.row {
  display: flex;
  gap: 2px;
  justify-content: center;
}

.box {
  width: 9vw;
  height: 9vw;
  border: 2px solid var(--text-primary);
  border-radius: 5px;
  background-color: var(--bg-container);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition:
    background-color 0.2s,
    border-color 0.2s;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.box-number {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 2vw;
  font-weight: 600;
  color: var(--text-primary);
  opacity: 0.35;
  pointer-events: none;
  user-select: none;
}

/* Hide box number when box contains a marble */
.box:has(.marble) .box-number {
  display: none;
}

/* Only show hover effect in active game phase (not practice mode) */
.game-container:not(.practice-mode) .box:not(:has(.marble)):hover {
  border-color: var(--primary-blue-bright);
}

.box.target-box {
  background-color: var(--bg-light-blue);
  border-color: var(--primary-blue-light);
  border-width: 3px;
  position: relative;
  overflow: hidden;
}

.box.feedback-preview {
  background-color: var(--feedback-preview-bg);
  border-color: var(--purple);
  border-width: 3px;
}

.box.feedback-correct {
  background-color: var(--feedback-correct-bg);
  border-color: var(--accent-green);
  border-width: 3px;
}

.box.feedback-incorrect {
  background-color: var(--feedback-incorrect-bg);
  border-color: var(--accent-red);
  border-width: 3px;
}

.marble {
  width: 7vw;
  height: 7vw;
  background: radial-gradient(
    circle at 30% 30%,
    var(--primary-blue-light),
    var(--primary-blue-dark)
  );
  border-radius: 50%;
  box-shadow: var(--shadow-marble);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-weight: bold;
  font-size: 2.5vw;
  text-shadow: var(--text-shadow-marble);
}

.ghost-marble {
  background: radial-gradient(
    circle at 30% 30%,
    var(--primary-blue-light),
    var(--primary-blue-dark)
  ) !important;
  opacity: 0.4;
  animation: ghostPulse 1s ease-in-out infinite;
}

@keyframes ghostPulse {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.7;
  }
}

/* Highlight first marble with pulsing glow and white hand icon */
.first-marble {
  position: relative;
  animation: firstMarbleGlow 2s ease-in-out infinite;
}

.first-marble::before {
  content: '🖐️';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.2em;
  filter: grayscale(100%) brightness(2);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 1;
  animation: handBounce 2s ease-in-out infinite;
}

@keyframes handBounce {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.15);
  }
}

@keyframes firstMarbleGlow {
  0%,
  100% {
    box-shadow: var(--shadow-marble), 0 0 0 0 rgba(74, 144, 226, 0.7);
  }
  50% {
    box-shadow: var(--shadow-marble), 0 0 8px 4px rgba(74, 144, 226, 0.5);
  }
}

/* Fade in animation for new rows */
@keyframes fadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

.fading-in {
  animation: fadeIn 0.6s ease-out forwards;
}

/* Fade out animation for removed rows */
@keyframes fadeOut {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.fading-out {
  animation: fadeOut 0.5s ease-out forwards;
}

.marble-group-container {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 5px 0;
  min-height: 80px;
}

.marble-group-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: grab;
}

.marble-group-wrapper:active {
  cursor: grabbing;
}

.marble-count-indicator,
.split-indicator {
  font-size: 5vw;
  font-weight: bold;
  color: var(--primary-blue-light);
  background-color: var(--marble-count-bg);
  padding: 5px 15px;
  border-radius: 5px;
  border: 2px dashed var(--primary-blue-light);
  box-sizing: border-box;
  text-align: center;
}

.marble-count-indicator {
  margin-top: 0;
  min-height: 30px;
  width: 100%;
}

.split-indicators-container {
  display: none;
  align-items: center;
  width: 100%;
}

.split-indicator-second {
  background-color: var(--split-second-bg);
  border-color: var(--accent-red);
  color: var(--accent-red);
  box-sizing: border-box;
}

.marble-group {
  display: flex;
  gap: calc(2vw + 2px);
  padding: 5px;
  margin-bottom: 5px;
}

.marble-group .marble {
  cursor: grab;
  background: radial-gradient(
    circle at 30% 30%,
    var(--primary-blue-light),
    var(--primary-blue-dark)
  );
}

.marble-group .marble:active {
  cursor: grabbing;
}

.marble-group-wrapper.dragging {
  cursor: grabbing !important;
}

.marble-group-wrapper.dragging .marble {
  pointer-events: none;
  opacity: 0.4;
  animation: ghostPulse 1s ease-in-out infinite;
  cursor: grabbing !important;
}

.controls {
  flex-shrink: 0;
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-bottom: 18px;
}

.controls button {
  height: 44px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
}

/* Instructions modal - specific overrides */
.instructions-modal-content {
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  text-align: left;
}

.instructions-modal-content h2 {
  margin-top: 0;
  margin-bottom: 20px;
  color: var(--text-dark);
  text-align: center;
  font-size: 1.8rem;
}

.instructions-content p {
  margin: 15px 0;
  line-height: 1.7;
  color: var(--text-secondary);
  font-size: 1rem;
}

.instructions-content strong {
  color: var(--text-dark);
  font-size: 1.05rem;
}

.modal-close-btn {
  position: absolute;
  top: 10px;
  right: 15px;
  background: none !important;
  border: none;
  font-size: 2.5rem;
  font-weight: 300;
  line-height: 1;
  color: #000 !important;
  opacity: 0.3;
  cursor: pointer;
  padding: 0;
  margin: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none !important;
  transform: none !important;
  transition: opacity 0.15s ease;
}

/* Main menu page styles */
.main-menu-page {
  flex: 1;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

/* Game content wrapper */
#game-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.main-menu-container {
  text-align: center;
  padding: 40px;
  max-width: 600px;
  width: 90%;
}

.main-menu-logo {
  margin-bottom: 60px;
}

.menu-marbles {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 30px;
}

.menu-marble {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);
  animation: floatMarble 3s ease-in-out infinite;
}

.menu-marble-1 {
  background: radial-gradient(circle at 30% 30%, #4a90e2, #2e5c8a);
  animation-delay: 0s;
}

.menu-marble-2 {
  background: radial-gradient(circle at 30% 30%, #9b59b6, #6c3483);
  animation-delay: 0.5s;
}

.menu-marble-3 {
  background: radial-gradient(circle at 30% 30%, #27ae60, #1e8449);
  animation-delay: 1s;
}

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

.main-menu-title {
  font-size: 4rem;
  color: white;
  margin-bottom: 0;
  font-weight: bold;
  text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.4);
  letter-spacing: 2px;
}

.main-menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
}

.main-menu-primary-btn,
.main-menu-secondary-btn {
  padding: 16px 45px;
  font-size: 1.1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s ease;
  width: 100%;
  max-width: 320px;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.main-menu-primary-btn {
  background-color: white;
  color: var(--purple);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.main-menu-primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.main-menu-secondary-btn {
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.main-menu-secondary-btn:hover {
  background-color: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.8);
}

/* Responsive adjustments for main menu */
@media (max-width: 480px) {
  .main-menu-title {
    font-size: 2.8rem;
    letter-spacing: 1px;
  }

  .menu-marble {
    width: 40px;
    height: 40px;
  }

  .menu-marbles {
    gap: 15px;
    margin-bottom: 25px;
  }

  .main-menu-logo {
    margin-bottom: 50px;
  }

  .main-menu-primary-btn,
  .main-menu-secondary-btn {
    padding: 14px 35px;
    font-size: 1rem;
  }
}

.modal-close-btn:hover {
  opacity: 0.6;
  background: none !important;
  color: #000 !important;
  box-shadow: none !important;
  transform: none !important;
}

button {
  padding: 10px 20px;
  font-size: 16px;
  background-color: var(--primary-blue-light);
  color: var(--text-light);
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background-color: var(--primary-blue-hover);
}

/* ===================================
   RESPONSIVE DESIGN - DESKTOP
   =================================== */

/* Tablets - intermediate sizing */
/* Tablet screens */
@media (min-width: 481px) and (max-width: 992px) {
  html, body {
    height: 100vh;
    overflow: hidden;
  }

  body {
    padding: 10px;
    display: flex;
  }

  .game-container {
    max-width: 100%;
    margin: 0 auto;
    padding: 15px;
    border-radius: 10px;
    box-shadow: var(--shadow-sm), inset 0 -60px 80px -30px var(--health-shadow-color);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    transition: box-shadow 0.5s ease;
  }

  .grid-container {
    flex: 1;
    overflow: hidden;
    min-height: auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }

  .row-wrapper {
    grid-template-columns: 1fr;
  }

  .row-label {
    display: none;
  }

  .stats-badge {
    padding: 8px 14px;
    min-width: 100px;
  }

  /* Fix horizontal overflow - reduce marble group gap to match grid spacing */
  .marble-group {
    gap: 11px; /* Matches visual gap between marbles in grid (box gap 1px + marble padding 10px) */
  }

  /* Fix horizontal overflow - reduce box size */
  .box {
    width: 7.5vw;
    height: 7.5vw;
  }

  .marble {
    width: calc(7.5vw - 10px);
    height: calc(7.5vw - 10px);
    font-size: 2.5vw;
  }

  .target-number-display .marble-icon {
    width: calc(7.5vw - 10px);
    height: calc(7.5vw - 10px);
  }

  .target-plus {
    font-size: 6vw;
  }

  .target-number {
    font-size: 6vw;
  }

  .row {
    gap: 1px;
  }

  /* Fix collapsed box sizes to match regular box size */
  .hundred-box {
    width: calc(75vw + 9px); /* 10 boxes * 7.5vw + 9 gaps * 1px */
    height: 7.5vw;
    font-size: 4vw;
  }

  .thousand-box {
    width: calc(75vw + 9px); /* 10 boxes * 7.5vw + 9 gaps * 1px */
    height: 7.5vw;
    font-size: 4vw;
  }
}

/* Desktop and larger screens */
@media (min-width: 993px) {
  html, body {
    height: 100vh;
    overflow: hidden;
  }

  body {
    padding: 20px;
    display: flex;
  }

  .game-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 30px;
    border-radius: 10px;
    box-shadow: var(--shadow-sm), inset 0 -60px 80px -30px var(--health-shadow-color);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    transition: box-shadow 0.5s ease;
  }

  .grid-container {
    flex: 1;
    overflow: hidden;
    min-height: auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }

  .mode-controls {
    margin-top: 0;
    flex-shrink: 1;
  }

  .controls {
    flex-shrink: 1;
  }

  .stats-badge {
    padding: 8px 14px;
    min-width: 100px;
  }

  .row-wrapper {
    grid-template-columns: 40px 1fr 40px;
  }

  .row-label {
    display: block;
  }

  .row-wrapper > .row-label {
    grid-column: 1;
  }

  .row-wrapper > .row,
  .row-wrapper > .hundred-box,
  .row-wrapper > .thousand-box {
    grid-column: 2;
  }

  .row {
    gap: 5px;
  }

  .box {
    width: 50px;
    height: 50px;
  }

  .marble {
    width: 40px;
    height: 40px;
    font-size: 14px;
  }

  .box-number {
    font-size: 11px;
  }

  .target-number-display .marble-icon {
    width: 40px;
    height: 40px;
  }

  .target-plus {
    font-size: 34px;
  }

  .target-number {
    font-size: 34px;
  }

  .grid-container {
    gap: 10px;
    padding: 20px;
    overflow-x: visible;
  }

  .marble-group {
    gap: 15px;
  }

  .marble-count-indicator,
  .split-indicator {
    font-size: 24px;
  }

  .hundred-box,
  .thousand-box {
    width: 545px; /* 10 boxes * 50px + 9 gaps * 5px */
    height: 50px;
    font-size: 24px;
  }
}

/* Stats bar - contains level and streak side by side */
.stats-bar {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  margin-bottom: 10px;
}

/* Common stats badge styles */
.stats-badge {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 20px;
  border: 2px solid;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  flex: 1;
  min-width: 80px;
  max-width: 150px;
  position: relative;
  cursor: help;
}

/* Custom tooltip styles */
.custom-tooltip {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
  min-width: 200px;
  max-width: 280px;
  box-shadow: 0 4px 12px var(--tooltip-shadow);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  pointer-events: none;
  z-index: 1000;
  overflow: hidden;
}

/* Adjust tooltip position for badges at screen edges */
.level-display .custom-tooltip {
  left: 0;
  transform: translateX(0);
}

.streak-counter .custom-tooltip {
  left: auto;
  right: 0;
  transform: translateX(0);
}

/* Adjust arrow position for edge-aligned tooltips */
.level-display .custom-tooltip::after {
  left: 20px;
  transform: translateX(0);
}

.streak-counter .custom-tooltip::after {
  left: auto;
  right: 20px;
  transform: translateX(0);
}

.tooltip-header {
  padding: 8px 12px;
  font-weight: bold;
  font-size: 14px;
}

.tooltip-body {
  padding: 8px 12px;
  background-color: var(--text-light);
}

.tooltip-progress-container {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background-color: rgba(0, 0, 0, 0.1);
  margin: 6px 0 4px 0;
  overflow: hidden;
}

.tooltip-progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0;
}

.tooltip-progress-text {
  font-size: 11px;
  opacity: 0.8;
}

.custom-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
}

/* Level tooltip - purple theme (inverted) */
.level-display .tooltip-header {
  background-color: var(--purple-medium);
  color: var(--text-light);
}

.level-display .tooltip-body {
  color: var(--purple-dark);
}

.level-display .tooltip-progress-fill {
  background: linear-gradient(90deg, var(--purple-medium), var(--purple-dark));
}

.level-display .custom-tooltip::after {
  border-bottom-color: var(--purple-medium);
}

/* Marble count tooltip - blue theme (inverted) */
.marble-count .tooltip-header {
  background-color: var(--primary-blue-light);
  color: var(--text-light);
}

.marble-count .tooltip-body {
  color: var(--primary-blue-dark);
}

.marble-count .tooltip-progress-fill {
  background: linear-gradient(90deg, var(--primary-blue-light), var(--primary-blue-dark));
}

.marble-count .custom-tooltip::after {
  border-bottom-color: var(--primary-blue-light);
}

/* Streak tooltip - yellow theme (inverted) */
.streak-counter .tooltip-header {
  background-color: var(--yellow);
  color: var(--text-dark);
}

.streak-counter .tooltip-body {
  color: var(--yellow-dark);
}

.streak-counter .tooltip-progress-fill {
  background: linear-gradient(90deg, var(--yellow-light), var(--yellow));
}

.streak-counter .custom-tooltip::after {
  border-bottom-color: var(--yellow);
}

.stats-badge:hover .custom-tooltip {
  opacity: 1;
  visibility: visible;
}

.stats-badge.hidden {
  cursor: default;
}

.stats-badge.hidden .custom-tooltip {
  display: none;
}

/* Common content container */
.stats-badge-content {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  height: 24px;
}

/* Common icon styles */
.stats-badge-icon {
  font-size: 18px;
}

/* Common number styles */
.stats-badge-number {
  font-size: 20px;
  font-weight: bold;
  min-width: 24px;
  text-align: center;
}

/* Common secondary text styles */
.stats-badge-secondary {
  font-size: 14px;
  font-weight: bold;
  opacity: 0.7;
}

/* Common progress bar container */
.stats-badge-progress-container {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
}

/* Common progress bar fill */
.stats-badge-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}

/* Level-specific colors */
.level-display {
  background: linear-gradient(135deg, var(--purple-lighter), var(--purple-medium));
  border-color: var(--purple-dark);
  box-shadow: 0 3px 8px var(--purple-shadow);
}

.level-display .stats-badge-number {
  color: var(--purple-dark);
  text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
}

.level-display .stats-badge-secondary {
  color: var(--purple-dark);
}

.level-display .stats-badge-progress-container {
  background-color: var(--purple-progress-bg);
}

.level-display .stats-badge-progress-fill {
  background: linear-gradient(90deg, var(--purple-medium), var(--purple-dark));
}

/* Marble count-specific colors */
.marble-count {
  background: linear-gradient(135deg, var(--primary-blue-lightest), var(--primary-blue-light));
  border-color: var(--primary-blue-dark);
  box-shadow: 0 3px 8px var(--blue-shadow);
}

.marble-count .stats-badge-number {
  color: var(--blue-text-dark);
  text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
}

.marble-count .stats-badge-secondary {
  color: var(--blue-text-medium);
}

.marble-count .stats-badge-progress-container {
  background-color: var(--blue-progress-bg);
}

.marble-count .stats-badge-progress-fill {
  background: linear-gradient(90deg, var(--primary-blue-light), var(--primary-blue-dark));
}

/* Streak-specific colors */
.streak-counter {
  background: linear-gradient(135deg, var(--yellow-lightest), var(--yellow-light));
  border-color: var(--yellow);
  box-shadow: 0 3px 8px var(--yellow-shadow);
}

.streak-counter .stats-badge-number {
  color: var(--yellow-dark);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.streak-counter .stats-badge-secondary {
  color: var(--yellow-darker);
}

.streak-counter .stats-badge-progress-container {
  background-color: var(--yellow-progress-bg);
}

.streak-counter .stats-badge-progress-fill {
  background: linear-gradient(90deg, var(--yellow-light), var(--yellow));
}

/* Icon animations */
.streak-counter .stats-badge-icon {
  animation: fireFlicker 1.5s ease-in-out infinite;
}

/* Grid overlay bar - container for lives, mode indicator, etc. */
.grid-overlay-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 5px;
  height: 0; /* Don't take up space in layout */
  transform: translateY(25px); /* Position it overlaid on grid */
  z-index: 10;
  pointer-events: none; /* Don't interfere with grid interactions */
}

/* Mode indicator */
.mode-indicator {
  display: flex;
  align-items: center;
  padding: 8px;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  cursor: help;
  pointer-events: auto; /* Allow hover */
}

.mode-icon {
  font-size: 1.2rem;
  display: inline-block;
  flex-shrink: 0;
}

.mode-label {
  font-size: 0.9rem;
  color: var(--text-primary);
  white-space: nowrap;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  transition: all 0.3s ease;
  margin-left: 0;
}

.mode-indicator:hover .mode-label {
  max-width: 150px;
  opacity: 1;
  margin: 0 5px;
}

/* Lives display - hearts */
.lives-display {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px;
  background-color: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border-radius: 20px;
  transition: opacity 0.3s ease;
}

.lives-display.hidden {
  display: none;
}

.lives-display.disabled {
  opacity: 0.3;
}

.lives-display .heart {
  font-size: 1.2rem;
  transition: opacity 0.3s ease;
  display: inline-block;
}

.lives-display .heart.alive {
  opacity: 1;
}

.lives-display .heart.lost {
  opacity: 0.3;
}

.lives-display .heart.bump {
  animation: heartBump 0.3s ease-out;
}

@keyframes heartBump {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}

.level-display .stats-badge-icon {
  animation: starTwinkle 3s ease-in-out infinite;
}

.marble-count .stats-badge-icon {
  animation: marbleBounce 4s ease-in-out infinite;
}

/* Hide stats badges when in practice mode */
.stats-badge.hidden {
  opacity: 0.3;
  transform: scale(0.9);
}


/* Fire flicker animation */
@keyframes fireFlicker {
  0%, 100% {
    transform: scale(1) rotate(-5deg);
  }
  25% {
    transform: scale(1.1) rotate(5deg);
  }
  50% {
    transform: scale(0.95) rotate(-3deg);
  }
  75% {
    transform: scale(1.05) rotate(3deg);
  }
}

/* Star twinkle animation - subtle scale and rotation */
@keyframes starTwinkle {
  0%, 100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  50% {
    transform: scale(1.05) rotate(5deg);
    opacity: 0.9;
  }
}

/* Marble bounce animation - gentle vertical movement */
@keyframes marbleBounce {
  0%, 100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-2px) scale(1.02);
  }
}

/* Badge bump animation (for level up and streak increase) */
@keyframes badgeBump {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

.stats-badge.bump {
  animation: badgeBump 0.3s ease-out;
}

.streak-counter.bump .stats-badge-icon {
  animation: fireGlow 0.3s ease-out;
}

@keyframes fireGlow {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }
  50% {
    transform: scale(1.2);
    filter: brightness(1.3);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

/* Mini-game Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  animation: modalFadeIn 0.3s ease-out;
  transition: opacity 0.5s ease-out;
  z-index: 1;
}

.modal-background.fade-out {
  opacity: 0;
}

.modal-content {
  background-color: white;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  max-width: 500px;
  width: 90%;
  text-align: center;
  animation: modalSlideIn 0.4s ease-out;
  position: relative;
  z-index: 2;
}

.modal-content h2 {
  color: var(--purple);
  margin-bottom: 20px;
  font-size: 28px;
}

.modal-message {
  font-size: 18px;
  color: var(--text-dark);
  margin-bottom: 15px;
  font-weight: bold;
}

.modal-submessage {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-stats {
  background-color: var(--bg-body);
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.modal-stats p {
  margin: 8px 0;
  color: var(--text-secondary);
}

/* Mode change modal specific styles */
.mode-change-content {
  max-width: 400px;
  padding: 20px 30px;
  position: relative;
  z-index: 1;
}

.mode-instruction {
  margin: 10px 0 0 0;
  text-align: center;
}

.mode-instruction p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.5;
}

.modal-close-btn {
  padding: 12px 30px;
  font-size: 18px;
  font-weight: bold;
  background: linear-gradient(135deg, var(--purple-medium), var(--purple));
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.modal-close-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.modal-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-top: 20px;
}

.modal-primary-btn {
  padding: 12px 30px;
  font-size: 18px;
  font-weight: bold;
  background: linear-gradient(135deg, var(--purple-medium), var(--purple));
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.modal-primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.modal-secondary-btn {
  padding: 12px 30px;
  font-size: 16px;
  background: white;
  color: var(--text-primary);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

/* Game Over Modal Styles */
.game-over-content {
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

.game-over-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
  margin: 25px 0;
  padding: 20px;
  background-color: var(--bg-body);
  border-radius: 10px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 15px;
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 32px;
  font-weight: bold;
  color: var(--purple);
}

@media (max-width: 600px) {
  .game-over-stats {
    grid-template-columns: 1fr;
    gap: 10px;
    margin: 15px 0;
    padding: 12px;
  }

  .stat-item {
    padding: 10px;
    gap: 5px;
  }

  .stat-label {
    font-size: 12px;
  }

  .stat-value {
    font-size: 24px;
  }
}

.modal-secondary-btn:hover {
  background: var(--bg-light);
  border-color: var(--purple);
}

@keyframes modalFadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

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

/* Mini-game styles */
.mini-game-content {
  position: relative;
  z-index: 1;
  background: linear-gradient(135deg, var(--purple-lightest) 0%, var(--purple-dark) 100%);
  padding: 30px;
  border-radius: 16px;
  border: 3px solid var(--purple-medium);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-width: 90vw;
  text-align: center;
  transition: box-shadow 0.3s ease-out;
}

.mini-game-content.shake {
  animation: shake 0.5s ease-in-out;
}

.mini-game-content.shine {
  box-shadow: 0 0 40px 10px rgba(46, 204, 113, 0.8),
              0 8px 24px rgba(0, 0, 0, 0.3);
}

.mini-game-content.slide-out-side {
  animation: slideOutSide 0.5s ease-in forwards;
}

.mini-game-content.collapse-to-target {
  animation: collapseToTarget 0.6s cubic-bezier(0.4, 0.0, 0.6, 1) forwards;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
  20%, 40%, 60%, 80% { transform: translateX(10px); }
}

@keyframes slideOutSide {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-150%);
  }
}

@keyframes collapseToTarget {
  0% {
    transform: translate(0, 0) scale(1);
  }
  100% {
    transform: translate(var(--collapse-x), var(--collapse-y)) scale(0);
  }
}

.mini-game-content h2 {
  margin: 0.5rem 0;
}

.fire-emoji {
  display: inline-block;
  animation: firePulse 2s ease-in-out infinite;
}

@keyframes firePulse {
  0%, 100% {
    transform: scale(1);
    filter: drop-shadow(0 0 5px rgba(255, 193, 7, 0.3));
  }
  50% {
    transform: scale(1.2);
    filter: drop-shadow(0 0 15px rgba(255, 193, 7, 0.6));
  }
}

.mini-game-problem {
  font-size: 2.5rem;
  font-weight: bold;
  color: var(--purple);
  margin-top: 1rem;
  background-color: var(--purple-lightest);
  padding: 10px 20px;
  border-radius: 5px;
  border: 2px solid var(--purple);
  display: inline-block;
}

.mini-grid-container {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 1rem;
  user-select: none;
}

.mini-row {
  display: flex;
  gap: 5px; /* Match main grid box spacing */
  justify-content: center;
  width: 100%;
}

.mini-box {
  width: 7vw;
  height: 7vw;
  flex-shrink: 0;
  border: 2px solid var(--text-primary);
  border-radius: 5px;
  background-color: var(--bg-container);
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background-color 0.2s,
    border-color 0.2s;
  position: relative;
  overflow: hidden;
  animation: boxAppear 0.3s ease-out backwards;
}

/* Stagger animation for boxes */
.mini-box:nth-child(1) { animation-delay: 0.05s; }
.mini-box:nth-child(2) { animation-delay: 0.1s; }
.mini-box:nth-child(3) { animation-delay: 0.15s; }
.mini-box:nth-child(4) { animation-delay: 0.2s; }
.mini-box:nth-child(5) { animation-delay: 0.25s; }
.mini-box:nth-child(6) { animation-delay: 0.3s; }
.mini-box:nth-child(7) { animation-delay: 0.35s; }
.mini-box:nth-child(8) { animation-delay: 0.4s; }
.mini-box:nth-child(9) { animation-delay: 0.45s; }
.mini-box:nth-child(10) { animation-delay: 0.5s; }

@keyframes boxAppear {
  from {
    opacity: 0;
    transform: scale(0.8) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Mini-grid cursor modes */
.mini-grid-container.visual-feedback .mini-box:not(.filled) {
  cursor: pointer;
}

.mini-grid-container.no-visual-feedback .mini-box:not(.filled) {
  cursor: crosshair;
}

.mini-box.filled {
  background: radial-gradient(
    circle at 30% 30%,
    var(--primary-blue-light),
    var(--primary-blue-dark)
  );
  box-shadow: var(--shadow-marble);
}

.mini-box:hover {
  border-color: var(--primary-blue-bright);
}

/* Responsive adjustments */
/* Mobile phones */
@media (max-width: 480px) {
  /* Thinner borders on very small screens */
  .box,
  .mini-box {
    border-width: 1px;
  }

  .box.target-box,
  .box.feedback-preview,
  .box.feedback-correct,
  .box.feedback-incorrect {
    border-width: 2px;
  }

  /* Larger boxes and marbles on small screens to use gained space */
  .mini-box {
    width: 8.5vw;
    height: 8.5vw;
  }

  .mini-box .marble {
    width: 7vw;
    height: 7vw;
  }

  /* Use almost full viewport width on small screens */
  .modal {
    padding: 0 4px;
  }

  .mini-game-content {
    max-width: none;
    width: 100%;
    padding: 12px 6px;
    border-radius: 8px;
    border-width: 2px;
  }

  .mini-grid-container,
  .mini-row {
    gap: 3px;
  }

  .instructions-modal-content {
    width: 95vw;
    padding: 20px;
    max-height: 85vh;
  }

  .instructions-modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: 15px;
  }

  .instructions-content p {
    margin: 12px 0;
    font-size: 0.95rem;
    line-height: 1.6;
  }

  .instructions-content strong {
    font-size: 1rem;
  }

  .modal-close-btn {
    font-size: 2.2rem;
    top: 8px;
    right: 12px;
    width: 36px;
    height: 36px;
  }
}

/* Tablets */
@media (min-width: 481px) and (max-width: 992px) {
  .mini-game-content {
    max-width: 90vw;
    padding: 20px 2vw;
  }

  .mini-game-problem {
    font-size: 2rem;
  }

  .mini-grid-container {
    padding: 0.75rem;
  }

  .modal-close-btn {
    font-size: 2.5rem;
    width: 40px;
    height: 40px;
  }
}

/* Desktop */
@media (min-width: 993px) {
  .mini-game-content {
    max-width: 600px;
    padding: 30px;
  }

  .mini-box {
    width: 50px;
    height: 50px;
  }

  .modal-close-btn {
    font-size: 2.5rem;
    width: 40px;
    height: 40px;
  }
}
