/* =========================================================
   1. BASE RESET & UTILITIES
========================================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

/* =========================================================
   2. LANDING PAGE THEMES (5 FUN THEMES VIA CSS VARIABLES)
========================================================= */
#landing-view {
  --bg-page: #ffffff;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-card: 2px solid #0f172a;
  --shadow-card: 0 8px 24px -8px rgba(0, 0, 0, 0.12);
  --shadow-card-hover: 0 16px 34px -10px rgba(0, 0, 0, 0.2);
  --radius-card: 16px;
  --accent: #3b82f6;
  --accent-text: #ffffff;
  --logo-font: 'Caveat', cursive;
  --tagline-font: 'Inter', sans-serif;
  --logo-color: #0f172a;
  --logo-shadow: none;
  --logo-transform: none;
  --ad-bg: #f8fafc;
  --ad-border: 1px dashed #cbd5e1;
  --ad-text: #94a3b8;
  --dropdown-bg: #ffffff;
  --dropdown-border: 1px solid #e2e8f0;
  --status-bg: #f0fdf4;
  --status-border: 1px solid #bbf7d0;
  --status-text: #166534;
  --page-pattern: none;

  min-height: 100vh;
  background-color: var(--bg-page);
  background-image: var(--page-pattern);
  color: var(--text-main);
  transition: background-color 0.25s ease, color 0.25s ease;
  display: flex;
  flex-direction: column;
}

#landing-view[data-theme="basic"] {
  --bg-page: #ffffff;
  --bg-card: #ffffff;
  --border-card: 2px solid #111827;
  --logo-font: 'Caveat', cursive;
  --tagline-font: 'Inter', sans-serif;
}

#landing-view[data-theme="basic"] .lab-logo {
  font-size: clamp(1.95rem, 3.6vw, 2.6rem);
  letter-spacing: 0.01em;
}

#landing-view[data-theme="retro"] {
  --bg-page: #008080;
  --bg-card: #c0c0c0;
  --text-main: #000000;
  --text-muted: #e2e8f0;
  --border-card: 3px outset #ffffff;
  --shadow-card: 5px 5px 0px #000000;
  --shadow-card-hover: 7px 7px 0px #000000;
  --radius-card: 0px;
  --accent: #000080;
  --accent-text: #ffffff;
  --logo-font: 'VT323', 'Courier New', monospace;
  --tagline-font: 'Tahoma', 'MS Sans Serif', monospace;
  --logo-color: #ffffff;
  --logo-shadow: 2px 2px 0px #000000;
  --ad-bg: #c0c0c0;
  --ad-border: 2px inset #ffffff;
  --ad-text: #000000;
  --dropdown-bg: #c0c0c0;
  --dropdown-border: 2px outset #ffffff;
  --status-bg: #c0c0c0;
  --status-border: 2px inset #ffffff;
  --status-text: #000000;
  font-family: 'Tahoma', sans-serif;
}

#landing-view[data-theme="neon"] {
  --bg-page: #060611;
  --bg-card: #0e0e22;
  --text-main: #f0f9ff;
  --text-muted: #a5b4fc;
  --border-card: 2px solid #00f3ff;
  --shadow-card: 0 0 22px rgba(0, 243, 255, 0.35), 0 0 8px rgba(188, 19, 254, 0.3);
  --shadow-card-hover: 0 0 36px rgba(0, 243, 255, 0.65), 0 0 20px rgba(255, 0, 234, 0.5);
  --radius-card: 14px;
  --accent: #bc13fe;
  --accent-text: #ffffff;
  --logo-font: 'Orbitron', sans-serif;
  --tagline-font: 'Orbitron', sans-serif;
  --logo-color: #00f3ff;
  --logo-shadow: 0 0 10px #00f3ff, 0 0 22px #bc13fe;
  --ad-bg: rgba(15, 15, 35, 0.82);
  --ad-border: 1px solid rgba(188, 19, 254, 0.45);
  --ad-text: #a5b4fc;
  --dropdown-bg: #111129;
  --dropdown-border: 1px solid #00f3ff;
  --status-bg: rgba(0, 255, 136, 0.1);
  --status-border: 1px solid #00ff88;
  --status-text: #00ff88;
  --page-pattern: radial-gradient(circle at 20% 20%, rgba(188, 19, 254, 0.14), transparent 40%),
                  radial-gradient(circle at 80% 70%, rgba(0, 243, 255, 0.12), transparent 45%);
}

