/* ════════════════════════════════════════════
   Lekstugan  |  style.css
════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────── */
:root {
  --bg:           #FFF9F0;
  --primary:      #FF6B6B;
  --primary-dk:   #E55050;
  --secondary:    #4ECDC4;
  --accent:       #FFE66D;
  --purple:       #A855F7;
  --green:        #22C55E;
  --orange:       #FF9F43;

  --text:         #2D2D2D;
  --text-mid:     #666;
  --text-lt:      #999;

  --surface:      #FFFFFF;
  --surface-alt:  #F6F6F6;
  --surface-input:#FAFAFA;
  --border:       #E5E5E5;
  --border-lt:    #EFEFEF;

  --shadow:       0 4px 20px rgba(0,0,0,.10);
  --shadow-lg:    0 8px 40px rgba(0,0,0,.16);
  --r:            16px;
  --r-sm:         8px;
  --r-lg:         24px;

  --topbar:       76px;
  --bottombar:    62px;
  --toolsw:       66px;
}

[data-theme="dark"] {
  --bg:           #18181B;
  --surface:      #27272A;
  --surface-alt:  #3F3F46;
  --surface-input:#3F3F46;
  --border:       #52525B;
  --border-lt:    #3F3F46;
  --text:         #F4F4F5;
  --text-mid:     #A1A1AA;
  --text-lt:      #71717A;
  --shadow:       0 4px 20px rgba(0,0,0,.40);
  --shadow-lg:    0 8px 40px rgba(0,0,0,.60);
}
[data-theme="dark"] .puzzle-win,
[data-theme="dark"] .balloon-overlay {
  background: rgba(0,0,0,.65);
}
[data-theme="dark"] #main-menu {
  background: var(--bg);
}
[data-theme="dark"] .icon-btn--danger  { background: rgba(192,57,43,.22); }
[data-theme="dark"] .icon-btn--success { background: rgba(22,163,74,.18); }
[data-theme="dark"] .p-card.matched .p-card-back { background: rgba(34,197,94,.15); }
[data-theme="dark"] .sticker-btn.active { background: rgba(255,107,107,.2); border-color: var(--primary); }
[data-theme="dark"] .tool-btn:hover,
[data-theme="dark"] .tool-btn.active,
[data-theme="dark"] .sticker-add-btn:hover,
[data-theme="dark"] .win-secondary-btn:hover,
[data-theme="dark"] .diff-btn:hover,
[data-theme="dark"] .diff-btn.active { background: rgba(168,85,247,.22); }
[data-theme="dark"] .jigsaw-board-wrap { background: #0D0D0F; }

/* ── Reset ─────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Nunito', 'Arial Rounded MT Bold', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
}

/* ── Screens ───────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
  z-index: 1;
}
.screen.active { display: flex; }

/* slide-in animation when activated */
.screen.slide-in {
  animation: slideIn .28s cubic-bezier(.4,0,.2,1) forwards;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Global Sound button ───────────────────── */
.settings-btn {
  position: fixed; bottom: 14px; right: 14px;
  z-index: 9999;
  background: var(--surface);
  border: none; border-radius: 50%;
  width: 44px; height: 44px;
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  transition: transform .3s;
}
.settings-btn:hover  { transform: scale(1.12); }
.settings-btn:active { transform: scale(.92); }
.settings-btn.open   { transform: rotate(60deg); }

.settings-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  z-index: 9990;
  display: flex; align-items: flex-end;
}
.settings-panel {
  width: 100%; max-height: 82vh;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -8px 40px rgba(0,0,0,.18);
  animation: slideUpPanel .28s cubic-bezier(.4,0,.2,1);
}
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 2px solid var(--border-lt);
  flex-shrink: 0;
}
.settings-title { font-size: 18px; font-weight: 800; }
.settings-body {
  overflow-y: auto; padding: 14px 16px 32px;
  display: flex; flex-direction: column; gap: 20px;
  -webkit-overflow-scrolling: touch;
}
.settings-section { display: flex; flex-direction: column; gap: 8px; }
.settings-section-title {
  font-size: 12px; font-weight: 800; color: var(--text-mid);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 2px;
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface-alt); border-radius: var(--r);
}
.settings-row-label { font-size: 16px; font-weight: 700; }
.settings-pill {
  width: 52px; height: 28px;
  background: var(--green);
  border: none; border-radius: 14px;
  cursor: pointer; position: relative; flex-shrink: 0;
  transition: background .2s;
}
.settings-pill.off { background: var(--border); }
.settings-pill-knob {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px;
  background: white; border-radius: 50%;
  transition: transform .2s;
  display: block; pointer-events: none;
}
.settings-pill:not(.off) .settings-pill-knob { transform: translateX(24px); }
.settings-help { display: flex; flex-direction: column; gap: 10px; }
.settings-help-item {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 14px; color: var(--text-mid); line-height: 1.5;
}
.settings-help-icon { font-size: 20px; flex-shrink: 0; margin-top: 1px; }
.settings-about p { font-size: 14px; color: var(--text-mid); line-height: 1.6; }
.settings-version { font-size: 12px; color: var(--text-lt); margin-top: 4px; }

