/* ============ IQ Game Land — Super Game UI ============ */
:root {
  --bg1: #7c3aed;
  --bg2: #2563eb;
  --card: #ffffff;
  --ink: #2d1b69;
  --sun: #fbbf24;
  --sun2: #f59e0b;
  --green: #22c55e;
  --green2: #16a34a;
  --pink: #ec4899;
  --orange: #fb923c;
  --red: #ef4444;
  --sky: #38bdf8;
  --radius: 22px;
  --shadow: 0 8px 0 rgba(0,0,0,.18), 0 14px 30px rgba(0,0,0,.25);
  --font: 'Noto Serif Lao', 'Noto Sans', serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 55%, #0ea5e9);
  background-attachment: fixed;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* floating decorative bubbles behind everything */
.bubbles { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.bubbles span {
  position: absolute; bottom: -12vh;
  border-radius: 50%;
  background: rgba(255,255,255,.10);
  animation: floatUp linear infinite;
}
@keyframes floatUp {
  to { transform: translateY(-125vh) rotate(40deg); }
}

#app { position: relative; z-index: 1; max-width: 560px; margin: 0 auto; min-height: 100dvh; padding: 12px 14px 28px; }

.screen { display: none; animation: screenIn .35s cubic-bezier(.2,1.4,.4,1); }
.screen.active { display: block; }
@keyframes screenIn {
  from { opacity: 0; transform: translateY(24px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0 14px;
}
.topbar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.92);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 700; font-size: 15px;
  box-shadow: 0 4px 0 rgba(0,0,0,.15);
}
.chip .em { font-size: 18px; }

.icon-btn {
  width: 46px; height: 46px; flex: none;
  border: none; border-radius: 16px;
  background: rgba(255,255,255,.92);
  font-size: 22px; cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,.18);
  transition: transform .1s;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font);
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.icon-btn.off { opacity: .45; filter: grayscale(1); }

/* ---------- hero / title ---------- */
.hero { text-align: center; padding: 6px 0 4px; }
.hero h1 {
  margin: 0;
  font-size: clamp(34px, 9vw, 46px);
  color: #fff;
  letter-spacing: 1px;
  text-shadow: 0 3px 0 #b45309, 0 6px 0 rgba(0,0,0,.25), 0 12px 24px rgba(0,0,0,.3);
  animation: titleBounce 2.6s ease-in-out infinite;
}
.hero h1 .hl { color: var(--sun); }
@keyframes titleBounce {
  0%, 100% { transform: scale(1) rotate(-1deg); }
  50% { transform: scale(1.04) rotate(1deg); }
}
.hero p { margin: 6px 0 0; color: rgba(255,255,255,.9); font-size: 16px; font-weight: 600; }

/* ---------- big juicy buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: none; cursor: pointer;
  font-family: var(--font); font-weight: 800;
  border-radius: var(--radius);
  transition: transform .1s, filter .15s;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,.2);
}
.btn:active { transform: translateY(4px) scale(.98); }
.btn-primary {
  background: linear-gradient(180deg, #4ade80, var(--green2));
  box-shadow: 0 7px 0 #15803d, 0 14px 24px rgba(0,0,0,.3);
  font-size: 24px; padding: 16px 40px;
}
.btn-primary:active { box-shadow: 0 2px 0 #15803d; }
.btn-sun {
  background: linear-gradient(180deg, #fcd34d, var(--sun2));
  box-shadow: 0 6px 0 #b45309;
  color: #78350f; text-shadow: none;
  font-size: 19px; padding: 13px 30px;
}
.btn-sun:active { box-shadow: 0 2px 0 #b45309; }
.btn-ghost {
  background: rgba(255,255,255,.2);
  box-shadow: 0 5px 0 rgba(0,0,0,.2);
  font-size: 17px; padding: 12px 24px;
}
.btn-block { width: 100%; }

/* ---------- profile screen ---------- */
.card {
  background: var(--card);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 22px 20px;
}
.profile-card { margin-top: 12px; text-align: center; }
.profile-card h2 { margin: 0 0 14px; font-size: 22px; }
.avatar-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;
  margin: 12px 0 18px;
}
.avatar-grid button {
  aspect-ratio: 1; border: 3px solid transparent; border-radius: 18px;
  background: #f1f5f9; font-size: 30px; cursor: pointer;
  transition: transform .12s, border-color .12s, background .12s;
}
.avatar-grid button:active { transform: scale(.9); }
.avatar-grid button.sel {
  border-color: var(--green);
  background: #dcfce7;
  transform: scale(1.12);
  animation: wiggle .4s;
}
@keyframes wiggle {
  25% { transform: scale(1.15) rotate(-8deg); }
  75% { transform: scale(1.15) rotate(8deg); }
}
.name-input {
  width: 100%; padding: 14px 16px;
  border: 3px solid #e2e8f0; border-radius: 18px;
  font-family: var(--font); font-size: 18px; font-weight: 700;
  text-align: center; color: var(--ink);
  outline: none;
}
.name-input:focus { border-color: var(--sky); }

