/* Sweet Sort — candy-land UI (home + board) */
@import url("https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=Nunito:wght@600;700;800&display=swap");

:root {
  --font-ui: "Nunito", system-ui, sans-serif;
  --font-display: "Fredoka", "Nunito", system-ui, sans-serif;
  --sky-bottom: #fff1c2;
  --game-accent: #e8b86a;
  --game-accent-hover: #f2ca82;
  --gold-border: #d4af6a;
  --level-plum: #2d1b2d;
  --chocolate: #3e1f1f;
  --panel-cream: #faf6f0;
  --tile-shadow: 0 3px 10px rgba(62, 31, 31, 0.12);
  --tile-shadow-hover: 0 5px 16px rgba(62, 31, 31, 0.16);
  --text-primary: #3e1f1f;
  --text-secondary: #6b4545;
  --shadow-light: 0 4px 14px rgba(62, 31, 31, 0.1);
  --shadow-medium: 0 10px 32px rgba(62, 31, 31, 0.14);
  --shadow-heavy: 0 20px 50px rgba(45, 27, 45, 0.18);
  --border-radius: 16px;
  --border-radius-lg: 28px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --board-gap: 6px;
  --board-padding: 10px;
}

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

body {
  font-family: var(--font-ui);
  background: var(--sky-bottom) url("../img/bg.png") no-repeat center center fixed;
  background-size: cover;
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow-x: hidden;
}

/* Soft candy haze + horizon warmth */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse 120% 70% at 50% 0%, rgba(255, 255, 255, 0.45) 0%, transparent 55%),
    radial-gradient(ellipse 90% 50% at 50% 100%, rgba(255, 214, 140, 0.35) 0%, transparent 60%);
  pointer-events: none;
  z-index: -1;
}

/* Game Header - no background, level left after home */
.game-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 100;
  min-height: 56px;
  background: transparent;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.level-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.level-label,
.level-number {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}

.level-label {
  color: rgba(255, 255, 255, 0.95);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-shadow: 0 1px 3px rgba(45, 27, 45, 0.45);
}

.level-number {
  color: #ffffff;
  text-shadow:
    0 1px 2px rgba(45, 27, 45, 0.5),
    0 0 12px rgba(255, 255, 255, 0.35);
}

/* Header Buttons - top right */
.header-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

/* Header controls — white candy chips, chocolate icons */
.icon-btn {
  background: linear-gradient(180deg, #ffffff 0%, #f4f0eb 100%);
  color: var(--chocolate);
  border: 1px solid rgba(255, 255, 255, 0.95);
  padding: 10px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 14px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--tile-shadow), 0 1px 0 rgba(255, 255, 255, 0.8) inset;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.icon-btn:hover {
  background: linear-gradient(180deg, #ffffff 0%, #faf4ff 100%);
  transform: translateY(-2px);
  box-shadow: var(--tile-shadow-hover);
}

.icon-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(62, 31, 31, 0.12);
}

.icon-btn.muted {
  opacity: 0.65;
  filter: saturate(0.5);
}

.icon-btn:disabled,
.modal-btn:disabled {
  pointer-events: none;
  opacity: 0.6;
}


/* Main Container */
.game-container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  text-align: center;
}

/* Wrapper shrinks to board width so indicators match column width */
.game-board-area {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: max-content;
  max-width: 92vw;
  margin: 0 auto;
}

.game-board-area .color-indicators,
.game-board-area .game-board {
  width: 100%;
  box-sizing: border-box;
}

/* Color Indicators - width = 100% of wrapper (= board). No transition on layout so no zoom on init. */
.color-indicators {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  padding: 0;
  position: relative;
  box-sizing: border-box;
}

