/* ═══════════════════════════════════════════════════
   Mind Sync — Premium Kids Puzzle UI
   ═══════════════════════════════════════════════════ */

:root {
  --sky-1: #7dd3fc;
  --sky-2: #c4b5fd;
  --sky-3: #fda4af;
  --blob-1: rgba(253, 186, 116, 0.55);
  --blob-2: rgba(192, 132, 252, 0.45);
  --blob-3: rgba(110, 231, 183, 0.5);
  --board-bg: rgba(255, 255, 255, 0.45);
  --board-border: rgba(255, 255, 255, 0.7);
  --text: #1e3a5f;
  --text-soft: #475569;
  --card-bg: rgba(255, 255, 255, 0.88);
  --btn-1: #fb923c;
  --btn-2: #f472b6;
  --accent: #8b5cf6;
  --tile-gap: 8px;
  --slide-ms: 300ms;
  --font: "Nunito", system-ui, sans-serif;
  --font-display: "Fredoka", "Nunito", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --radius: 20px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  --glow: 0 0 24px rgba(139, 92, 246, 0.35);
  --board-max: 660px;
  --board-gutter: 16px;
  --ui-chrome: 220px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  max-width: 100vw;
  height: 100%;
  height: 100dvh;
  min-height: 100%;
  min-height: -webkit-fill-available;
  overflow: hidden;
  overflow-x: hidden;
  overscroll-behavior: none;
  font-family: var(--font);
  color: var(--text);
  touch-action: manipulation;
}

html:fullscreen,
html:-webkit-full-screen,
body.is-mobile-fullscreen {
  width: 100% !important;
  height: 100% !important;
  overflow: hidden;
}

html:fullscreen .app,
html:-webkit-full-screen .app,
body.is-mobile-fullscreen .app {
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-height: -webkit-fill-available;
}

body.is-mobile-play {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

body.high-contrast {
  --text: #000;
  --text-soft: #222;
  --card-bg: #fff;
  filter: contrast(1.15);
}

body.dark-mode {
  filter: brightness(0.85) saturate(0.9);
}

/* ── Loading ── */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: linear-gradient(160deg, var(--sky-1), var(--sky-2), var(--sky-3));
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-mascot {
  font-size: 64px;
  animation: mascot-bob 1.2s ease-in-out infinite;
}

.loading-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
}

.loading-bar {
  width: min(220px, 70vw);
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.4);
  overflow: hidden;
}

.loading-bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--btn-1), var(--btn-2));
  animation: load-fill 1.2s ease forwards;
}

.loading-text {
  font-size: 0.9rem;
  color: var(--text-soft);
}

/* ── App shell ── */
.app {
  position: relative;
  width: 100%;
  max-width: 100vw;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ── Magic background ── */
.magic-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, var(--sky-1) 0%, var(--sky-2) 45%, var(--sky-3) 100%);
  animation: bg-shift 18s ease-in-out infinite alternate;
}

.bg-clouds {
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background:
    radial-gradient(ellipse 120px 40px at 15% 20%, #fff 50%, transparent 55%),
    radial-gradient(ellipse 90px 30px at 80% 15%, #fff 50%, transparent 55%),
    radial-gradient(ellipse 140px 45px at 60% 75%, #fff 50%, transparent 55%);
  animation: clouds-drift 40s linear infinite;
}

.bg-blobs .blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  animation: blob-float 12s ease-in-out infinite;
}

.blob-1 { width: 45vw; height: 45vw; top: -10%; left: -10%; background: var(--blob-1); }
.blob-2 { width: 38vw; height: 38vw; bottom: -5%; right: -8%; background: var(--blob-2); animation-delay: -4s; }
.blob-3 { width: 30vw; height: 30vw; top: 40%; left: 50%; background: var(--blob-3); animation-delay: -7s; }

.bg-particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ── Top bar ── */
.top-bar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(6px + var(--safe-top)) calc(12px + var(--safe-right)) 2px calc(12px + var(--safe-left));
}

.top-bar-left, .top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo-emoji { font-size: 1.3rem; animation: sparkle 2s ease infinite; }

.logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1rem, 3.5vw, 1.25rem);
  color: var(--text);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 2px solid rgba(255, 255, 255, 0.65);
  border-radius: 14px;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.icon-btn:hover { transform: scale(1.05); box-shadow: var(--glow); }