/* ── Confetti canvas ───────────────────────── */
#confetti-canvas {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 9998;
  width: 100%; height: 100%;
}

/* ══════════════════════════════════════════════
   MAIN MENU
══════════════════════════════════════════════ */
#main-menu {
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(160deg, var(--bg) 0%, #FFF0F8 100%);
}
.menu-header {
  text-align: center;
  margin-bottom: 36px;
}
.app-logo {
  font-size: clamp(46px, 12vw, 88px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -2px;
}
.app-logo span {
  display: inline-block;
  animation: floatLetter 2.8s ease-in-out infinite;
}
.logo-r { color: var(--primary);   animation-delay: 0s;    }
.logo-i { color: var(--accent);    animation-delay: .25s;  filter: drop-shadow(0 2px 0 #c9a800); }
.logo-t { color: var(--secondary); animation-delay: .5s;   }
.logo-a { color: var(--purple);    animation-delay: .75s;  }

@keyframes floatLetter {
  0%,100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-10px) rotate(2deg); }
}

.app-subtitle {
  font-size: 18px; font-weight: 700;
  color: var(--text-mid);
  margin-top: 8px;
  letter-spacing: .5px;
}

.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: min(440px, 100%);
}

.menu-btn {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  padding: 22px 16px;
  border: none; border-radius: var(--r-lg);
  cursor: pointer;
  min-height: 138px;
  font-family: inherit;
  box-shadow: 0 6px 24px rgba(0,0,0,.13);
  transition: transform .18s, box-shadow .18s;
  position: relative; overflow: hidden;
}
.menu-btn::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(255,255,255,.12);
  opacity: 0;
  transition: opacity .15s;
}
.menu-btn:hover::after  { opacity: 1; }
.menu-btn:hover  { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.menu-btn:active { transform: scale(.95); }

.menu-drawing { background: linear-gradient(135deg,#FF6B6B,#FF8E53); color:white; }
.menu-puzzles { background: linear-gradient(135deg,#A855F7,#7C3AED); color:white; }
.menu-math    { background: linear-gradient(135deg,#22D3EE,#22C55E); color:white; }
.menu-photo   { background: linear-gradient(135deg,#F43F5E,#EC4899); color:white; }

.menu-icon  { font-size: 46px; filter: drop-shadow(0 3px 6px rgba(0,0,0,.22)); }
.menu-label { font-size: 17px; font-weight: 800; text-align: center; text-shadow: 0 1px 4px rgba(0,0,0,.2); }

/* bounce on click */
@keyframes btnBounce {
  0%   { transform: scale(1); }
  28%  { transform: scale(.91); }
  60%  { transform: scale(1.08); }
  80%  { transform: scale(.97); }
  100% { transform: scale(1); }
}
.bounce { animation: btnBounce .38s cubic-bezier(.36,.07,.19,.97) forwards; }

/* ══════════════════════════════════════════════
   SHARED TOP BAR
══════════════════════════════════════════════ */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  height: var(--topbar);
  padding: 0 12px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
  flex-shrink: 0;
  z-index: 10;
}
.module-title {
  font-size: 22px; font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; text-align: center;
}
.top-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Buttons ───────────────────────────────── */
.back-btn {
  display: flex; align-items: center; gap: 4px;
  background: var(--primary); color: white;
  border: none; border-radius: var(--r-sm);
  padding: 10px 16px;
  font-size: 17px; font-weight: 800; font-family: inherit;
  cursor: pointer; white-space: nowrap; min-height: 52px;
  transition: background .15s, transform .1s;
  flex-shrink: 0;
}
.back-btn:hover  { background: var(--primary-dk); }
.back-btn:active { transform: scale(.93); }

.icon-btn {
  display: flex; align-items: center; justify-content: center; gap: 3px;
  background: var(--surface-alt); color: var(--text);
  border: none; border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: 18px; font-weight: 700; font-family: inherit;
  cursor: pointer; white-space: nowrap; min-height: 52px;
  transition: background .15s, transform .1s;
}
.icon-btn:hover  { background: var(--border); }
.icon-btn:active { transform: scale(.93); }

.icon-btn--danger  { background: #FFE5E5; color: #C0392B; }
.icon-btn--danger:hover  { background: #FFD0D0; }
.icon-btn--success { background: #E5F7EE; color: #16A34A; }
.icon-btn--success:hover { background: #CCEFDB; }

.big-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 14px 32px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: white; border: none; border-radius: var(--r-lg);
  font-size: 19px; font-weight: 800; font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(255,107,107,.4);
  transition: transform .15s, box-shadow .15s;
}
.big-btn:hover  { transform: translateY(-2px); box-shadow: 0 7px 24px rgba(255,107,107,.5); }
.big-btn:active { transform: scale(.95); }

/* ══════════════════════════════════════════════
   DRAWING STUDIO LAYOUT
══════════════════════════════════════════════ */
.studio-layout {
  display: flex; flex-direction: column;
  height: 100%; overflow: hidden;
}
.studio-main {
  display: flex; flex: 1; overflow: hidden; min-height: 0;
}

/* ── Left tools panel ──────────────────────── */
.tools-panel {
  width: var(--toolsw);
  background: var(--surface);
  border-right: 2px solid var(--border-lt);
  display: flex; flex-direction: column;
  align-items: center;
  padding: 10px 6px;
  gap: 5px;
  overflow-y: auto;
  flex-shrink: 0;
}
.tool-group { display: flex; flex-direction: column; gap: 5px; width: 100%; }
.tool-divider {
  width: 80%; height: 2px;
  background: var(--border-lt); border-radius: 2px;
  margin: 3px auto;
}
.tool-btn {
  width: 52px; height: 52px;
  background: var(--surface-alt);
  border: 2px solid transparent;
  border-radius: var(--r-sm);
  font-size: 22px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  font-family: inherit; font-weight: 900;
  position: relative;
}
.tool-btn:hover  { background: #EEE6FF; border-color: var(--purple); }
.tool-btn:active { transform: scale(.9); }
.tool-btn.active {
  background: #EEE6FF;
  border-color: var(--purple);
  box-shadow: 0 2px 10px rgba(168,85,247,.3);
}

/* ── Canvas wrapper ────────────────────────── */
.canvas-wrapper {
  flex: 1; overflow: hidden; position: relative;
  background: var(--surface-alt);
  cursor: none;
}
#draw-canvas {
  display: block;
  touch-action: none;
  cursor: none;
}

/* ── Sticker panel ─────────────────────────── */
.sticker-panel {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 3px solid var(--accent);
  border-radius: var(--r) var(--r) 0 0;
  padding: 10px 14px 12px;
  box-shadow: 0 -6px 28px rgba(0,0,0,.12);
  z-index: 20;
  max-height: 56%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 8px;
}

/* Header row */
.sticker-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.sticker-panel-title {
  font-size: 13px; font-weight: 800; color: var(--text-mid);
  text-transform: uppercase; letter-spacing: .5px;
}

/* Sticker grids */
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 5px;
}
.sticker-btn {
  width: 100%; aspect-ratio: 1;
  border: 2px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-input);
  font-size: 24px; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all .14s;
  overflow: hidden;
}
.sticker-btn:hover  { border-color: var(--primary); background: #FFF5F5; transform: scale(1.1); }
.sticker-btn:active { transform: scale(.88); }
.sticker-btn.active {
  border-color: var(--primary); background: #FFE5E5;
  box-shadow: 0 0 0 3px rgba(255,107,107,.25);
}
.sticker-btn--image { padding: 3px; }
.sticker-btn--image img { width: 100%; height: 100%; object-fit: contain; border-radius: 4px; display: block; }

/* Custom stickers section */
.custom-sticker-section { flex-shrink: 0; }
.custom-sticker-label {
  font-size: 11px; font-weight: 800; color: var(--text-lt);
  text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 5px;
}
.sticker-custom-wrap { position: relative; }
.sticker-del-btn {
  position: absolute; top: -5px; right: -5px;
  width: 18px; height: 18px;
  background: var(--primary); color: white;
  border: none; border-radius: 50%;
  font-size: 9px; line-height: 1;
  cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
  opacity: 0; transition: opacity .15s;
  font-family: inherit; font-weight: 900;
}
.sticker-custom-wrap:hover .sticker-del-btn { opacity: 1; }

/* Add-image buttons */
.sticker-add-row {
  display: flex; gap: 7px; flex-shrink: 0; padding-top: 2px;
}
.sticker-add-btn {
  flex: 1; padding: 8px 6px;
  background: var(--surface-alt); color: var(--text);
  border: 2px dashed var(--border); border-radius: var(--r-sm);
  font-size: 13px; font-weight: 700; font-family: inherit;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  transition: all .15s; white-space: nowrap;
}
.sticker-add-btn:hover  { background: #EEE6FF; border-color: var(--purple); color: var(--purple); }
.sticker-add-btn:active { transform: scale(.95); }


/* ── Background picker panel ──────────────── */
#bg-panel { border-top-color: var(--secondary); }

.bg-option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 6px;
}
.bg-option-btn {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 5px; padding: 8px 4px; width: 100%;
  background: var(--surface-input); border: 2px solid var(--border);
  border-radius: var(--r-sm); cursor: pointer;
  font-family: inherit; transition: all .14s;
}
.bg-option-btn:hover  { border-color: var(--secondary); background: #F0FFFE; transform: scale(1.04); }
.bg-option-btn:active { transform: scale(.92); }
.bg-option-emoji { font-size: 26px; line-height: 1; }
.bg-option-label {
  font-size: 10px; font-weight: 800; color: var(--text-mid);
  text-align: center; line-height: 1.2;
}
.bg-blank-icon {
  width: 28px; height: 28px;
  border: 2px solid var(--border); border-radius: 3px;
  background: var(--surface);
}

/* ── Color trigger button ──────────────────── */
.color-trigger-btn {
  width: 40px !important; height: 40px !important;
  border-radius: 50% !important;
  border-width: 3px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,.22) !important;
  transition: transform .15s, box-shadow .15s !important;
  padding: 0 !important; font-size: 0 !important;
}
.color-trigger-btn.open {
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--purple) !important;
  transform: scale(1.1) !important;
}

/* ── Color flyout ──────────────────────────── */
.color-flyout {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 200px;
  background: var(--surface);
  border-right: 3px solid var(--accent);
  border-radius: 0 var(--r) var(--r) 0;
  padding: 14px 12px;
  box-shadow: 6px 0 28px rgba(0,0,0,.13);
  z-index: 22;
  display: flex; flex-direction: column; gap: 10px;
  transform: translateX(-100%);
  transition: transform .26s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.color-flyout.open {
  transform: translateX(0);
}
.color-flyout-title {
  font-size: 12px; font-weight: 800; color: var(--text-mid);
  text-transform: uppercase; letter-spacing: .5px;
  flex-shrink: 0;
}
.color-flyout-palette {
  display: grid !important;
  grid-template-columns: repeat(4, 1fr) !important;
  gap: 6px !important;
  max-width: none !important;
  flex-wrap: unset !important;
}
.color-flyout-custom {
  width: 44px !important; height: 44px !important;
  align-self: flex-start;
  flex-shrink: 0;
}

/* ── Bottom bar ────────────────────────────── */
.bottom-bar {
  background: var(--surface);
  border-top: 2px solid var(--border-lt);
  padding: 8px 12px;
  flex-shrink: 0;
  display: flex; align-items: center;
  overflow: hidden;
  min-height: var(--bottombar);
}
.color-palette {
  display: flex; flex-wrap: wrap; gap: 5px;
  max-width: 340px;
}
.color-swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,.1);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  flex-shrink: 0;
  padding: 0;
  display: block;
}
.color-swatch:hover  { transform: scale(1.28); }
.color-swatch.active {
  transform: scale(1.28);
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--purple);
}
.color-picker {
  width: 38px; height: 38px;
  border: 2px solid var(--border); border-radius: 50%;
  cursor: pointer; padding: 2px;
  background: none; flex-shrink: 0;
  overflow: hidden;
}
.color-picker::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
.color-picker::-webkit-color-swatch { border: none; border-radius: 50%; }

.sliders-row { display: flex; gap: 16px; flex-wrap: wrap; }
.slider-wrap { display: flex; align-items: center; gap: 7px; }
.slider-label { font-size: 12px; font-weight: 800; color: var(--text-mid); min-width: 44px; }
.fun-slider {
  width: 100px; height: 6px;
  -webkit-appearance: none; appearance: none;
  border-radius: 3px;
  background: linear-gradient(to right, var(--primary), var(--accent));
  outline: none; cursor: pointer;
}
.fun-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--primary);
  cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.22);
}
.fun-slider::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--primary);
  cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.22);
}
.slider-val { font-size: 12px; font-weight: 700; color: var(--text-mid); min-width: 36px; text-align: right; }


/* ══════════════════════════════════════════════
   MODULE SHARED LAYOUT
══════════════════════════════════════════════ */
.module-layout {
  display: flex; flex-direction: column;
  height: 100%; overflow: hidden;
  position: relative;
}

/* ══════════════════════════════════════════════
   PUZZLES
══════════════════════════════════════════════ */
.puzzle-area {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  padding: 16px;
  gap: 16px;
  position: relative;
}
.puzzle-stats { display: flex; gap: 14px; }
.stat-box {
  background: var(--surface); border-radius: var(--r);
  padding: 10px 22px; text-align: center;
  box-shadow: var(--shadow); min-width: 80px;
}
.stat-label { display: block; font-size: 11px; font-weight: 800; color: var(--text-lt); text-transform: uppercase; letter-spacing: .5px; }
.stat-val   { display: block; font-size: 26px; font-weight: 900; color: var(--primary); }

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: min(480px, 100%);
}
.p-card {
  aspect-ratio: 1;
  cursor: pointer;
  perspective: 700px;
  border-radius: var(--r);
}
.p-card-inner {
  width: 100%; height: 100%;
  position: relative;
  transition: transform .42s cubic-bezier(.4,0,.2,1);
  transform-style: preserve-3d;
}
.p-card.flipped .p-card-inner { transform: rotateY(180deg); }
.p-card-front, .p-card-back {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--r);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 12px rgba(0,0,0,.12);
}
.p-card-front {
  background: linear-gradient(135deg, var(--primary), var(--purple));
  font-size: clamp(22px,7vw,36px);
  color: white; font-weight: 900;
}
.p-card-back {
  background: var(--surface);
  transform: rotateY(180deg);
  font-size: clamp(28px,9vw,48px);
}
.p-card.matched .p-card-back {
  background: linear-gradient(135deg, #E5F7EE, #CCFCE3);
  border: 3px solid var(--green);
}

.puzzle-win {
  position: absolute; inset: 0;
  background: rgba(255,255,255,.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; backdrop-filter: blur(3px);
}
.win-card {
  background: var(--surface); border-radius: var(--r-lg);
  padding: 36px 48px; text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popUp .38s cubic-bezier(.36,.07,.19,.97);
}
@keyframes popUp {
  from { transform: scale(.4); opacity: 0; }
  70%  { transform: scale(1.06); }
  to   { transform: scale(1); opacity: 1; }
}
.win-emoji { font-size: 64px; margin-bottom: 12px; }
.win-card h2 { font-size: 32px; font-weight: 900; color: var(--primary); margin-bottom: 6px; }
.win-card p  { font-size: 17px; color: var(--text-mid); margin-bottom: 22px; }
.win-secondary-row {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
  margin-top: 14px;
}
.win-secondary-btn {
  padding: 9px 14px;
  background: var(--surface-alt); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--r);
  font-size: 14px; font-weight: 800; font-family: inherit;
  cursor: pointer; white-space: nowrap;
  transition: all .15s;
}
.win-secondary-btn:hover  { background: #EEE6FF; border-color: var(--purple); color: var(--purple); }
.win-secondary-btn:active { transform: scale(.93); }


/* ══════════════════════════════════════════════
   GAME TABS
══════════════════════════════════════════════ */
.game-tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 2px solid var(--border-lt);
  flex-shrink: 0;
}
.game-tab {
  flex: 1; padding: 10px 16px;
  background: none; border: none;
  border-bottom: 3px solid transparent;
  font-size: 16px; font-weight: 800; font-family: inherit;
  color: var(--text-mid);
  cursor: pointer;
  transition: all .15s;
  margin-bottom: -2px;
}
.game-tab:hover   { background: var(--surface-alt); }
.game-tab.active  { color: var(--purple); border-bottom-color: var(--purple); }

.game-panel {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; position: relative;
}

/* ══════════════════════════════════════════════
   BALLOON POP GAME
══════════════════════════════════════════════ */
.balloon-hud {
  display: flex; gap: 14px; align-items: center;
  padding: 10px 16px; justify-content: center;
  background: var(--surface); border-bottom: 2px solid var(--border-lt);
  flex-shrink: 0;
}
.balloon-pause-btn {
  font-size: 20px !important;
  min-height: 44px !important;
  padding: 8px 14px !important;
}
.balloon-pause-btn:disabled { opacity: 0.35; cursor: default; }
#balloon-canvas {
  display: block; touch-action: none;
  cursor: pointer; width: 100%;
  flex: 1; min-height: 0;
  background: linear-gradient(180deg, #e0f0ff 0%, #f8faff 100%);
}
.balloon-overlay {
  position: absolute; inset: 0;
  background: rgba(255,255,255,.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; backdrop-filter: blur(3px);
}
.balloon-overlay-card {
  background: var(--surface); border-radius: var(--r-lg);
  padding: 36px 48px; text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popUp .38s cubic-bezier(.36,.07,.19,.97);
}
.balloon-overlay-card h2 { font-size: 32px; font-weight: 900; color: var(--primary); margin-bottom: 6px; }
.balloon-overlay-card p  { font-size: 17px; color: var(--text-mid); margin-bottom: 22px; }
.balloon-overlay-card .win-emoji { font-size: 64px; margin-bottom: 12px; }
.balloon-overlay-card .win-secondary-row { margin-top: 14px; }

/* ══════════════════════════════════════════════
   JIGSAW PUZZLE
══════════════════════════════════════════════ */
.jigsaw-start {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow-y: auto;
}
.jigsaw-start-card {
  background: var(--surface); border-radius: var(--r-lg);
  padding: 32px 36px; text-align: center;
  box-shadow: var(--shadow-lg); max-width: 360px; width: 100%;
}
.jigsaw-start-card .win-emoji { font-size: 56px; margin-bottom: 10px; }
.jigsaw-start-card h2 { font-size: 26px; font-weight: 900; color: var(--purple); margin-bottom: 8px; }
.jigsaw-start-card p  { font-size: 15px; color: var(--text-mid); margin-bottom: 20px; }

.diff-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 22px; }
.diff-btn {
  flex: 1; padding: 10px 6px;
  background: var(--surface-alt); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--r);
  font-size: 13px; font-weight: 800; font-family: inherit;
  cursor: pointer; line-height: 1.35; transition: all .15s;
}
.diff-btn small { font-size: 12px; font-weight: 700; color: var(--text-lt); display: block; }
.diff-btn:hover  { border-color: var(--purple); background: #EEE6FF; }
.diff-btn.active { border-color: var(--purple); background: #EEE6FF; color: var(--purple); }

/* Play area */
.jigsaw-play {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; position: relative;
}
.jigsaw-play-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 0 12px;
  height: var(--topbar);
  background: var(--surface); border-bottom: 2px solid var(--border-lt);
  flex-shrink: 0;
}
.jigsaw-board-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  overflow: hidden; background: #D8D8D8; min-height: 0;
  padding: 12px;
}
#jigsaw-board {
  position: relative;
  box-shadow: 0 6px 32px rgba(0,0,0,.25);
  flex-shrink: 0;
}

