/* ═══════════════════════════════════════════════════
   PIXEL REVEAL · style.css
   Fantasy math game for ages 5–7
═══════════════════════════════════════════════════ */

/* ── Design Tokens ───────────────────────────────── */
:root {
  --bg:          #FFF8F0;
  --tile:        #A0C4FF;
  --tile-bd:     #7BA7D9;
  --btn-a:       #B5EAD7;
  --btn-a-sh:    #7DC9A8;
  --btn-b:       #FFB7B2;
  --btn-b-sh:    #D98880;
  --btn-c:       #C7CEEA;
  --btn-c-sh:    #9FA8BE;
  --correct:     #55EFC4;
  --gold:        #FDCB6E;
  --purple:      #A29BFE;
  --purple-sh:   #7B67D9;
  --pink:        #FD79A8;
  --text:        #2D3436;
  --muted:       #888;
  --shadow:      rgba(0,0,0,0.13);
  --radius:      22px;
  --radius-sm:   12px;
  --font:        'Nunito', 'Arial Rounded MT Bold', sans-serif;
}

/* ── Reset ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

/* ═══════════════════════════════════════════════════
   SCREEN SYSTEM
═══════════════════════════════════════════════════ */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  overflow: hidden;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* ═══════════════════════════════════════════════════
   SHARED COMPONENTS
═══════════════════════════════════════════════════ */

/* Buttons */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-weight: 800;
  line-height: 1;
  transition: transform 0.08s, box-shadow 0.08s;
  white-space: nowrap;
}
button:active { transform: translateY(3px) scale(0.97); }

.btn-primary {
  background: var(--purple);
  color: #fff;
  font-size: 1.25rem;
  padding: 16px 38px;
  box-shadow: 0 6px 0 var(--purple-sh), 0 8px 20px var(--shadow);
}
.btn-primary:active { box-shadow: 0 2px 0 var(--purple-sh); }

.btn-ghost {
  background: #fff;
  color: var(--purple);
  font-size: 1rem;
  padding: 13px 28px;
  box-shadow: 0 4px 0 #ddd, 0 6px 16px var(--shadow);
  border: 2.5px solid var(--purple);
}
.btn-ghost:active { box-shadow: 0 1px 0 #ddd; }

.btn-back {
  background: #fff;
  color: var(--text);
  font-size: 1.2rem;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  box-shadow: 0 4px 14px var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px 8px;
  width: 100%;
  max-width: 580px;
}
.top-bar-title {
  font-size: 1.4rem;
  font-weight: 900;
  flex: 1;
  text-align: center;
}
.top-bar-spacer { width: 46px; flex-shrink: 0; }

/* ═══════════════════════════════════════════════════
   SCREEN 1 · HOME
═══════════════════════════════════════════════════ */
#screen-home {
  justify-content: center;
  background: linear-gradient(155deg, #FFF1E0 0%, #EEF4FF 60%, #F5E6FF 100%);
}

/* Floating decorations */
.home-bg-deco { position: absolute; inset: 0; pointer-events: none; }
.deco {
  position: absolute;
  font-size: 2rem;
  opacity: 0.18;
  animation: float-slow 6s ease-in-out infinite;
}
.d1 { top: 8%;  left: 8%;  animation-delay: 0s;   font-size: 1.6rem; }
.d2 { top: 14%; right: 10%; animation-delay: 1.5s; font-size: 2.4rem; }
.d3 { bottom: 22%; left: 6%; animation-delay: 3s;  font-size: 2.2rem; }
.d4 { bottom: 12%; right: 8%; animation-delay: 0.8s; font-size: 1.8rem; }
.d5 { top: 50%; right: 5%; animation-delay: 2.2s; font-size: 1.5rem; }

@keyframes float-slow {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%       { transform: translateY(-14px) rotate(8deg); }
}

.home-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 36px;
  z-index: 1;
  padding: 20px;
}

.logo { text-align: center; }

.logo-emoji {
  font-size: 4.5rem;
  display: block;
  animation: bounce-float 2.8s ease-in-out infinite;
}
@keyframes bounce-float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-12px); }
}

.logo-title {
  font-size: clamp(2.4rem, 8vw, 3.4rem);
  font-weight: 900;
  background: linear-gradient(130deg, var(--purple) 0%, var(--pink) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  margin-top: 4px;
}

.logo-tagline {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 700;
  margin-top: 8px;
  letter-spacing: 0.3px;
}

.home-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Collection Book icon inside the ghost button */
.book-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 4px;
  margin-top: -2px;
}

/* ═══════════════════════════════════════════════════
   SCREEN 2 · LEVEL SELECT
═══════════════════════════════════════════════════ */
#screen-levels { background: var(--bg); justify-content: flex-start; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 8px 18px 24px;
  width: 100%;
  max-width: 580px;
  overflow-y: auto;
}