.icon-btn:active { transform: scale(0.95); }
.btn-icon { font-size: 1.1rem; line-height: 1; }

/* ── Compact game HUD ── */
.game-hud {
  position: relative;
  z-index: 9;
  width: 100%;
  max-width: min(680px, calc(100% - 20px - var(--safe-left) - var(--safe-right)));
  margin: 0 auto;
  padding: 2px calc(10px + var(--safe-right)) 4px calc(10px + var(--safe-left));
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.xp-compact {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.xp-tag {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
}

.xp-track.slim {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.1);
  overflow: hidden;
  min-width: 60px;
}

.xp-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #facc15, #fb923c);
  transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.currency-compact {
  display: flex;
  gap: 10px;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
}

.hud-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--card-bg);
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

.hud-chip b, .hud-chip span {
  font-family: var(--font-display);
  font-weight: 700;
}

/* ── Play area ── */
.play-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 0;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
  padding: 0 calc(8px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(8px + var(--safe-left));
}

/* ── Mascot ── */
.mascot {
  position: absolute;
  z-index: 8;
  bottom: calc(90px + var(--safe-bottom));
  left: calc(12px + var(--safe-left));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  pointer-events: none;
}

.mascot-body {
  font-size: 2.4rem;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
  animation: mascot-bob 2.5s ease-in-out infinite;
  transform-origin: center bottom;
}

.mascot-body.is-blinking {
  animation: mascot-blink 0.2s ease;
}

.mascot.is-idle .mascot-body {
  animation: mascot-bob 2.5s ease-in-out infinite, mascot-wiggle 6s ease-in-out infinite;
}