/* Slots – faint image hint */
.jigsaw-slot {
  position: absolute;
  background-repeat: no-repeat;
  opacity: 0.2;
  box-sizing: border-box;
  border: 1px solid rgba(0,0,0,.07);
  transition: opacity .3s;
}

/* Pieces */
.jigsaw-piece {
  background-repeat: no-repeat;
  flex-shrink: 0;
  cursor: grab;
  box-sizing: border-box;
  border: 2px solid rgba(255,255,255,.55);
  border-radius: 3px;
  box-shadow: 0 2px 10px rgba(0,0,0,.28);
  touch-action: none;
  user-select: none;
  transition: transform .12s, box-shadow .12s;
}
.jigsaw-piece:hover  { transform: scale(1.05); box-shadow: 0 5px 18px rgba(0,0,0,.38); }
.jigsaw-piece--dragging {
  position: absolute; cursor: grabbing;
  transform: scale(1.08);
  box-shadow: 0 10px 36px rgba(0,0,0,.45);
  transition: none; z-index: 200;
}
.jigsaw-piece--placed {
  cursor: default;
  border-color: rgba(255,255,255,.3);
  box-shadow: none;
  transform: none !important;
  transition: none;
}
.jigsaw-piece--placed:hover { transform: none !important; box-shadow: none; }

