/* styles.css — custom styling beyond Tailwind utilities: the game shell, the
   number pad, and the structural fixes for the four documented mobile bugs.
   Palette mirrors the Tailwind config (ink/surface/primary/...). */

:root {
  --ink: #0f0b1e;
  --surface: #1a1330;
  --surface2: #241a40;
  --primary: #22d3ee;
  --secondary: #facc15;
  --success: #a3e635;
  --danger: #ec4899;
  --muted: #9a8fc0;
  /* Per-kid accent — overridden inline on themed containers. */
  --accent: #22d3ee;
  --accent-ink: #0f0b1e;
}

* {
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior-y: none;
}

/* ====================================================================== */
/*  Shared game shell                                                      */
/*  Bug #1: header + progress are normal-flow blocks ABOVE the play area,  */
/*          never overlaid on it.                                          */
/*  Bug #4: 100dvh (not 100vh) + safe-area top padding so mobile chrome    */
/*          never clips the question.                                      */
/* ====================================================================== */
.game-root {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: radial-gradient(
      130% 100% at 50% 0%,
      var(--surface) 0%,
      var(--ink) 60%
    )
    fixed;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}

.header-strip {
  flex: 0 0 auto;
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  text-align: center;
}
.header-strip .question {
  font-family: "Space Grotesk", Inter, sans-serif;
  font-weight: 700;
  font-size: clamp(1.75rem, 8vw, 3rem);
  line-height: 1.1;
  white-space: nowrap; /* never wrap mid-formula */
  color: #fff;
  text-shadow: 0 2px 18px rgba(34, 211, 238, 0.25);
}

