/* ===== DESIGN TOKENS ===== */
:root {
  --color-bg: #f3f4f6;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-primary: #6366f1;
  --color-primary-dark: #4f46e5;
  --color-success: #16a34a;
  --color-success-light: #dcfce7;
  --color-error: #dc2626;
  --color-error-light: #fef2f2;
  --color-info: #2563eb;
  --color-warning: #d97706;
  --color-purple: #9333ea;
  --color-yellow: #ca8a04;
  --start-level-purple: #5436a0;
  --start-level-purple-light: #7b52ab;
  --start-card-bg-top: rgba(210, 195, 255, 0.58);
  --start-card-bg-bottom: rgba(175, 155, 240, 0.42);
  --start-card-border: rgba(220, 210, 255, 0.85);
  --start-btn-top: #b794f6;
  --start-btn-mid: #8b5cf6;
  --start-btn-bottom: #6d28d9;
  --btn-white-border: rgba(255, 255, 255, 0.92);
  --hint-btn-top: #c4b5fd;
  --hint-btn-mid: #9d50bb;
  --hint-btn-bottom: #7c3aed;
  --hint-btn-shadow: rgba(91, 33, 182, 0.38);
  --solution-btn-top: #6ee7b7;
  --solution-btn-mid: #27ae60;
  --solution-btn-bottom: #059669;
  --solution-btn-shadow: rgba(5, 120, 85, 0.38);
  --reset-btn-top: #fcd34d;
  --reset-btn-mid: #f39c12;
  --reset-btn-bottom: #d97706;
  --reset-btn-shadow: rgba(180, 83, 9, 0.38);
  --undo-btn-top: rgba(199, 210, 254, 0.95);
  --undo-btn-mid: rgba(165, 180, 252, 0.9);
  --undo-btn-bottom: rgba(129, 140, 248, 0.85);
  --undo-btn-text: #4338ca;
  --undo-btn-shadow: rgba(99, 102, 241, 0.28);
  --back-btn-top: #818cf8;
  --back-btn-bottom: #4338ca;
  --back-btn-shadow: rgba(67, 56, 202, 0.4);
  --icon-btn-top: #c4b5fd;
  --icon-btn-mid: #9d50bb;
  --icon-btn-bottom: #7c3aed;
  --icon-btn-shadow: rgba(91, 33, 182, 0.35);
  --board-glass-top: rgba(255, 255, 255, 0.88);
  --board-glass-mid: rgba(232, 246, 255, 0.78);
  --board-glass-bottom: rgba(210, 236, 255, 0.72);
  --board-border: rgba(186, 210, 255, 0.95);
  --board-border-glow: rgba(192, 132, 252, 0.45);
  --board-grid-top: #c8e8ff;
  --board-grid-bottom: #b0dcfb;
  --board-grid-border: rgba(148, 190, 235, 0.95);
  --board-grid-inset: rgba(70, 120, 180, 0.22);
  --board-frame-shadow: rgba(72, 56, 130, 0.28);
  --place-label-gradient: linear-gradient(90deg, #e980d1 0%, #c084fc 52%, #ffb38a 100%);
  --place-number-yellow: #fff200;
  --level-badge-gradient: linear-gradient(90deg, #e980d1 0%, #c084fc 55%, #ffb38a 100%);
  --level-badge-text: #5436a0;
  --tile-empty-top: #ffffff;
  --tile-empty-bottom: #ffffff;
  --tile-empty-border: #b8ddff;
  --tile-empty-ring: #7ddfff;
  --tile-empty-lip: #c5dff5;
  /* Pre-filled / clue cells — saturated lavender */
  --tile-purple-top: #dfc2ff;
  --tile-purple-mid: #caa5f7;
  --tile-purple-bottom: #b995eb;
  --tile-purple-border: #a880e0;
  --tile-purple-lip: #8f66c9;
  --tile-purple-text: #4b1d7a;
  /* Player-placed cells — bright turquoise cyan */
  --tile-cyan-top: #7ce9f5;
  --tile-cyan-mid: #5dd9e8;
  --tile-cyan-bottom: #4fd0e3;
  --tile-cyan-border: #36c4da;
  --tile-cyan-lip: #28b0c8;
  --tile-cyan-text: #1a5e6f;
  /* Start cell — bright lime green */
  --tile-green-top: #9ef09e;
  --tile-green-mid: #82e882;
  --tile-green-bottom: #6edc6e;
  --tile-green-border: #58cc58;
  --tile-green-lip: #45b845;
  --tile-green-text: #1e5128;
  --tile-orange-top: #ffc896;
  --tile-orange-bottom: #ffab70;
  --tile-orange-border: #f08a45;
  --tile-orange-text: #6b3a12;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 15px rgba(0, 0, 0, 0.1);
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --game-board-max: 28rem;
}

html {
  overflow: hidden;
  height: 100%;
}

body {
  font-family: "Poppins", sans-serif;
  touch-action: manipulation;
  margin: 0;
  overflow: hidden;
  max-width: 100vw;
}

/* ===== LAYOUT & REUSABLE UTILITIES ===== */
.game-body {
  background: var(--color-bg) url("../img/bg.png") center center / cover no-repeat fixed;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  padding: 0;
  position: relative;
  box-sizing: border-box;
}

.game-screen {
  position: relative;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  gap: 0.375rem;
  overflow: hidden;
  padding:
    max(0.5rem, env(safe-area-inset-top, 0px)) max(0.75rem, env(safe-area-inset-right, 0px)) max(0.5rem, env(safe-area-inset-bottom, 0px)) max(0.75rem, env(safe-area-inset-left, 0px));
  box-sizing: border-box;
}

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

/* In-game modals — board visible behind, not clickable */
.game-screen-modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px)) max(1rem, env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
  pointer-events: auto;
}

.game-screen-modal.hidden {
  display: none !important;
}

.game-screen-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 8, 45, 0.48);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: auto;
}

.game-screen-modal .popup-content.game-modal {
  position: relative;
  z-index: 2;
  pointer-events: auto;
}

.game-modal--compact {
  padding: 2.5rem 1.25rem 1.25rem;
}

