/* ===== GLOBAL STYLES ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-accent: #63B3ED;
  --success: #38A169;
  --error: #E53E3E;
  --hint-highlight: #6366F1;
  --border-radius: 6px;
  --border-radius-lg: 12px;
  --border-radius-xl: 20px;
}

body {
  font-family: 'Roboto', sans-serif;
  background: linear-gradient(180deg, #FFFFFF 0%, #F0F7FF 50%, #E6F2FF 100%);
  min-height: 100vh;
  color: #333;
  overflow-x: hidden;
}

.game-body {
  position: relative;
}

/* ===== HOME SCREEN ===== */
#home-screen {
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(180deg, #FFFFFF 0%, #F0F7FF 50%, #E6F2FF 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

#home-screen.hidden {
  display: none;
}

.home-screen-content {
  max-width: 900px;
  width: 100%;
  max-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  margin: auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.logo-container {
  text-align: center;
  margin-bottom: 14px;
  position: relative;
  z-index: 1;
  padding: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.game-logo-img {
  max-width: 100%;
  height: auto;
  max-height: 110px;
  object-fit: contain;
}

.game-modes-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  max-width: 690px;
  width: 100%;
  margin: 0 auto 23px;
  position: relative;
  z-index: 1;
  padding: 0 17px 23px;
  box-sizing: border-box;
  justify-items: stretch;
  align-items: stretch;
}

.game-modes-grid > * {
  min-width: 0;
}

.game-mode-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(239, 246, 255, 0.86));
  border: 1.5px solid rgba(11, 45, 118, 0.18);
  border-radius: var(--border-radius-xl);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(10px);
  width: 100% !important;
  aspect-ratio: 1 !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  min-width: 0 !important;
  max-width: 100% !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  align-items: center !important;
  box-sizing: border-box !important;
  padding: 14px !important;
  box-shadow: 0 12px 30px rgba(11, 45, 118, 0.10);
}

.game-mode-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--brand-blue-700), var(--brand-gold-500));
  opacity: 0.8;
}

.game-mode-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(450px 220px at 20% 15%, rgba(45, 108, 240, 0.12), transparent 60%),
    radial-gradient(420px 220px at 85% 85%, rgba(245, 158, 11, 0.10), transparent 60%);
  pointer-events: none;
  opacity: 0.9;
}