.level-card {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 6px 12px;
  text-align: center;
  box-shadow: 0 4px 14px var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  aspect-ratio: 1;
  justify-content: center;
}
.level-card:not(.locked):hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 24px var(--shadow);
}
.level-card:not(.locked):active { transform: scale(0.95); }

.level-card.locked {
  opacity: 0.45;
  cursor: not-allowed;
  background: #f5f5f5;
}

.lc-num {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--purple);
  line-height: 1;
}
.lc-emoji { font-size: 1.5rem; line-height: 1; }
.lc-stars { font-size: 0.62rem; min-height: 14px; }

/* ═══════════════════════════════════════════════════
   SCREEN 3 · GAME
═══════════════════════════════════════════════════ */
#screen-game {
  justify-content: flex-start;
  background: var(--bg);
}

/* HUD */
.game-hud {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 6px;
  width: 100%;
  max-width: 560px;
}
.hud-level {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hud-progress {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  background: #fff;
  padding: 5px 14px;
  border-radius: 20px;
  box-shadow: 0 2px 8px var(--shadow);
  white-space: nowrap;
}

/* Game area */
.game-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 6px 14px;
  min-height: 0;
}

/* Image + tile container */
.image-container {
  position: relative;
  /* clamp: no smaller than 200px, no bigger than 360px, responsive to viewport */
  width: min(360px, 88vw, calc(100dvh - 280px));
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 36px var(--shadow);
}

.reveal-image {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  border-radius: inherit;
}

.tile-grid {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 0;      /* no gap — prevents image bleeding through seams */
  padding: 0;
}

/* Individual tile — uses Ludo tile-cover asset, falls back to CSS colour */
.tile {
  background-color: var(--tile);
  background-image: url('assets/images/tile-cover.png');
  background-size: 55%;
  background-position: center;
  background-repeat: no-repeat;
  /* subtle white inner border gives tile separation without creating a gap */
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.45);
  position: relative;
  overflow: hidden;
  /* 3D flip setup */
  transform-origin: center center;
  backface-visibility: hidden;
}

/* ── Flip animation: tile rotates on Y-axis and vanishes at the 90° edge ── */
.tile.flipping {
  animation: tile-flip 0.42s ease-in forwards;
}

@keyframes tile-flip {
  0%   { transform: perspective(600px) rotateY(0deg);  opacity: 1; }
  48%  { transform: perspective(600px) rotateY(88deg); opacity: 1; }
  50%  { transform: perspective(600px) rotateY(90deg); opacity: 0; }
  100% { transform: perspective(600px) rotateY(90deg); opacity: 0; }
}

.tile.revealed {
  opacity: 0;
  pointer-events: none;
  transition: none;
}

/* Question area */
.question-area {
  width: 100%;
  max-width: 560px;
  padding: 6px 16px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.question-display {
  font-size: clamp(1.6rem, 5vw, 2rem);
  font-weight: 900;
  text-align: center;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  line-height: 1.2;
}

.q-stars {
  letter-spacing: 3px;
  font-size: clamp(1.3rem, 4vw, 1.7rem);
}
.q-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  display: block;
  margin-bottom: 2px;
}

/* Answer buttons row */
.answer-row {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
}

.ans-btn {
  flex: 1;
  max-width: 120px;
  min-height: 80px;
  font-size: clamp(1.6rem, 5vw, 2rem);
  font-weight: 900;
  border-radius: var(--radius);
  border: none;
  color: var(--text);
  transition: transform 0.08s, box-shadow 0.08s;
  cursor: pointer;
}
.ans-btn:nth-child(1) { background: var(--btn-a); box-shadow: 0 5px 0 var(--btn-a-sh), 0 6px 16px var(--shadow); }
.ans-btn:nth-child(2) { background: var(--btn-b); box-shadow: 0 5px 0 var(--btn-b-sh), 0 6px 16px var(--shadow); }
.ans-btn:nth-child(3) { background: var(--btn-c); box-shadow: 0 5px 0 var(--btn-c-sh), 0 6px 16px var(--shadow); }
.ans-btn:active { transform: translateY(4px); }

/* Answer animations */
@keyframes ans-correct {
  0%   { transform: scale(1);    background-color: inherit; }
  25%  { transform: scale(1.18); background-color: var(--correct); }
  70%  { transform: scale(1.05); }
  100% { transform: scale(1);    background-color: inherit; }
}
@keyframes ans-shake {
  0%, 100% { transform: translateX(0); }
  18%       { transform: translateX(-8px); }
  36%       { transform: translateX(8px); }
  54%       { transform: translateX(-5px); }
  72%       { transform: translateX(5px); }
}

.ans-btn.anim-correct { animation: ans-correct 0.45s ease forwards; }
.ans-btn.anim-shake   { animation: ans-shake   0.42s ease; }