.game-modal__badge--success {
  background: linear-gradient(180deg, #fde68a 0%, #fbbf24 55%, #f59e0b 100%);
}

.game-modal__badge--warning {
  background: linear-gradient(180deg, #fecaca 0%, #f9a8d4 50%, #c084fc 100%);
}

.game-modal__badge--loading {
  background: linear-gradient(180deg, #bfdbfe 0%, #c4b5fd 50%, #f0abfc 100%);
}

.loading-progress__bar {
  display: block;
  width: 100%;
  height: 10px;
  margin-top: 1.1rem;
  border: none;
  border-radius: 999px;
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(196, 181, 253, 0.35);
  box-shadow: inset 0 1px 2px rgba(91, 33, 182, 0.12);
}

.loading-progress__bar::-webkit-progress-bar {
  border-radius: 999px;
  background: rgba(196, 181, 253, 0.35);
}

.loading-progress__bar::-webkit-progress-value {
  border-radius: 999px;
  background: linear-gradient(90deg, #e980d1 0%, #c084fc 52%, #ffb38a 100%);
  box-shadow: 0 0 10px rgba(192, 132, 252, 0.45);
  transition: width 0.35s ease;
}

.loading-progress__bar::-moz-progress-bar {
  border-radius: 999px;
  background: linear-gradient(90deg, #e980d1 0%, #c084fc 52%, #ffb38a 100%);
  box-shadow: 0 0 10px rgba(192, 132, 252, 0.45);
}

body.game-screen-modal-open {
  overflow: hidden;
}

/* Game header — in-flow grid layout (no fixed overlap) */
.game-header {
  position: relative;
  width: 100%;
  max-width: 100%;
  z-index: 50;
  grid-row: 1;
  align-self: start;
  justify-self: stretch;
  box-sizing: border-box;
  min-width: 0;
}

.game-header__top {
  display: contents;
}

.header-back {
  position: static;
  z-index: 50;
  display: flex;
  flex-direction: row;
  align-items: center;
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  min-width: 0;
  max-width: 100%;
}

.header-controls {
  position: static;
  transform: none;
  z-index: 50;
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  max-width: 100%;
  min-width: 0;
}

.header-icons {
  position: static;
  z-index: 50;
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  flex-shrink: 0;
}

.game-screen:has(.play-again-wrap:not(.hidden)) .game-card {
  width: min(calc(100vw - 1.5rem),
      calc(100dvh - 13rem),
      var(--game-board-max));
}

@media (min-width: 641px) {
  .game-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-rows: auto;
    align-items: center;
    gap: 0.5rem;
  }
}

.level-display-text {
  margin: 0;
  white-space: nowrap;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--start-level-purple);
  letter-spacing: 0.025em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.game-card {
  grid-row: 2;
  align-self: center;
  justify-self: center;
  width: min(calc(100vw - 1.5rem),
      calc(100dvh - 10.5rem),
      var(--game-board-max));
  max-width: min(calc(100vw - 1.5rem), var(--game-board-max));
  max-height: 100%;
  min-height: 0;
  flex-shrink: 1;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  background: linear-gradient(165deg,
      var(--board-glass-top) 0%,
      var(--board-glass-mid) 48%,
      var(--board-glass-bottom) 100%);
  backdrop-filter: blur(20px) saturate(1.35);
  -webkit-backdrop-filter: blur(20px) saturate(1.35);
  border-radius: 1.875rem;
  padding: 0.875rem;
  border: 2.5px solid rgba(255, 255, 255, 0.92);
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    inset 0 -3px 10px rgba(120, 160, 210, 0.12),
    0 6px 0 rgba(160, 180, 230, 0.35),
    0 16px 36px var(--board-frame-shadow),
    0 0 0 1px var(--board-border-glow);
  isolation: isolate;
}

.game-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 2.5px;
  background: linear-gradient(160deg,
      rgba(255, 160, 220, 0.55) 0%,
      rgba(192, 132, 252, 0.4) 35%,
      rgba(125, 211, 252, 0.45) 100%);
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  z-index: 0;
}

.game-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 8%;
  right: 8%;
  height: 38%;
  border-radius: 0 0 999px 999px;
  background: linear-gradient(180deg,
      rgba(255, 255, 255, 0.42) 0%,
      rgba(255, 255, 255, 0) 100%);
  pointer-events: none;
  z-index: 0;
}

.game-card>* {
  position: relative;
  z-index: 1;
}

@media (min-width: 640px) {
  .game-card {
    padding: 1rem;
    border-radius: 2rem;
  }
}

.status-bar {
  text-align: center;
  margin-bottom: 0;
  min-height: 2.5rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(90deg,
      #f472b6 0%,
      #e879f9 28%,
      #c084fc 58%,
      #fb923c 100%);
  border-radius: 9999px;
  border: 2.5px solid rgba(255, 255, 255, 0.95);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -2px 4px rgba(160, 60, 140, 0.18),
    0 4px 0 rgba(168, 70, 150, 0.28),
    0 8px 18px rgba(180, 80, 160, 0.28);
  padding: 0.375rem 1.5rem;
  width: 100%;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

.status-text {
  font-size: 1.0625rem;
  font-weight: 800;
  line-height: 1;
  margin: 0;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 2px rgba(100, 40, 100, 0.25);
  color: #ffffff;
  text-transform: capitalize;
}

.status-text__number {
  color: var(--place-number-yellow);
  font-size: 1.35em;
  font-weight: 800;
  margin-left: 0.2em;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35),
    0 2px 4px rgba(120, 80, 0, 0.35);
}

.status-text--number {
  color: var(--place-number-yellow);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35),
    0 2px 4px rgba(120, 80, 0, 0.35);
}

.play-again-wrap {
  grid-row: 3;
  align-self: end;
  width: min(100%, calc(100vw - 1.5rem));
  max-width: var(--game-board-max);
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 0;
}

.play-again-wrap.hidden {
  display: none !important;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

/* Start Screen Styles */
.start-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: var(--color-bg) url("../img/bg.png") center center / cover no-repeat fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  transition: opacity 0.3s ease-out, visibility 0.3s ease-out;
  padding:
    max(1rem, env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px)) max(1rem, env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
  box-sizing: border-box;
  overflow-y: auto;
}

.start-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-screen-content {
  text-align: center;
  padding: 2rem;
  max-width: 500px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
}

.start-screen-logo {
  margin-bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.start-screen-logo-img {
  display: block;
  width: min(88vw, 320px);
  height: auto;
  object-fit: contain;
}

.start-screen .level-card {
  background: linear-gradient(180deg,
      var(--start-card-bg-top) 0%,
      var(--start-card-bg-bottom) 100%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 40px;
  padding: 1.5rem 1.25rem;
  margin-bottom: 0;
  border: 2px solid var(--start-card-border);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 8px 28px rgba(84, 54, 160, 0.18);
  animation: cardSlideIn 0.5s ease-out;
  width: 148px;
  height: 148px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  margin-right: auto;
  gap: 0.25rem;
}

.start-screen .level-card-label {
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--start-level-purple);
  line-height: 1;
}

.start-screen .level-card-number {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--start-level-purple);
  text-align: center;
  line-height: 1;
  margin-bottom: 0;
}

.start-screen-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  width: 100%;
}

.start-play-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: min(320px, 82vw);
  padding: 1rem 2.5rem;
  border: 2.5px solid rgba(255, 255, 255, 0.95);
  border-radius: 9999px;
  background: linear-gradient(180deg,
      var(--start-btn-top) 0%,
      var(--start-btn-mid) 45%,
      var(--start-btn-bottom) 100%);
  color: #ffffff;
  font-family: "Poppins", sans-serif;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 1px 2px rgba(75, 30, 130, 0.45);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 4px 0 rgba(91, 33, 182, 0.35),
    0 10px 28px rgba(109, 40, 217, 0.32);
  overflow: hidden;
}