.game-mode-card[data-mode-id="beginner"]::before { background: linear-gradient(90deg, #38A169, #2F855A); }
.game-mode-card[data-mode-id="easy"]::before { background: linear-gradient(90deg, #0C8EF4, #0A6BC2); }
.game-mode-card[data-mode-id="medium"]::before { background: linear-gradient(90deg, #6D349F, #5A2A85); }
.game-mode-card[data-mode-id="hard"]::before { background: linear-gradient(90deg, #FF5F2D, #E04A1A); }
.game-mode-card[data-mode-id="expert"]::before { background: linear-gradient(90deg, #FF00BF, #CC0099); }
.game-mode-card[data-mode-id="extreme"]::before { background: linear-gradient(90deg, #6D349F, #4A1F6B); }
.game-mode-card[data-mode-id="fast"]::before { background: linear-gradient(90deg, #FF5F2D, #E04A1A); }
.game-mode-card[data-mode-id="16x16"]::before { background: linear-gradient(90deg, #0CC0C0, #0A9A9A); }


.game-mode-card.unlocked:hover {
  transform: translateY(-6px) scale(1.015);
  box-shadow: 0 20px 50px rgba(11, 45, 118, 0.16);
  border-color: rgba(245, 158, 11, 0.55);
}

.game-mode-card.unlocked:active {
  transform: translateY(-2px) scale(1.005);
  box-shadow: 0 14px 34px rgba(11, 45, 118, 0.14);
}

.game-mode-card.locked {
  opacity: 0.75;
  cursor: not-allowed;
}

.game-mode-icon {
  font-size: 26px;
  margin-bottom: 10px;
  display: block;
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: rgba(219, 234, 254, 0.75);
  border: 1px solid rgba(11, 45, 118, 0.14);
  color: var(--brand-blue-800);
  box-shadow: 0 10px 24px rgba(11, 45, 118, 0.10);
  position: relative;
  z-index: 1;
}

.game-mode-name {
  font-size: 15px;
  font-weight: 900;
  margin-bottom: 6px;
  color: var(--ink);
  letter-spacing: 0.2px;
  position: relative;
  z-index: 1;
}

.game-mode-details {
  font-size: 12px;
  color: rgba(71, 85, 105, 0.95);
  line-height: 1.25;
  max-width: 140px;
  position: relative;
  z-index: 1;
}

.game-mode-lock {
  position: absolute;
  top: 10px;
  right: 10px;
  opacity: 1;
  font-size: 12px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(11, 45, 118, 0.12);
  color: rgba(71, 85, 105, 0.95);
  box-shadow: 0 10px 22px rgba(11, 45, 118, 0.10);
  z-index: 2;
}

/* Locked cards: frosted overlay for a "disabled" game feel */
.game-mode-card.locked::after {
  opacity: 0.55;
  filter: grayscale(0.35);
}

.game-mode-card.locked::before {
  opacity: 0.45;
}

.game-mode-card.locked {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(239, 246, 255, 0.70));
}

.game-mode-card.locked .game-mode-icon {
  background: rgba(226, 232, 240, 0.70);
  color: rgba(71, 85, 105, 0.95);
  box-shadow: none;
}

/* ===== GAME SCREEN ===== */
.game-screen {
  min-height: 100vh;
  padding: 10px;
  background: linear-gradient(180deg, #FFFFFF 0%, #F0F7FF 50%, #E6F2FF 100%);
}

.game-screen.hidden {
  display: none;
}

/* ===== GAME BOARD ===== */
.game-board-container {
  display: flex;
  justify-content: center;
  margin-bottom: 15px;
  padding: 0 5px;
}

.game-grid {
  display: grid;
  gap: 0;
  background: #FFFFFF;
  padding: 0;
  border: 2.2px solid #7F818D;
  border-radius: 0;
  max-width: min(90vw, 500px);
  min-width: 250px;
  width: 100%;
  aspect-ratio: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.game-grid[data-size="6"] {
  grid-template-columns: repeat(6, 1fr);
}

.game-grid[data-size="9"] {
  grid-template-columns: repeat(9, 1fr);
}

.game-grid[data-size="16"] {
  grid-template-columns: repeat(16, 1fr);
}

.grid-cell {
  background: #FFFFFF;
  border: 0.65px solid #9CA3AF;
  border-radius: 0;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  min-width: 0;
  min-height: 0;
  margin: 0;
}

.grid-cell:hover:not(.prefilled):not(.selected) {
  background: #F5F5F5;
}

.grid-cell.selected {
  background: #6366F1 !important;
  border-color: #6366F1;
}

.grid-cell.same-group:not(.selected) {
  background: rgba(99, 179, 237, 0.15);
}

.grid-cell.same-color:not(.selected) {
  background: #6366F1;
}

.grid-cell.prefilled:not(.selected):not(.same-color):not(.same-group) {
  background: #FFFFFF;
}

.grid-cell.prefilled {
  cursor: not-allowed;
}

.grid-cell.conflict {
  animation: shake 0.5s, pulseGlow 0.5s ease-in-out;
  background: rgba(229, 62, 62, 0.2);
}

/* Keep digits readable on the highlight backgrounds */
.grid-cell.selected .ball-digit,
.grid-cell.same-color .ball-digit,
.grid-cell.conflict .ball-digit {
  color: #FFFFFF;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.35);
}

.grid-cell.subgrid-border-right {
  border-right: 2.2px solid #7F818D !important;
}

.grid-cell.subgrid-border-bottom {
  border-bottom: 2.2px solid #7F818D !important;
}

.game-top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: nowrap;
  gap: 6px;
  width: 100%;
  position: relative;
}

.game-top-nav > * {
  display: flex;
  align-items: center;
}

.game-top-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-width: 0;
}

.game-top-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  flex-wrap: nowrap;
}

.game-mode-name {
  font-size: 18px;
  font-weight: 700;
  color: #333;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
}

.nav-button {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.9));
  border: 1.5px solid rgba(99, 179, 237, 0.25);
  border-radius: var(--border-radius-lg);
  padding: 0;
  font-size: 16px;
  color: #333;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  white-space: nowrap;
  min-height: 44px;
  height: 44px;
  width: 44px;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  backdrop-filter: blur(10px);
}

.nav-button:hover {
  background: linear-gradient(135deg, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0.98));
  border-color: var(--primary-accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(99, 179, 237, 0.2), 0 2px 4px rgba(0, 0, 0, 0.08);
}

.nav-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(99, 179, 237, 0.15), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.nav-button i {
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-stats {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: nowrap;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  padding: 6px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(239, 246, 255, 0.55));
  box-shadow: 0 10px 26px rgba(11, 45, 118, 0.10);
  border: 1px solid rgba(11, 45, 118, 0.10);
  backdrop-filter: blur(10px);
}

.mistakes-counter,
.timer {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0 8px;
  font-size: 15px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 0;
  height: auto;
  box-shadow: none;
  backdrop-filter: none;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  transition: none;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7),
               0 6px 16px rgba(11, 45, 118, 0.12);
}

.mistakes-counter i,
.timer i {
  font-size: 16px;
  opacity: 1;
}

.timer i {
  color: var(--brand-gold-500);
}

.mistakes-counter i {
  color: rgba(229, 62, 62, 0.95);
}

.mistakes-counter.error {
  color: var(--error);
}

.mistakes-counter.error i {
  color: var(--error);
  opacity: 1;
}

.action-buttons {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.action-btn {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(99, 179, 237, 0.3);
  border-radius: var(--border-radius-lg);
  padding: 10px 15px;
  font-size: 15px;
  color: #333;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px;
  position: relative;
  flex: 0 0 auto !important;
  min-width: 120px !important;
  width: auto;
  height: 44px !important;
  min-height: 44px !important;
  max-height: 44px !important;
  box-sizing: border-box !important;
}

.action-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 1);
  border-color: var(--primary-accent);
  transform: translateY(-2px);
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}

.hint-count {
  background: var(--hint-highlight);
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

/* ===== DIGIT TILES ===== */
.ball {
  width: 90%;
  height: 90%;
  border-radius: 50%;
  position: relative;
  transition: all 0.3s ease;
}

.game-grid .ball {
  /* Grid values should be square (not circular balls) */
  border-radius: 0;
  width: 100%;
  height: 100%;
}

.ball-placed {
  animation: ballPlace 0.3s ease;
}

.ball-count,
.ball-digit {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  font-weight: 900;
  color: #111827;
  text-shadow: none;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  line-height: 0.9;
}

/* Player placed numbers: use blue text */
.ball-placed .ball-digit {
  color: #0C8EF4 !important;
}

/* If a placed number is shown on blue highlight cells, keep it solid white */
.grid-cell.selected .ball-placed .ball-digit,
.grid-cell.same-color .ball-placed .ball-digit,
.grid-cell.conflict .ball-placed .ball-digit {
  color: #FFFFFF !important;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.35) !important;
}

/* ===== COLOR PALETTE ===== */
.color-palette-container {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  padding: 0 10px;
}

.color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  max-width: 100%;
  align-items: flex-start;
  background: linear-gradient(180deg, #FFFFFF 0%, #F8F9FA 100%);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 20px;
  padding: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.digit-palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 6px;
  position: relative;
}

.color-palette .ball {
  width: 50px;
  height: 50px;
  min-width: 50px;
  min-height: 50px;
  border-radius: 6px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background-color: rgba(99, 179, 237, 0.15); /* square colored card like before */
  box-shadow: none;
}

.color-palette .ball-digit,
.color-palette .ball-count {
  position: static;
  transform: none;
  text-shadow: none;
  color: #1F2937;
}

.color-palette .ball-digit {
  font-size: 20px;
}

.color-palette .ball-count {
  font-size: 12px;
  font-weight: 900;
}

.digit-palette-item:hover:not(.disabled) .ball {
  transform: scale(1.15);
}

.digit-palette-item:active:not(.disabled) .ball {
  transform: scale(1.0);
}

.digit-palette-item.disabled {
  display: none;
}

.digit-palette-item.selected .ball {
  border: none !important;
}

/* Make the selected number on the palette match the row/column highlight */
.digit-palette-item.selected .ball {
  background-color: #6366F1 !important; /* same as .grid-cell.selected */
  box-shadow: none !important;
}

.digit-palette-item.selected .ball-digit,
.digit-palette-item.selected .ball-count {
  color: #FFFFFF !important;
  text-shadow: none !important;
}

/* Tooltip shown above palette tiles when user tries to pick a number too early */
.palette-tip {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.95);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 999px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.22);
  z-index: 50;
  white-space: nowrap;
  pointer-events: none;
}

.palette-tip::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid rgba(17, 24, 39, 0.95);
}

.game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball {
  width: 35px;
  height: 35px;
  min-width: 35px;
  min-height: 35px;
}

.game-grid[data-size="16"] ~ .color-palette-container .color-palette {
  gap: 4px;
}

.game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball-count,
.game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball-digit {
  font-size: 14px;
}

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  background: white;
  border-radius: var(--border-radius-xl);
  padding: 30px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modalFadeIn 0.3s ease;
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  cursor: pointer;
  transition: color 0.3s ease;
}

.modal-close:hover {
  color: #333;
}

.modal-icon {
  font-size: 64px;
  text-align: center;
  margin-bottom: 20px;
}

.modal-icon.success {
  color: var(--success);
}

.modal-icon.error {
  color: var(--error);
}

.modal-content h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 15px;
  text-align: center;
  color: #333;
}

.modal-content p {
  font-size: 16px;
  line-height: 1.6;
  color: #666;
  margin-bottom: 20px;
  text-align: center;
}

.completion-time {
  font-size: 18px;
  font-weight: 700;
  color: var(--success);
  text-align: center;
  margin-bottom: 25px;
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Level complete: show Home + Play Again on one line */
#level-complete-modal .modal-buttons {
  flex-direction: row;
}

#level-complete-modal .modal-buttons .modal-btn {
  flex: 1 1 0;
}

@media (max-width: 420px) {
  #level-complete-modal .modal-buttons {
    flex-direction: column;
  }
}

.modal-btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--border-radius-lg);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
}

.modal-btn.primary {
  background: var(--primary-accent);
  color: white;
}

.modal-btn.primary:hover {
  background: #4A9DD8;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(99, 179, 237, 0.3);
}

.modal-btn.secondary {
  background: rgba(0, 0, 0, 0.05);
  color: #333;
}

.modal-btn.secondary:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* ===== HOW TO PLAY MODAL - GAME STYLE ===== */
.how-to-play-modal {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: 3px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 20px 60px rgba(102, 126, 234, 0.4), 
              0 0 40px rgba(118, 75, 162, 0.3),
              inset 0 0 20px rgba(255, 255, 255, 0.1);
  overflow: hidden;
  position: relative;
}

.how-to-play-modal::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
  pointer-events: none;
}

.how-to-play-header {
  text-align: center;
  margin-bottom: 30px;
  position: relative;
  z-index: 1;
}

/* Header without the top icon/subtitle */
.modal-content.how-to-play-modal .how-to-play-header {
  margin-bottom: 18px;
}

.how-to-play-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  border: 3px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  animation: iconFloat 3s ease-in-out infinite;
}