/* ═══════════════════════════════════════════════════
   SCREEN 4 · WIN
═══════════════════════════════════════════════════ */
#screen-win {
  justify-content: center;
  background: linear-gradient(155deg, #FFF1E0 0%, #EEF4FF 60%, #F5E6FF 100%);
}

/* Confetti layer */
.confetti-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.cf {
  position: absolute;
  top: -24px;
  border-radius: 2px;
  animation: cf-fall linear forwards;
}
@keyframes cf-fall {
  0%   { transform: translateY(0)      rotate(0deg);   opacity: 1; }
  90%  { opacity: 1; }
  100% { transform: translateY(110vh)  rotate(800deg); opacity: 0; }
}

/* Win content */
.win-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  z-index: 1;
  padding: 16px 20px;
  width: 100%;
  max-width: 480px;
}

.win-title {
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  font-weight: 900;
  background: linear-gradient(130deg, var(--purple), var(--pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}

.win-image {
  width: min(240px, 62vw);
  aspect-ratio: 1;
  border-radius: var(--radius);
  box-shadow: 0 12px 42px var(--shadow);
  background-size: cover;
  background-position: center;
  animation: win-img-pop 0.5s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes win-img-pop {
  0%   { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}

.win-stars {
  display: flex;
  gap: 10px;
  font-size: 2.2rem;
}
.ws {
  display: inline-block;
  opacity: 0.18;
  transform: scale(0.6);
  transition: opacity 0.25s, transform 0.25s;
}
.ws.earned {
  opacity: 1;
  transform: scale(1);
  animation: star-pop 0.5s cubic-bezier(0.34,1.56,0.64,1) forwards;
}
@keyframes star-pop {
  0%   { transform: scale(0.4) rotate(-15deg); opacity: 0; }
  60%  { transform: scale(1.3) rotate(5deg);  opacity: 1; }
  100% { transform: scale(1)   rotate(0deg);  opacity: 1; }
}

.win-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.win-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ═══════════════════════════════════════════════════
   SCREEN 5 · COLLECTION BOOK
═══════════════════════════════════════════════════ */
#screen-collection { background: var(--bg); justify-content: flex-start; }

.collection-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 8px 18px 24px;
  width: 100%;
  max-width: 560px;
  overflow-y: auto;
}

.coll-card {
  border-radius: var(--radius-sm);
  aspect-ratio: 1;
  overflow: hidden;
  box-shadow: 0 4px 16px var(--shadow);
  position: relative;
  background: #ebebeb;
  cursor: default;
}
.coll-card.earned {
  background-size: cover;
  background-position: center;
  cursor: pointer;
}
.coll-card.locked-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  color: #bbb;
}
.coll-card.locked-slot .lock-icon { font-size: 1.8rem; }
.coll-card .coll-label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.48);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  text-align: center;
  padding: 4px 2px;
  line-height: 1.2;
}
.coll-card.earned .coll-stars {
  position: absolute;
  top: 4px; right: 6px;
  font-size: 0.7rem;
}

/* ═══════════════════════════════════════════════════
   IMAGE GRADIENT PLACEHOLDERS  (fallback when PNG absent)
   Applied by JS via class name — colours match each character
═══════════════════════════════════════════════════ */
.img-baby-panda     { background: linear-gradient(135deg,#f0f0f0,#e0e8f4); }
.img-bunny          { background: linear-gradient(135deg,#FFE8EE,#FFC8D8); }
.img-penguin        { background: linear-gradient(135deg,#D4EEFF,#A8CCE8); }
.img-dolphin        { background: linear-gradient(135deg,#A8D8EA,#7CB9D4); }
.img-fox            { background: linear-gradient(135deg,#FFD4A3,#FF9A56); }
.img-elephant       { background: linear-gradient(135deg,#D8D8D8,#B0B8C4); }
.img-castle         { background: linear-gradient(135deg,#FFD3E0,#FFB6C8); }
.img-unicorn        { background: linear-gradient(135deg,#FFE29F,#FFA99F 50%,#A18CD1); }
.img-dragon-baby    { background: linear-gradient(135deg,#A8EDEA,#B8A0DC); }
.img-dragon-sparkle { background: linear-gradient(135deg,#84FAB0,#FFE08A 50%,#FFA99F); }

/* ═══════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════ */
@media (min-width: 600px) {
  .image-container { width: min(400px, 80vw, calc(100dvh - 260px)); }
  .ans-btn { min-height: 90px; max-width: 140px; }
  .level-grid { gap: 14px; }
}
@media (min-width: 900px) {
  .image-container { width: min(460px, 70vw, calc(100dvh - 240px)); }
  .ans-btn { max-width: 160px; }
  .question-display { font-size: 2.2rem; }
}
/* Landscape phones: shrink grid so question area stays visible */
@media (max-height: 520px) {
  .image-container { width: min(220px, 40vh); }
  .question-display { font-size: 1.3rem; min-height: 38px; }
  .ans-btn { min-height: 62px; font-size: 1.4rem; }
}