.color-indicator {
  flex: 1;
  height: 12px;
  border-radius: 6px;
  box-shadow: var(--shadow-light);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.color-indicator.emoji-indicator {
  height: 56px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  background: linear-gradient(180deg, #ffffff 0%, #faf6f2 100%);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  box-shadow: var(--tile-shadow);
}

.color-indicator::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s ease;
}

.color-indicator:hover::before {
  left: 100%;
}

.color-indicator:hover {
  transform: scaleY(1.15);
  box-shadow: var(--shadow-medium);
}

/* Game board — big white candy panel */
.game-board {
  display: grid;
  gap: var(--board-gap);
  width: 100%;
  max-width: min(400px, 92vw);
  max-height: min(75vh, 75dvh);
  aspect-ratio: 1 / 1;
  padding: var(--board-padding);
  background: linear-gradient(180deg, #ffffff 0%, var(--panel-cream) 100%);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-medium), 0 0 0 1px rgba(255, 255, 255, 0.85) inset;
  margin: 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.95);
  position: relative;
  box-sizing: border-box;
  flex-shrink: 0;
  min-width: 0;
  min-height: 0;
}

/* Dynamic grid sizes – explicit width so .game-board-area (max-content) can size correctly */
.game-board.size-3 {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: min(300px, 92vw);
  max-width: min(300px, 92vw);
}
.game-board.size-3 .game-ball { width: min(88cqw, 88cqh); height: min(88cqw, 88cqh); }

.game-board.size-4 {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  width: min(400px, 92vw);
  max-width: min(400px, 92vw);
}
.game-board.size-4 .game-ball { width: min(85cqw, 85cqh); height: min(85cqw, 85cqh); }

.game-board.size-5 {
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  width: min(500px, 92vw);
  max-width: min(500px, 92vw);
}
.game-board.size-5 .game-ball { width: min(82cqw, 82cqh); height: min(82cqw, 82cqh); }

.game-board.size-6 {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  width: min(600px, 92vw);
  max-width: min(600px, 92vw);
}
.game-board.size-6 .game-ball { width: min(78cqw, 78cqh); height: min(78cqw, 78cqh); }

.game-board.size-7 {
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(7, 1fr);
  width: min(700px, 92vw);
  max-width: min(700px, 92vw);
}
.game-board.size-7 .game-ball { width: min(74cqw, 74cqh); height: min(74cqw, 74cqh); }

.game-board.size-8 {
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(800px, 92vw);
  max-width: min(800px, 92vw);
}
.game-board.size-8 .game-ball { width: min(70cqw, 70cqh); height: min(70cqw, 70cqh); }

.game-board.size-9 {
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: min(900px, 92vw);
  max-width: min(900px, 92vw);
}
.game-board.size-9 .game-ball { width: min(66cqw, 66cqh); height: min(66cqw, 66cqh); }

.game-board.size-10 {
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  width: min(1000px, 92vw);
  max-width: min(1000px, 92vw);
}
.game-board.size-10 .game-ball { width: min(62cqw, 62cqh); height: min(62cqw, 62cqh); }

.game-board.size-11 {
  grid-template-columns: repeat(11, 1fr);
  grid-template-rows: repeat(11, 1fr);
  width: min(1100px, 92vw);
  max-width: min(1100px, 92vw);
}
.game-board.size-11 .game-ball { width: min(58cqw, 58cqh); height: min(58cqw, 58cqh); }

/* Grid dimension classes (cols × rows) – used with size-N for non-square boards
   Explicit width/height limits ensure square cells: constrain by the smaller of width-based or height-based fit */
.game-board.grid-3-3 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); aspect-ratio: 3 / 3; }
.game-board.grid-3-4 {
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(4, 1fr); aspect-ratio: 3 / 4;
  width: min(300px, 92vw, calc(min(75vh, 75dvh) * 3 / 4)); max-width: min(300px, 92vw, calc(min(75vh, 75dvh) * 3 / 4));
}
.game-board.grid-3-5 {
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(5, 1fr); aspect-ratio: 3 / 5;
  width: min(300px, 92vw, calc(min(75vh, 75dvh) * 3 / 5)); max-width: min(300px, 92vw, calc(min(75vh, 75dvh) * 3 / 5));
}
.game-board.grid-4-4 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); aspect-ratio: 4 / 4; }
.game-board.grid-4-5 {
  grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(5, 1fr); aspect-ratio: 4 / 5;
  width: min(400px, 92vw, calc(min(75vh, 75dvh) * 4 / 5)); max-width: min(400px, 92vw, calc(min(75vh, 75dvh) * 4 / 5));
}
.game-board.grid-4-6 {
  grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(6, 1fr); aspect-ratio: 4 / 6;
  width: min(400px, 92vw, calc(min(75vh, 75dvh) * 4 / 6)); max-width: min(400px, 92vw, calc(min(75vh, 75dvh) * 4 / 6));
}
.game-board.grid-5-5 { grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(5, 1fr); aspect-ratio: 5 / 5; }
.game-board.grid-5-6 {
  grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(6, 1fr); aspect-ratio: 5 / 6;
  width: min(500px, 92vw, calc(min(75vh, 75dvh) * 5 / 6)); max-width: min(500px, 92vw, calc(min(75vh, 75dvh) * 5 / 6));
}
.game-board.grid-5-7 {
  grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(7, 1fr); aspect-ratio: 5 / 7;
  width: min(500px, 92vw, calc(min(75vh, 75dvh) * 5 / 7)); max-width: min(500px, 92vw, calc(min(75vh, 75dvh) * 5 / 7));
}
.game-board.grid-6-6 { grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(6, 1fr); aspect-ratio: 6 / 6; }
.game-board.grid-6-7 {
  grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(7, 1fr); aspect-ratio: 6 / 7;
  width: min(600px, 92vw, calc(min(75vh, 75dvh) * 6 / 7)); max-width: min(600px, 92vw, calc(min(75vh, 75dvh) * 6 / 7));
}
.game-board.grid-6-8 {
  grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(8, 1fr); aspect-ratio: 6 / 8;
  width: min(600px, 92vw, calc(min(75vh, 75dvh) * 6 / 8)); max-width: min(600px, 92vw, calc(min(75vh, 75dvh) * 6 / 8));
}
.game-board.grid-7-7 { grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(7, 1fr); aspect-ratio: 7 / 7; }
.game-board.grid-7-8 {
  grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(8, 1fr); aspect-ratio: 7 / 8;
  width: min(700px, 92vw, calc(min(75vh, 75dvh) * 7 / 8)); max-width: min(700px, 92vw, calc(min(75vh, 75dvh) * 7 / 8));
}
.game-board.grid-7-9 {
  grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(9, 1fr); aspect-ratio: 7 / 9;
  width: min(700px, 92vw, calc(min(75vh, 75dvh) * 7 / 9)); max-width: min(700px, 92vw, calc(min(75vh, 75dvh) * 7 / 9));
}
.game-board.grid-8-8 { grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); aspect-ratio: 8 / 8; }
.game-board.grid-8-9 {
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(9, 1fr); aspect-ratio: 8 / 9;
  width: min(800px, 92vw, calc(min(75vh, 75dvh) * 8 / 9)); max-width: min(800px, 92vw, calc(min(75vh, 75dvh) * 8 / 9));
}
.game-board.grid-8-10 {
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(10, 1fr); aspect-ratio: 8 / 10;
  width: min(800px, 92vw, calc(min(75vh, 75dvh) * 8 / 10)); max-width: min(800px, 92vw, calc(min(75vh, 75dvh) * 8 / 10));
}
.game-board.grid-9-9 { grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); aspect-ratio: 9 / 9; }
.game-board.grid-9-10 {
  grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(10, 1fr); aspect-ratio: 9 / 10;
  width: min(900px, 92vw, calc(min(75vh, 75dvh) * 9 / 10)); max-width: min(900px, 92vw, calc(min(75vh, 75dvh) * 9 / 10));
}
.game-board.grid-9-11 {
  grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(11, 1fr); aspect-ratio: 9 / 11;
  width: min(900px, 92vw, calc(min(75vh, 75dvh) * 9 / 11)); max-width: min(900px, 92vw, calc(min(75vh, 75dvh) * 9 / 11));
}

/* Win celebration – no shadow */
@keyframes board-pulse {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: none; }
}
.game-board.board-celebrate {
  animation: board-pulse 0.5s ease-in-out 3;
}

/* Size classes on indicators only affect layout; width comes from .game-board-area */
.color-indicators.size-3,
.color-indicators.size-4,
.color-indicators.size-5,
.color-indicators.size-6,
.color-indicators.size-7,
.color-indicators.size-8,
.color-indicators.size-9,
.color-indicators.size-10,
.color-indicators.size-11 {
  width: 100%;
}

.game-board::before {
  content: none;
}

/* Board cells — glossy white tiles */
.board-cell {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1 / 1;
  background: linear-gradient(165deg, #ffffff 0%, #f7f2ec 100%);
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  container-type: size;
  container-name: cell;
  box-shadow: var(--tile-shadow);
  border: 1px solid rgba(255, 255, 255, 0.9);
}

.board-cell:hover {
  background: linear-gradient(165deg, #ffffff 0%, #fff8fc 100%);
  transform: scale(1.02);
  box-shadow: var(--tile-shadow-hover);
}

.board-cell.empty {
  background: transparent;
  border: 2px dashed rgba(255, 160, 120, 0.75);
  padding: 8px;
  cursor: default;
  box-sizing: border-box;
  position: relative;
  box-shadow: none;
}

/* Empty slot — soft cream inset */
.board-cell.empty::after {
  content: "";
  position: absolute;
  inset: 8px;
  background: linear-gradient(180deg, rgba(255, 248, 240, 0.95) 0%, rgba(255, 235, 220, 0.55) 100%);
  border-radius: calc(var(--border-radius) - 4px);
  pointer-events: none;
}

.board-cell.empty:hover {
  transform: none;
  box-shadow: none;
}

/* Game Balls - emoji display */
.game-ball {
  width: min(85cqw, 85cqh);
  height: min(85cqw, 85cqh);
  min-width: 0;
  min-height: 0;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(75cqw, 75cqh);
  line-height: 1;
}

.game-ball:hover {
  transform: scale(1.1);
}

.board-cell.empty .game-ball {
  transform: scale(0);
  opacity: 0;
  cursor: default;
}

/* Modal Styles - Arcade / Game Screen */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--sky-bottom) url("../img/bg.png") no-repeat center center;
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  box-sizing: border-box;
}