.how-to-play-icon i {
  font-size: 40px;
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.how-to-play-modal h2 {
  font-size: 32px;
  font-weight: 800;
  margin: 0 0 8px 0;
  color: #ffffff;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.3),
               0 0 30px rgba(255, 255, 255, 0.3);
  letter-spacing: 1px;
}

.how-to-play-subtitle {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.2);
}

.how-to-play-content {
  position: relative;
  z-index: 1;
}

.rules-intro {
  text-align: center;
  margin-bottom: 25px;
}

.rules-intro p {
  font-size: 18px;
  color: rgba(255, 255, 255, 0.95);
  font-weight: 600;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.2);
  margin: 0;
}

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.rule-item {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  animation: ruleSlideIn 0.5s ease-out backwards;
}

.rule-item:nth-child(1) {
  animation-delay: 0.1s;
}

.rule-item:nth-child(2) {
  animation-delay: 0.2s;
}

.rule-item:nth-child(3) {
  animation-delay: 0.3s;
}

.rule-item:hover {
  transform: translateX(5px);
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.rule-icon {
  width: 50px;
  height: 50px;
  min-width: 50px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.1));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.rule-icon i {
  font-size: 24px;
  color: #ffffff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.rule-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.rule-text strong {
  font-size: 18px;
  color: #ffffff;
  font-weight: 700;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.3);
  letter-spacing: 0.5px;
}

.rule-text span {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.5;
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
}

.how-to-play-modal .modal-close {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.how-to-play-modal .modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  transform: rotate(90deg) scale(1.1);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* ===== ANIMATIONS ===== */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 10px rgba(209, 15, 19, 0.4); }
  50% { box-shadow: 0 0 20px rgba(209, 15, 19, 0.7); }
}

@keyframes ballPlace {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes iconFloat {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-10px) rotate(5deg);
  }
}