/* ---------- hub: game grid ---------- */
.stats-row { display: flex; gap: 10px; justify-content: center; margin: 4px 0 16px; flex-wrap: wrap; }
.game-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.game-card {
  position: relative;
  border: none; cursor: pointer;
  border-radius: var(--radius);
  padding: 18px 12px 14px;
  font-family: var(--font);
  color: #fff; text-align: center;
  box-shadow: 0 6px 0 rgba(0,0,0,.25), 0 12px 22px rgba(0,0,0,.25);
  transition: transform .12s;
  overflow: hidden;
}
.game-card:active { transform: translateY(4px) scale(.97); }
.game-card .gi {
  font-size: 52px; line-height: 1;
  display: block; margin-bottom: 8px;
  filter: drop-shadow(0 4px 3px rgba(0,0,0,.25));
  animation: iconFloat 3s ease-in-out infinite;
}
@keyframes iconFloat {
  50% { transform: translateY(-6px) rotate(3deg); }
}
.game-card h3 { margin: 0; font-size: 18px; text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.game-card p { margin: 4px 0 8px; font-size: 12.5px; opacity: .92; font-weight: 600; }
.game-card .lvl {
  display: inline-block;
  background: rgba(0,0,0,.22);
  border-radius: 999px; padding: 3px 12px;
  font-size: 13px; font-weight: 800;
}
.game-card .shine {
  position: absolute; top: -60%; left: -30%;
  width: 40%; height: 220%;
  background: rgba(255,255,255,.18);
  transform: rotate(22deg);
  animation: shine 3.5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes shine {
  0%, 60% { left: -45%; } 100% { left: 140%; }
}
.gc-frogs   { background: linear-gradient(160deg, #4ade80, #15803d); }
.gc-triple  { background: linear-gradient(160deg, #fb923c, #c2410c); }
.gc-memory  { background: linear-gradient(160deg, #38bdf8, #1d4ed8); }
.gc-odd     { background: linear-gradient(160deg, #f472b6, #be185d); }
.gc-math    { background: linear-gradient(160deg, #a78bfa, #6d28d9); }
.gc-sequence{ background: linear-gradient(160deg, #facc15, #ca8a04); }
.gc-diff    { background: linear-gradient(160deg, #2dd4bf, #0f766e); }

/* ---------- spot the difference ---------- */
.diff-wrap { display: flex; flex-direction: column; gap: 10px; }
.diff-panel {
  position: relative; width: 100%;
  aspect-ratio: 5 / 3;
  border-radius: 16px; overflow: hidden;
  border: 3px solid #e7e5e4;
  background: #fff;
}
.diff-panel svg { display: block; width: 100%; height: 100%; }
.dring {
  fill: rgba(250, 204, 21, .18);
  stroke: #facc15; stroke-width: 5;
  filter: drop-shadow(0 0 4px rgba(250, 204, 21, .8));
  pointer-events: none;
  animation: dringPop .5s cubic-bezier(.2,2,.4,1);
  transform-box: fill-box; transform-origin: center;
}
@keyframes dringPop {
  from { transform: scale(.3); opacity: 0; }
  60% { transform: scale(1.25); }
  to { transform: scale(1); opacity: 1; }
}
.dring-bad {
  fill: none; stroke: #ef4444; stroke-width: 5;
  pointer-events: none;
  animation: dringBad .5s ease-out forwards;
  transform-box: fill-box; transform-origin: center;
}
@keyframes dringBad {
  from { transform: scale(.5); opacity: 1; }
  to { transform: scale(1.5); opacity: 0; }
}

/* ---------- game screen ---------- */
.game-hud {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.game-stage {
  background: var(--card);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 14px;
  min-height: 380px;
  position: relative;
  overflow: hidden;
}
.hint-bar {
  text-align: center; font-weight: 800; font-size: 17px;
  color: #fff; margin-bottom: 10px;
  text-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.timer-wrap {
  height: 14px; border-radius: 999px;
  background: rgba(0,0,0,.25);
  overflow: hidden; flex: 1; min-width: 90px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.3);
}
.timer-bar {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #4ade80, #fbbf24, #ef4444);
  border-radius: 999px;
  transition: width .3s linear;
}
.timer-wrap.danger .timer-bar { animation: pulse .5s infinite; }
@keyframes pulse { 50% { filter: brightness(1.5); } }

/* ---------- frogs game ---------- */
.frog-scene {
  position: relative; width: 100%;
  border-radius: 18px; overflow: hidden;
  background: #fafaf7;
  aspect-ratio: 3 / 4;
  border: 3px solid #e7e5e4;
}
.frog-scene .decor {
  position: absolute; pointer-events: none;
  filter: grayscale(1) contrast(.75) opacity(.8);
  line-height: 1;
}
.frog-scene .frog {
  position: absolute; cursor: pointer;
  filter: grayscale(1) contrast(.7) opacity(.85);
  line-height: 1;
  border: none; background: none; padding: 4px;
  transition: filter .3s;
}
.frog-scene .frog.found {
  filter: none;
  animation: frogFound .6s cubic-bezier(.2,2,.4,1);
  pointer-events: none;
}
@keyframes frogFound {
  0% { transform: scale(1); }
  40% { transform: scale(1.8) rotate(-12deg); }
  100% { transform: scale(1.25); }
}
.frog-ring {
  position: absolute; border: 4px solid var(--green);
  border-radius: 50%; pointer-events: none;
  animation: ringPop .6s ease-out forwards;
}
@keyframes ringPop {
  from { transform: scale(.4); opacity: 1; }
  to { transform: scale(1.6); opacity: 0; }
}
.miss-x {
  position: absolute; pointer-events: none;
  font-size: 30px; font-weight: 900; color: var(--red);
  animation: missFade .5s ease-out forwards;
}
@keyframes missFade {
  from { transform: scale(.6); opacity: 1; }
  to { transform: scale(1.6) translateY(-16px); opacity: 0; }
}

/* ---------- triple match ---------- */
.triple-board {
  position: relative; width: 100%;
  aspect-ratio: 3.4 / 4; border-radius: 18px;
  background: linear-gradient(180deg, #ecfeff, #cffafe);
  border: 3px solid #a5f3fc;
  overflow: hidden;
}
.tile {
  position: absolute;
  border: none; cursor: pointer;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,.15), 0 5px 10px rgba(0,0,0,.15);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, opacity .3s;
  padding: 0; line-height: 1;
}
.tile:active { transform: scale(.9); }
.tile.dim { filter: brightness(.75) saturate(.6); }
.tray {
  display: flex; gap: 6px; justify-content: center;
  margin-top: 12px;
  background: rgba(0,0,0,.06);
  border-radius: 16px; padding: 8px;
}
.tray .slot {
  width: 44px; height: 44px; border-radius: 12px;
  background: #fff; border: 2px dashed #cbd5e1;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1;
}
.tray .slot.filled { border-style: solid; border-color: var(--sky); animation: slotIn .2s; }
@keyframes slotIn { from { transform: scale(.5); } }

/* ---------- memory ---------- */
.mem-grid { display: grid; gap: 10px; }
.mem-card {
  aspect-ratio: 1; border: none; cursor: pointer;
  perspective: 500px; background: none; padding: 0;
}
.mem-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .4s cubic-bezier(.2,1.4,.4,1);
}
.mem-card.open .mem-inner { transform: rotateY(180deg); }
.mem-face {
  position: absolute; inset: 0;
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-size: clamp(26px, 8vw, 40px);
}
.mem-back {
  background: linear-gradient(160deg, #818cf8, #4f46e5);
  box-shadow: 0 4px 0 #3730a3;
  color: rgba(255,255,255,.9); font-size: 24px;
}
.mem-front {
  background: #fff;
  border: 3px solid #e0e7ff;
  transform: rotateY(180deg);
}
.mem-card.matched .mem-front {
  background: #dcfce7; border-color: var(--green);
  animation: matchPop .5s cubic-bezier(.2,2,.4,1);
}
@keyframes matchPop { 40% { transform: rotateY(180deg) scale(1.15); } }

/* ---------- odd one out / math / sequence share grids ---------- */
.odd-grid { display: grid; gap: 8px; }
.odd-grid button {
  aspect-ratio: 1; border: none; cursor: pointer;
  border-radius: 14px; background: #f8fafc;
  font-size: clamp(22px, 7vw, 36px);
  transition: transform .1s;
  line-height: 1; padding: 0;
}
.odd-grid button:active { transform: scale(.88); }
.odd-grid button.right { background: #dcfce7; animation: matchPop2 .45s; }
.odd-grid button.wrong { background: #fee2e2; animation: shake .35s; }
@keyframes matchPop2 { 40% { transform: scale(1.2); } }
@keyframes shake {
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}

.math-q {
  text-align: center; font-size: clamp(38px, 12vw, 56px);
  font-weight: 900; margin: 24px 0 26px; color: var(--ink);
}
.math-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.math-answers button {
  border: none; cursor: pointer;
  border-radius: 18px; padding: 20px 8px;
  font-family: var(--font); font-size: 28px; font-weight: 900;
  background: linear-gradient(180deg, #e0f2fe, #bae6fd);
  color: #0c4a6e;
  box-shadow: 0 5px 0 #7dd3fc;
  transition: transform .1s;
}
.math-answers button:active { transform: translateY(3px); }
.math-answers button.right { background: linear-gradient(180deg, #bbf7d0, #86efac); box-shadow: 0 5px 0 #4ade80; }
.math-answers button.wrong { background: linear-gradient(180deg, #fecaca, #fca5a5); box-shadow: 0 5px 0 #f87171; animation: shake .35s; }

.seq-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 340px; margin: 10px auto; }
.seq-pad {
  aspect-ratio: 1; border: none; cursor: pointer;
  border-radius: 22px; font-size: 44px;
  opacity: .85; transition: transform .1s, filter .1s, opacity .1s;
  box-shadow: 0 6px 0 rgba(0,0,0,.25);
}
.seq-pad:active { transform: translateY(3px); }
.seq-pad.lit { opacity: 1; filter: brightness(1.35) saturate(1.3); transform: scale(1.07); }
.seq-status { text-align: center; font-size: 19px; font-weight: 800; margin: 10px 0; min-height: 28px; }

/* ---------- results overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: center; justify-content: center;
  background: rgba(15, 8, 50, .55);
  backdrop-filter: blur(4px);
  padding: 20px;
}
.overlay.show { display: flex; }
.result-card {
  background: linear-gradient(180deg, #fff, #f0f9ff);
  border-radius: 30px;
  padding: 28px 24px;
  width: 100%; max-width: 380px;
  text-align: center;
  box-shadow: 0 10px 0 rgba(0,0,0,.2), 0 24px 60px rgba(0,0,0,.4);
  animation: popIn .45s cubic-bezier(.2,1.6,.4,1);
}
@keyframes popIn {
  from { transform: scale(.5) translateY(60px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.result-card h2 { margin: 0 0 4px; font-size: 30px; }
.result-stars { font-size: 46px; letter-spacing: 6px; margin: 10px 0; }
.result-stars .on { animation: starIn .5s cubic-bezier(.2,2,.4,1) backwards; display: inline-block; }
.result-stars .on:nth-child(2) { animation-delay: .18s; }
.result-stars .on:nth-child(3) { animation-delay: .36s; }
.result-stars .offs { opacity: .25; filter: grayscale(1); }
@keyframes starIn {
  from { transform: scale(0) rotate(-120deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.result-nums {
  display: flex; justify-content: center; gap: 18px;
  margin: 12px 0 20px; font-weight: 800; font-size: 16px;
  color: #475569; flex-wrap: wrap;
}
.result-nums b { color: var(--ink); font-size: 20px; display: block; }
.result-actions { display: flex; flex-direction: column; gap: 10px; }

/* ---------- leaderboard ---------- */
.lb-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.lb-row {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 16px;
  padding: 10px 14px; font-weight: 700;
  box-shadow: 0 3px 0 rgba(0,0,0,.12);
}
.lb-row .rank { width: 30px; text-align: center; font-size: 18px; }
.lb-row .av { font-size: 26px; }
.lb-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .pts { color: var(--sun2); }
.lb-row:nth-child(1) { background: linear-gradient(90deg, #fef9c3, #fff); }
.lb-row:nth-child(2) { background: linear-gradient(90deg, #f1f5f9, #fff); }
.lb-row:nth-child(3) { background: linear-gradient(90deg, #ffedd5, #fff); }

/* ---------- confetti ---------- */
.confetti {
  position: fixed; z-index: 60; top: -20px;
  pointer-events: none;
  animation: confFall linear forwards;
}
@keyframes confFall {
  to { transform: translateY(115vh) rotate(720deg); opacity: .9; }
}

/* floating score popup */
.float-score {
  position: fixed; z-index: 55; pointer-events: none;
  font-weight: 900; font-size: 26px; color: var(--sun);
  text-shadow: 0 2px 0 rgba(0,0,0,.4);
  animation: floatScore .8s ease-out forwards;
}
@keyframes floatScore {
  from { transform: translateY(0) scale(.7); opacity: 1; }
  to { transform: translateY(-70px) scale(1.2); opacity: 0; }
}

.center { text-align: center; }
.mt { margin-top: 14px; }
.white { color: #fff; }

@media (min-width: 480px) {
  .game-grid { gap: 16px; }
}