.mascot-bubble {
  max-width: 180px;
  padding: 10px 14px;
  border-radius: 16px 16px 16px 4px;
  background: #ffffff;
  border: 2px solid rgba(30, 58, 95, 0.12);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 1.35;
  color: #1e3a5f;
  opacity: 0;
  transform: translateY(8px) scale(0.9);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mascot.is-talking .mascot-bubble {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ── Game board ── */
.game-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.board-wrap {
  position: relative;
  --board-size: max(
    200px,
    min(
      calc(100dvw - var(--board-gutter)),
      calc(100dvh - var(--ui-chrome)),
      var(--board-max)
    )
  );
  width: var(--board-size);
  height: var(--board-size);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  flex-shrink: 0;
}

.board-wrap.board-paused {
  filter: brightness(0.85) saturate(0.9);
  pointer-events: none;
}

.board-wrap.board-enter {
  animation: board-enter 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.board-wrap.board-solved .tile { animation: solved-bounce 0.6s ease; }

.board {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: var(--tile-gap);
  border-radius: 24px;
  background: var(--board-bg);
  backdrop-filter: blur(16px);
  border: 3px solid var(--board-border);
  box-shadow:
    var(--shadow),
    inset 0 2px 20px rgba(255, 255, 255, 0.4),
    0 0 40px rgba(139, 92, 246, 0.15);
  overflow: hidden;
  box-sizing: border-box;
}

/* ── Tiles ── */
.tile, .empty-slot {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
  transition: transform var(--slide-ms) cubic-bezier(0.4, 0, 0.2, 1);
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 16px;
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1;
  color: #fff;
  cursor: pointer;
  box-sizing: border-box;
  appearance: none;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  box-shadow:
    0 6px 0 rgba(0, 0, 0, 0.12),
    0 8px 20px rgba(0, 0, 0, 0.15),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
  overflow: visible;
  transition:
    transform var(--slide-ms) cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 0.2s ease,
    filter 0.2s ease;
}

.tile.tile-correct {
  box-shadow:
    0 6px 0 rgba(0, 0, 0, 0.1),
    0 8px 20px rgba(0, 0, 0, 0.12),
    0 0 14px rgba(250, 204, 21, 0.55),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

.tile.tile-hint {
  z-index: 4;
  animation: hint-pulse 0.9s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% {
    box-shadow:
      0 6px 0 rgba(0, 0, 0, 0.1),
      0 8px 20px rgba(0, 0, 0, 0.12),
      0 0 18px rgba(250, 204, 21, 0.9),
      inset 0 2px 0 rgba(255, 255, 255, 0.5);
    filter: brightness(1.15);
  }
  50% {
    box-shadow:
      0 6px 0 rgba(0, 0, 0, 0.1),
      0 10px 24px rgba(0, 0, 0, 0.15),
      0 0 28px rgba(251, 191, 36, 1),
      inset 0 2px 0 rgba(255, 255, 255, 0.6);
    filter: brightness(1.3);
  }
}

.tile.tile-adjacent {
  box-shadow:
    0 6px 0 rgba(0, 0, 0, 0.1),
    0 8px 20px rgba(0, 0, 0, 0.12),
    0 0 10px rgba(255, 255, 255, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

@media (hover: hover) {
  .tile:hover {
    filter: brightness(1.12);
    z-index: 3;
    box-shadow:
      0 10px 0 rgba(0, 0, 0, 0.1),
      0 14px 28px rgba(0, 0, 0, 0.2),
      0 0 22px rgba(255, 255, 255, 0.45),
      inset 0 2px 0 rgba(255, 255, 255, 0.55);
  }
}

.tile:active { filter: brightness(0.95); transform: scale(0.97); }

.tile-bounce {
  animation: tile-bounce-glow 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tile-1 { background: linear-gradient(145deg, #38bdf8, #0284c7); }
.tile-2 { background: linear-gradient(145deg, #2dd4bf, #0d9488); }
.tile-3 { background: linear-gradient(145deg, #fde047, #eab308); color: #713f12; text-shadow: none; }
.tile-4 { background: linear-gradient(145deg, #fb7185, #e11d48); }
.tile-5 { background: linear-gradient(145deg, #a78bfa, #7c3aed); }
.tile-6 { background: linear-gradient(145deg, #fb923c, #ea580c); }
.tile-7 { background: linear-gradient(145deg, #4ade80, #16a34a); }
.tile-8 { background: linear-gradient(145deg, #f472b6, #db2777); }

.tile::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 10%;
  right: 10%;
  height: 35%;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.5), transparent);
  pointer-events: none;
}

/* ── Sparkle layer ── */
.sparkle-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}

.sparkle-pop {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 8px #facc15;
  animation: sparkle-pop 0.5s ease forwards;
  pointer-events: none;
}

/* ── Empty portal slot ── */
.empty-slot {
  border-radius: 16px;
  border: 2px dashed rgba(167, 139, 250, 0.65);
  background:
    radial-gradient(circle at 50% 50%, rgba(167, 139, 250, 0.35), rgba(139, 92, 246, 0.12) 55%, transparent 70%),
    rgba(255, 255, 255, 0.12);
  box-shadow:
    inset 0 0 24px rgba(139, 92, 246, 0.35),
    0 0 18px rgba(167, 139, 250, 0.25);
  animation: portal-pulse 2.4s ease-in-out infinite;
  pointer-events: none;
  overflow: hidden;
}

.portal-swirl {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  animation: portal-spin 4s linear infinite;
}

.portal-star {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(1rem, 4vw, 1.6rem);
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 0 12px #facc15;
  animation: sparkle 1.8s ease-in-out infinite;
}

/* ── Control panel ── */
.control-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, var(--board-max));
  max-width: 100%;
  flex-shrink: 0;
  padding: 10px 14px;
  border-radius: 20px;
  background: var(--card-bg);
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow), 0 0 24px rgba(139, 92, 246, 0.12);
  backdrop-filter: blur(14px);
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  min-height: 56px;
  padding: 8px 4px;
  border: 0;
  border-radius: 14px;
  font-family: var(--font);
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.14), 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  margin: 0;
}

.action-btn:hover {
  transform: translateY(-2px) scale(1.03);
  filter: brightness(1.08);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12), 0 8px 20px rgba(0, 0, 0, 0.15), 0 0 16px rgba(255, 255, 255, 0.2);
}

.action-btn:active {
  transform: translateY(2px) scale(0.96);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.14);
}

.action-btn:disabled { opacity: 0.5; cursor: default; transform: none; filter: none; }
.action-icon { font-size: 1.35rem; line-height: 1; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.15)); }

.action-shuffle { background: linear-gradient(180deg, #a78bfa, #7c3aed); }
.action-restart { background: linear-gradient(180deg, #38bdf8, #0284c7); }
.action-hint { background: linear-gradient(180deg, #facc15, #eab308); color: #713f12; }
.action-sound { background: linear-gradient(180deg, #4ade80, #16a34a); }

/* ── Modals / panels ── */
.modal-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: rgba(30, 58, 95, 0.35);
  backdrop-filter: blur(8px);
  overflow-x: hidden;
  overflow-y: auto;
}

.menu-card, .victory-card {
  width: min(400px, 94vw);
  padding: clamp(20px, 4vh, 32px);
  border-radius: 28px;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  border: 3px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow), 0 0 60px rgba(139, 92, 246, 0.2);
  text-align: center;
}

.pop-in { animation: pop-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }

.victory-card.pop-in {
  animation: victory-pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.menu-hero { font-size: 3.5rem; margin-bottom: 4px; animation: mascot-bob 2s ease-in-out infinite; }
.menu-title { font-family: var(--font-display); font-size: clamp(1.8rem, 6vw, 2.4rem); font-weight: 700; color: var(--text); }
.menu-sub { color: var(--text-soft); font-size: 0.95rem; margin: 6px 0 14px; }

.daily-challenge {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 12px 0;
  padding: 12px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(250,204,21,0.2), rgba(251,146,60,0.2));
  border: 2px dashed rgba(251, 146, 60, 0.4);
}

.daily-badge { font-weight: 800; font-size: 0.85rem; }
.daily-text { font-size: 0.8rem; color: var(--text-soft); }

.size-picker {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 14px 0;
  width: 100%;
}

.size-chip {
  flex: 1;
  min-width: 0;
  padding: 10px 10px;
  border-radius: 14px;
  border: 2px solid color-mix(in srgb, var(--text) 24%, transparent);
  background: color-mix(in srgb, var(--text) 7%, transparent);
  font-family: var(--font-display);
  font-size: clamp(0.72rem, 2.8vw, 0.85rem);
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  margin: 0;
  box-shadow: none;
}

.size-chip:hover {
  background: color-mix(in srgb, var(--text) 11%, transparent);
  border-color: color-mix(in srgb, var(--text) 32%, transparent);
}

.size-chip.is-active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--accent);
  box-shadow: var(--glow);
  transform: scale(1.04);
}

.primary-btn {
  display: block;
  width: 100%;
  margin: 8px 0 4px;
  padding: 16px 24px;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--btn-1), var(--btn-2));
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.15), var(--shadow);
  transition: transform 0.15s ease;
}

.primary-btn:hover { transform: scale(1.03); }
.primary-btn:active { transform: scale(0.97); }

.pulse-glow { animation: pulse-glow 2s ease infinite; }

.secondary-btn {
  display: block;
  width: 100%;
  margin: 6px 0;
  padding: 12px 20px;
  border: 2px solid color-mix(in srgb, var(--text) 18%, transparent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: none;
  transition: transform 0.15s ease, background 0.15s ease;
}

.secondary-btn:hover {
  transform: scale(1.02);
  background: color-mix(in srgb, var(--text) 10%, transparent);
}
.secondary-btn:active { transform: scale(0.98); }

.tips-list {
  list-style: none;
  text-align: left;
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 600;
}

.tips-list strong { color: var(--accent); }

.pause-emoji, .victory-emoji { font-size: 3rem; margin-bottom: 8px; }

/* ── Settings ── */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

.setting-row input {
  width: 44px;
  height: 26px;
  accent-color: var(--accent);
}

/* ── Theme grid ── */
.theme-card {
  overflow: hidden;
  max-height: min(92vh, 640px);
  display: flex;
  flex-direction: column;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
  max-height: min(46vh, 340px);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(139, 92, 246, 0.35) transparent;
  -webkit-overflow-scrolling: touch;
}

.theme-grid::-webkit-scrollbar {
  width: 6px;
  height: 0;
}

.theme-grid::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(139, 92, 246, 0.35);
}

.theme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 8px;
  border-radius: 16px;
  border: 2px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.5);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  margin: 0;
  min-width: 0;
  width: 100%;
  box-shadow: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.theme-option.is-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent), 0 0 14px rgba(139, 92, 246, 0.35);
}
.theme-option.is-locked { opacity: 0.5; cursor: not-allowed; }
.theme-emoji { font-size: 1.8rem; }

/* ── Victory ── */
.victory-panel { z-index: 30; }

.confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.confetti-canvas.is-active { z-index: 31; }

.victory-card { position: relative; z-index: 2; }

.star-rating {
  font-size: 1.8rem;
  letter-spacing: 4px;
  margin: 8px 0;
  animation: star-pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.victory-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.v-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 6px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.5);
}

.v-stat span { font-size: 1.2rem; }
.v-stat b { font-family: var(--font-display); font-size: 1.3rem; }
.v-stat small { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; color: var(--text-soft); }

.reward-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.reward-pill {
  padding: 8px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(250,204,21,0.3), rgba(251,146,60,0.3));
  font-weight: 700;
  font-size: clamp(0.75rem, 2.5vw, 0.9rem);
  animation: reward-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s backwards;
}

.new-record {
  font-family: var(--font-display);
  font-weight: 700;
  color: #eab308;
  margin-bottom: 8px;
  animation: pulse-glow 1.5s ease infinite;
}

/* ── Achievement toast ── */
.achievement-toast {
  position: fixed;
  z-index: 50;
  top: calc(16px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 14px 20px;
  border-radius: 20px;
  background: #fff;
  border: 3px solid #facc15;
  box-shadow: var(--shadow), 0 0 30px rgba(250, 204, 21, 0.4);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.achievement-toast.show { transform: translateX(-50%) translateY(0); }
.ach-icon { font-size: 2rem; }
.achievement-toast strong { display: block; font-family: var(--font-display); }
.achievement-toast p { font-size: 0.8rem; color: var(--text-soft); margin-top: 2px; }

/* ═══ KEYFRAMES ═══ */
@keyframes bg-shift {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(15deg); }
}

@keyframes clouds-drift {
  0% { transform: translateX(0); }
  100% { transform: translateX(30px); }
}

@keyframes blob-float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(20px, -15px) scale(1.05); }
  66% { transform: translate(-15px, 10px) scale(0.95); }
}

@keyframes mascot-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes mascot-wiggle {
  0%, 90%, 100% { transform: translateY(0) rotate(0); }
  93% { transform: translateY(-2px) rotate(-4deg); }
  96% { transform: translateY(-2px) rotate(4deg); }
}

@keyframes mascot-blink {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(0.1); }
}

@keyframes tile-wobble {
  0%, 100% { transform: translate3d(var(--tx, 0), var(--ty, 0), 0) rotate(0); }
  25% { transform: translate3d(var(--tx, 0), var(--ty, 0), 0) rotate(-2deg); }
  75% { transform: translate3d(var(--tx, 0), var(--ty, 0), 0) rotate(2deg); }
}

@keyframes sparkle-pop {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(2.5) translateY(-12px); }
}

@keyframes portal-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes sparkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.15); }
}

@keyframes load-fill {
  0% { width: 0; }
  100% { width: 100%; }
}

@keyframes board-enter {
  0% { opacity: 0; transform: scale(0.85); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes card-pop {
  0% { opacity: 0; transform: translateY(12px) scale(0.9); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes pop-in {
  0% { opacity: 0; transform: scale(0.8) translateY(20px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes victory-pop {
  0% { opacity: 0; transform: scale(0.7) translateY(30px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes portal-pulse {
  0%, 100% { box-shadow: inset 0 0 20px rgba(139, 92, 246, 0.2); }
  50% { box-shadow: inset 0 0 30px rgba(139, 92, 246, 0.45), 0 0 16px rgba(139, 92, 246, 0.2); }
}

@keyframes tile-bounce-glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}

@keyframes solved-bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 6px 0 rgba(0,0,0,0.15), var(--shadow), 0 0 20px rgba(139,92,246,0.3); }
  50% { box-shadow: 0 6px 0 rgba(0,0,0,0.15), var(--shadow), 0 0 36px rgba(139,92,246,0.55); }
}

@keyframes star-pop {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes reward-pop {
  0% { transform: scale(0) rotate(-10deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* ── Portrait lock overlay ── */
#portrait-lock {
  display: none;
}

html.mobile-device.landscape-locked #portrait-lock {
  display: flex !important;
}

html.mobile-device.landscape-locked #app,
html.mobile-device.landscape-locked #loading {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.portrait-lock {
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) calc(24px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(24px + var(--safe-left));
  background: linear-gradient(160deg, var(--sky-1), var(--sky-2), var(--sky-3));
}

.portrait-lock-card {
  width: min(320px, 90vw);
  padding: 28px 24px;
  border-radius: 24px;
  background: var(--card-bg);
  border: 3px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  text-align: center;
}

.portrait-lock-icon {
  font-size: 3.5rem;
  margin-bottom: 12px;
  animation: portrait-wiggle 1.5s ease-in-out infinite;
}

.portrait-lock-card h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--text);
  margin-bottom: 8px;
}

.portrait-lock-card p {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-soft);
}

body.is-landscape-locked .app,
body.is-landscape-locked .loading-screen {
  pointer-events: none;
  user-select: none;
  visibility: hidden;
}

@keyframes portrait-wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-12deg); }
  75% { transform: rotate(12deg); }
}

/* ═══ RESPONSIVE ═══ */

/* ── Large desktop / monitors ── */
@media (min-width: 1200px) {
  :root { --ui-chrome: 200px; --board-max: 680px; }
  .game-hud { max-width: 680px; }
}

/* ── Laptop / desktop ── */
@media (min-width: 900px) {
  :root { --ui-chrome: 210px; }
  .control-panel { gap: 10px; padding: 12px 16px; }
  .action-btn { min-height: 60px; font-size: 0.68rem; }
  .action-icon { font-size: 1.5rem; }
}

/* ── Tablet portrait (iPad, etc.) ── */
@media (min-width: 600px) and (max-width: 899px) {
  :root { --ui-chrome: 215px; --board-gutter: 24px; }
  .hud-chip { font-size: 0.78rem; padding: 6px 12px; }
  .control-panel { gap: 10px; }
  .action-btn { min-height: 58px; }
}

/* Portrait-only layout: board stacked above controls on every screen size.
   Landscape side-by-side layout removed — it conflicted with portrait lock. */

/* ── Phone landscape (all widths) ── */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --ui-chrome: 108px; --board-gutter: 12px; }
  .play-area {
    flex-direction: column;
    gap: 6px;
    padding-bottom: calc(6px + var(--safe-bottom));
  }
  .game-stage {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    height: auto;
  }
  .board-wrap {
    --board-size: min(
      calc(100dvh - var(--ui-chrome) - 80px),
      calc(100dvw - var(--board-gutter)),
      var(--board-max)
    );
  }
  .top-bar { padding-top: calc(4px + var(--safe-top)); padding-bottom: 0; }
  .logo-text { font-size: 0.95rem; }
  .icon-btn { width: 34px; height: 34px; border-radius: 12px; }
  .game-hud { padding-top: 0; padding-bottom: 2px; }
  .hud-top { display: none; }
  .hud-chips { gap: 4px; }
  .hud-chip { font-size: 0.62rem; padding: 3px 8px; }
  .control-panel {
    flex: 0 0 auto;
    width: min(100%, 420px);
    padding: 6px 10px;
    gap: 6px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .action-btn { min-height: 44px; font-size: 0.55rem; padding: 6px 2px; }
  .action-icon { font-size: 1.1rem; }
  .mascot { bottom: calc(8px + var(--safe-bottom)); left: calc(8px + var(--safe-left)); }
  .mascot-body { font-size: 1.8rem; }
  .mascot-bubble { max-width: 140px; font-size: 0.75rem; padding: 8px 10px; }
  .menu-card, .victory-card { padding: 16px; max-height: 92dvh; overflow-y: auto; }
  .menu-hero { font-size: 2.2rem; }
  .menu-title { font-size: 1.6rem; }
}

/* ── Phone landscape, very short (fold cover, old phones) ── */
@media (orientation: landscape) and (max-height: 360px) {
  :root { --ui-chrome: 100px; }
  .hud-chips { display: none; }
  .mascot { display: none; }
  .control-panel {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: min(100%, 420px);
  }
  .action-btn span:not(.action-icon) { display: none; }
  .action-btn { min-height: 40px; }
}

/* ── Small phones & fold cover (portrait) ── */
@media (max-width: 480px) {
  :root { --ui-chrome: 235px; --board-gutter: 12px; }
  .hud-chips { gap: 5px; }
  .hud-chip { font-size: 0.68rem; padding: 4px 9px; }
  .control-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
  }
  .action-btn { min-height: 52px; font-size: 0.6rem; }
  .mascot { bottom: calc(100px + var(--safe-bottom)); right: calc(8px + var(--safe-right)); left: auto; align-items: flex-end; }
  .mascot-bubble { border-radius: 16px 16px 4px 16px; max-width: 150px; }
}

/* ── Extra narrow (fold cover, mini phones) ── */
@media (max-width: 340px) {
  :root { --ui-chrome: 250px; }
  .logo-text { display: none; }
  .hud-chips {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }
  .hud-chip { justify-content: center; font-size: 0.62rem; }
  .currency-compact { font-size: 0.68rem; gap: 6px; }
  .xp-tag { font-size: 0.65rem; }
  .mascot { display: none; }
  .menu-card, .victory-card { width: min(360px, 96vw); padding: 16px; }
  .size-chip { padding: 8px 6px; font-size: 0.68rem; }
  .victory-stats { gap: 4px; }
  .v-stat { padding: 8px 4px; }
  .v-stat b { font-size: 1.1rem; }
}

/* ── Fold unfolded / square-ish screens ── */
@media (min-width: 600px) and (max-width: 900px) and (min-aspect-ratio: 0.9) and (max-aspect-ratio: 1.15) {
  :root { --ui-chrome: 200px; --board-max: 580px; }
}

/* ── Tall narrow phones (modern flagships) ── */
@media (max-width: 430px) and (min-height: 800px) {
  :root { --ui-chrome: 240px; }
}

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