@keyframes ruleSlideIn {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ===== UTILITY CLASSES ===== */

/* ===== RESPONSIVE DESIGN ===== */

/* Desktop (≥1025px) - Default styles already defined above */

/* Tablet Landscape (769px-1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .game-screen {
    padding: 15px;
  }

  .game-grid {
    max-width: min(85vw, 480px);
  }

  .game-modes-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    max-width: 575px;
    padding: 0 14px 17px;
  }

  .game-mode-card {
    padding: 12px;
    aspect-ratio: 1 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
  }

  .game-mode-icon {
    font-size: 23px;
    margin-bottom: 7px;
  }

  .game-mode-name {
    font-size: 14px;
    margin-bottom: 5px;
  }

  .game-mode-details {
    font-size: 12px;
  }

  .action-btn {
    padding: 10px 14px;
    font-size: 14px;
    flex: 0 0 auto !important;
    min-width: 110px !important;
    width: auto;
    height: 42px !important;
    min-height: 42px !important;
    max-height: 42px !important;
    box-sizing: border-box !important;
  }

  .color-palette .ball {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
  }

  .color-palette .ball-count,
  .color-palette .ball-digit {
    font-size: 17px;
  }

  .nav-button {
    padding: 0;
    font-size: 15px;
    min-height: 42px;
    height: 42px;
    width: 42px;
  }

  .nav-button i {
    font-size: 16px;
  }

  .mistakes-counter,
  .timer {
    padding: 9px 14px;
    font-size: 14px;
    min-height: 42px;
    height: 42px;
  }

  .mistakes-counter i,
  .timer i {
    font-size: 15px;
  }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
  .game-screen {
    padding: 12px;
  }

  .game-modes-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 9px;
    max-width: 518px;
    padding: 0 14px 17px;
  }

  .game-mode-card {
    padding: 10px;
    aspect-ratio: 1 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
  }

  .game-mode-icon {
    font-size: 21px;
    margin-bottom: 6px;
  }

  .game-mode-name {
    font-size: 13px;
    margin-bottom: 3px;
  }

  .game-mode-details {
    font-size: 10px;
  }

  .game-top-nav {
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: nowrap !important;
  }

  .game-top-left {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .game-top-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: nowrap !important;
  }

  .game-mode-name {
    margin: 0;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .game-stats {
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
    flex-wrap: nowrap;
  }

  .action-buttons {
    gap: 8px;
    margin-bottom: 15px;
  }

  .action-btn {
    font-size: 13px;
    padding: 9px 12px;
    flex: 0 0 auto !important;
    min-width: 100px !important;
    width: auto;
    height: 40px !important;
    min-height: 40px !important;
    max-height: 40px !important;
    box-sizing: border-box !important;
  }

  .game-board-container {
    padding: 0 8px;
    margin-bottom: 15px;
  }

  .game-grid {
    max-width: min(90vw, 450px);
    border-width: 2px;
  }

  .grid-cell {
    border-width: 0.6px;
  }

  .color-palette-container {
    margin-top: 15px;
    padding: 0 8px;
  }

  .color-palette {
    gap: 5px;
    padding: 5px;
  }

  .color-palette .ball {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
  }

  .color-palette .ball-count,
  .color-palette .ball-digit {
    font-size: 15px;
  }

  .nav-button {
    padding: 0;
    font-size: 15px;
    min-height: 40px;
    height: 40px;
    width: 40px;
  }

  .nav-button i {
    font-size: 15px;
  }

  .mistakes-counter,
  .timer {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 40px;
    height: 40px;
  }

  .mistakes-counter i,
  .timer i {
    font-size: 14px;
  }

  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
  }

  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball-count {
    font-size: 12px;
  }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
  #home-screen {
    padding: 10px;
  }

  .home-screen-content {
    width: 100%;
    max-width: 100vw;
    max-height: 100vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .logo-container {
    padding: 6px;
    margin-bottom: 0;
  }

  .game-logo-img {
    max-height: 40px;
  }

  .game-screen {
    padding: 10px;
  }

  .game-modes-grid {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 7px !important;
    padding: 0 9px 14px !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 auto 14px !important;
    grid-auto-columns: 1fr !important;
    box-sizing: border-box !important;
  }

  .game-mode-card {
    padding: 9px;
    aspect-ratio: 1 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
  }

  .game-mode-icon {
    font-size: 18px;
    margin-bottom: 5px;
  }

  .game-mode-name {
    font-size: 12px;
    margin-bottom: 3px;
  }

  .game-mode-details {
    font-size: 9px;
  }

  .game-top-nav {
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: nowrap !important;
  }

  .game-top-left {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-start;
  }

  .game-top-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: nowrap !important;
  }

  .game-mode-name {
    margin: 0;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
  }

  .game-stats {
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: nowrap;
  }

  .action-buttons {
    gap: 6px;
    margin-bottom: 12px;
  }

  .action-btn {
    font-size: 12px;
    padding: 8px 12px;
    gap: 6px;
    flex: 0 0 auto !important;
    width: 90px !important;
    min-width: 90px !important;
    max-width: 90px !important;
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    box-sizing: border-box !important;
  }

  .action-btn span {
    font-size: 12px;
  }

  .hint-count {
    width: 18px;
    height: 18px;
    font-size: 11px;
  }

  .game-board-container {
    padding: 0 5px;
    margin-bottom: 12px;
  }

  .game-grid {
    max-width: min(95vw, 420px);
    border-width: 2px;
  }

  .grid-cell {
    border-width: 0.5px;
  }

  .ball-count,
  .ball-digit {
    font-size: 16px;
  }

  .color-palette-container {
    margin-top: 12px;
    padding: 0 5px;
  }

  .color-palette {
    gap: 4px;
    padding: 4px;
  }

  .color-palette .ball {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
  }

  .color-palette .ball-count,
  .color-palette .ball-digit {
    font-size: 13px;
  }

  .nav-button {
    padding: 0;
    font-size: 14px;
    min-height: 38px;
    height: 38px;
    width: 38px;
  }

  .nav-button i {
    font-size: 14px;
  }

  .mistakes-counter,
  .timer {
    padding: 7px 12px;
    font-size: 12px;
    gap: 6px;
    min-height: 38px;
    height: 38px;
  }

  .mistakes-counter i,
  .timer i {
    font-size: 13px;
  }

  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
  }

  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball-count,
  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball-digit {
    font-size: 11px;
  }

  .modal-content {
    padding: 20px;
    width: 95%;
  }

  .modal-content h2 {
    font-size: 24px;
  }

  .modal-content p {
    font-size: 14px;
  }

  .how-to-play-modal {
    padding: 20px;
  }

  .how-to-play-icon {
    width: 60px;
    height: 60px;
    margin-bottom: 15px;
  }

  .how-to-play-icon i {
    font-size: 30px;
  }

  .how-to-play-modal h2 {
    font-size: 26px;
  }

  .how-to-play-subtitle {
    font-size: 14px;
  }

  .rule-item {
    padding: 15px;
    gap: 15px;
  }

  .rule-icon {
    width: 45px;
    height: 45px;
    min-width: 45px;
  }

  .rule-icon i {
    font-size: 20px;
  }

  .rule-text strong {
    font-size: 16px;
  }

  .rule-text span {
    font-size: 14px;
  }

  .modal-icon {
    font-size: 56px;
  }
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
  #home-screen {
    padding: 8px;
  }

  .home-screen-content {
    width: 100%;
    max-width: 100vw;
    max-height: 100vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .logo-container {
    padding: 8px;
    margin-bottom: 0;
  }

  .game-logo-img {
    max-height: 50px;
  }

  .game-screen {
    padding: 8px;
  }

  .game-modes-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 0 9px 12px;
    max-width: 100%;
    width: 100%;
    margin: 0 auto 12px;
  }

  .game-mode-card {
    padding: 7px;
    aspect-ratio: 1 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
  }

  .game-mode-icon {
    font-size: 16px;
    margin-bottom: 5px;
  }

  .game-mode-name {
    font-size: 10px;
    margin-bottom: 2px;
  }

  .game-mode-details {
    font-size: 8px;
  }

  .game-top-nav {
    flex-direction: row !important;
    align-items: center;
    margin-bottom: 10px;
    gap: 6px;
    flex-wrap: nowrap !important;
  }

  .game-top-left {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-start;
  }

  .game-top-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
    flex-wrap: nowrap !important;
  }

  .game-mode-name {
    font-size: 14px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
  }

  .game-stats {
    gap: 6px;
    flex-shrink: 0;
    flex-wrap: nowrap;
  }

  .action-buttons {
    gap: 5px;
    margin-bottom: 10px;
  }

  .action-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    max-width: 44px !important;
    max-height: 44px !important;
    border-radius: 50% !important;
    justify-content: center !important;
    padding: 0 !important;
    font-size: 16px;
    flex: 0 0 auto !important;
    box-sizing: border-box !important;
  }

  .action-btn span {
    display: none;
  }

  .hint-count {
    width: 16px;
    height: 16px;
    font-size: 10px;
    position: absolute;
    top: -4px;
    right: -4px;
  }

  .game-board-container {
    padding: 0 3px;
    margin-bottom: 10px;
  }

  .game-grid {
    max-width: min(98vw, 380px);
    border-width: 1.8px;
  }

  .grid-cell {
    border-width: 0.45px;
  }

  .ball-count,
  .ball-digit {
    font-size: 16px;
  }

  .color-palette-container {
    margin-top: 10px;
    padding: 0 3px;
  }

  .color-palette {
    gap: 3px;
    padding: 3px;
  }

  .color-palette .ball {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
  }

  .color-palette .ball-count,
  .color-palette .ball-digit {
    font-size: 11px;
  }

  .nav-button {
    padding: 0;
    font-size: 13px;
    min-height: 36px;
    height: 36px;
    width: 36px;
  }

  .nav-button i {
    font-size: 13px;
  }

  .mistakes-counter,
  .timer {
    padding: 6px 10px;
    font-size: 11px;
    gap: 5px;
    min-height: 36px;
    height: 36px;
  }

  .mistakes-counter i,
  .timer i {
    font-size: 12px;
  }

  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
  }

  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball-count,
  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball-digit {
    font-size: 9px;
  }

  .modal-content {
    padding: 15px;
    width: 98%;
  }

  .modal-content h2 {
    font-size: 20px;
  }

  .modal-content p {
    font-size: 13px;
  }

  .how-to-play-modal {
    padding: 15px;
  }

  .how-to-play-header {
    margin-bottom: 20px;
  }

  .how-to-play-icon {
    width: 50px;
    height: 50px;
    margin-bottom: 12px;
  }

  .how-to-play-icon i {
    font-size: 24px;
  }

  .how-to-play-modal h2 {
    font-size: 22px;
  }

  .how-to-play-subtitle {
    font-size: 12px;
  }

  .rules-intro p {
    font-size: 16px;
  }

  .rules-list {
    gap: 12px;
  }

  .rule-item {
    padding: 12px;
    gap: 12px;
  }

  .rule-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .rule-icon i {
    font-size: 18px;
  }

  .rule-text strong {
    font-size: 15px;
  }

  .rule-text span {
    font-size: 13px;
  }

  .modal-icon {
    font-size: 48px;
  }

  .logo-container {
    padding: 12px;
    margin-bottom: 0;
  }

  .game-logo-img {
    max-height: 80px;
  }
}

/* Landscape Mobile (orientation: landscape) */
@media (max-width: 1024px) and (orientation: landscape) {
  .game-screen {
    padding: 8px;
    min-height: auto;
  }

  .game-top-nav {
    flex-direction: row !important;
    align-items: center;
    margin-bottom: 8px;
    gap: 6px;
    flex-wrap: nowrap !important;
  }

  .game-top-left {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-start;
  }

  .game-top-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
    flex-wrap: nowrap !important;
  }

  .game-mode-name {
    font-size: 14px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
  }

  .game-stats {
    gap: 6px;
    flex-shrink: 0;
    flex-wrap: nowrap;
  }

  .nav-button {
    padding: 0;
    font-size: 13px;
    min-height: 36px;
    height: 36px;
    width: 36px;
  }

  .nav-button i {
    font-size: 13px;
  }

  .mistakes-counter,
  .timer {
    padding: 6px 10px;
    font-size: 11px;
    min-height: 36px;
    height: 36px;
  }

  .mistakes-counter i,
  .timer i {
    font-size: 12px;
  }

  .action-buttons {
    gap: 5px;
    margin-bottom: 8px;
  }

  .action-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    max-width: 44px;
    max-height: 44px;
    border-radius: 50%;
    justify-content: center;
    padding: 0;
    font-size: 16px;
    flex: 0 0 auto;
  }

  .action-btn span {
    display: none;
  }

  .hint-count {
    width: 14px;
    height: 14px;
    font-size: 9px;
    position: absolute;
    top: -3px;
    right: -3px;
  }

  .game-board-container {
    padding: 0 5px;
    margin-bottom: 8px;
  }

  .game-grid {
    max-width: min(37.5vh, 37.5vw, 300px);
    border-width: 1.8px;
  }

  .grid-cell {
    border-width: 0.4px;
  }

  .ball-count,
  .ball-digit {
    font-size: 12px;
  }

  .color-palette-container {
    margin-top: 8px;
    padding: 0 5px;
  }

  .color-palette {
    gap: 3px;
    padding: 3px;
  }

  .color-palette .ball {
    width: 22.5px;
    height: 22.5px;
    min-width: 22.5px;
    min-height: 22.5px;
  }

  .color-palette .ball-count,
  .color-palette .ball-digit {
    font-size: 10px;
  }

  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball {
    width: 16.5px;
    height: 16.5px;
    min-width: 16.5px;
    min-height: 16.5px;
  }

  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball-count,
  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball-digit {
    font-size: 8px;
  }

  /* Adjust home screen for landscape */
  #home-screen {
    padding: 8px;
  }

  .home-screen-content {
    width: 100%;
    max-width: 100vw;
    max-height: 100vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .logo-container {
    padding: 10px;
    margin-bottom: 0;
  }

  .game-logo-img {
    max-height: 60px;
  }

  .game-modes-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    padding: 0 7px 9px;
    max-width: 100%;
    width: 100%;
    margin: 0 auto 9px;
  }

  .game-mode-card {
    padding: 6px;
    aspect-ratio: 1 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
  }

  .game-mode-icon {
    font-size: 14px;
    margin-bottom: 3px;
  }

  .game-mode-name {
    font-size: 9px;
    margin-bottom: 2px;
  }

  .game-mode-details {
    font-size: 7px;
  }
}