#landing-view[data-theme="sketchbook"] {
  --bg-page: #fdfbf4;
  --bg-card: #fffef9;
  --text-main: #262626;
  --text-muted: #57534e;
  --border-card: 2.5px solid #262626;
  --shadow-card: 5px 6px 0px #262626;
  --shadow-card-hover: 8px 9px 0px #262626;
  --radius-card: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --accent: #e11d48;
  --accent-text: #ffffff;
  --logo-font: 'Patrick Hand', cursive;
  --tagline-font: 'Patrick Hand', cursive;
  --logo-color: #1c1917;
  --logo-shadow: 2px 2px 0px #fde047;
  --logo-transform: rotate(-2deg);
  --ad-bg: #fffef9;
  --ad-border: 2px dashed #44403c;
  --ad-text: #57534e;
  --dropdown-bg: #fffef9;
  --dropdown-border: 2px solid #262626;
  --status-bg: #fef9c3;
  --status-border: 2px solid #262626;
  --status-text: #1c1917;
  --page-pattern: linear-gradient(to right, rgba(0,0,0,0.035) 1px, transparent 1px),
                  linear-gradient(to bottom, rgba(0,0,0,0.035) 1px, transparent 1px);
  background-size: 26px 26px;
}

#landing-view[data-theme="matrix"] {
  --bg-page: #000000;
  --bg-card: #020b03;
  --text-main: #00ff41;
  --text-muted: #00cc33;
  --border-card: 1.5px solid #00ff41;
  --shadow-card: 0 0 15px rgba(0, 255, 65, 0.25);
  --shadow-card-hover: 0 0 28px rgba(0, 255, 65, 0.55);
  --radius-card: 4px;
  --accent: #00ff41;
  --accent-text: #000000;
  --logo-font: 'JetBrains Mono', monospace;
  --tagline-font: 'JetBrains Mono', monospace;
  --logo-color: #00ff41;
  --logo-shadow: 0 0 12px rgba(0, 255, 65, 0.8);
  --ad-bg: #020902;
  --ad-border: 1px solid #00661a;
  --ad-text: #00aa2b;
  --dropdown-bg: #020b03;
  --dropdown-border: 1px solid #00ff41;
  --status-bg: #031405;
  --status-border: 1px solid #00ff41;
  --status-text: #00ff41;
  --page-pattern: repeating-linear-gradient(0deg, rgba(0,255,65,0.03) 0px, rgba(0,255,65,0.03) 1px, transparent 1px, transparent 3px);
  font-family: 'JetBrains Mono', monospace;
}

/* =========================================================
   3. LANDING HEADER & STAGE
========================================================= */
.lab-header {
  width: 100%;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: relative;
  z-index: 40;
}

.lab-logo {
  font-family: var(--logo-font);
  font-size: clamp(1.5rem, 3vw, 2.05rem);
  font-weight: 800;
  color: var(--logo-color);
  text-shadow: var(--logo-shadow);
  transform: var(--logo-transform);
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  user-select: none;
  transition: all 0.25s ease;
}

.lab-logo .logo-dot {
  font-size: 0.65em;
  opacity: 0.78;
  font-weight: 700;
}

#landing-view[data-theme="matrix"] .lab-logo::after {
  content: '_';
  animation: blink-cursor 1s steps(2) infinite;
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--status-bg);
  border: var(--status-border);
  color: var(--status-text);
  font-size: 0.8rem;
  font-weight: 700;
  font-family: 'Space Grotesk', sans-serif;
  white-space: nowrap;
}