.modal-backdrop::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse 100% 80% at 50% 20%, rgba(255, 255, 255, 0.35) 0%, transparent 55%);
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
  pointer-events: none;
  z-index: -1;
}

.modal-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* How to Play: let the candy background show through; light vignette only */
#how-to-play-modal.modal-backdrop {
  background: transparent;
}

#how-to-play-modal.modal-backdrop::before {
  background:
    radial-gradient(ellipse 95% 70% at 50% 20%, rgba(255, 255, 255, 0.22) 0%, transparent 55%),
    radial-gradient(ellipse 80% 55% at 50% 100%, rgba(255, 214, 140, 0.18) 0%, transparent 50%),
    linear-gradient(180deg, rgba(45, 27, 45, 0.28) 0%, rgba(45, 27, 45, 0.42) 100%);
  backdrop-filter: blur(2px) saturate(1.05);
  -webkit-backdrop-filter: blur(2px) saturate(1.05);
}

/* How to Play sheet — frosted candy panel aligned with board / modals */
.modal-content.modal-content--how-to-play {
  width: min(440px, 94vw);
  padding: 28px 26px 30px;
  text-align: left;
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: var(--border-radius-lg);
  background:
    linear-gradient(165deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 248, 252, 0.97) 42%, rgba(255, 241, 230, 0.96) 100%);
  box-shadow:
    var(--shadow-heavy),
    0 0 0 1px rgba(212, 175, 106, 0.35) inset,
    0 0 40px rgba(232, 184, 106, 0.2);
}

.modal-content.modal-content--how-to-play::before {
  background: radial-gradient(
    ellipse 130% 55% at 50% 0%,
    rgba(255, 200, 220, 0.4) 0%,
    rgba(255, 230, 200, 0.15) 45%,
    transparent 70%
  );
  border-radius: inherit;
}

.how-to-play-hero {
  text-align: center;
  margin-bottom: 4px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(212, 175, 106, 0.35);
  position: relative;
  z-index: 1;
}

.how-to-play-heading {
  font-family: var(--font-display);
  font-size: clamp(1.45rem, 4.5vw, 1.75rem);
  font-weight: 800;
  color: #b8456e;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.15;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.95);
  margin: 0;
}

.modal-content.modal-content--how-to-play .how-to-play {
  margin-top: 4px;
}

.modal-content.modal-content--how-to-play .game-rules {
  gap: 12px;
  margin-top: 18px;
}

.modal-content.modal-content--how-to-play .rule-card {
  align-items: stretch;
  gap: 14px;
  padding: 12px 14px;
  border-radius: var(--border-radius);
  background: linear-gradient(165deg, #ffffff 0%, #faf6f2 100%);
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow: var(--tile-shadow), 0 0 0 1px rgba(212, 175, 106, 0.12) inset;
}

.modal-content.modal-content--how-to-play .rule-card:hover {
  transform: translateX(4px);
  box-shadow: var(--tile-shadow-hover), 0 0 0 1px rgba(232, 184, 106, 0.25) inset;
}

.modal-content.modal-content--how-to-play .rule-icon {
  width: 46px;
  min-height: 46px;
  height: auto;
  align-self: center;
  font-size: 1.55rem;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #fff0f5 55%, #ffe9d6 100%);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--tile-shadow), 0 1px 0 rgba(255, 255, 255, 0.85) inset;
}

.modal-content.modal-content--how-to-play .rule-text {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
}

.modal-buttons--how-to-play {
  margin-top: 22px;
  justify-content: center;
}

.modal-content.modal-content--how-to-play .modal-buttons--how-to-play .modal-btn {
  flex: 0 1 auto;
  max-width: 220px;
  min-width: 160px;
  padding: 14px 28px;
  font-size: 0.95rem;
  background: linear-gradient(180deg, #fff8fb 0%, #ffe9f0 35%, var(--game-accent-hover) 100%);
  border: 1px solid rgba(184, 69, 110, 0.28);
  color: var(--chocolate);
  box-shadow: var(--tile-shadow), 0 0 20px rgba(232, 184, 106, 0.35);
}

.modal-content.modal-content--how-to-play .modal-buttons--how-to-play .modal-btn:hover {
  background: linear-gradient(180deg, #ffffff 0%, #fff4f8 40%, #ffd8e8 100%);
  box-shadow: var(--tile-shadow-hover), 0 0 24px rgba(232, 184, 106, 0.45);
}

@media (max-width: 640px) {
  .modal-content.modal-content--how-to-play {
    padding: 18px 16px 22px;
    width: 96%;
  }

  .modal-content.modal-content--how-to-play .how-to-play-heading {
    font-size: 1.35rem;
  }

  .modal-content.modal-content--how-to-play .game-rules {
    gap: 10px;
    margin-top: 14px;
  }

  .modal-content.modal-content--how-to-play .rule-card {
    padding: 10px 12px;
    gap: 12px;
  }

  .modal-content.modal-content--how-to-play .rule-icon {
    width: 42px;
    min-height: 42px;
    font-size: 1.4rem;
  }
}

@media (max-width: 480px) {
  .modal-content.modal-content--how-to-play .how-to-play-hero {
    padding-bottom: 14px;
  }

  .modal-content.modal-content--how-to-play .rule-text {
    font-size: 0.86rem;
  }
}

/* Modal card — frosted cream panel */
.modal-content {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.97) 0%,
    rgba(255, 250, 245, 0.98) 100%
  );
  padding: 36px 40px;
  text-align: center;
  color: var(--text-primary);
  transform: scale(0.92) translateY(24px);
  transition: var(--transition);
  max-width: 90%;
  width: 420px;
  max-height: 95vh;
  box-shadow: var(--shadow-heavy), 0 0 0 1px rgba(255, 255, 255, 0.9) inset;
  border: 2px solid rgba(212, 175, 106, 0.45);
  border-radius: var(--border-radius-lg);
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  margin: auto;
  word-wrap: break-word;
  overflow-wrap: break-word;
  display: block;
  backdrop-filter: blur(16px) saturate(1.15);
  -webkit-backdrop-filter: blur(16px) saturate(1.15);
}

.modal-backdrop.visible .modal-content {
  transform: scale(1) translateY(0);
}

/* Keep all modal text/buttons above the glow */
.modal-content > * {
  position: relative;
  z-index: 1;
}

/* Subtle glass highlight at top */
.modal-content::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: radial-gradient(
    ellipse 120% 80% at 50% 0%,
    rgba(255, 214, 180, 0.35) 0%,
    transparent 65%
  );
  border-radius: calc(var(--border-radius-lg) - 2px) calc(var(--border-radius-lg) - 2px) 0 0;
  pointer-events: none;
  z-index: 0;
}

/* Start screen — no frosted white card; background art stays visible */
#start-modal .modal-content {
  background: transparent;
  box-shadow: none;
  border: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

#start-modal .modal-content::before {
  display: none;
}