@keyframes wrongShake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-9px); }
  45%     { transform: translateX(9px); }
  65%     { transform: translateX(-5px); }
  85%     { transform: translateX(5px); }
}
.jigsaw-piece--wrong { animation: wrongShake .38s ease-in-out; }

/* Tray */
#jigsaw-tray {
  display: flex; flex-wrap: wrap; gap: 5px;
  padding: 8px 10px; align-content: flex-start;
  overflow-y: auto; max-height: 220px;
  background: var(--surface); border-top: 2px solid var(--border-lt);
  flex-shrink: 0;
}

/* Drag layer */
.jigsaw-drag-layer {
  position: absolute; inset: 0;
  pointer-events: none; z-index: 100;
}

/* Hint overlay */
.jigsaw-hint-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); z-index: 90;
  cursor: pointer;
  animation: fadeIn .18s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.jigsaw-hint-overlay img {
  max-width: 88%; max-height: 88%;
  border-radius: var(--r); box-shadow: var(--shadow-lg);
}

/* ══════════════════════════════════════════════
   WHACK-A-MOLE
══════════════════════════════════════════════ */
.mole-hud {
  display: flex; gap: 14px; align-items: center;
  padding: 10px 16px; justify-content: center;
  background: var(--surface); border-bottom: 2px solid var(--border-lt);
  flex-shrink: 0;
}
.mole-field {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(10px, 2vw, 20px);
  padding: clamp(12px, 3vw, 28px);
  background: linear-gradient(180deg, #a8e063 0%, #78c030 100%);
  max-width: 560px;
  max-height: 560px;
  width: 100%;
  margin: auto;
  align-self: center;
}
.mole-cell {
  position: relative;
  display: flex; align-items: flex-end; justify-content: center;
  overflow: hidden;
  border-radius: 50% 50% var(--r) var(--r);
  background: radial-gradient(ellipse at 50% 80%, #7a4f2b 60%, #5a3018 100%);
  box-shadow: inset 0 6px 18px rgba(0,0,0,.38), 0 4px 12px rgba(0,0,0,.22);
  cursor: pointer;
  aspect-ratio: 1;
  min-height: 0;
  transition: box-shadow .1s;
}
.mole-cell:active { box-shadow: inset 0 8px 24px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.18); }
.mole-face {
  font-size: clamp(32px, min(7vw, 7vh), 96px);
  line-height: 1;
  transform: translateY(110%);
  transition: transform .14s cubic-bezier(.34,1.56,.64,1);
  will-change: transform;
  pointer-events: none;
  padding-bottom: 4px;
  user-select: none;
}
.mole-cell.active .mole-face {
  transform: translateY(0%);
}
@keyframes moleSmack {
  0%   { transform: translateY(0%) scale(1); }
  25%  { transform: translateY(-10%) scale(1.2); }
  55%  { transform: translateY(20%) scale(0.82); }
  100% { transform: translateY(110%) scale(1); }
}
.mole-cell.smacked .mole-face {
  animation: moleSmack .32s ease-out forwards;
  transition: none;
}
.mole-popup {
  position: absolute; top: 8%; left: 50%;
  transform: translateX(-50%);
  font-size: 20px; font-weight: 900;
  color: #22C55E; pointer-events: none;
  animation: molePopScore .7s ease-out forwards;
  z-index: 10; white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0,0,0,.3);
}
@keyframes molePopScore {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-36px); }
}