/* Extra small landscape adjustments */
@media (max-width: 640px) and (orientation: landscape) {
  .game-grid {
    max-width: min(33.75vh, 33.75vw, 262.5px);
  }

  .color-palette .ball {
    width: 21px;
    height: 21px;
    min-width: 21px;
    min-height: 21px;
  }

  .color-palette .ball-count,
  .color-palette .ball-digit {
    font-size: 9px;
  }

  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball {
    width: 15px;
    height: 15px;
    min-width: 15px;
    min-height: 15px;
  }

  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball-count,
  .game-grid[data-size="16"] ~ .color-palette-container .color-palette .ball-digit {
    font-size: 7px;
  }
}

/* =======================================================================
   SUDOKU MASTER (LOGO) THEME OVERRIDES — light, game-like blue + gold
   App stays light; colors and UI accents match the logo.
   ======================================================================= */

:root {
  /* Brand palette (derived from logo) */
  --brand-blue-950: #061a44;
  --brand-blue-900: #0b2d76;
  --brand-blue-800: #0f3aa0;
  --brand-blue-700: #1a56db;
  --brand-blue-600: #2d6cf0;
  --brand-blue-200: #dbeafe;
  --brand-blue-100: #eff6ff;

  --brand-gold-600: #fbbf24;
  --brand-gold-500: #f59e0b;
  --brand-gold-200: #fde68a;

  --ink: #0f172a;
  --muted: #475569;

  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --stroke: rgba(11, 45, 118, 0.18);
  --stroke-strong: rgba(11, 45, 118, 0.28);

  --shadow-soft: 0 10px 30px rgba(11, 45, 118, 0.10);
  --shadow-pop: 0 16px 42px rgba(11, 45, 118, 0.14);

  /* Map existing tokens to brand */
  --primary-accent: var(--brand-blue-700);
  --hint-highlight: var(--brand-gold-500);
}