.progress-strip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 1rem 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.progress-strip .chips {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}
.progress-strip b {
  color: #fff;
  font-weight: 700;
}
.progress-strip .mode-name {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.play-area {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  margin: 0 0.5rem;
  border-radius: 1.25rem;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.pad-slot {
  flex: 0 0 auto;
  padding: 0.5rem 0.5rem 0;
}

.quit-btn {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-weight: 700;
  min-height: 36px;
}
.quit-btn:hover {
  background: rgba(236, 72, 153, 0.2);
  color: #fff;
}

/* ====================================================================== */
/*  Number pad                                                             */
/*  Bug #2: the input is inputmode=none + readonly so the OS keyboard      */
/*          never opens; the pad is the only input method.                 */
/* ====================================================================== */
.answer-display {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  margin: 0 auto 0.5rem;
  max-width: 360px;
  font-size: 2.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 1rem;
  color: #fff;
  caret-color: transparent;
}
.answer-display.flash-correct {
  animation: flashGood 0.45s ease;
}
.answer-display.flash-wrong {
  animation: flashBad 0.45s ease;
}
@keyframes flashGood {
  0% { background: var(--success); color: var(--ink); transform: scale(1.04); }
  100% { background: var(--surface); }
}
@keyframes flashBad {
  0% { background: var(--danger); color: #fff; transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
  100% { background: var(--surface); transform: translateX(0); }
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  max-width: 360px;
  margin: 0 auto;
}
.numpad button {
  min-height: 56px;
  min-width: 56px;
  font-size: 1.5rem;
  font-weight: 700;
  border-radius: 1rem;
  background: var(--surface2);
  color: #fff;
  touch-action: manipulation;
  user-select: none;
  transition: transform 0.05s ease, background 0.1s ease;
}
.numpad button:active {
  transform: scale(0.94);
  background: var(--accent);
  color: var(--accent-ink);
}
.numpad button.key-enter {
  background: var(--accent);
  color: var(--accent-ink);
}
.numpad button.key-back {
  background: rgba(255, 255, 255, 0.08);
}

/* ====================================================================== */
/*  auto-grid                                                              */
/*  Bug #3: cards lay out in a fluid grid that collapses to one column on  */
/*          narrow phones so formula text never wraps mid-card.            */
/* ====================================================================== */
.auto-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
@media (max-width: 480px) {
  .auto-grid {
    grid-template-columns: 1fr;
  }
}

/* ====================================================================== */
/*  Generic component helpers                                              */
/* ====================================================================== */
.card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 1.25rem;
}
.btn-primary {
  background: var(--primary);
  color: var(--ink);
  font-weight: 800;
  border-radius: 1rem;
  min-height: 56px;
  transition: filter 0.1s ease, transform 0.05s ease;
}
.btn-primary:active {
  transform: scale(0.98);
}
.btn-primary:hover {
  filter: brightness(1.08);
}
.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-weight: 700;
  border-radius: 1rem;
  min-height: 48px;
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
}
.input {
  width: 100%;
  background: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1rem;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  color: #fff;
  outline: none;
}
.input:focus {
  border-color: var(--accent);
}

/* ====================================================================== */
/*  Whack-a-mole                                                           */
/* ====================================================================== */
.mole-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(6px, 2vw, 14px);
  width: 100%;
  height: 100%;
  padding: clamp(8px, 3vw, 18px);
}
.hole {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  border-radius: 999px / 60%;
  background: radial-gradient(
    ellipse at 50% 120%,
    #0a0716 0%,
    #150f28 55%,
    transparent 75%
  );
}
.hole::after {
  /* the dirt rim at the front of the hole */
  content: "";
  position: absolute;
  bottom: 0;
  left: 6%;
  right: 6%;
  height: 26%;
  border-radius: 50%;
  background: linear-gradient(#2a1f4a, #1a1330);
  z-index: 2;
}
.mole {
  width: 76%;
  height: 78%;
  border-radius: 44% 44% 40% 40%;
  background: radial-gradient(circle at 50% 35%, var(--accent), #0b8aa3 90%);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.5rem, 7vw, 2.5rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transform: translateY(115%);
  transition: transform 0.16s cubic-bezier(0.25, 0.9, 0.35, 1.2);
  box-shadow: inset 0 -8px 14px rgba(0, 0, 0, 0.25);
  touch-action: manipulation;
  user-select: none;
}
.hole.up .mole {
  transform: translateY(8%);
}
.hole.bonk .mole {
  animation: bonk 0.25s ease;
}
@keyframes bonk {
  0% { transform: translateY(8%) scale(1); }
  50% { transform: translateY(40%) scale(0.85); }
  100% { transform: translateY(115%); }
}

/* ====================================================================== */
/*  Space invaders                                                         */
/* ====================================================================== */
.invader-fleet {
  position: absolute;
  inset: 0;
  transform: translateY(-6%);
  will-change: transform;
}
.invader-fleet.marching {
  transform: translateY(82%);
  transition: transform var(--march, 7000ms) linear;
}
.invader {
  position: absolute;
  top: 4px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  touch-action: manipulation;
  user-select: none;
}
.invader .ufo {
  font-size: clamp(1.8rem, 8vw, 2.75rem);
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(34, 211, 238, 0.35));
  animation: hover 0.9s ease-in-out infinite alternate;
}
.invader .ival {
  font-weight: 800;
  font-size: clamp(1rem, 4.5vw, 1.4rem);
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  border: 2px solid var(--accent);
  color: #fff;
  border-radius: 0.6rem;
  padding: 0 0.5rem;
  min-width: 2.2rem;
  text-align: center;
}
@keyframes hover {
  from { transform: translateY(-2px); }
  to { transform: translateY(2px); }
}
.invader.explode {
  animation: explode 0.32s forwards;
  pointer-events: none;
}
@keyframes explode {
  0% { transform: translateX(-50%) scale(1); opacity: 1; }
  40% { transform: translateX(-50%) scale(1.5); opacity: 1; }
  100% { transform: translateX(-50%) scale(0.2); opacity: 0; }
}

/* ====================================================================== */
/*  Rain drops                                                             */
/* ====================================================================== */
.drop {
  position: absolute;
  top: 0;
  transform: translateX(-50%) translateY(-48px);
  white-space: nowrap; /* never wrap a formula mid-symbol */
  background: linear-gradient(160deg, var(--accent), #0b8aa3);
  color: var(--accent-ink);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.05rem, 5vw, 1.55rem);
  padding: 0.5rem 0.9rem;
  border-radius: 50% 50% 50% 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  will-change: transform;
}
.drop.pop {
  animation: dropPop 0.26s forwards;
}
@keyframes dropPop {
  0% { filter: brightness(1.4); }
  100% { transform: translateX(-50%) translateY(var(--y, 0)) scale(1.5); opacity: 0; }
}
.drop.splash {
  animation: dropSplash 0.3s forwards;
}
@keyframes dropSplash {
  0% { opacity: 1; }
  100% { transform: translateX(-50%) translateY(var(--y, 0)) scaleY(0.3); opacity: 0; }
}

.fade-in {
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.pop-in {
  animation: popIn 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}