/* ══════════════════════════════════════════════
   FYRA I RAD
══════════════════════════════════════════════ */
.fyra-hud {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; gap: 10px;
  background: var(--surface); border-bottom: 2px solid var(--border-lt);
  flex-shrink: 0;
}
.fyra-turn-box {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  flex: 1;
}
.fyra-turn-disc {
  width: 32px; height: 32px; border-radius: 50%;
  background: #EF4444;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  transition: background .2s;
}
.fyra-turn-disc.p2 { background: #FBBF24; }
.fyra-turn-label {
  font-size: 12px; font-weight: 800; color: var(--text-mid);
  text-transform: uppercase; letter-spacing: .5px;
}
.fyra-board-wrap {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 12px; gap: 0; overflow: hidden;
}
.fyra-drop-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  width: min(100%, 560px);
  padding: 0 12px;
}
.fyra-drop-btn {
  background: none; border: none; cursor: pointer;
  font-size: clamp(18px, 3vw, 26px);
  padding: 4px 0;
  opacity: 0;
  transition: opacity .15s, transform .15s;
  color: var(--text-mid);
}
.fyra-drop-btn:hover  { opacity: 1; transform: translateY(2px); }
.fyra-drop-btn:active { transform: translateY(5px); }
.fyra-drop-btn.active { opacity: 0.55; }
.fyra-board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  padding: 12px;
  background: #1E40AF;
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,.35);
  width: min(100%, 560px);
}
.fyra-cell {
  aspect-ratio: 1;
  border-radius: 50%;
  background: #1E3A8A;
  box-shadow: inset 0 4px 12px rgba(0,0,0,.5);
  cursor: pointer;
}
.fyra-cell.p1 {
  background: #EF4444;
  box-shadow: 0 2px 8px rgba(239,68,68,.45), inset 0 -3px 8px rgba(0,0,0,.2);
}
.fyra-cell.p2 {
  background: #FBBF24;
  box-shadow: 0 2px 8px rgba(251,191,36,.45), inset 0 -3px 8px rgba(0,0,0,.2);
}
.fyra-cell.win-cell {
  animation: fyraWin .55s ease-in-out infinite alternate;
}
.fyra-cell.drop-in {
  animation: fyraDropIn .22s ease-out;
}
@keyframes fyraDropIn {
  from { transform: translateY(-120%) scale(.7); opacity: .4; }
  to   { transform: translateY(0)     scale(1);  opacity: 1; }
}
@keyframes fyraWin {
  from { transform: scale(1);    filter: brightness(1); }
  to   { transform: scale(1.12); filter: brightness(1.35); }
}