.start-play-button:hover {
  transform: translateY(-2px);
  filter: brightness(1.04);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 5px 0 rgba(91, 33, 182, 0.35),
    0 14px 32px rgba(109, 40, 217, 0.38);
}

.start-play-button:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 2px 0 rgba(91, 33, 182, 0.35),
    0 6px 18px rgba(109, 40, 217, 0.28);
}

.start-play-button:focus {
  outline: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 4px 0 rgba(91, 33, 182, 0.35),
    0 10px 28px rgba(109, 40, 217, 0.32),
    0 0 0 3px rgba(167, 139, 250, 0.45);
}

@keyframes cardSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Game board grid */
.grid-container {
  display: grid;
  gap: 6px;
  padding: 10px;
  border-radius: 1.375rem;
  background: linear-gradient(180deg,
      var(--board-grid-top) 0%,
      var(--board-grid-bottom) 100%);
  border: 2px solid var(--board-grid-border);
  box-shadow:
    inset 0 4px 12px var(--board-grid-inset),
    inset 0 1px 0 rgba(255, 255, 255, 0.65),
    0 1px 0 rgba(255, 255, 255, 0.75);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  flex: 1 1 auto;
  align-self: center;
  grid-template-columns: repeat(var(--grid-cols, 3), 1fr);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  container-type: inline-size;
}

.grid-container::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(ellipse 90% 60% at 50% 0%,
      rgba(255, 255, 255, 0.28) 0%,
      rgba(255, 255, 255, 0) 70%);
  pointer-events: none;
  z-index: 0;
}

.grid-container .cell {
  z-index: 1;
}

.grid-container[data-size="3"] {
  --grid-cols: 3;
}

.grid-container[data-size="4"] {
  --grid-cols: 4;
}

.grid-container[data-size="5"] {
  --grid-cols: 5;
}

.grid-container[data-size="6"] {
  --grid-cols: 6;
}

.grid-container[data-size="7"] {
  --grid-cols: 7;
}

.grid-container.is-dragging {
  cursor: grabbing;
}

.grid-container.is-dragging .cell-empty {
  cursor: grabbing;
}

.cell-empty {
  cursor: pointer;
}

.cell {
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 26%;
  font-weight: 800;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    border-color 0.12s ease;
  user-select: none;
  background: linear-gradient(180deg, #ffffff 0%, #f4f9ff 100%);
  border: 2px solid var(--tile-empty-border);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.98),
    inset 0 -2px 4px rgba(160, 195, 230, 0.22),
    0 3px 0 var(--tile-empty-lip),
    0 5px 8px rgba(100, 150, 200, 0.18);
  position: relative;
  font-size: clamp(0.875rem,
      calc(100cqi / var(--grid-cols, 4) * 0.52),
      2.75rem);
  min-height: 0;
  min-width: 0;
  line-height: 1;
  z-index: 0;
}

.cell:not(.cell-empty) {
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.cell-clue::before,
.cell-user::before,
.cell-start::before,
.cell-end::before {
  content: "";
  position: absolute;
  top: 7%;
  left: 9%;
  width: 44%;
  height: 22%;
  border-radius: 999px;
  background: linear-gradient(180deg,
      rgba(255, 255, 255, 0.82) 0%,
      rgba(255, 255, 255, 0.28) 100%);
  pointer-events: none;
  z-index: 1;
}

.cell-disabled {
  cursor: default;
}

.cell-empty::after {
  content: "";
  position: absolute;
  width: 24%;
  height: 24%;
  min-width: 8px;
  min-height: 8px;
  border-radius: 50%;
  background: transparent;
  border: 2.5px solid var(--tile-empty-ring);
  box-shadow: inset 0 0 4px rgba(125, 220, 255, 0.25);
  pointer-events: none;
  z-index: 2;
}

.cell-clue {
  background: linear-gradient(180deg,
      var(--tile-purple-top) 0%,
      var(--tile-purple-mid) 52%,
      var(--tile-purple-bottom) 100%);
  color: var(--tile-purple-text);
  cursor: not-allowed;
  border: 2px solid var(--tile-purple-border);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.65),
    inset 0 -3px 6px rgba(120, 80, 180, 0.18),
    0 4px 0 var(--tile-purple-lip),
    0 6px 10px rgba(110, 70, 170, 0.28);
}

.cell-start {
  background: linear-gradient(180deg,
      var(--tile-green-top) 0%,
      var(--tile-green-mid) 52%,
      var(--tile-green-bottom) 100%);
  color: var(--tile-green-text);
  border: 2px solid var(--tile-green-border);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.65),
    inset 0 -3px 6px rgba(60, 150, 80, 0.18),
    0 4px 0 var(--tile-green-lip),
    0 6px 10px rgba(60, 150, 80, 0.28);
}

.cell-end {
  background: linear-gradient(180deg,
      var(--tile-orange-top) 0%,
      var(--tile-orange-bottom) 100%);
  color: var(--tile-orange-text);
  border: 2px solid var(--tile-orange-border);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.65),
    inset 0 -3px 6px rgba(200, 120, 50, 0.18),
    0 4px 0 #e07830,
    0 6px 10px rgba(200, 120, 50, 0.28);
}

.cell-user {
  background: linear-gradient(180deg,
      var(--tile-cyan-top) 0%,
      var(--tile-cyan-mid) 52%,
      var(--tile-cyan-bottom) 100%);
  color: var(--tile-cyan-text);
  border: 2px solid var(--tile-cyan-border);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.65),
    inset 0 -3px 6px rgba(30, 150, 180, 0.18),
    0 4px 0 var(--tile-cyan-lip),
    0 6px 10px rgba(30, 150, 180, 0.28);
}

.cell-empty:hover {
  border-color: #8edcff;
  transform: translateY(-1px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.98),
    inset 0 -2px 4px rgba(160, 195, 230, 0.22),
    0 4px 0 var(--tile-empty-lip),
    0 7px 12px rgba(100, 150, 200, 0.22);
}