/* Start modal: logo on top, level card below */
.modal-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 24px;
  position: relative;
  z-index: 1;
}

.modal-logo {
  text-align: center;
  position: relative;
  z-index: 1;
}

.modal-logo img {
  width: auto;
  height: auto;
  max-width: 190px;
  max-height: 155px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 4px 12px rgba(45, 27, 45, 0.2));
}

.modal-hero .modal-logo img {
  max-width: 220px;
  max-height: 170px;
}

.modal-hero .modal-level-badge {
  width: 110px;
  height: 110px;
  font-size: 0.7rem;
  border-radius: 22px;
  border: 2px solid var(--gold-border);
  box-shadow: var(--shadow-medium), 0 0 0 1px rgba(45, 27, 45, 0.35) inset;
  background: var(--level-plum);
}

.modal-level-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 88px;
  height: 88px;
  flex-shrink: 0;
  background: var(--level-plum);
  color: var(--game-accent);
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: var(--border-radius);
  border: 2px solid var(--gold-border);
  box-shadow: var(--shadow-light);
  text-transform: uppercase;
  letter-spacing: 1.8px;
  line-height: 1.2;
  position: relative;
  z-index: 1;
  gap: 2px;
}

.modal-level-badge span {
  display: block;
  font-size: 2.1rem;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  letter-spacing: 0;
  color: #ffe9a8;
}

.modal-hero .modal-level-badge span {
  font-size: 2.6rem;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 12px;
  color: #b8456e;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
  position: relative;
  z-index: 1;
}

.modal-subtitle {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
  position: relative;
  z-index: 1;
}