/* ══════════════════════════════════════════════
   DRAWING GALLERY
══════════════════════════════════════════════ */
.gallery-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  z-index: 30;
  display: flex; align-items: flex-end;
}
.gallery-panel {
  width: 100%; max-height: 72vh;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -8px 40px rgba(0,0,0,.18);
  animation: slideUpPanel .28s cubic-bezier(.4,0,.2,1);
}
@keyframes slideUpPanel {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.gallery-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 2px solid var(--border-lt);
  flex-shrink: 0;
}
.gallery-title { font-size: 18px; font-weight: 800; }
.gallery-header-actions { display: flex; gap: 8px; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px; padding: 14px;
  overflow-y: auto; flex: 1;
  -webkit-overflow-scrolling: touch;
}
.gallery-thumb-wrap {
  position: relative;
  border-radius: var(--r-sm); overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
  cursor: pointer;
  transition: transform .14s, box-shadow .14s;
  aspect-ratio: 4/3;
  background: var(--surface-alt);
}
.gallery-thumb-wrap:hover  { transform: scale(1.05); box-shadow: 0 6px 20px rgba(0,0,0,.22); }
.gallery-thumb-wrap:active { transform: scale(.95); }
.gallery-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-del-btn {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px;
  background: var(--primary); color: white;
  border: 2px solid var(--surface); border-radius: 50%;
  font-size: 10px; font-weight: 900; font-family: inherit;
  cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .15s; z-index: 5;
}
.gallery-thumb-wrap:hover .gallery-del-btn { opacity: 1; }
@media (pointer: coarse) { .gallery-del-btn { opacity: 1; } }
.gallery-empty {
  text-align: center; color: var(--text-mid);
  font-size: 15px; font-weight: 700;
  padding: 32px 20px; line-height: 1.6;
}