.cell-user:active,
.cell-empty:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.12),
    0 1px 0 var(--tile-cyan-lip),
    0 2px 4px rgba(30, 150, 180, 0.2);
}

.cell-empty:active {
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.1),
    0 1px 0 var(--tile-empty-lip),
    0 2px 4px rgba(100, 150, 200, 0.18);
}

.cell.highlight {
  border: 2.5px solid #a78bfa;
  box-shadow:
    0 0 0 2px rgba(167, 139, 250, 0.35),
    0 0 14px rgba(167, 139, 250, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.55);
  z-index: 10;
  transform: scale(1.04);
}

.cell.error {
  animation: shake 0.5s;
  background: linear-gradient(180deg, #fecaca 0%, #fca5a5 100%);
  border-color: #ef4444;
  color: #991b1b;
}

@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

.hint-highlight {
  background: linear-gradient(180deg, #fef08a 0%, #fde047 100%) !important;
  color: #854d0e !important;
  border: 2.5px solid #f59e0b !important;
  animation: pulse 1s infinite;
  transform: scale(1.05);
  box-shadow:
    0 0 0 2px rgba(245, 158, 11, 0.25),
    0 4px 12px rgba(245, 158, 11, 0.35) !important;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

/* ===== Unified Game Modal Popups ===== */
.popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: max(1.25rem, env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px)) max(1.25rem, env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
  box-sizing: border-box;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-y: auto;
  background:
    rgba(15, 10, 40, 0.38) url("../img/bg.png") center center / cover no-repeat fixed;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.popup-content {
  background: white;
  border-radius: 20px;
  padding: 1rem;
  max-width: min(400px, 90vw);
  width: 85%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  animation: popupSlideIn 0.3s ease-out;
  margin: auto;
  flex-shrink: 0;
}

.popup-content.game-modal {
  position: relative;
  background: #ffffff;
  border-radius: 32px;
  padding: 2.75rem 1.25rem 1.35rem;
  max-width: min(360px, 92vw);
  width: 100%;
  max-height: none;
  overflow: visible;
  box-shadow: 0 22px 48px rgba(110, 61, 145, 0.22);
  margin: 2.5rem auto;
  border: none;
}

.popup-content.game-modal::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 32px;
  padding: 3px;
  background: linear-gradient(180deg,
      #ff80bf 0%,
      #e879f9 28%,
      #c084fc 55%,
      #80dfff 100%);
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.game-modal__badge {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(180deg, #f0abfc 0%, #d8b4fe 42%, #a78bfa 100%);
  border: 2.5px solid #ffffff;
  box-shadow:
    0 4px 16px rgba(139, 92, 246, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 3;
}

.game-modal__badge svg {
  width: 40px;
  height: 40px;
  display: block;
}

.game-modal__title {
  margin: 0 0 0.35rem;
  text-align: center;
  font-size: 1.625rem;
  font-weight: 800;
  color: #6e3d91;
  letter-spacing: 0.01em;
  line-height: 1.15;
}

.game-modal__subtitle {
  margin: 0 0 1rem;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  color: #7c5ea8;
  line-height: 1.4;
}

.game-modal__body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.15rem;
  overflow-y: auto;
  max-height: calc(88vh - 11rem);
}

.game-modal__section {
  background: #f0f4ff;
  border: 1.5px solid #c7d7ff;
  border-radius: 18px;
  padding: 0.85rem 0.95rem;
}

.game-modal__section-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.45rem;
  font-size: 1rem;
  font-weight: 800;
  color: #6e3d91;
  line-height: 1.2;
}

.game-modal__section-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
  font-size: 1.05rem;
  line-height: 1;
}

.game-modal__section-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.game-modal__text {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.5;
  color: #4a3f63;
  white-space: pre-line;
}

.game-modal__list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.55;
  color: #4a3f63;
}

.game-modal__list li+li {
  margin-top: 0.35rem;
}

.game-modal__btn {
  display: block;
  width: 100%;
  padding: 0.95rem 1.5rem;
  border: none;
  border-radius: 9999px;
  background: linear-gradient(180deg, #9b6fd0 0%, #8e54b1 45%, #6e3d91 100%);
  color: #ffffff;
  font-family: "Poppins", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(55, 20, 90, 0.35);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 4px 0 #5a2f78,
    0 10px 24px rgba(110, 61, 145, 0.32);
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.game-modal__btn+.game-modal__btn {
  margin-top: 0.65rem;
}

.game-modal__btn--secondary {
  background: #ffffff;
  color: #6e3d91;
  text-shadow: none;
  border: 2px solid #8e54b1;
  box-shadow: none;
}

.game-modal__btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 5px 0 #5a2f78,
    0 14px 28px rgba(110, 61, 145, 0.36);
}

.game-modal__btn:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 2px 0 #5a2f78,
    0 6px 16px rgba(110, 61, 145, 0.26);
}

.game-modal__btn:focus {
  outline: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 4px 0 #5a2f78,
    0 10px 24px rgba(110, 61, 145, 0.32),
    0 0 0 3px rgba(167, 139, 250, 0.45);
}

@media (max-width: 480px) {
  .popup-content.game-modal {
    border-radius: 28px;
    padding: 2.5rem 1rem 1.15rem;
    margin: 2rem auto;
  }

  .popup-content.game-modal::before {
    border-radius: 28px;
  }

  .game-modal__badge {
    width: 48px;
    height: 48px;
  }

  .game-modal__badge svg {
    width: 36px;
    height: 36px;
  }

  .game-modal__title {
    font-size: 1.45rem;
  }

  .game-modal__subtitle {
    font-size: 0.8125rem;
    margin-bottom: 0.85rem;
  }

  .game-modal__section {
    border-radius: 16px;
    padding: 0.75rem 0.85rem;
  }

  .game-modal__section-title {
    font-size: 0.9375rem;
  }

  .game-modal__text,
  .game-modal__list {
    font-size: 0.75rem;
  }

  .game-modal__btn {
    font-size: 0.9375rem;
    padding: 0.875rem 1.25rem;
  }
}

@keyframes popupSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.hidden {
  display: none !important;
}

.audio-icon {
  display: block;
}

.error-highlight {
  background-color: #fecaca !important;
  border: 3px solid #dc2626 !important;
  animation: errorPulse 0.5s ease-in-out;
}

@keyframes errorPulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }

  100% {
    transform: scale(1);
  }
}

/* Level Display Styles */
#levelDisplay {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--level-badge-gradient);
  border: 2px solid rgba(220, 200, 255, 0.88);
  border-radius: 9999px;
  padding: 0.35rem 0.95rem;
  margin: 0;
  margin-left: 0.5rem;
  position: static;
  flex-shrink: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    0 4px 14px rgba(180, 100, 200, 0.2);
}

