/* ===== 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: 0;
  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: 80px;
  object-fit: contain;
}

.game-modes-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  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: rgba(255, 255, 255, 0.95);
  border: 2px solid rgba(99, 179, 237, 0.3);
  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 4px 12px rgba(0, 0, 0, 0.08);
}

.game-mode-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #63B3ED, #4A9DD8);
  opacity: 0.8;
}

.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(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  border-color: var(--primary-accent);
  background: rgba(255, 255, 255, 1);
}

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

.game-mode-icon {
  font-size: 28px;
  margin-bottom: 9px;
  display: block;
}

.game-mode-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
  color: #333;
}

.game-mode-details {
  font-size: 13px;
  color: #666;
  line-height: 1.3;
}

.game-mode-lock {
  position: absolute;
  top: 10px;
  right: 10px;
  opacity: 0.5;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  margin-top: 12px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #63B3ED, #4A9DD8);
  transition: width 0.3s ease;
}

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

.progress-fill[data-progress-width] {
  width: calc(var(--progress-width, 0) * 1%);
}

/* ===== 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: #F8F9FA;
}

.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);
}

.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%;
}

.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: 8px 12px;
  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;
  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;
}

.mistakes-counter,
.timer {
  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: 8px 12px;
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #333;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 44px;
  height: 44px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  backdrop-filter: blur(10px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.mistakes-counter.error {
  border-color: var(--error);
  color: var(--error);
  background: linear-gradient(135deg, rgba(229, 62, 62, 0.1), rgba(229, 62, 62, 0.05));
  box-shadow: 0 2px 8px rgba(229, 62, 62, 0.15), 0 1px 2px rgba(0, 0, 0, 0.04);
}

.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;
}

.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;
}

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

.ball[data-color="red"] { background-color: #D10F13; }
.ball[data-color="darkGreen"] { background-color: #133E10; }
.ball[data-color="darkBlue"] { background-color: #1C249A; }
.ball[data-color="yellow"] { background-color: #F3CB0C; }
.ball[data-color="purple"] { background-color: #6D349F; }
.ball[data-color="magenta"] { background-color: #EE00D1; }
.ball[data-color="green"] { background-color: #00E893; }
.ball[data-color="blue"] { background-color: #0C8EF4; }
.ball[data-color="brown"] { background-color: #6C502F; }
.ball[data-color="lightPink"] { background-color: #E89EB8; }
.ball[data-color="peach"] { background-color: #FFCA99; }
.ball[data-color="orange"] { background-color: #FF5F2D; }
.ball[data-color="oliveGreen"] { background-color: #849E00; }
.ball[data-color="darkGrey"] { background-color: #34353B; }
.ball[data-color="darkRed"] { background-color: #740C08; }
.ball[data-color="lightBlue"] { background-color: #B5C7EB; }
.ball[data-color="pink"] { background-color: #FF00BF; }
.ball[data-color="rose"] { background-color: #FF0061; }
.ball[data-color="grey"] { background-color: #464B58; }
.ball[data-color="lightOrange"] { background-color: #E08E5C; }
.ball[data-color="cyan"] { background-color: #0CC0C0; }
.ball[data-color="mint"] { background-color: #5CE0AF; }

.ball[data-color] {
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.18);
}

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

.ball-count {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  font-weight: 900;
  color: #FFFFFF;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  line-height: 1;
}

/* ===== 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);
}

.color-ball-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: 50%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

.color-ball-item.disabled {
  display: none;
}

.color-ball-item.selected .ball {
  border: 3px solid #6366F1;
  box-sizing: border-box;
}

.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 {
  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;
}

.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;
}

.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 ===== */
.hidden {
  display: none !important;
}

/* ===== 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 {
    font-size: 17px;
  }

  .nav-button {
    padding: 9px 14px;
    font-size: 15px;
    min-height: 42px;
    height: 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 {
    font-size: 15px;
  }

  .nav-button {
    padding: 8px 12px;
    font-size: 15px;
    min-height: 40px;
    height: 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 {
    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 {
    font-size: 13px;
  }

  .nav-button {
    padding: 7px 12px;
    font-size: 14px;
    min-height: 38px;
    height: 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 {
    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 {
    font-size: 14px;
  }

  .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 {
    font-size: 11px;
  }

  .nav-button {
    padding: 6px 10px;
    font-size: 13px;
    min-height: 36px;
    height: 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 {
    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: 6px 10px;
    font-size: 13px;
    min-height: 36px;
    height: 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 {
    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 {
    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 {
    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 {
    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 {
    font-size: 7px;
  }
}