/* ══════════════════════════════════════════════
   PHOTOBOOTH
══════════════════════════════════════════════ */
.pb-start-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow-y: auto;
}
.pb-start-card {
  background: var(--surface); border-radius: var(--r-lg);
  padding: 32px 36px; text-align: center;
  box-shadow: var(--shadow-lg); max-width: 360px; width: 100%;
}
.pb-start-card h2 { font-size: 26px; font-weight: 900; color: #F43F5E; margin-bottom: 8px; }
.pb-start-card p  { font-size: 15px; color: var(--text-mid); margin-bottom: 20px; }
.pb-error { color: var(--primary); font-size: 14px; font-weight: 700; margin-top: 12px; }

.pb-camera-wrap {
  flex: 1; display: flex; flex-direction: column;
  background: #000; overflow: hidden;
}
.pb-video {
  flex: 1; width: 100%; object-fit: cover;
  transform: scaleX(-1);
  min-height: 0;
}
.pb-camera-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px;
  background: var(--surface); border-top: 2px solid var(--border-lt);
  flex-shrink: 0;
}

.pb-edit-wrap {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}
.pb-canvas-wrap {
  flex: 1; overflow: hidden; position: relative;
  background: var(--surface-alt);
  cursor: crosshair;
  display: flex; align-items: center; justify-content: center;
}
.pb-canvas-wrap.tool-sticker { cursor: default; }
#pb-canvas {
  display: block;
  touch-action: none;
  max-width: 100%; max-height: 100%;
  box-shadow: 0 4px 24px rgba(0,0,0,.22);
}
.pb-color-btn {
  width: 38px !important; height: 38px !important;
  border-radius: 50% !important;
  border-width: 3px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,.22) !important;
  padding: 0 !important; font-size: 0 !important;
  margin-top: auto !important;
}
.pb-bottom-bar { justify-content: space-between; }