#levelDisplay .level-display-text {
  margin: 0;
  white-space: nowrap;
  text-shadow: none;
  color: var(--level-badge-text);
  font-size: 0.9375rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

/* Back Button and Level Display Container */
.header-back {
  gap: 0;
  flex-wrap: nowrap;
}

/* Back Button Icon */
.back-button-icon {
  background: linear-gradient(180deg,
      var(--back-btn-top) 0%,
      var(--back-btn-bottom) 100%);
  color: white;
  border: 2px solid var(--btn-white-border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 3px 0 var(--back-btn-shadow),
    0 8px 18px rgba(67, 56, 202, 0.28);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  margin: 0;
}

.back-button-icon::before {
  display: none;
}

.back-button-icon:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 4px 0 var(--back-btn-shadow),
    0 10px 22px rgba(67, 56, 202, 0.32);
}

.back-button-icon:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 2px 0 var(--back-btn-shadow),
    0 5px 12px rgba(67, 56, 202, 0.24);
}

.back-button-icon svg {
  transition: transform 0.2s ease;
}

.back-button-icon:hover svg {
  transform: translateX(-2px);
}

/* Mobile responsive for level selection */
@media (max-width: 640px) {
  .levels-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
  }

  .level-button {
    font-size: 1rem;
    min-height: 50px;
  }

  #levelDisplay {
    padding: 0.3rem 0.75rem;
  }

  #levelDisplay .level-display-text {
    font-size: 0.8125rem;
  }
}

/* Beautiful Button Styles */
.beautiful-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  text-decoration: none;
  min-width: 100px;
  z-index: 1;
}

.beautiful-button::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;
  z-index: -1;
}

.beautiful-button:hover::before {
  left: 100%;
}

.beautiful-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  animation: buttonPulse 0.6s ease-in-out;
}

@keyframes buttonPulse {
  0% {
    transform: translateY(-2px) scale(1);
  }

  50% {
    transform: translateY(-2px) scale(1.05);
  }

  100% {
    transform: translateY(-2px) scale(1);
  }
}

.beautiful-button:active {
  transform: translateY(0);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.beautiful-button:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.beautiful-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.beautiful-button:disabled:hover {
  transform: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Game screen header — pill button theme */
.header-controls .beautiful-button {
  border: 2px solid var(--btn-white-border);
  border-radius: 9999px;
  padding: 0.625rem 1.125rem;
  font-weight: 700;
  font-size: 0.8125rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  min-width: auto;
  letter-spacing: 0.02em;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.header-controls .beautiful-button::before {
  display: none;
}

.header-controls .beautiful-button:hover {
  animation: none;
  filter: brightness(1.05);
}

.header-controls .beautiful-button:active {
  transform: translateY(2px);
}

.header-controls .beautiful-button:focus {
  outline: none;
}

/* Hint Button */
.header-controls .hint-button {
  background: linear-gradient(180deg,
      var(--hint-btn-top) 0%,
      var(--hint-btn-mid) 45%,
      var(--hint-btn-bottom) 100%);
  color: white;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 3px 0 var(--hint-btn-shadow),
    0 8px 20px rgba(139, 92, 246, 0.32);
}

.header-controls .hint-button:hover {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 4px 0 var(--hint-btn-shadow),
    0 10px 24px rgba(139, 92, 246, 0.38);
}

.header-controls .hint-button:disabled {
  background: linear-gradient(180deg, #e5e7eb 0%, #d1d5db 50%, #9ca3af 100%);
  color: rgba(255, 255, 255, 0.9);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 2px 0 rgba(107, 114, 128, 0.25),
    0 4px 12px rgba(107, 114, 128, 0.18);
  opacity: 0.75;
}

/* Solution Button */
.header-controls .solution-button {
  background: linear-gradient(180deg,
      var(--solution-btn-top) 0%,
      var(--solution-btn-mid) 45%,
      var(--solution-btn-bottom) 100%);
  color: white;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 3px 0 var(--solution-btn-shadow),
    0 8px 20px rgba(16, 185, 129, 0.32);
}

.header-controls .solution-button:hover {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 4px 0 var(--solution-btn-shadow),
    0 10px 24px rgba(16, 185, 129, 0.38);
}

.header-controls .solution-button:disabled {
  background: linear-gradient(180deg, #e5e7eb 0%, #d1d5db 50%, #9ca3af 100%);
  color: rgba(255, 255, 255, 0.9);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 2px 0 rgba(107, 114, 128, 0.25),
    0 4px 12px rgba(107, 114, 128, 0.18);
  opacity: 0.75;
}

/* Reset Button */
.header-controls .reset-button {
  background: linear-gradient(180deg,
      var(--reset-btn-top) 0%,
      var(--reset-btn-mid) 45%,
      var(--reset-btn-bottom) 100%);
  color: white;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 3px 0 var(--reset-btn-shadow),
    0 8px 20px rgba(245, 158, 11, 0.32);
}

.header-controls .reset-button:hover {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 4px 0 var(--reset-btn-shadow),
    0 10px 24px rgba(245, 158, 11, 0.38);
}

.header-controls .reset-button:disabled {
  background: linear-gradient(180deg, #e5e7eb 0%, #d1d5db 50%, #9ca3af 100%);
  color: rgba(255, 255, 255, 0.9);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 2px 0 rgba(107, 114, 128, 0.25),
    0 4px 12px rgba(107, 114, 128, 0.18);
  opacity: 0.75;
}

/* Undo Button */
.header-controls .undo-button {
  background: linear-gradient(180deg,
      var(--undo-btn-top) 0%,
      var(--undo-btn-mid) 50%,
      var(--undo-btn-bottom) 100%);
  color: var(--undo-btn-text);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 3px 0 var(--undo-btn-shadow),
    0 8px 18px rgba(129, 140, 248, 0.22);
}

.header-controls .undo-button:hover {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.65),
    0 4px 0 var(--undo-btn-shadow),
    0 10px 22px rgba(129, 140, 248, 0.28);
}

.header-controls .undo-button:disabled {
  background: linear-gradient(180deg,
      rgba(229, 231, 235, 0.85) 0%,
      rgba(209, 213, 219, 0.8) 50%,
      rgba(156, 163, 175, 0.75) 100%);
  color: rgba(107, 114, 128, 0.85);
  text-shadow: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 2px 0 rgba(156, 163, 175, 0.2),
    0 4px 10px rgba(107, 114, 128, 0.12);
  opacity: 0.7;
}

/* Square Icon Buttons (Top Right) */
.header-icons .icon-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "Poppins", sans-serif;
  border: 2px solid var(--btn-white-border);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 3px 0 var(--icon-btn-shadow),
    0 8px 18px rgba(139, 92, 246, 0.28);
  overflow: hidden;
  width: 44px;
  height: 44px;
  padding: 0;
  flex-shrink: 0;
  background: linear-gradient(180deg,
      var(--icon-btn-top) 0%,
      var(--icon-btn-mid) 45%,
      var(--icon-btn-bottom) 100%);
  color: white;
}

.icon-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "Poppins", sans-serif;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  width: 44px;
  height: 44px;
  padding: 0;
  flex-shrink: 0;
}

.square-icon-button {
  aspect-ratio: 1;
}

.header-icons .icon-button::before {
  display: none;
}

.header-icons .icon-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 4px 0 var(--icon-btn-shadow),
    0 10px 22px rgba(139, 92, 246, 0.34);
}

.header-icons .icon-button:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 2px 0 var(--icon-btn-shadow),
    0 5px 12px rgba(139, 92, 246, 0.22);
}

.icon-button::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;
  z-index: 1;
}