#landing-view[data-theme="retro"] .status-pill {
  border-radius: 0;
  font-family: 'Tahoma', sans-serif;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: #22c55e;
  box-shadow: 0 0 8px #22c55e;
  animation: pulse-green 1.5s infinite ease-in-out;
}

@keyframes pulse-green {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.85);
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
  }
}

.theme-dropdown-wrap {
  position: relative;
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--bg-card);
  border: var(--border-card);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: transform 0.15s ease;
}

#landing-view[data-theme="retro"] .theme-btn {
  border-radius: 0;
}

.theme-btn:hover {
  transform: translateY(-1px);
}

.theme-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 210px;
  background: var(--dropdown-bg);
  border: var(--dropdown-border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.18);
  z-index: 100;
  display: none;
  flex-direction: column;
  gap: 4px;
}

#landing-view[data-theme="retro"] .theme-menu {
  border-radius: 0;
}

.theme-menu.open {
  display: flex;
}

.theme-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-main);
  text-align: left;
  transition: background 0.15s ease;
}

.theme-option:hover {
  background: rgba(128, 128, 128, 0.15);
}

.theme-option.active {
  background: var(--accent);
  color: var(--accent-text);
}

.lab-stage {
  width: 100%;
  padding: 12px 24px 90px;
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
}

.ad-sidebar {
  width: 160px;
  min-height: 540px;
  flex-shrink: 0;
  background: var(--ad-bg);
  border: var(--ad-border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  color: var(--ad-text);
  position: sticky;
  top: 20px;
  transition: all 0.25s ease;
}

#landing-view[data-theme="retro"] .ad-sidebar {
  border-radius: 0;
}

.ad-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.75;
  margin-bottom: 10px;
  padding: 2px 8px;
  border: 1px solid currentColor;
  border-radius: 99px;
}

.ad-copy {
  font-size: 0.8rem;
  line-height: 1.5;
  opacity: 0.85;
}

.ad-mobile-banner {
  display: none;
}

@media (max-width: 1023px) {
  .ad-sidebar {
    display: none;
  }
  .lab-stage {
    padding: 14px 16px 96px;
    justify-content: center;
  }
  .ad-mobile-banner {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-card);
    border-top: 1px solid rgba(128,128,128,0.22);
    box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
    z-index: 50;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 16px;
    color: var(--text-muted);
    font-size: 0.8rem;
  }
}

.lab-center {
  flex: 1;
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.lab-tagline {
  margin: 4px 0 32px;
  font-family: var(--tagline-font);
  font-size: 0.96rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: all 0.25s ease;
}

#landing-view[data-theme="neon"] .lab-tagline {
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-shadow: 0 0 8px rgba(0, 243, 255, 0.35);
}

#landing-view[data-theme="sketchbook"] .lab-tagline {
  font-size: 1.15rem;
}

.games-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 560px));
  justify-content: center;
  gap: 26px;
}

.game-card {
  display: block;
  width: 100%;
  background: var(--bg-card);
  border: var(--border-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 0;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
  overflow: hidden;
}

.game-card:hover {
  transform: translateY(-4px) scale(1.015);
  box-shadow: var(--shadow-card-hover);
}

.retro-titlebar {
  display: none;
}

#landing-view[data-theme="retro"] .game-card {
  padding: 3px;
}

#landing-view[data-theme="retro"] .retro-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(90deg, #000080, #1084d0);
  color: #ffffff;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 3px;
}

.retro-win-btns {
  display: flex;
  gap: 2px;
}

.retro-win-btns span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 14px;
  background: #c0c0c0;
  color: #000;
  border: 1.5px outset #fff;
  font-size: 10px;
  line-height: 1;
}

.card-artwork-box {
  width: 100%;
  aspect-ratio: 2.33 / 1;
  overflow: hidden;
  background: #fbf6ea;
  position: relative;
  filter: none !important;
  box-shadow: none !important;
  display: block;
}

#landing-view[data-theme="retro"] .card-artwork-box {
  border: 2px inset #ffffff;
}