/* ══════════════════════════════════════════════
   MATH GAME
══════════════════════════════════════════════ */
.math-start-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow-y: auto;
}
.math-start-card {
  background: var(--surface); border-radius: var(--r-lg);
  padding: 32px 36px; text-align: center;
  box-shadow: var(--shadow-lg); max-width: 360px; width: 100%;
}
.math-start-card h2 { font-size: 26px; font-weight: 900; color: var(--secondary); margin-bottom: 8px; }
.math-start-card p  { font-size: 15px; color: var(--text-mid); margin-bottom: 20px; }

.math-progress-bar {
  height: 6px; background: var(--border-lt); flex-shrink: 0;
}
.math-progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--secondary), var(--green));
  transition: width .4s ease;
}

.math-hud {
  display: flex; gap: 14px; align-items: center; justify-content: center;
  padding: 10px 16px;
  background: var(--surface); border-bottom: 2px solid var(--border-lt);
  flex-shrink: 0;
}
.math-streak {
  font-size: 20px; font-weight: 900;
  animation: btnBounce .38s cubic-bezier(.36,.07,.19,.97);
}

.math-game {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}
.math-problem-area {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
.math-problem {
  font-size: clamp(40px, 12vw, 80px); font-weight: 900;
  color: var(--text); text-align: center; letter-spacing: 4px;
  animation: popUp .22s cubic-bezier(.36,.07,.19,.97);
}

.math-choices {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; padding: 0 16px 12px;
  flex-shrink: 0;
}
.math-choice-btn {
  padding: 18px 10px;
  background: var(--surface-alt); color: var(--text);
  border: 3px solid var(--border); border-radius: var(--r);
  font-size: clamp(22px, 6vw, 36px); font-weight: 900; font-family: inherit;
  cursor: pointer;
  transition: transform .1s, background .12s, border-color .12s;
  box-shadow: var(--shadow);
}
.math-choice-btn:hover  { background: var(--border-lt); transform: scale(1.04); }
.math-choice-btn:active { transform: scale(.93); }
.math-choice-btn.correct {
  background: #dcfce7; border-color: var(--green); color: #15803d;
  animation: btnBounce .38s cubic-bezier(.36,.07,.19,.97);
}
.math-choice-btn.wrong {
  background: #fee2e2; border-color: var(--primary); color: #b91c1c;
  animation: wrongShake .38s ease-in-out;
}
[data-theme="dark"] .math-choice-btn.correct { background: rgba(34,197,94,.2);   color: #86efac; border-color: var(--green); }
[data-theme="dark"] .math-choice-btn.wrong   { background: rgba(255,107,107,.2); color: #fca5a5; border-color: var(--primary); }

.math-feedback {
  text-align: center; font-size: 18px; font-weight: 800;
  padding: 8px 16px 12px; flex-shrink: 0;
  animation: slideIn .18s ease-out;
}
.math-feedback.correct { color: var(--green); }
.math-feedback.wrong   { color: var(--primary); }

.math-stars { font-size: 32px; margin: 8px 0 16px; letter-spacing: 4px; }

/* ── Utility ───────────────────────────────── */
.hidden { display: none !important; }

/* ── Scrollbar ─────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-lt); }

/* ── Print ─────────────────────────────────── */
@media print {
  .top-bar, .bottom-bar, .sound-btn,
  #confetti-canvas { display: none !important; }
  .colour-canvas-view { display: flex !important; }
  #colour-canvas { max-width: 100% !important; box-shadow: none !important; }
}

/* ── Responsive ────────────────────────────── */
@media (max-width: 480px) {
  :root {
    --topbar:    68px;
    --bottombar: 58px;
    --toolsw:    58px;
  }
  .menu-btn   { min-height: 118px; }
  .menu-icon  { font-size: 38px; }
  .menu-label { font-size: 14px; }
  .tool-btn   { width: 44px; height: 44px; font-size: 19px; }
  .color-swatch { width: 24px; height: 24px; }
  .fun-slider { width: 72px; }
  .win-card   { padding: 28px 24px; }
  .win-card h2 { font-size: 26px; }
  .puzzle-grid { gap: 7px; }
  .color-palette { gap: 4px; }
}
@media (max-width: 360px) {
  :root { --toolsw: 52px; }
  .tool-btn { width: 40px; height: 40px; font-size: 17px; }
}