.icon-button:hover::before {
  left: 100%;
}

.icon-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.icon-button:active {
  transform: translateY(0);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.icon-button svg {
  position: relative;
  z-index: 2;
  transition: transform 0.2s ease;
}

.icon-button:hover svg {
  transform: scale(1.1);
}

/* Icon Buttons - fallback for non-header usage */
.icon-button {
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.icon-button:hover {
  background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
  box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4);
}

.header-icons .icon-button:hover {
  background: linear-gradient(180deg,
      var(--icon-btn-top) 0%,
      var(--icon-btn-mid) 45%,
      var(--icon-btn-bottom) 100%);
}

.play-again-button {
  background: linear-gradient(180deg,
      var(--reset-btn-top) 0%,
      var(--reset-btn-mid) 45%,
      var(--reset-btn-bottom) 100%);
  color: white;
  font-size: 1.125rem;
  padding: 1rem 2.5rem;
  min-width: 200px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  border: 2.5px solid var(--btn-white-border);
  border-radius: 9999px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 4px 0 var(--reset-btn-shadow),
    0 10px 28px rgba(245, 158, 11, 0.32);
  display: inline-block;
  margin-top: 1rem;
}

.play-again-button:hover {
  filter: brightness(1.05);
  transform: translateY(-2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 5px 0 var(--reset-btn-shadow),
    0 14px 32px rgba(245, 158, 11, 0.38);
}

.play-again-button:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 2px 0 var(--reset-btn-shadow),
    0 6px 18px rgba(245, 158, 11, 0.28);
}

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

/* Mobile header — controls below back/icon row */
@media (max-width: 640px) {
  .game-header {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    background: transparent;
  }

  .game-header__top {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 0.375rem;
    min-width: 0;
  }

  .header-back,
  .header-icons,
  .header-controls {
    position: static;
    grid-column: auto;
    grid-row: auto;
    justify-self: stretch;
    transform: none;
    max-width: 100%;
  }

  .header-back {
    flex: 1 1 auto;
    min-width: 0;
  }

  #levelDisplay {
    min-width: 0;
    max-width: calc(100vw - 7rem);
  }

  #levelDisplay .level-display-text {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .header-icons {
    flex-shrink: 0;
  }

  .header-controls {
    width: 100%;
    justify-content: center;
    gap: 0.3125rem;
    flex-wrap: wrap;
  }

  .header-controls .beautiful-button {
    padding: 0.4375rem 0.625rem;
    font-size: 0.6875rem;
    max-width: 100%;
  }

  .game-card {
    width: min(calc(100vw - 1.25rem),
        calc(100dvh - 11rem),
        var(--game-board-max));
  }

  .status-text {
    font-size: clamp(0.9375rem, 3.5vw, 1.125rem);
  }

  .status-text__number {
    font-size: 1.4em;
  }

  .grid-container[data-size="5"],
  .grid-container[data-size="6"],
  .grid-container[data-size="7"] {
    gap: 2px;
    padding: 4px;
  }

  .grid-container[data-size="6"] .cell,
  .grid-container[data-size="7"] .cell {
    border-radius: 18%;
    min-height: 0;
    min-width: 0;
  }

  .play-again-wrap {
    width: min(100%, calc(100vw - 1.25rem));
  }
}

@media (max-width: 480px) {
  .header-controls {
    gap: 0.25rem;
  }

  .header-controls .beautiful-button {
    padding: 0.4rem 0.5rem;
    font-size: 0.625rem;
  }
}

@media (max-width: 360px) {
  .header-controls .beautiful-button {
    flex: 1 1 calc(50% - 0.25rem);
    max-width: calc(50% - 0.25rem);
    min-width: 0;
  }

  .game-card {
    width: min(calc(100vw - 1rem),
        calc(100dvh - 12rem),
        var(--game-board-max));
  }
}