.card-artwork-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-artwork-box svg {
  width: 100%;
  height: 100%;
  display: block;
}

.coming-soon-note {
  margin-top: 38px;
  font-family: var(--tagline-font);
  font-size: 0.85rem;
  color: var(--text-muted);
  opacity: 0.78;
}

/* =========================================================
   4. INTERNAL GAME VIEW (#game-view) - INDIE PUZZLE GAME UI
========================================================= */
#game-view {
  min-height: 100vh;
  background-color: #f4efe6;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(253, 224, 178, 0.44), transparent 38%),
    radial-gradient(circle at 86% 22%, rgba(199, 226, 214, 0.44), transparent 40%),
    radial-gradient(circle at 50% 92%, rgba(224, 214, 245, 0.36), transparent 45%);
  color: #1f1b18;
  font-family: 'Fredoka', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}

.game-topbar {
  background: rgba(255, 252, 245, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1.5px solid #e6decb;
  padding: 11px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: 13px;
  background: #f5efe3;
  border: 1.5px solid #dfd3bd;
  color: #3a3026;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 2.5px 0 #d8cbb3;
  transition: transform 0.12s ease, background 0.15s ease;
}

.back-btn:hover {
  background: #ece3d1;
}

.back-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #d8cbb3;
}

.game-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-header-title h1 {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.52rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #241d17;
}

.exp-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  font-weight: 700;
  background: #5b4df0;
  color: #ffffff;
  padding: 4px 10px;
  border-radius: 9px;
  box-shadow: 0 2px 0 #3d31b8;
}

.sound-btn {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: #f5efe3;
  border: 1.5px solid #dfd3bd;
  box-shadow: 0 2.5px 0 #d8cbb3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  transition: transform 0.12s ease, background 0.15s ease;
}

.sound-btn:hover {
  background: #ece3d1;
}

.sound-btn:active {
  transform: translateY(1px);
}

/* PC Layout: Controls Pushed Left | Square Board Center | Ad Far Right */
.game-shell {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px;
  gap: 28px;
  align-items: start;
  padding: 18px 12px 38px 22px;
  flex: 1;
}