body,
#home-screen,
.game-screen {
  background: radial-gradient(1100px 700px at 20% -10%, rgba(45, 108, 240, 0.22), transparent 55%),
              radial-gradient(900px 600px at 110% 10%, rgba(245, 158, 11, 0.16), transparent 55%),
              linear-gradient(180deg, #ffffff 0%, var(--brand-blue-100) 55%, #ffffff 100%) !important;
  color: var(--ink);
}

/* Home mode cards feel more "game" */
.game-mode-card {
  border-color: var(--stroke-strong);
  box-shadow: var(--shadow-soft);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.90));
}

.game-mode-card.unlocked:hover {
  border-color: rgba(245, 158, 11, 0.55);
  box-shadow: var(--shadow-pop);
}

.game-mode-icon {
  color: var(--brand-blue-800);
}

/* Top nav + stats: crisp blue glass */
.nav-button,
.mistakes-counter,
.timer {
  border-color: var(--stroke);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(239, 246, 255, 0.88));
  box-shadow: 0 8px 22px rgba(11, 45, 118, 0.10);
  color: var(--ink);
}

.nav-button:hover {
  border-color: rgba(245, 158, 11, 0.55);
  box-shadow: 0 12px 28px rgba(11, 45, 118, 0.14);
}

.mistakes-counter.error {
  border-color: rgba(229, 62, 62, 0.55);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(254, 226, 226, 0.75));
}

/* Action buttons: game-y pill look */
.action-btn {
  border-color: var(--stroke);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(239, 246, 255, 0.86));
  box-shadow: 0 10px 26px rgba(11, 45, 118, 0.10);
}

.action-btn:hover:not(:disabled) {
  border-color: rgba(245, 158, 11, 0.55);
  box-shadow: 0 14px 34px rgba(11, 45, 118, 0.14);
}

.hint-count {
  background: radial-gradient(circle at 30% 30%, var(--brand-gold-200), var(--brand-gold-500));
  color: #1f2937;
  box-shadow: 0 6px 14px rgba(245, 158, 11, 0.35);
}