@media (max-width: 640px) and (orientation: landscape) and (max-height: 600px) {
  .game-screen {
    gap: 0.25rem;
    padding-top: max(0.25rem, env(safe-area-inset-top, 0px));
    padding-bottom: max(0.25rem, env(safe-area-inset-bottom, 0px));
  }

  .game-header {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
  }

  .game-header__top {
    flex: 1 1 auto;
    min-width: 0;
  }

  .header-controls {
    flex: 1 1 100%;
    gap: 0.25rem;
  }

  .header-controls .beautiful-button {
    flex: 1 1 auto;
    max-width: none;
    padding: 0.3125rem 0.5rem;
    font-size: 0.625rem;
  }

  .game-card {
    width: min(calc(100vw - 1rem),
        calc(100dvh - 7rem),
        var(--game-board-max));
    max-height: min(55dvh, 100%);
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  .header-controls .beautiful-button {
    padding: 0.5rem 0.875rem;
    font-size: 0.75rem;
  }

  .game-card {
    width: min(calc(100vw - 2rem),
        calc(100dvh - 10rem),
        var(--game-board-max));
  }
}

/* Override min-height for game layout */
@media (orientation: landscape) {
  body.game-body {
    min-height: 100dvh !important;
    height: 100dvh;
    max-height: 100dvh;
  }
}

/* Keep min-height for web screens (desktop) */
@media (min-width: 1024px) {
  body.game-body {
    min-height: 100dvh !important;
    height: 100dvh;
  }
}

/* Extra small screens - ensure popup never exceeds viewport */
@media (max-width: 320px) {
  .popup-content:not(.game-modal) {
    width: 95%;
    max-width: min(320px, calc(100vw - 0.5rem));
    padding: 0.75rem;
    margin: auto;
  }

  .popup-content.game-modal {
    width: 100%;
    max-width: min(360px, calc(100vw - 1rem));
    margin: 2rem auto;
  }

  .popup-header h1 {
    line-height: 1.1;
  }

  .popup-header p {
    font-size: 0.875rem;
  }
}

/* Landscape Mobile (orientation: landscape) */
@media (orientation: landscape) and (max-height: 600px) {
  body.game-body {
    padding: 0;
  }

  .popup-content:not(.game-modal) {
    max-height: 90vh;
    padding: 1rem;
    margin: 0.5rem;
    max-width: min(400px, 90vw);
  }

  .popup-header h1 {
    margin-bottom: 0.5rem;
  }

  .popup-header p {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
  }

  .rules-section {
    margin-bottom: 0.5rem;
  }

  .rule-item {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
  }

  .rule-number {
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
    margin-right: 0.75rem;
  }

  .celebration-section {
    margin-bottom: 0.5rem;
  }

  .celebration-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
  }

  .start-button,
  .next-button {
    padding: 0.75rem;
    font-size: 1rem;
    min-width: 160px;
  }

  .game-over-popup {
    max-height: 85vh;
    padding: 1rem;
  }

  .success-icon {
    font-size: 2.5rem;
  }

  .achievement-badge {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
  }

  .badge-icon {
    font-size: 1.25rem;
    margin-right: 0.5rem;
  }

  .badge-title {
    font-size: 0.875rem;
  }

  .badge-subtitle {
    font-size: 0.625rem;
  }

  .celebration-message {
    font-size: 0.875rem;
    padding: 0 0.5rem;
  }

  .celebration-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.25rem;
    min-width: 140px;
  }

  .confetti {
    font-size: 1rem;
  }

  .how-to-play-title {
    font-size: 1.125rem;
    gap: 0.25rem;
    margin-bottom: 0.375rem;
  }

  .title-icon {
    font-size: 1.25rem;
  }

  .levels-grid {
    max-height: 20rem;
    padding: 0.5rem;
  }

  .level-button {
    font-size: 0.875rem;
    min-height: 40px;
  }
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
  body.game-body {
    padding: 0;
    overflow-x: hidden;
  }

  .start-screen-content {
    padding: 1rem;
    gap: 1.75rem;
  }

  .start-screen .level-card {
    width: 132px;
    height: 132px;
    padding: 1.25rem 1rem;
    border-radius: 36px;
  }

  .start-screen .level-card-label {
    font-size: 0.75rem;
  }

  .start-screen .level-card-number {
    font-size: 3rem;
  }

  .start-screen-buttons {
    gap: 0.75rem;
  }

  .start-play-button {
    width: min(300px, 84vw);
    padding: 0.9375rem 2rem;
    font-size: 1rem;
  }

  .grid-container {
    gap: 1px;
    padding: 4px;
  }

  .cell {
    border-radius: 6px;
    min-height: 25px;
    min-width: 25px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

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

  .level-display-text {
    font-size: 0.75rem;
    font-weight: 600;
  }

  .back-button-icon {
    width: 32px;
    height: 32px;
  }

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

  .beautiful-button {
    font-size: 0.625rem;
    padding: 0.5rem 1rem;
    min-width: 70px;
    border-radius: 8px;
  }

  .header-controls .beautiful-button {
    border-radius: 9999px;
    padding: 0.45rem 0.75rem;
    min-width: auto;
  }

  .popup-content:not(.game-modal) {
    width: 90%;
    padding: 1rem;
    margin: 0.5rem;
    border-radius: 12px;
    max-width: min(350px, 90vw);
  }

  .popup-header h1 {
    margin-bottom: 0.5rem;
    line-height: 1.1;
  }

  .popup-header p {
    font-size: 0.875rem;
  }

  .how-to-play-title {
    font-size: 1rem;
    gap: 0.25rem;
    margin-bottom: 0.375rem;
  }

  .title-icon {
    font-size: 1.125rem;
  }

  .rule-item {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
  }

  .rule-number {
    width: 20px;
    height: 20px;
    font-size: 0.625rem;
    margin-right: 0.5rem;
  }

  .rule-item p {
    font-size: 0.75rem;
    line-height: 1.4;
  }

  .start-button,
  .next-button {
    padding: 0.75rem;
    font-size: 0.875rem;
    min-width: 140px;
  }

  .levels-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    padding: 0.5rem;
  }

  .level-button {
    font-size: 0.75rem;
    min-height: 40px;
    border-radius: 8px;
  }

  .celebration-section {
    margin-bottom: 0.75rem;
  }

  .celebration-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
  }

  .game-over-popup {
    margin: 0.5rem;
    max-width: min(350px, calc(100vw - 1rem));
    padding: 0.75rem;
  }

  .success-icon {
    font-size: 2.5rem;
  }

  .success-ring {
    width: 50px;
    height: 50px;
  }

  .achievement-badge {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    border-radius: 12px;
  }

  .badge-icon {
    font-size: 1.25rem;
    margin-right: 0.375rem;
  }

  .badge-title {
    font-size: 0.875rem;
  }

  .badge-subtitle {
    font-size: 0.625rem;
  }

  .celebration-message {
    font-size: 0.875rem;
    padding: 0 0.5rem;
  }

  .celebration-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.25rem;
    min-width: 140px;
  }

  .confetti {
    font-size: 1rem;
  }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
  body.game-body {
    padding: 0;
    overflow-x: hidden;
  }

  .start-screen-content {
    padding: 1.5rem;
  }

  .start-screen .level-card {
    width: 140px;
    height: 140px;
    padding: 1.35rem 1.1rem;
    border-radius: 38px;
  }

  .start-screen .level-card-number {
    font-size: 3.25rem;
  }

  .grid-container {
    gap: 1.5px;
    padding: 5px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

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

  .cell {
    border-radius: 8px;
    min-height: 28px;
    min-width: 28px;
  }

  .beautiful-button {
    font-size: 0.75rem;
    padding: 0.625rem 1.25rem;
    min-width: 80px;
  }


  .level-display-text {
    font-size: 0.875rem;
    font-weight: 600;
  }

  .back-button-icon {
    width: 36px;
    height: 36px;
  }

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

  .start-button {
    font-size: 1rem;
    padding: 0.875rem 1.75rem;
    min-width: 180px;
  }

  .popup-footer .beautiful-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.5rem;
    min-width: 120px;
  }

  .levels-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
  }

  .level-button {
    font-size: 1rem;
    min-height: 50px;
  }

  /* Mobile adjustments for game over popup */
  .game-over-popup {
    margin: 0.5rem;
    max-width: min(400px, calc(100vw - 1rem));
  }

  .success-icon {
    font-size: 3rem;
  }

  .success-ring {
    width: 60px;
    height: 60px;
  }

  .achievement-badge {
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
  }

  .badge-icon {
    font-size: 1.5rem;
    margin-right: 0.5rem;
  }

  .badge-title {
    font-size: 1rem;
  }

  .badge-subtitle {
    font-size: 0.75rem;
  }

  .celebration-message {
    font-size: 1rem;
    padding: 0 1rem;
  }

  .celebration-button {
    font-size: 1rem;
    padding: 0.875rem 1.5rem;
    min-width: 180px;
  }

  .confetti {
    font-size: 1.25rem;
  }

  /* Mobile adjustments for How to Play title */
  .how-to-play-title {
    font-size: 1.25rem;
    gap: 0.375rem;
    margin-bottom: 0.5rem;
    padding: 0.125rem 0;
  }

  .title-icon {
    font-size: 1.5rem;
  }
}

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

  .grid-container {
    gap: 2px;
    padding: 6px;
  }

  .icon-button {
    width: 42px;
    height: 42px;
  }

  .icon-button svg {
    width: 19px;
    height: 19px;
  }

  .beautiful-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.5rem;
    min-width: 90px;
  }


  .level-display-text {
    font-size: 1rem;
  }

  .back-button-icon {
    width: 38px;
    height: 38px;
  }

  .back-button-icon svg {
    width: 19px;
    height: 19px;
  }

  .popup-content:not(.game-modal) {
    max-width: 480px;
    padding: 1.5rem;
  }

  .levels-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
  }

  .level-button {
    font-size: 1.125rem;
    min-height: 55px;
  }

  .how-to-play-title {
    font-size: 1.375rem;
  }

  .rule-item {
    padding: 0.75rem;
  }

  .rule-number {
    width: 26px;
    height: 26px;
    font-size: 0.8rem;
  }

  .start-button,
  .next-button {
    padding: 1rem;
    font-size: 1.125rem;
    min-width: 190px;
  }

  .celebration-icon {
    font-size: 3.5rem;
  }

  .success-icon {
    font-size: 3.5rem;
  }

  .achievement-badge {
    padding: 1rem 1.25rem;
  }

  .badge-icon {
    font-size: 1.75rem;
  }

  .badge-title {
    font-size: 1.125rem;
  }

  .celebration-message {
    font-size: 1.125rem;
  }

  .celebration-button {
    font-size: 1.125rem;
    padding: 1rem 1.75rem;
    min-width: 190px;
  }
}

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

  .grid-container {
    gap: 2px;
    padding: 7px;
  }

  .beautiful-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.5rem;
    min-width: 100px;
  }


  .level-display-text {
    font-size: 1.125rem;
  }

  .back-button-icon {
    width: 40px;
    height: 40px;
  }

  .popup-content:not(.game-modal) {
    max-width: 550px;
    padding: 1.5rem;
  }

  .levels-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
  }

  .level-button {
    font-size: 1.25rem;
    min-height: 60px;
  }

  .how-to-play-title {
    font-size: 1.5rem;
  }

  .rule-item {
    padding: 0.75rem;
  }

  .rule-number {
    width: 28px;
    height: 28px;
    font-size: 0.875rem;
  }

  .start-button,
  .next-button {
    padding: 1rem;
    font-size: 1.125rem;
    min-width: 200px;
  }

  .celebration-icon {
    font-size: 4rem;
  }

  .success-icon {
    font-size: 4rem;
  }

  .achievement-badge {
    padding: 1rem 1.5rem;
  }

  .badge-icon {
    font-size: 2rem;
  }

  .badge-title {
    font-size: 1.25rem;
  }

  .celebration-message {
    font-size: 1.125rem;
  }

  .celebration-button {
    font-size: 1.125rem;
    padding: 1rem 2rem;
    min-width: 200px;
  }
}