.modal-stats {
  background: rgba(255, 245, 250, 0.85);
  padding: 18px 20px;
  border-radius: var(--border-radius);
  border: 1px solid rgba(212, 175, 106, 0.35);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  box-shadow: var(--tile-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.stat-label {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  color: #c45c8a;
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 800;
}

/* Modal buttons — cream pill, chocolate label */
.modal-btn {
  background: linear-gradient(180deg, #ffffff 0%, #f2ebe4 100%);
  color: var(--chocolate);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 14px 28px;
  border: 1px solid rgba(62, 31, 31, 0.12);
  border-radius: 999px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--tile-shadow), 0 1px 0 rgba(255, 255, 255, 0.9) inset;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 8px;
  white-space: nowrap;
  min-width: 120px;
  flex-shrink: 0;
}

.modal-btn:hover {
  background: linear-gradient(180deg, #ffffff 0%, #faf4ff 100%);
  transform: translateY(-2px);
  box-shadow: var(--tile-shadow-hover);
}

.modal-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(62, 31, 31, 0.12);
}

.modal-btn.secondary {
  background: linear-gradient(180deg, #fff8fb 0%, #f5e8ee 100%);
  color: var(--chocolate);
  box-shadow: var(--tile-shadow);
}

/* Modal button container for better layout */
.modal-buttons {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

/* Keep buttons in same row on all screen sizes */
.modal-buttons .modal-btn {
  flex: 1 1 0;
  min-width: 0;
  max-width: 160px;
  padding: 14px 16px;
  font-size: 0.9rem;
  margin: 0;
}

/* Start screen — primary CTA a bit larger */
#start-game-btn {
  flex: 0 1 auto;
  max-width: none;
  min-width: 200px;
  padding: 17px 40px;
  font-size: 1.08rem;
}

/* How to Play Section */
.how-to-play {
  text-align: left;
  padding: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Game Rules Layout - Simple List */
.game-rules {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 20px;
}

.rule-card {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 0;
  background: transparent;
  border: none;
  transition: var(--transition);
}

.rule-card:hover {
  transform: translateX(5px);
}

.rule-icon {
  flex-shrink: 0;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
}

.rule-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
  font-weight: 500;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  flex: 1;
}

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

/* Desktop (≥1025px) - Keep current desktop styles as base */
@media (min-width: 1025px) {
  .game-container {
    max-width: 600px;
  }

  .color-indicators {
    max-width: 500px;
    width: 100%;
  }

  .game-board {
    max-width: 500px;
  }

  .modal-content {
    width: 480px;
  }

  .modal-backdrop.visible {
    align-items: center !important;
  }
}

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

  .color-indicators {
    max-width: 480px;
    width: 100%;
  }

  .game-board {
    max-width: 480px;
  }

  .modal-backdrop {
    padding: 15px;
  }

  .modal-backdrop.visible {
    align-items: center !important;
  }

  .modal-content {
    width: 90%;
    max-width: 480px;
    max-height: 92vh;
    padding: 25px 35px;
  }
}

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

  .color-indicators {
    max-width: 450px;
    width: 100%;
  }

  .game-board {
    max-width: 450px;
  }

  .modal-backdrop {
    padding: 15px;
  }

  .modal-backdrop.visible {
    align-items: center !important;
  }

  .modal-content {
    width: 95%;
    max-width: 450px;
    max-height: 85vh;
    padding: 25px 35px;
  }

  .modal-title {
    font-size: 2.2rem;
  }

  .game-rules {
    gap: 18px;
  }

  .rule-card {
    gap: 12px;
  }

  .rule-icon {
    font-size: 1.6rem;
    width: 36px;
    height: 36px;
  }

  .rule-text {
    font-size: 0.92rem;
  }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
  body {
    padding: 15px;
  }

  .game-header {
    padding: 12px 15px;
    min-height: 55px;
  }

  .level-label,
  .level-number {
    font-size: 0.95rem;
  }

  .icon-btn {
    padding: 9px;
    min-width: 44px;
    min-height: 44px;
  }

  .icon-btn svg {
    width: 18px;
    height: 18px;
  }

  .game-container {
    max-width: 100%;
    padding-top: 75px;
  }

  .color-indicators {
    gap: var(--board-gap);
    padding: 0 var(--board-padding);
    margin-bottom: 16px;
    width: 100%;
  }

  .color-indicators.colors-5,
  .color-indicators.colors-6,
  .color-indicators.colors-7,
  .color-indicators.colors-8 {
    max-width: 100%;
  }

  .game-board {
    gap: var(--board-gap);
    padding: var(--board-padding);
    max-width: 100%;
  }

  .game-board.size-5,
  .game-board.size-6,
  .game-board.size-7,
  .game-board.size-8 {
    max-width: 100%;
  }

  .modal-backdrop {
    padding: 10px;
  }

  .modal-backdrop.visible {
    align-items: center !important;
  }

  .modal-content {
    padding: 20px 25px;
    width: 95%;
    max-height: 90vh;
    margin: auto;
  }

  .modal-title {
    font-size: 2rem;
  }

  .modal-subtitle {
    font-size: 1.05rem;
  }

  .modal-stats {
    grid-template-columns: 1fr 1fr;
    gap: 18px;
  }

  .stat-value {
    font-size: 1.3rem;
  }

  .game-rules {
    gap: 16px;
  }

  .rule-card {
    gap: 12px;
  }

  .rule-icon {
    font-size: 1.5rem;
    width: 34px;
    height: 34px;
  }

  .rule-text {
    font-size: 0.9rem;
  }

  .modal-buttons .modal-btn {
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
    padding: 13px 12px;
    font-size: 0.9rem;
  }

  .board-cell {
    aspect-ratio: 1 / 1 !important; /* Keep cells square */
  }

  .board-cell.empty {
    background: transparent !important;
    border: 2px dashed rgba(255, 160, 120, 0.75) !important;
    padding: 8px !important;
  }
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
  body {
    padding: 12px;
  }

  .game-header {
    padding: 10px 12px;
    min-height: 50px;
  }

  .level-label,
  .level-number {
    font-size: 0.9rem;
  }

  .icon-btn {
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
  }

  .icon-btn svg {
    width: 16px;
    height: 16px;
  }

  .game-container {
    max-width: 100%;
    padding-top: 70px;
  }

  .color-indicators {
    gap: var(--board-gap);
    padding: 0 var(--board-padding);
    margin-bottom: 14px;
    width: 100%;
  }

  .color-indicators.colors-5,
  .color-indicators.colors-6,
  .color-indicators.colors-7,
  .color-indicators.colors-8 {
    max-width: 100%;
  }

  .game-board {
    gap: var(--board-gap);
    padding: var(--board-padding);
    max-width: 100%;
  }

  .game-board.size-5,
  .game-board.size-6,
  .game-board.size-7,
  .game-board.size-8 {
    max-width: 100%;
  }

  .modal-backdrop {
    padding: 8px;
  }

  .modal-backdrop.visible {
    align-items: center !important;
  }

  .modal-content {
    padding: 18px 22px;
    width: 95%;
    max-height: 90vh;
    margin: auto;
  }

  .modal-title {
    font-size: 1.8rem;
  }

  .modal-subtitle {
    font-size: 1rem;
  }

  .modal-stats {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .stat-value {
    font-size: 1.2rem;
  }

  .game-rules {
    gap: 14px;
  }

  .rule-card {
    gap: 10px;
  }

  .rule-icon {
    font-size: 1.4rem;
    width: 32px;
    height: 32px;
  }

  .rule-text {
    font-size: 0.85rem;
  }

  .modal-buttons .modal-btn {
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
    padding: 12px 10px;
    font-size: 0.85rem;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .board-cell:hover,
  .game-ball:hover,
  .color-indicator:hover {
    transform: none;
  }

  .icon-btn:hover,
  .modal-btn:hover {
    transform: none;
  }

  .board-cell:active,
  .game-ball:active {
    transform: scale(0.95);
  }

  .icon-btn:active,
  .modal-btn:active {
    transform: scale(0.95);
  }
}

/* Landscape Mobile (orientation: landscape) - board size reduced 15% for better fit */
@media (orientation: landscape) and (max-height: 640px) {
  body {
    padding: 8px;
  }

  .game-header {
    padding: 8px 15px;
    min-height: 45px;
  }

  .level-label,
  .level-number {
    font-size: 0.85rem;
  }

  .icon-btn {
    padding: 6px;
    min-width: 44px;
    min-height: 44px;
  }

  .game-container {
    max-width: 100%;
    padding-top: 60px;
    padding-left: 12px;
    padding-right: 12px;
  }

  /* Game board area - 15% smaller for landscape */
  .game-board-area {
    max-width: min(calc(95vw * 0.85), 85%);
  }

  .color-indicators {
    gap: var(--board-gap);
    margin-bottom: 12px;
    width: 100%;
  }

  .color-indicator {
    height: 10px;
    border-radius: 5px;
  }

  /* Board size reduced 15% for landscape - square cells maintained */
  .game-board {
    gap: var(--board-gap);
    padding: var(--board-padding);
    max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85));
    max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85));
  }

  /* Size-specific max dimensions - 15% smaller for landscape */
  .game-board.size-3 { width: min(255px, calc(95vw * 0.85), calc(85dvh * 0.85)); max-width: min(255px, calc(95vw * 0.85), calc(85dvh * 0.85)); }
  .game-board.size-4 { width: min(340px, calc(95vw * 0.85), calc(85dvh * 0.85)); max-width: min(340px, calc(95vw * 0.85), calc(85dvh * 0.85)); }
  .game-board.size-5 { width: min(425px, calc(95vw * 0.85), calc(85dvh * 0.85)); max-width: min(425px, calc(95vw * 0.85), calc(85dvh * 0.85)); }
  .game-board.size-6 { width: min(510px, calc(95vw * 0.85), calc(85dvh * 0.85)); max-width: min(510px, calc(95vw * 0.85), calc(85dvh * 0.85)); }
  .game-board.size-7 { width: min(595px, calc(95vw * 0.85), calc(85dvh * 0.85)); max-width: min(595px, calc(95vw * 0.85), calc(85dvh * 0.85)); }
  .game-board.size-8 { width: min(680px, calc(95vw * 0.85), calc(85dvh * 0.85)); max-width: min(680px, calc(95vw * 0.85), calc(85dvh * 0.85)); }
  .game-board.size-9 { width: min(765px, calc(95vw * 0.85), calc(85dvh * 0.85)); max-width: min(765px, calc(95vw * 0.85), calc(85dvh * 0.85)); }
  .game-board.size-10 { width: min(850px, calc(95vw * 0.85), calc(85dvh * 0.85)); max-width: min(850px, calc(95vw * 0.85), calc(85dvh * 0.85)); }
  .game-board.size-11 { width: min(935px, calc(95vw * 0.85), calc(85dvh * 0.85)); max-width: min(935px, calc(95vw * 0.85), calc(85dvh * 0.85)); }

  /* Non-square grids - 15% smaller, square cells maintained */
  .game-board.grid-3-3 { max-width: min(255px, calc(95vw * 0.85), calc(85dvh * 0.85)); max-height: min(255px, calc(85dvh * 0.85), calc(95vw * 0.85)); }
  .game-board.grid-3-4 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 3 / 4)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 4 / 3)); }
  .game-board.grid-3-5 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 3 / 5)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 5 / 3)); }
  .game-board.grid-4-5 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 4 / 5)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 5 / 4)); }
  .game-board.grid-4-6 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 4 / 6)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 6 / 4)); }
  .game-board.grid-5-6 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 5 / 6)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 6 / 5)); }
  .game-board.grid-5-7 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 5 / 7)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 7 / 5)); }
  .game-board.grid-6-7 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 6 / 7)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 7 / 6)); }
  .game-board.grid-6-8 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 6 / 8)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 8 / 6)); }
  .game-board.grid-7-8 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 7 / 8)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 8 / 7)); }
  .game-board.grid-7-9 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 7 / 9)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 9 / 7)); }
  .game-board.grid-8-9 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 8 / 9)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 9 / 8)); }
  .game-board.grid-8-10 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 8 / 10)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 10 / 8)); }
  .game-board.grid-9-10 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 9 / 10)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 10 / 9)); }
  .game-board.grid-9-11 { max-width: min(calc(95vw * 0.85), calc(85dvh * 0.85 * 9 / 11)); max-height: min(calc(85dvh * 0.85), calc(95vw * 0.85 * 11 / 9)); }

  .game-ball {
    width: min(90cqw, 90cqh);
    height: min(90cqw, 90cqh);
  }

  .board-cell {
    background: linear-gradient(165deg, #ffffff 0%, #f7f2ec 100%) !important;
    aspect-ratio: 1;
  }

  .board-cell.empty {
    background: transparent !important;
    border: 2px dashed rgba(255, 160, 120, 0.75) !important;
    padding: 8px !important;
  }
}