/* Grid board: cleaner strokes + brand highlights */
.game-grid {
  border-color: rgba(11, 45, 118, 0.55);
  box-shadow: 0 14px 40px rgba(11, 45, 118, 0.14);
  background: linear-gradient(180deg, #ffffff, rgba(239, 246, 255, 0.55));
}

.grid-cell {
  border-color: rgba(15, 58, 160, 0.22);
}

.grid-cell:hover:not(.prefilled):not(.selected) {
  background: rgba(219, 234, 254, 0.55);
}

.grid-cell.selected {
  background: linear-gradient(135deg, rgba(45, 108, 240, 0.95), rgba(26, 86, 219, 0.95)) !important;
  border-color: rgba(245, 158, 11, 0.75) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.grid-cell.same-group:not(.selected) {
  background: rgba(45, 108, 240, 0.12);
}

.grid-cell.same-color:not(.selected) {
  background: rgba(245, 158, 11, 0.58);
}

.grid-cell.subgrid-border-right {
  border-right-color: rgba(11, 45, 118, 0.55) !important;
}

.grid-cell.subgrid-border-bottom {
  border-bottom-color: rgba(11, 45, 118, 0.55) !important;
}

/* Numbers on highlight backgrounds */
.grid-cell.selected .ball-digit,
.grid-cell.same-color .ball-digit,
.grid-cell.conflict .ball-digit {
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(6, 26, 68, 0.45);
}

/* Palette: match brand, make selection pop in gold */
.color-palette {
  border-color: var(--stroke);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(239, 246, 255, 0.80));
  box-shadow: 0 14px 40px rgba(11, 45, 118, 0.12);
}

.digit-palette-item.selected .ball {
  background: radial-gradient(circle at 30% 30%, var(--brand-gold-200), var(--brand-gold-500)) !important;
  box-shadow: 0 12px 22px rgba(245, 158, 11, 0.35) !important;
  border-color: rgba(11, 45, 118, 0.35) !important;
}

.digit-palette-item.selected .ball-digit,
.digit-palette-item.selected .ball-count {
  color: #1f2937 !important;
  text-shadow: none !important;
}

/* Modals: brighter, more game-like */
.modal-content {
  border-color: rgba(11, 45, 118, 0.22);
  box-shadow: 0 30px 90px rgba(11, 45, 118, 0.20);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(239, 246, 255, 0.88));
}

/* Ensure How To Play stays high-contrast + "game" styled.
   (The generic .modal-content theme override above otherwise overrides it.) */
.modal-content.how-to-play-modal {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(239, 246, 255, 0.88));
  border: 2px solid rgba(11, 45, 118, 0.22);
  box-shadow: 0 30px 90px rgba(11, 45, 118, 0.20);
  position: relative;
}

.modal-content.how-to-play-modal .how-to-play-subtitle,
.modal-content.how-to-play-modal .rules-intro p,
.modal-content.how-to-play-modal .rule-text strong,
.modal-content.how-to-play-modal .rule-text span,
.modal-content.how-to-play-modal h2 {
  color: var(--ink);
}

.modal-content.how-to-play-modal h2,
.modal-content.how-to-play-modal .how-to-play-subtitle,
.modal-content.how-to-play-modal .rules-intro p,
.modal-content.how-to-play-modal .rule-text strong,
.modal-content.how-to-play-modal .rule-text span {
  text-shadow: none;
}

.modal-content.how-to-play-modal .how-to-play-subtitle {
  color: var(--brand-blue-700);
  font-weight: 700;
}

.modal-content.how-to-play-modal .rule-item {
  background: rgba(219, 234, 254, 0.62);
  border-color: rgba(11, 45, 118, 0.18);
}

.modal-content.how-to-play-modal .rule-item:hover {
  background: rgba(219, 234, 254, 0.82);
  border-color: rgba(245, 158, 11, 0.55);
}

.modal-content.how-to-play-modal .modal-close {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid rgba(11, 45, 118, 0.14);
}

.modal-content.how-to-play-modal .how-to-play-icon {
  background: linear-gradient(135deg, rgba(45, 108, 240, 0.18), rgba(245, 158, 11, 0.12));
  border: 2px solid rgba(11, 45, 118, 0.22);
  box-shadow: 0 18px 45px rgba(11, 45, 118, 0.16);
}

.modal-content.how-to-play-modal .how-to-play-icon i {
  color: var(--brand-blue-800);
  text-shadow: 0 2px 18px rgba(11, 45, 118, 0.25);
}

.modal-content.how-to-play-modal .rule-icon {
  background: linear-gradient(135deg, rgba(45, 108, 240, 0.28), rgba(255, 255, 255, 0.25));
  border-color: rgba(245, 158, 11, 0.35);
}

.modal-content.how-to-play-modal .rule-icon i {
  color: var(--brand-blue-800);
  text-shadow: 0 2px 12px rgba(11, 45, 118, 0.25);
}

.modal-btn.primary {
  background: linear-gradient(135deg, var(--brand-blue-700), var(--brand-blue-800));
}

.modal-btn.primary:hover {
  background: linear-gradient(135deg, var(--brand-blue-600), var(--brand-blue-700));
  box-shadow: 0 10px 26px rgba(45, 108, 240, 0.28);
}

.modal-btn.secondary:hover {
  background: rgba(219, 234, 254, 0.85);
}

/* Final HUD override: ensure stats never look like separate buttons */
.game-top-nav .game-stats {
  border-radius: 14px;
}

.game-top-nav .game-stats > .mistakes-counter,
.game-top-nav .game-stats > .timer {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  min-height: 0 !important;
  height: auto !important;
  padding: 2px 10px !important;
}

.game-top-nav .game-stats > .timer {
  padding-left: 14px !important;
  margin-left: 6px;
  border-left: 1px solid rgba(11, 45, 118, 0.18);
}

/* ===========================
   HOME SCREEN - FINAL ARCADE CARDS
   (Override everything above)
   =========================== */
#home-screen .game-modes-grid {
  gap: 14px;
}

#home-screen .game-mode-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(239, 246, 255, 0.86));
  border: 1.5px solid rgba(11, 45, 118, 0.14);
  border-radius: 22px;
  box-shadow: 0 16px 44px rgba(11, 45, 118, 0.10);
  padding: 14px 14px 16px !important;
  backdrop-filter: blur(12px);
  user-select: none;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 10px;
}

#home-screen .game-mode-card::before {
  display: none;
}

#home-screen .game-mode-card::after {
  display: none;
}

#home-screen .game-mode-card.unlocked:hover {
  transform: translateY(-6px);
  border-color: rgba(245, 158, 11, 0.50);
  box-shadow: 0 24px 70px rgba(11, 45, 118, 0.16);
}

