/* =========================================================
   Hanvi's Fun Games – one fixed screen per page, fits every
   phone / iPad / desktop in portrait and landscape.
   ========================================================= */
:root {
  --bg: #fff8e7;
  --ink: #3b2f5c;
  --pink: #ff7aa2;
  --green: #4cc9a0;
  --blue: #6c8cff;
  --yellow: #ffd166;
  --shadow: 0 6px 0 rgba(59, 47, 92, 0.15);
  --gap: clamp(8px, 2vmin, 20px);
  --btn: 52px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-touch-callout: none;   /* no iOS long-press menu */
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* The page itself never moves: no scroll, no bounce, no zoom. */
html, body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  font-family: "Comic Sans MS", "Chalkboard SE", "Marker Felt", "Trebuchet MS", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
.hidden { display: none !important; }

/* ---------- Top bar (game pages) ---------- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  position: relative;
  z-index: 10;
}
.topbar h1 {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: clamp(1rem, 4.5vw, 2rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex: none;
  width: var(--btn);
  height: var(--btn);
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: calc(var(--btn) * 0.5);
  display: grid;
  place-items: center;
  text-decoration: none;
}
.icon-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(59, 47, 92, 0.15); }

.home-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--btn);
  padding: 0 16px;
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font-size: calc(var(--btn) * 0.4);
  font-weight: bold;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 6px 0 #e0a92e;
}
.home-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #e0a92e; }

/* Short screens (phones in landscape): smaller bar */
@media (max-height: 500px) {
  :root { --btn: 42px; }
  .topbar { padding: 6px 12px; }
}

/* ---------- Site shell (index.html): frame + music button ---------- */
.shell { padding: 0; }
.shell iframe {
  position: fixed;
  top: var(--safe-t);
  left: var(--safe-l);
  width: calc(100% - var(--safe-l) - var(--safe-r));
  height: calc(100% - var(--safe-t) - var(--safe-b));
  border: 0;
  display: block;
}
.music-btn {
  position: fixed;
  left: calc(12px + var(--safe-l));
  bottom: calc(12px + var(--safe-b));
  z-index: 60;
  --btn: 46px;
}
.music-btn.off { opacity: 0.6; }

/* ---------- Home page ---------- */
.hero { flex: none; text-align: center; padding: clamp(8px, 3vmin, 32px) 16px clamp(4px, 1vmin, 8px); }
.hero h1 {
  font-size: clamp(1.7rem, min(8vw, 8vh), 3.8rem);
  color: #ff5d8f;
  text-shadow: 3px 3px 0 var(--yellow);
}
.hero p { font-size: clamp(1rem, min(4vw, 3.5vh), 1.4rem); margin-top: 4px; }

.games {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);        /* portrait: 2 across, 4 rows */
  grid-auto-rows: 1fr;
  gap: var(--gap);
  padding: var(--gap) 16px calc(var(--gap) + 58px);   /* bottom room for the music button */
}
.game-card {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 22px;
  color: #fff;
  text-align: center;
  line-height: 1.1;
  text-decoration: none;
  font-size: clamp(0.95rem, min(4.6vw, 3vh), 1.8rem);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
  transition: transform 0.15s;
}
.game-card .emoji { font-size: clamp(1.8rem, min(12vw, 8vh), 5rem); line-height: 1; }
.game-card:active { transform: translateY(4px); }
.c1 { background: var(--pink); }
.c2 { background: var(--green); }
.c3 { background: var(--blue); }
.c4 { background: #ff9f43; }
.c5 { background: #a66cff; }
.c6 { background: #2bb3d9; }
.c7 { background: #34b56f; }
.c8 { background: #ff6b81; }

@media (orientation: landscape) {
  .games {
    grid-template-columns: repeat(4, 1fr);      /* landscape: 4 across, 2 rows */
    max-width: 1100px;
    padding-bottom: var(--gap);
    padding-left: calc(16px + 58px);
    padding-right: calc(16px + 58px);
  }
  .game-card { font-size: clamp(0.9rem, min(2.4vw, 4.5vh), 1.7rem); }
  .game-card .emoji { font-size: clamp(1.8rem, min(8vw, 14vh), 5rem); }
}

/* ---------- Start / win overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: min(24px, 3.5vh);
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  text-align: center;
  background: rgba(255, 248, 231, 0.97);
}
.overlay .emoji { font-size: min(7rem, 20vmin); line-height: 1.1; animation: bounce 1.2s infinite; }
.overlay h2 { font-size: clamp(1.4rem, min(7vw, 7vh), 2.8rem); }

.big-btn {
  background: var(--green);
  color: #fff;
  font-size: clamp(1.3rem, min(6vw, 6vh), 2rem);
  padding: min(18px, 2.5vh) 48px;
  border-radius: 999px;
  box-shadow: 0 8px 0 #2f9c79;
}
.big-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 #2f9c79; }

/* ---------- Confetti ---------- */
.confetti {
  position: fixed;
  top: -20px;
  width: 12px;
  height: 16px;
  z-index: 100;
  pointer-events: none;
  border-radius: 3px;
  animation: fall linear forwards;
}

@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
@keyframes wobble {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-10deg); }
  40% { transform: rotate(10deg); }
  60% { transform: rotate(-6deg); }
  80% { transform: rotate(6deg); }
}
@keyframes grow { 50% { transform: scale(1.2); } }

/* ---------- Balloon Pop ---------- */
.sky {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(#8fd3ff, #dff4ff);
}
.balloons-page .topbar { position: fixed; top: var(--safe-t); left: var(--safe-l); right: var(--safe-r); }
.score {
  position: fixed;
  bottom: calc(12px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: #fff;
  padding: 6px 24px;
  border-radius: 999px;
  font-size: clamp(1.3rem, min(6vw, 6vh), 2rem);
  box-shadow: var(--shadow);
  pointer-events: none;
}
.balloon-wrap { position: absolute; left: 0; top: 0; will-change: transform; cursor: pointer; padding-bottom: 60px; }
.balloon {
  position: relative;
  width: var(--s);
  height: calc(var(--s) * 1.2);
  border-radius: 50% 50% 48% 48% / 55% 55% 45% 45%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.65) 0 11%, transparent 12%),
    var(--c);
}
.balloon::before {               /* knot */
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 10px solid var(--c);
}
.balloon::after {                /* string */
  content: "";
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  width: 2px;
  height: 50px;
  background: rgba(0, 0, 0, 0.25);
}
.balloon.popped { animation: popped 0.25s forwards; }
@keyframes popped { to { transform: scale(1.6); opacity: 0; } }

/* ---------- Animal Match ---------- */
.level { flex: none; text-align: center; font-size: clamp(1rem, 3vh, 1.4rem); }
.board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gap) var(--gap) calc(var(--gap) + 50px);  /* bottom room for the music button */
}
.board { display: grid; gap: var(--gap); --cw: 100px; }
.card { width: var(--cw); height: calc(var(--cw) * 4 / 3); padding: 0; perspective: 800px; }
.card .inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.4s;
  transform-style: preserve-3d;
}
.card.flipped .inner { transform: rotateY(180deg); }
.card .face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: calc(var(--cw) * 0.15);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.15);
}
.card .front {
  background: var(--blue) radial-gradient(circle, rgba(255, 255, 255, 0.25) 2px, transparent 3px) 0 0 / 16px 16px;
  font-size: calc(var(--cw) * 0.4);
}
.card .back { background: #fff; transform: rotateY(180deg); font-size: calc(var(--cw) * 0.6); }
.card.matched .back { background: #d6ffe9; }
.card.matched .inner { animation: matched 0.5s 0.4s; }
@keyframes matched { 50% { transform: rotateY(180deg) scale(1.12); } }

/* ---------- Find the Color ---------- */
.prompt {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: min(12px, 1.5vh) 16px;
  font-size: clamp(1.5rem, min(8vw, 7vh), 3.2rem);
}
.prompt .word {
  text-shadow: 2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink);
}
.choices {
  flex: 1;
  min-height: 0;
  display: grid;
  align-content: center;
  justify-content: center;
  gap: var(--gap);
  padding: var(--gap);
  --size: 120px;
}
.choice {
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2);
}
.choice:active { transform: translateY(4px); }
.choice.wrong { animation: wobble 0.5s; }
.choice.right { animation: grow 0.6s; }
.stars {
  flex: none;
  text-align: center;
  font-size: clamp(1.1rem, min(6vw, 5vh), 2.2rem);
  min-height: 1.5em;
  letter-spacing: 2px;
  padding: 0 64px min(12px, 2vh);    /* side room for the music button */
  white-space: nowrap;
}

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