/* Ensure minimum touch target size for accessibility */
@media (max-width: 480px) {
  .board-cell {
    aspect-ratio: 1 / 1 !important; /* Keep cells square */
  }

  .board-cell.empty {
    background: transparent !important;
    border: 2px dashed rgba(255, 160, 120, 0.75) !important;
    padding: 8px !important;
  }

  .icon-btn {
    min-height: 44px;
    min-width: 44px;
  }

  .modal-btn {
    min-height: 44px;
    min-width: 120px;
  }
}

/* Extra small screens (≤360px) - Very small phones */
@media (max-width: 360px) {
  body {
    padding: 8px;
  }

  .game-header {
    padding: 8px 10px;
    min-height: 45px;
  }

  .level-label,
  .level-number {
    font-size: 0.8rem;
  }

  .icon-btn {
    padding: 6px;
    min-width: 44px;
    min-height: 44px;
  }

  .icon-btn svg {
    width: 15px;
    height: 15px;
  }

  .game-container {
    padding-top: 65px;
  }

  .color-indicators {
    gap: var(--board-gap);
    padding: 0 var(--board-padding);
    margin-bottom: 12px;
    width: 100%;
  }

  .game-board {
    gap: var(--board-gap);
    padding: var(--board-padding);
  }

  .modal-backdrop {
    padding: 5px;
  }

  .modal-backdrop.visible {
    align-items: center !important;
  }

  .modal-content {
    padding: 15px 20px;
    width: 95%;
    max-height: 95vh;
    margin: auto;
  }

  .modal-title {
    font-size: 1.6rem;
  }

  .modal-subtitle {
    font-size: 0.95rem;
  }

  .modal-buttons .modal-btn {
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
    padding: 10px 8px;
    font-size: 0.8rem;
  }
}

/* Large screens (≥1400px) - Ultra-wide displays */
@media (min-width: 1400px) {
  .game-container {
    max-width: 700px;
  }

  .color-indicators {
    max-width: 600px;
    width: 100%;
  }

  .game-board {
    max-width: 600px;
  }

  .modal-content {
    width: 500px;
  }

  .modal-backdrop.visible {
    align-items: center !important;
  }
}

/* Prevent text selection on game elements */
.game-board,
.board-cell,
.game-ball,
.icon-btn,
.modal-btn {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Smooth scrolling for modals */
.modal-backdrop {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Custom scrollbar for modal content */
.modal-content::-webkit-scrollbar {
  width: 6px;
}

.modal-content::-webkit-scrollbar-track {
  background: rgba(255, 240, 230, 0.6);
  border-radius: 3px;
}

.modal-content::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--game-accent-hover) 0%, var(--game-accent) 100%);
  border-radius: 3px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
  background: var(--game-accent-hover);
}

/* Ensure modal content is scrollable when needed */
.modal-content {
  scrollbar-width: thin;
  scrollbar-color: var(--game-accent) rgba(255, 235, 220, 0.8);
}

/* Prevent horizontal scrolling on body when modal is open */
body.modal-open {
  overflow-x: hidden;
  position: fixed;
  width: 100%;
}

/* When How to Play is open, hide the game screen behind so only the pop-up is visible */
body.how-to-play-open .game-header,
body.how-to-play-open .game-container {
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
}