#home-screen .game-mode-card.unlocked:active {
  transform: translateY(-2px);
}

#home-screen .game-mode-card.locked {
  opacity: 0.72;
  filter: saturate(0.85);
  box-shadow: 0 14px 40px rgba(11, 45, 118, 0.08);
}

#home-screen .game-mode-card.locked::after {
  display: none;
}

#home-screen .game-mode-icon {
  width: 54px !important;
  height: 54px !important;
  min-width: 54px !important;
  min-height: 54px !important;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.80);
  border: 1.5px solid rgba(11, 45, 118, 0.12);
  display: grid !important;
  place-items: center !important;
  font-size: 26px !important;
  margin-bottom: 2px !important;
  color: var(--brand-blue-800);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.75),
              0 14px 26px rgba(11, 45, 118, 0.10);
  position: relative;
  z-index: 1;
}

#home-screen .game-mode-name {
  font-size: 14px !important;
  font-weight: 950 !important;
  letter-spacing: 0.3px;
  margin: 0 !important;
  color: var(--ink) !important;
  position: relative;
  z-index: 1;
  line-height: 1.15;
  text-align: center;
}

#home-screen .game-mode-details {
  font-size: 11px !important;
  font-weight: 900;
  color: rgba(11, 45, 118, 0.75) !important;
  line-height: 1.1;
  max-width: 160px;
  position: relative;
  z-index: 1;
  text-align: center;
}

#home-screen .lock-progress {
  width: min(160px, 92%);
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 0;
  position: relative;
  z-index: 1;
}

#home-screen .lock-progress-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(11, 45, 118, 0.10);
  overflow: hidden;
  border: 1px solid rgba(11, 45, 118, 0.10);
  box-shadow: inset 0 1px 2px rgba(11, 45, 118, 0.10);
}

#home-screen .lock-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-blue-700), var(--brand-gold-500));
  box-shadow: 0 8px 18px rgba(26, 86, 219, 0.18);
}

/* Progress width utilities (no inline CSS needed) */
#home-screen .lock-progress-fill.p0 { width: 0%; }
#home-screen .lock-progress-fill.p5 { width: 5%; }
#home-screen .lock-progress-fill.p10 { width: 10%; }
#home-screen .lock-progress-fill.p15 { width: 15%; }
#home-screen .lock-progress-fill.p20 { width: 20%; }
#home-screen .lock-progress-fill.p25 { width: 25%; }
#home-screen .lock-progress-fill.p30 { width: 30%; }
#home-screen .lock-progress-fill.p35 { width: 35%; }
#home-screen .lock-progress-fill.p40 { width: 40%; }
#home-screen .lock-progress-fill.p45 { width: 45%; }
#home-screen .lock-progress-fill.p50 { width: 50%; }
#home-screen .lock-progress-fill.p55 { width: 55%; }
#home-screen .lock-progress-fill.p60 { width: 60%; }
#home-screen .lock-progress-fill.p65 { width: 65%; }
#home-screen .lock-progress-fill.p70 { width: 70%; }
#home-screen .lock-progress-fill.p75 { width: 75%; }
#home-screen .lock-progress-fill.p80 { width: 80%; }
#home-screen .lock-progress-fill.p85 { width: 85%; }
#home-screen .lock-progress-fill.p90 { width: 90%; }
#home-screen .lock-progress-fill.p95 { width: 95%; }
#home-screen .lock-progress-fill.p100 { width: 100%; }

#home-screen .game-mode-lock {
  width: 28px !important;
  height: 28px !important;
  font-size: 13px !important;
  border-radius: 999px;
  top: 12px !important;
  right: 12px !important;
  background: rgba(255, 255, 255, 0.92) !important;
  border: 1.4px solid rgba(11, 45, 118, 0.14) !important;
  color: rgba(71, 85, 105, 0.95) !important;
  box-shadow: 0 14px 26px rgba(11, 45, 118, 0.10);
  z-index: 3;
}

/* Icon tile accents per mode */
#home-screen .game-mode-card[data-mode-id="beginner"] .game-mode-icon {
  background: linear-gradient(135deg, rgba(56, 161, 105, 0.18), rgba(47, 133, 90, 0.10));
  border-color: rgba(47, 133, 90, 0.28);
  color: #2F855A;
}
#home-screen .game-mode-card[data-mode-id="easy"] .game-mode-icon {
  background: linear-gradient(135deg, rgba(12, 142, 244, 0.20), rgba(10, 107, 194, 0.10));
  border-color: rgba(10, 107, 194, 0.28);
  color: #0A6BC2;
}
#home-screen .game-mode-card[data-mode-id="medium"] .game-mode-icon {
  background: linear-gradient(135deg, rgba(109, 52, 159, 0.18), rgba(90, 42, 133, 0.10));
  border-color: rgba(90, 42, 133, 0.28);
  color: #5A2A85;
}
#home-screen .game-mode-card[data-mode-id="hard"] .game-mode-icon,
#home-screen .game-mode-card[data-mode-id="fast"] .game-mode-icon {
  background: linear-gradient(135deg, rgba(255, 95, 45, 0.22), rgba(224, 74, 26, 0.10));
  border-color: rgba(224, 74, 26, 0.30);
  color: #E04A1A;
}
#home-screen .game-mode-card[data-mode-id="expert"] .game-mode-icon {
  background: linear-gradient(135deg, rgba(255, 0, 191, 0.18), rgba(204, 0, 153, 0.10));
  border-color: rgba(204, 0, 153, 0.28);
  color: #CC0099;
}
#home-screen .game-mode-card[data-mode-id="extreme"] .game-mode-icon {
  background: linear-gradient(135deg, rgba(109, 52, 159, 0.18), rgba(74, 31, 107, 0.10));
  border-color: rgba(74, 31, 107, 0.28);
  color: #4A1F6B;
}
#home-screen .game-mode-card[data-mode-id="16x16"] .game-mode-icon {
  background: linear-gradient(135deg, rgba(12, 192, 192, 0.18), rgba(10, 154, 154, 0.10));
  border-color: rgba(10, 154, 154, 0.28);
  color: #0A9A9A;
}