/* Desktop (≥1025px) */
@media (min-width: 1025px) {
  body.game-body {
    padding: 0;
  }

  .grid-container {
    gap: 2px;
    padding: 6px;
  }

  .icon-button {
    width: 44px;
    height: 44px;
  }

  .icon-button svg {
    width: 20px;
    height: 20px;
  }

  .beautiful-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.5rem;
    min-width: 100px;
  }


  #levelDisplay p {
    font-size: 1.125rem;
  }

  .popup-content:not(.game-modal) {
    max-width: 400px;
    padding: 1.5rem;
  }

  .levels-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
  }

  .level-button {
    font-size: 1.25rem;
    min-height: 60px;
  }

  .how-to-play-title {
    font-size: 1.5rem;
  }

  .rule-item {
    padding: 0.75rem;
  }

  .rule-number {
    width: 28px;
    height: 28px;
    font-size: 0.875rem;
  }

  .start-button,
  .next-button {
    padding: 1rem;
    font-size: 1.125rem;
    min-width: 200px;
  }

  .celebration-icon {
    font-size: 4rem;
  }

  .success-icon {
    font-size: 4rem;
  }

  .achievement-badge {
    padding: 1rem 1.5rem;
  }

  .badge-icon {
    font-size: 2rem;
  }

  .badge-title {
    font-size: 1.25rem;
  }

  .celebration-message {
    font-size: 1.125rem;
  }

  .celebration-button {
    font-size: 1.125rem;
    padding: 1rem 2rem;
    min-width: 200px;
  }
}

/* Large Desktop (≥1440px) */
@media (min-width: 1440px) {
  body.game-body {
    padding: 0;
  }

  .popup-content:not(.game-modal) {
    max-width: 480px;
    padding: 1.5rem;
  }

  .levels-grid {
    max-width: 800px;
    margin: 0 auto;
  }

  .level-button {
    font-size: 1.375rem;
    min-height: 70px;
  }

  .how-to-play-title {
    font-size: 1.75rem;
  }

  .rule-item {
    padding: 1rem;
  }

  .rule-number {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }

  .start-button,
  .next-button {
    padding: 1.25rem;
    font-size: 1.25rem;
    min-width: 220px;
  }

  .celebration-icon {
    font-size: 5rem;
  }

  .success-icon {
    font-size: 5rem;
  }

  .achievement-badge {
    padding: 1.25rem 2rem;
  }

  .badge-icon {
    font-size: 2.5rem;
  }

  .badge-title {
    font-size: 1.5rem;
  }

  .celebration-message {
    font-size: 1.25rem;
  }

  .celebration-button {
    font-size: 1.25rem;
    padding: 1.25rem 2.5rem;
    min-width: 220px;
  }
}