/* Ensure modal backdrop covers entire viewport */
.modal-backdrop {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 9999 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Force perfect centering for all screen sizes */
@media (max-width: 768px) {
  .modal-backdrop.visible {
    align-items: center !important;
    justify-content: center !important;
  }

  .modal-content {
    margin: auto !important;
  }
}

/* Optimize for reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .ball-moving {
    animation: none;
  }
}

/* Animation for ball movement */
@keyframes ballMove {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

.ball-moving {
  animation: ballMove 0.3s ease-in-out;
}

/* ========================================
   GAME BOARD ENTRANCE ANIMATION
   ======================================== */

@keyframes board-entrance {
  0% {
    opacity: 0;
    transform: scale(0.7) translateY(20px);
    filter: blur(4px);
  }
  60% {
    opacity: 1;
    transform: scale(1.02) translateY(-4px);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
    filter: blur(0);
  }
}

@keyframes board-glow-pulse {
  0%, 100% {
    box-shadow: none;
  }
  50% {
    box-shadow: none;
  }
}

@keyframes ball-pop-in {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  70% {
    transform: scale(1.15);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes color-indicator-slide {
  0% {
    opacity: 0;
    transform: translateY(-12px) scaleY(0.5);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scaleY(1);
  }
}

/* Board entrance state */
.game-board-area.board-entering .game-board {
  animation: board-entrance 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
             board-glow-pulse 1.2s ease-in-out 0.5s 2;
}

.game-board-area.board-entering .color-indicator {
  animation: color-indicator-slide 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
}

.game-board-area.board-entering .game-ball {
  animation: ball-pop-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
}

/*
 * Entrance stagger via nth-child (no inline styles on cells).
 * Ball: (n - 1) * 28ms — match ENTRANCE_STAGGER_BALL_MS in script.js.
 * Indicators: 80ms + (n - 1) * 60ms — match ENTRANCE_INDICATOR_* in script.js.
 */
.game-board-area.board-entering .board-cell:nth-child(1) .game-ball { animation-delay: 0ms; }
.game-board-area.board-entering .board-cell:nth-child(2) .game-ball { animation-delay: 28ms; }
.game-board-area.board-entering .board-cell:nth-child(3) .game-ball { animation-delay: 56ms; }
.game-board-area.board-entering .board-cell:nth-child(4) .game-ball { animation-delay: 84ms; }
.game-board-area.board-entering .board-cell:nth-child(5) .game-ball { animation-delay: 112ms; }
.game-board-area.board-entering .board-cell:nth-child(6) .game-ball { animation-delay: 140ms; }
.game-board-area.board-entering .board-cell:nth-child(7) .game-ball { animation-delay: 168ms; }
.game-board-area.board-entering .board-cell:nth-child(8) .game-ball { animation-delay: 196ms; }
.game-board-area.board-entering .board-cell:nth-child(9) .game-ball { animation-delay: 224ms; }
.game-board-area.board-entering .board-cell:nth-child(10) .game-ball { animation-delay: 252ms; }
.game-board-area.board-entering .board-cell:nth-child(11) .game-ball { animation-delay: 280ms; }
.game-board-area.board-entering .board-cell:nth-child(12) .game-ball { animation-delay: 308ms; }
.game-board-area.board-entering .board-cell:nth-child(13) .game-ball { animation-delay: 336ms; }
.game-board-area.board-entering .board-cell:nth-child(14) .game-ball { animation-delay: 364ms; }
.game-board-area.board-entering .board-cell:nth-child(15) .game-ball { animation-delay: 392ms; }
.game-board-area.board-entering .board-cell:nth-child(16) .game-ball { animation-delay: 420ms; }
.game-board-area.board-entering .board-cell:nth-child(17) .game-ball { animation-delay: 448ms; }
.game-board-area.board-entering .board-cell:nth-child(18) .game-ball { animation-delay: 476ms; }
.game-board-area.board-entering .board-cell:nth-child(19) .game-ball { animation-delay: 504ms; }
.game-board-area.board-entering .board-cell:nth-child(20) .game-ball { animation-delay: 532ms; }
.game-board-area.board-entering .board-cell:nth-child(21) .game-ball { animation-delay: 560ms; }
.game-board-area.board-entering .board-cell:nth-child(22) .game-ball { animation-delay: 588ms; }
.game-board-area.board-entering .board-cell:nth-child(23) .game-ball { animation-delay: 616ms; }
.game-board-area.board-entering .board-cell:nth-child(24) .game-ball { animation-delay: 644ms; }
.game-board-area.board-entering .board-cell:nth-child(25) .game-ball { animation-delay: 672ms; }
.game-board-area.board-entering .board-cell:nth-child(26) .game-ball { animation-delay: 700ms; }
.game-board-area.board-entering .board-cell:nth-child(27) .game-ball { animation-delay: 728ms; }
.game-board-area.board-entering .board-cell:nth-child(28) .game-ball { animation-delay: 756ms; }
.game-board-area.board-entering .board-cell:nth-child(29) .game-ball { animation-delay: 784ms; }
.game-board-area.board-entering .board-cell:nth-child(30) .game-ball { animation-delay: 812ms; }
.game-board-area.board-entering .board-cell:nth-child(31) .game-ball { animation-delay: 840ms; }
.game-board-area.board-entering .board-cell:nth-child(32) .game-ball { animation-delay: 868ms; }
.game-board-area.board-entering .board-cell:nth-child(33) .game-ball { animation-delay: 896ms; }
.game-board-area.board-entering .board-cell:nth-child(34) .game-ball { animation-delay: 924ms; }
.game-board-area.board-entering .board-cell:nth-child(35) .game-ball { animation-delay: 952ms; }
.game-board-area.board-entering .board-cell:nth-child(36) .game-ball { animation-delay: 980ms; }
.game-board-area.board-entering .board-cell:nth-child(37) .game-ball { animation-delay: 1008ms; }
.game-board-area.board-entering .board-cell:nth-child(38) .game-ball { animation-delay: 1036ms; }
.game-board-area.board-entering .board-cell:nth-child(39) .game-ball { animation-delay: 1064ms; }
.game-board-area.board-entering .board-cell:nth-child(40) .game-ball { animation-delay: 1092ms; }
.game-board-area.board-entering .board-cell:nth-child(41) .game-ball { animation-delay: 1120ms; }
.game-board-area.board-entering .board-cell:nth-child(42) .game-ball { animation-delay: 1148ms; }
.game-board-area.board-entering .board-cell:nth-child(43) .game-ball { animation-delay: 1176ms; }
.game-board-area.board-entering .board-cell:nth-child(44) .game-ball { animation-delay: 1204ms; }
.game-board-area.board-entering .board-cell:nth-child(45) .game-ball { animation-delay: 1232ms; }
.game-board-area.board-entering .board-cell:nth-child(46) .game-ball { animation-delay: 1260ms; }
.game-board-area.board-entering .board-cell:nth-child(47) .game-ball { animation-delay: 1288ms; }
.game-board-area.board-entering .board-cell:nth-child(48) .game-ball { animation-delay: 1316ms; }
.game-board-area.board-entering .board-cell:nth-child(49) .game-ball { animation-delay: 1344ms; }
.game-board-area.board-entering .board-cell:nth-child(50) .game-ball { animation-delay: 1372ms; }
.game-board-area.board-entering .board-cell:nth-child(51) .game-ball { animation-delay: 1400ms; }
.game-board-area.board-entering .board-cell:nth-child(52) .game-ball { animation-delay: 1428ms; }
.game-board-area.board-entering .board-cell:nth-child(53) .game-ball { animation-delay: 1456ms; }
.game-board-area.board-entering .board-cell:nth-child(54) .game-ball { animation-delay: 1484ms; }
.game-board-area.board-entering .board-cell:nth-child(55) .game-ball { animation-delay: 1512ms; }
.game-board-area.board-entering .board-cell:nth-child(56) .game-ball { animation-delay: 1540ms; }
.game-board-area.board-entering .board-cell:nth-child(57) .game-ball { animation-delay: 1568ms; }
.game-board-area.board-entering .board-cell:nth-child(58) .game-ball { animation-delay: 1596ms; }
.game-board-area.board-entering .board-cell:nth-child(59) .game-ball { animation-delay: 1624ms; }
.game-board-area.board-entering .board-cell:nth-child(60) .game-ball { animation-delay: 1652ms; }
.game-board-area.board-entering .board-cell:nth-child(61) .game-ball { animation-delay: 1680ms; }
.game-board-area.board-entering .board-cell:nth-child(62) .game-ball { animation-delay: 1708ms; }
.game-board-area.board-entering .board-cell:nth-child(63) .game-ball { animation-delay: 1736ms; }
.game-board-area.board-entering .board-cell:nth-child(64) .game-ball { animation-delay: 1764ms; }
.game-board-area.board-entering .board-cell:nth-child(65) .game-ball { animation-delay: 1792ms; }
.game-board-area.board-entering .board-cell:nth-child(66) .game-ball { animation-delay: 1820ms; }
.game-board-area.board-entering .board-cell:nth-child(67) .game-ball { animation-delay: 1848ms; }
.game-board-area.board-entering .board-cell:nth-child(68) .game-ball { animation-delay: 1876ms; }
.game-board-area.board-entering .board-cell:nth-child(69) .game-ball { animation-delay: 1904ms; }
.game-board-area.board-entering .board-cell:nth-child(70) .game-ball { animation-delay: 1932ms; }
.game-board-area.board-entering .board-cell:nth-child(71) .game-ball { animation-delay: 1960ms; }
.game-board-area.board-entering .board-cell:nth-child(72) .game-ball { animation-delay: 1988ms; }
.game-board-area.board-entering .board-cell:nth-child(73) .game-ball { animation-delay: 2016ms; }
.game-board-area.board-entering .board-cell:nth-child(74) .game-ball { animation-delay: 2044ms; }
.game-board-area.board-entering .board-cell:nth-child(75) .game-ball { animation-delay: 2072ms; }
.game-board-area.board-entering .board-cell:nth-child(76) .game-ball { animation-delay: 2100ms; }
.game-board-area.board-entering .board-cell:nth-child(77) .game-ball { animation-delay: 2128ms; }
.game-board-area.board-entering .board-cell:nth-child(78) .game-ball { animation-delay: 2156ms; }
.game-board-area.board-entering .board-cell:nth-child(79) .game-ball { animation-delay: 2184ms; }
.game-board-area.board-entering .board-cell:nth-child(80) .game-ball { animation-delay: 2212ms; }
.game-board-area.board-entering .board-cell:nth-child(81) .game-ball { animation-delay: 2240ms; }
.game-board-area.board-entering .board-cell:nth-child(82) .game-ball { animation-delay: 2268ms; }
.game-board-area.board-entering .board-cell:nth-child(83) .game-ball { animation-delay: 2296ms; }
.game-board-area.board-entering .board-cell:nth-child(84) .game-ball { animation-delay: 2324ms; }
.game-board-area.board-entering .board-cell:nth-child(85) .game-ball { animation-delay: 2352ms; }
.game-board-area.board-entering .board-cell:nth-child(86) .game-ball { animation-delay: 2380ms; }
.game-board-area.board-entering .board-cell:nth-child(87) .game-ball { animation-delay: 2408ms; }
.game-board-area.board-entering .board-cell:nth-child(88) .game-ball { animation-delay: 2436ms; }
.game-board-area.board-entering .board-cell:nth-child(89) .game-ball { animation-delay: 2464ms; }
.game-board-area.board-entering .board-cell:nth-child(90) .game-ball { animation-delay: 2492ms; }
.game-board-area.board-entering .board-cell:nth-child(91) .game-ball { animation-delay: 2520ms; }
.game-board-area.board-entering .board-cell:nth-child(92) .game-ball { animation-delay: 2548ms; }
.game-board-area.board-entering .board-cell:nth-child(93) .game-ball { animation-delay: 2576ms; }
.game-board-area.board-entering .board-cell:nth-child(94) .game-ball { animation-delay: 2604ms; }
.game-board-area.board-entering .board-cell:nth-child(95) .game-ball { animation-delay: 2632ms; }
.game-board-area.board-entering .board-cell:nth-child(96) .game-ball { animation-delay: 2660ms; }
.game-board-area.board-entering .board-cell:nth-child(97) .game-ball { animation-delay: 2688ms; }
.game-board-area.board-entering .board-cell:nth-child(98) .game-ball { animation-delay: 2716ms; }
.game-board-area.board-entering .board-cell:nth-child(99) .game-ball { animation-delay: 2744ms; }
.game-board-area.board-entering .board-cell:nth-child(100) .game-ball { animation-delay: 2772ms; }
.game-board-area.board-entering .board-cell:nth-child(101) .game-ball { animation-delay: 2800ms; }
.game-board-area.board-entering .board-cell:nth-child(102) .game-ball { animation-delay: 2828ms; }
.game-board-area.board-entering .board-cell:nth-child(103) .game-ball { animation-delay: 2856ms; }
.game-board-area.board-entering .board-cell:nth-child(104) .game-ball { animation-delay: 2884ms; }
.game-board-area.board-entering .board-cell:nth-child(105) .game-ball { animation-delay: 2912ms; }
.game-board-area.board-entering .board-cell:nth-child(106) .game-ball { animation-delay: 2940ms; }
.game-board-area.board-entering .board-cell:nth-child(107) .game-ball { animation-delay: 2968ms; }
.game-board-area.board-entering .board-cell:nth-child(108) .game-ball { animation-delay: 2996ms; }
.game-board-area.board-entering .board-cell:nth-child(109) .game-ball { animation-delay: 3024ms; }
.game-board-area.board-entering .board-cell:nth-child(110) .game-ball { animation-delay: 3052ms; }
.game-board-area.board-entering .board-cell:nth-child(111) .game-ball { animation-delay: 3080ms; }
.game-board-area.board-entering .board-cell:nth-child(112) .game-ball { animation-delay: 3108ms; }
.game-board-area.board-entering .board-cell:nth-child(113) .game-ball { animation-delay: 3136ms; }
.game-board-area.board-entering .board-cell:nth-child(114) .game-ball { animation-delay: 3164ms; }
.game-board-area.board-entering .board-cell:nth-child(115) .game-ball { animation-delay: 3192ms; }
.game-board-area.board-entering .board-cell:nth-child(116) .game-ball { animation-delay: 3220ms; }
.game-board-area.board-entering .board-cell:nth-child(117) .game-ball { animation-delay: 3248ms; }
.game-board-area.board-entering .board-cell:nth-child(118) .game-ball { animation-delay: 3276ms; }
.game-board-area.board-entering .board-cell:nth-child(119) .game-ball { animation-delay: 3304ms; }
.game-board-area.board-entering .board-cell:nth-child(120) .game-ball { animation-delay: 3332ms; }
.game-board-area.board-entering .board-cell:nth-child(121) .game-ball { animation-delay: 3360ms; }
.game-board-area.board-entering .board-cell:nth-child(122) .game-ball { animation-delay: 3388ms; }
.game-board-area.board-entering .board-cell:nth-child(123) .game-ball { animation-delay: 3416ms; }
.game-board-area.board-entering .board-cell:nth-child(124) .game-ball { animation-delay: 3444ms; }
.game-board-area.board-entering .board-cell:nth-child(125) .game-ball { animation-delay: 3472ms; }
.game-board-area.board-entering .board-cell:nth-child(126) .game-ball { animation-delay: 3500ms; }
.game-board-area.board-entering .board-cell:nth-child(127) .game-ball { animation-delay: 3528ms; }
.game-board-area.board-entering .board-cell:nth-child(128) .game-ball { animation-delay: 3556ms; }
.game-board-area.board-entering .board-cell:nth-child(129) .game-ball { animation-delay: 3584ms; }
.game-board-area.board-entering .board-cell:nth-child(130) .game-ball { animation-delay: 3612ms; }
.game-board-area.board-entering .color-indicator:nth-child(1) { animation-delay: 80ms; }
.game-board-area.board-entering .color-indicator:nth-child(2) { animation-delay: 140ms; }
.game-board-area.board-entering .color-indicator:nth-child(3) { animation-delay: 200ms; }
.game-board-area.board-entering .color-indicator:nth-child(4) { animation-delay: 260ms; }
.game-board-area.board-entering .color-indicator:nth-child(5) { animation-delay: 320ms; }
.game-board-area.board-entering .color-indicator:nth-child(6) { animation-delay: 380ms; }
.game-board-area.board-entering .color-indicator:nth-child(7) { animation-delay: 440ms; }
.game-board-area.board-entering .color-indicator:nth-child(8) { animation-delay: 500ms; }
.game-board-area.board-entering .color-indicator:nth-child(9) { animation-delay: 560ms; }
.game-board-area.board-entering .color-indicator:nth-child(10) { animation-delay: 620ms; }
.game-board-area.board-entering .color-indicator:nth-child(11) { animation-delay: 680ms; }
.game-board-area.board-entering .color-indicator:nth-child(12) { animation-delay: 740ms; }

.game-board-area.board-entering .board-cell.empty {
  animation: board-cell-fade 0.4s ease-out 0.3s forwards;
  opacity: 0;
}

@keyframes board-cell-fade {
  to {
    opacity: 1;
  }
}