.game-workspace {
  grid-column: 1;
  width: 100%;
  display: grid;
  grid-template-columns: 295px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

@media (max-width: 1180px) {
  .game-shell {
    display: block;
    padding: 16px 16px 84px;
  }
  .game-workspace {
    grid-template-columns: 285px minmax(0, 1fr);
    gap: 18px;
  }
  .game-ad-sidebar {
    display: none !important;
  }
}

@media (max-width: 880px) {
  .game-topbar {
    padding: 11px 14px;
  }
  .game-shell {
    padding: 14px 14px 84px;
  }
  .game-workspace {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

.controls-panel {
  background: #fffdf8;
  border: 2px solid #e5dcc9;
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 10px 28px rgba(64, 48, 28, 0.08);
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 82px;
}

@media (max-width: 880px) {
  .controls-panel {
    position: static;
  }
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.control-label {
  font-size: 0.84rem;
  font-weight: 700;
  color: #5a4c3e;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.step-num {
  font-style: normal;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px;
  height: 21px;
  border-radius: 7px;
  background: #efe6d5;
  color: #5b4df0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  margin-right: 5px;
}

.frame-current-name {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: #8c7b68;
}

.upload-btn {
  width: 100%;
  padding: 11px 14px;
  border-radius: 13px;
  border: 2px dashed #cfc3ad;
  background: #faf5eb;
  color: #3f3429;
  font-weight: 600;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.upload-btn:hover {
  border-color: #5b4df0;
  background: #f0eeff;
  color: #4338ca;
  transform: translateY(-1px);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #f2ebe0;
  padding: 4px;
  border-radius: 13px;
  border: 1.5px solid #e5dcc9;
}

.seg-btn {
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #6b5b4b;
  transition: all 0.15s ease;
}

.seg-btn.active {
  background: #fffdf9;
  color: #1f1b18;
  box-shadow: 0 2px 6px rgba(60, 40, 20, 0.12);
}

.seg-btn.chaos-active {
  background: #e11d48;
  color: #ffffff;
  box-shadow: 0 2px 0 #9f1239;
}

.chaos-speed-panel {
  background: #fff1f2;
  border: 1.5px solid #fecdd3;
  border-radius: 13px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fade-slide 0.2s ease;
}

@keyframes fade-slide {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chaos-speed-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #be123c;
  display: flex;
  justify-content: space-between;
}

.chaos-interval-pills {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.chaos-sec-btn {
  padding: 6px 2px;
  border-radius: 8px;
  background: #ffffff;
  border: 1.5px solid #fda4af;
  color: #9f1239;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  font-weight: 700;
  transition: all 0.15s ease;
}

.chaos-sec-btn.active {
  background: #e11d48;
  border-color: #e11d48;
  color: #ffffff;
}

.grid-slider-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.grid-slider {
  flex: 1;
  accent-color: #5b4df0;
  cursor: pointer;
}

.grid-badge {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 0.88rem;
  background: #eeecff;
  color: #4338ca;
  border: 1.5px solid #d5d0ff;
  padding: 4px 10px;
  border-radius: 8px;
  min-width: 58px;
  text-align: center;
}

.frame-swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.frame-swatch {
  height: 40px;
  border-radius: 11px;
  background: #f5efe3;
  border: 2px solid #e0d6c3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}

.frame-swatch:hover {
  transform: translateY(-2px);
}

.frame-swatch.active {
  border-color: #5b4df0;
  background: #eeecff;
  box-shadow: 0 3px 0 #5b4df0;
  transform: translateY(-1px);
}

.swatch-preview {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  display: block;
}

.swatch-wood {
  background: #eaeede;
  border: 4px solid #9a6939;
}

.swatch-gallery {
  background: #f6f0e2;
  border: 4px solid #d2a643;
}

.swatch-pastel {
  background: #fcfaff;
  border: 4px solid #f7c5d8;
}

.swatch-dark {
  background: #22252c;
  border: 4px solid #181715;
  box-shadow: inset 0 0 0 1px rgba(212, 175, 55, 0.55);
}

.swatch-ink {
  background: #faf5e8;
  border: 3px solid #1c1917;
  box-shadow: 2px 2px 0 #1c1917;
}

.primary-action-btn {
  width: 100%;
  padding: 13px;
  border-radius: 14px;
  background: #5b4df0;
  color: #ffffff;
  font-weight: 700;
  font-size: 0.98rem;
  letter-spacing: 0.01em;
  box-shadow: 0 4px 0 #3d31b8, 0 8px 18px rgba(91, 77, 240, 0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
}

.primary-action-btn:hover:not(:disabled) {
  background: #4e40e5;
  transform: translateY(-1px);
}

.primary-action-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #3d31b8;
}

.primary-action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.game-ad-sidebar {
  grid-column: 2;
  justify-self: end;
  width: 165px;
  min-height: 580px;
  background: linear-gradient(180deg, #fffdf8 0%, #f7f1e5 100%);
  border: 1.5px solid #e5dcc9;
  border-radius: 20px;
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  text-align: center;
  position: sticky;
  top: 82px;
  box-shadow: 0 8px 24px rgba(64, 48, 28, 0.05);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.game-ad-sidebar:hover {
  border-color: #c7b99e;
  box-shadow: 0 10px 28px rgba(64, 48, 28, 0.09);
}

.game-ad-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5b4df0;
  background: #eeecff;
  border: 1px solid #d5d0ff;
  padding: 4px 10px;
  border-radius: 999px;
}

.game-ad-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: #5a4c3e;
}

.game-ad-icon {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(135deg, #f3e8d2, #e9dcc2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}

.game-ad-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #2b221a;
}

.game-ad-sub {
  font-size: 0.76rem;
  color: #7c6e5d;
  line-height: 1.5;
}

.game-ad-cta {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  background: #efe7d8;
  color: #463a2e;
  font-size: 0.76rem;
  font-weight: 600;
}

.game-ad-mobile {
  display: none;
}

@media (max-width: 1180px) {
  .game-ad-mobile {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 54px;
    background: rgba(255, 252, 245, 0.96);
    backdrop-filter: blur(8px);
    border-top: 1px solid #e5dcc9;
    box-shadow: 0 -4px 18px rgba(64, 48, 28, 0.07);
    z-index: 45;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 16px;
    font-size: 0.82rem;
    color: #5a4c3e;
    font-weight: 600;
  }
}

.board-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

/* Match HUD & Roast Banner width to the Big Square Frame */
.hud-bar,
.live-roast-banner,
.chaos-strip {
  width: min(100%, clamp(520px, 74vh, 780px));
}

.hud-bar {
  background: #fffdf8;
  border: 2px solid #e5dcc9;
  border-radius: 16px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  box-shadow: 0 4px 14px rgba(64, 48, 28, 0.04);
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.96rem;
  font-weight: 600;
  color: #5a4c3e;
}

.hud-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.06rem;
  font-weight: 700;
  color: #241d17;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.peek-btn {
  padding: 7px 14px;
  border-radius: 11px;
  background: #f4ede0;
  border: 1.5px solid #dfd3bd;
  font-size: 0.86rem;
  font-weight: 600;
  color: #3a3026;
  user-select: none;
  box-shadow: 0 2px 0 #d8cbb3;
  transition: transform 0.1s ease, background 0.15s ease;
}

.peek-btn:hover:not(:disabled) {
  background: #ebe1cf;
}

.peek-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.peek-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.live-roast-banner {
  background: #1c1917;
  color: #ffffff;
  border-radius: 16px;
  padding: 10px 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 22px rgba(28, 25, 23, 0.18);
  border: 1.5px solid #44403c;
  transition: transform 0.22s ease;
}

.live-roast-banner.pop {
  animation: roast-pop 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes roast-pop {
  0% { transform: scale(0.96); border-color: #ec4899; }
  50% { transform: scale(1.015); border-color: #38bdf8; }
  100% { transform: scale(1); border-color: #44403c; }
}

.tiktok-avatar {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fe2c55, #25f4ee);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.roast-body {
  flex: 1;
  text-align: left;
}

.roast-user {
  font-size: 0.72rem;
  font-weight: 600;
  color: #a8a29e;
  margin-bottom: 1px;
}

.roast-msg {
  font-size: 0.94rem;
  font-weight: 600;
  color: #fafaf9;
  line-height: 1.35;
}

.chaos-strip {
  background: #fff1f2;
  border: 1.5px solid #fecdd3;
  color: #be123c;
  border-radius: 13px;
  padding: 8px 14px;
  font-size: 0.86rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chaos-progress-track {
  flex: 1;
  height: 7px;
  background: #ffe4e6;
  border-radius: 99px;
  overflow: hidden;
}

.chaos-progress-fill {
  height: 100%;
  width: 100%;
  background: #e11d48;
  transition: width 0.15s linear;
}

/* =========================================================
   5. LARGE SQUARE PUZZLE FRAME + 5 SELECTABLE FRAME STYLES
========================================================= */
.puzzle-frame {
  width: min(100%, clamp(520px, 74vh, 780px));
  aspect-ratio: 1 / 1;
  position: relative;
  padding: 18px;
  border-radius: 26px;
  touch-action: none;
  user-select: none;
  display: flex;
  transition: all 0.28s ease;
  --mat-bg: #e7ede5;
  --mat-dot: #c3cfbe;
  --mat-border: #d4cbb8;
}

.puzzle-mat-inner {
  flex: 1;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  background: var(--mat-bg);
  border: 1.5px solid var(--mat-border);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 10px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  transition: background 0.28s ease, border-color 0.28s ease;
}

.puzzle-frame[data-frame="wood"] {
  background: linear-gradient(145deg, #c18f5c, #9a6939 55%, #7c4f24);
  border: 2px solid #6b421b;
  box-shadow: 0 18px 40px rgba(68, 42, 16, 0.2), inset 0 2px 3px rgba(255, 232, 200, 0.45);
  --mat-bg: #eaeede;
  --mat-dot: #c2ccb4;
  --mat-border: #d9cfb9;
}

.puzzle-frame[data-frame="gallery"] {
  background: linear-gradient(135deg, #edd082, #be9034 45%, #e6c269 75%, #9f7420);
  border: 2px solid #8a6116;
  border-radius: 18px;
  box-shadow: 0 18px 42px rgba(92, 65, 14, 0.22), inset 0 0 0 4px #f8f2e2;
  --mat-bg: #f6f0e2;
  --mat-dot: #d6cbb4;
  --mat-border: #d6c59d;
}

.puzzle-frame[data-frame="pastel"] {
  background: linear-gradient(135deg, #ffdce5, #e5e0ff 55%, #d6f0ff);
  border: 2.5px solid #ffffff;
  border-radius: 28px;
  box-shadow: 0 10px 0 rgba(167, 139, 250, 0.25), 0 18px 36px rgba(91, 77, 240, 0.14);
  --mat-bg: #fcfaff;
  --mat-dot: #ddd6fe;
  --mat-border: #e9e4ff;
}

.puzzle-frame[data-frame="dark"] {
  background: linear-gradient(145deg, #2b2927, #1c1a18);
  border: 2px solid #3f3b36;
  box-shadow: 0 20px 44px rgba(15, 12, 10, 0.28), inset 0 0 0 2px rgba(212, 175, 55, 0.32);
  --mat-bg: #22252c;
  --mat-dot: #3a3f4b;
  --mat-border: #46433e;
}

.puzzle-frame[data-frame="ink"] {
  background: #fffdf8;
  border: 3px solid #1c1917;
  border-radius: 18px;
  box-shadow: 7px 8px 0 #1c1917;
  --mat-bg: #faf5e8;
  --mat-dot: #d6cbb5;
  --mat-border: #1c1917;
}

.puzzle-frame.chaos-shake {
  animation: chaos-shake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97);
  outline: 3px solid #e11d48;
}

@keyframes chaos-shake {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  20% { transform: translate(-6px, 3px) rotate(-1deg); }
  40% { transform: translate(6px, -4px) rotate(1deg); }
  60% { transform: translate(-4px, -2px) rotate(-0.8deg); }
  80% { transform: translate(4px, 3px) rotate(0.6deg); }
}

.upload-empty-state {
  width: 100%;
  height: 100%;
  border: 2.5px dashed rgba(90, 76, 62, 0.28);
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.72);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.puzzle-frame[data-frame="dark"] .upload-empty-state {
  background: rgba(34, 37, 44, 0.88);
  border-color: rgba(255, 255, 255, 0.22);
}

.puzzle-frame[data-frame="dark"] .upload-empty-title {
  color: #f8fafc;
}

.puzzle-frame[data-frame="dark"] .upload-empty-sub {
  color: #94a3b8;
}

.upload-empty-state:hover,
.upload-empty-state.dragover {
  border-color: #5b4df0;
  background: rgba(238, 236, 255, 0.72);
}

.upload-art-badge {
  filter: drop-shadow(0 6px 14px rgba(64, 48, 28, 0.12));
  transition: transform 0.2s ease;
}

.upload-empty-state:hover .upload-art-badge {
  transform: scale(1.06) rotate(-2deg);
}

.upload-empty-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: #241d17;
}

.upload-empty-sub {
  font-size: 0.94rem;
  font-weight: 500;
  color: #6b5b4b;
  max-width: 390px;
  line-height: 1.5;
}

#jigsaw-table {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background-color: var(--mat-bg);
  background-image: radial-gradient(var(--mat-dot) 1.35px, transparent 1.35px);
  background-size: 22px 22px;
  overflow: hidden;
  transition: background-color 0.28s ease;
}

@media (max-width: 640px) {
  .puzzle-frame {
    padding: 12px;
    border-radius: 20px;
  }
}

#sliding-board {
  position: relative;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 10px;
}

.peek-overlay {
  position: absolute;
  inset: 0;
  z-index: 250;
  border-radius: 10px;
  background: rgba(28, 25, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.peek-overlay.visible {
  opacity: 1;
}

.peek-overlay img {
  max-width: 78%;
  max-height: 78%;
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.45);
  border: 3px solid #ffffff;
}

.jigsaw-piece {
  position: absolute;
  cursor: grab;
  touch-action: none;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.25));
  transition: filter 0.18s ease;
}

.jigsaw-piece.dragging {
  cursor: grabbing;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.36));
}

.jigsaw-piece.merged {
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.16));
}

.jigsaw-piece.just-snapped {
  animation: snap-glow 0.4s ease;
}

@keyframes snap-glow {
  0% { filter: drop-shadow(0 0 14px #22c55e) brightness(1.12); }
  100% { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.16)) brightness(1); }
}

.sliding-tile {
  position: absolute;
  border-radius: 5px;
  cursor: pointer;
  transition: left 0.14s ease, top 0.14s ease;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.45), 0 2px 5px rgba(0,0,0,0.18);
  z-index: 5;
}

.sliding-tile.correct-pos {
  box-shadow: inset 0 0 0 1.5px rgba(34, 197, 94, 0.65);
}

.helper-hint {
  font-size: 0.88rem;
  color: #6b5b4b;
  font-weight: 500;
  text-align: center;
  max-width: 600px;
}

/* =========================================================
   6. MODALS & TOAST
========================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 20, 16, 0.72);
  backdrop-filter: blur(6px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.modal-card {
  width: 100%;
  max-width: 470px;
  background: #fffdf8;
  border: 2px solid #e7decb;
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.32);
  text-align: center;
  color: #1f1b18;
  font-family: 'Fredoka', sans-serif;
  position: relative;
  animation: modal-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.92) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f2ebe0;
  font-weight: 700;
  color: #5a4c3e;
}

.victory-emoji {
  font-size: 2.8rem;
  line-height: 1;
  margin-bottom: 8px;
}

.victory-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.65rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.stat-box {
  background: #f7f1e5;
  border: 1.5px solid #e5dcc9;
  border-radius: 14px;
  padding: 10px;
}

.stat-box-label {
  font-size: 0.76rem;
  color: #7c6e5d;
  font-weight: 600;
  text-transform: uppercase;
}

.stat-box-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.25rem;
  font-weight: 700;
  color: #1f1b18;
  margin-top: 2px;
}

.ai-verdict-box {
  background: #1c1917;
  color: #ffffff;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 18px;
  position: relative;
  text-align: left;
  border: 2px solid #5b4df0;
}

.ai-verdict-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
  color: #a5b4fc;
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.ai-verdict-text {
  font-size: 1.04rem;
  font-weight: 600;
  line-height: 1.48;
}

.reroll-btn {
  font-size: 0.76rem;
  color: #c7d2fe;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255,255,255,0.1);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-screenshot {
  width: 100%;
  padding: 13px;
  border-radius: 13px;
  background: linear-gradient(135deg, #5b4df0, #7c3aed);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.96rem;
  box-shadow: 0 4px 0 #3d31b8, 0 8px 18px rgba(124, 58, 237, 0.3);
}

.btn-tiktok {
  width: 100%;
  padding: 12px;
  border-radius: 13px;
  background: #1c1917;
  color: #ffffff;
  font-weight: 700;
  font-size: 0.94rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-replay {
  width: 100%;
  padding: 11px;
  border-radius: 13px;
  background: #f2ebe0;
  color: #3a3026;
  font-weight: 600;
  font-size: 0.94rem;
}

.screenshot-preview-img {
  width: 100%;
  max-height: 55vh;
  object-fit: contain;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  margin: 10px 0 14px;
  background: #0f172a;
}

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #1c1917;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}