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

:root {
  --bg: #FFF7EC;
  --text: #3D2C2E;
  --text-muted: #8B7E80;
  --card: #ffffff;
  --accent-red: #FF6B6B;
  --accent-teal: #4ECDC4;
  --accent-yellow: #FFD93D;
  --accent-purple: #6C5CE7;
  --accent-orange: #FF9F43;
  --accent-green: #2ECC71;
  --frame-line: #E3D5C8;
  --shadow-sm: 0 4px 12px rgba(61, 44, 46, 0.08);
  --shadow-md: 0 8px 28px rgba(61, 44, 46, 0.12);
  --radius: 20px;
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* blobs */
.blob { position: fixed; border-radius: 50%; filter: blur(90px); opacity: 0.22; z-index: 0; animation: blobFloat 14s ease-in-out infinite alternate; pointer-events: none; }
.blob-1 { width: 380px; height: 380px; background: var(--accent-red); top: -140px; left: -80px; }
.blob-2 { width: 340px; height: 340px; background: var(--accent-teal); bottom: -100px; right: -60px; animation-delay: -5s; }
.blob-3 { width: 280px; height: 280px; background: var(--accent-yellow); top: 35%; left: 55%; animation-delay: -9s; }
@keyframes blobFloat {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(24px, -32px) scale(1.06); }
}

/* top bar */
.top-bar { position: relative; z-index: 10; padding: 12px 20px; }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 0.95rem;
  color: var(--text-muted); text-decoration: none;
  padding: 8px 14px; border-radius: 14px;
  background: rgba(255,255,255,0.6); backdrop-filter: blur(8px);
  transition: background 0.2s, color 0.2s;
}
.back-btn:hover { background: rgba(255,255,255,0.9); color: var(--text); }

/* game wrapper */
.game-wrapper {
  position: relative; z-index: 1; flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 16px 24px;
  max-width: 540px; margin: 0 auto; width: 100%;
}

/* header */
.game-header { text-align: center; margin-bottom: 6px; animation: fadeDown 0.5s ease both; }
.game-header h1 {
  font-family: 'Baloo 2', cursive; font-weight: 800;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  background: linear-gradient(135deg, var(--accent-red), var(--accent-purple));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.emoji-bounce {
  display: inline-block; -webkit-text-fill-color: initial;
  animation: emojiBounce 2s ease-in-out infinite;
}
@keyframes emojiBounce {
  0%, 100% { transform: translateY(0) rotate(0); }
  25%  { transform: translateY(-6px) rotate(-8deg); }
  75%  { transform: translateY(-3px) rotate(6deg); }
}
.subtitle { font-size: 0.95rem; font-weight: 600; color: var(--text-muted); margin-top: 2px; }
@keyframes fadeDown {
  0% { opacity: 0; transform: translateY(-18px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ── Big count readout ── */
.count-display {
  display: flex; align-items: center; justify-content: center;
  margin: 6px 0 14px;
  animation: fadeDown 0.5s 0.1s ease both;
}
.count-num {
  font-family: 'Baloo 2', cursive; font-weight: 800;
  font-size: 3.4rem; line-height: 1;
  color: var(--accent-purple);
  min-width: 90px; text-align: center;
  transition: color 0.3s;
}
.count-num.pop { animation: countPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes countPop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.28); }
  100% { transform: scale(1); }
}
.count-num.full { color: var(--accent-green); }

/* ── Ten frame ── */
.frame-stage { position: relative; animation: fadeDown 0.5s 0.2s ease both; }

.ten-frame {
  display: grid;
  grid-template-columns: repeat(5, 72px);
  grid-template-rows: repeat(2, 72px);
  gap: 4px;
  padding: 4px;
  background: var(--frame-line);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
}

.tf-cell {
  background: var(--card);
  border: none;
  border-radius: 11px;
  padding: 0;
  cursor: pointer;
  font: inherit;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  overflow: visible;
  transition: background 0.2s, transform 0.15s;
  touch-action: manipulation;
}
.tf-cell:hover { background: #FFFBF5; }
.tf-cell:active { transform: scale(0.94); }

/* The middle gap between the two fives — a real ten frame reads as 5 + 5 */
.tf-cell:nth-child(5), .tf-cell:nth-child(10) { margin-right: 0; }

/* ── Balloons ── */
.balloon {
  width: 46px; height: 56px;
  border-radius: 50% 50% 48% 48% / 56% 56% 44% 44%;
  position: relative;
  box-shadow:
    inset -7px -7px 14px rgba(0,0,0,0.13),
    inset 6px 6px 12px rgba(255,255,255,0.30),
    0 4px 10px rgba(0,0,0,0.13);
  animation: balloonIn 0.42s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  pointer-events: none;
}
/* knot */
.balloon::before {
  content: ''; position: absolute;
  bottom: -6px; left: 50%; transform: translateX(-50%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 8px solid currentColor;
}
/* shine */
.balloon::after {
  content: ''; position: absolute;
  top: 10px; left: 11px;
  width: 11px; height: 15px;
  border-radius: 50%;
  background: rgba(255,255,255,0.55);
  filter: blur(1px);
}

@keyframes balloonIn {
  0%   { opacity: 0; transform: translateY(34px) scale(0.35) rotate(-12deg); }
  70%  { opacity: 1; transform: translateY(-4px) scale(1.06) rotate(3deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}

.balloon.popping { animation: balloonPop 0.3s ease-out forwards; }
@keyframes balloonPop {
  0%   { transform: scale(1); opacity: 1; }
  35%  { transform: scale(1.32); opacity: 1; }
  100% { transform: scale(0.15); opacity: 0; }
}

/* idle bob so the full frame feels alive */
.balloon.bob { animation: balloonBob 2.6s ease-in-out infinite; }
@keyframes balloonBob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-4px) rotate(2deg); }
}

/* ── Pop burst particles ── */
.burst {
  position: absolute; border-radius: 50%;
  pointer-events: none; z-index: 20;
  animation: burstFly 0.5s ease-out forwards;
}
@keyframes burstFly {
  0%   { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0.2); }
}

/* ── Confetti at ten ── */
.confetti {
  position: absolute; width: 9px; height: 14px;
  border-radius: 2px; pointer-events: none; z-index: 25;
  animation: confettiFall 1.5s ease-in forwards;
}
@keyframes confettiFall {
  0%   { opacity: 1; transform: translate(0, 0) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) rotate(var(--rot)); }
}

/* ── Celebration badge ── */
.celebrate {
  position: absolute;
  top: -10px; left: 50%;
  transform: translate(-50%, -100%) scale(0.4);
  font-family: 'Baloo 2', cursive; font-weight: 800;
  font-size: 2.6rem;
  color: #fff;
  padding: 10px 30px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-teal));
  box-shadow: 0 10px 34px rgba(46,204,113,0.45);
  opacity: 0;
  pointer-events: none;
  z-index: 30;
  white-space: nowrap;
}
.celebrate.show { animation: celebratePop 1.9s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
@keyframes celebratePop {
  0%   { opacity: 0; transform: translate(-50%, -70%)  scale(0.4) rotate(-8deg); }
  16%  { opacity: 1; transform: translate(-50%, -100%) scale(1.12) rotate(3deg); }
  26%  { opacity: 1; transform: translate(-50%, -100%) scale(1) rotate(0); }
  76%  { opacity: 1; transform: translate(-50%, -100%) scale(1) rotate(0); }
  100% { opacity: 0; transform: translate(-50%, -125%) scale(0.9) rotate(0); }
}

/* ── Number bond readout ── */
.bond-readout {
  text-align: center;
  margin: 16px 0 4px;
  min-height: 56px;
  animation: fadeDown 0.5s 0.3s ease both;
}
.bond-line {
  font-family: 'Baloo 2', cursive; font-weight: 800;
  font-size: 1.6rem; color: var(--text);
  line-height: 1.3;
}
.bond-line .hl-five  { color: var(--accent-orange); }
.bond-line .hl-extra { color: var(--accent-purple); }
.bond-line .hl-total { color: var(--accent-green); }
/* the + and = sit back so the three numbers read first */
.bond-line .bond-op {
  color: var(--text-muted);
  font-weight: 700;
  margin: 0 0.34em;
}
.need-line {
  font-size: 0.95rem; font-weight: 700;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Actions ── */
.actions {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center;
  animation: fadeDown 0.5s 0.4s ease both;
  margin-top: 14px;
}
.btn {
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 0.95rem;
  border: none; border-radius: 16px; padding: 12px 22px; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.25s, opacity 0.3s;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.93); }
.btn:disabled { opacity: 0.35; pointer-events: none; }
.btn-icon { font-size: 1.1rem; display: inline-block; }

.btn-add {
  background: linear-gradient(135deg, var(--accent-red), #FF8E8E);
  color: #fff; box-shadow: 0 4px 14px rgba(255,107,107,0.34);
}
.btn-add:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(255,107,107,0.44); }

.btn-pop { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-pop:hover:not(:disabled) { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.btn-clear { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-clear:hover:not(:disabled) { box-shadow: var(--shadow-md); transform: translateY(-2px); }

/* ── Small screens ── */
@media (max-width: 420px) {
  .ten-frame { grid-template-columns: repeat(5, 60px); grid-template-rows: repeat(2, 60px); }
  .balloon { width: 38px; height: 47px; }
  .balloon::after { top: 8px; left: 9px; width: 9px; height: 12px; }
  .count-num { font-size: 2.8rem; }
  .celebrate { font-size: 2rem; padding: 8px 22px; }
  .bond-line { font-size: 1.35rem; }
  .btn { padding: 11px 16px; font-size: 0.88rem; }
}

@media (prefers-reduced-motion: reduce) {
  .blob, .emoji-bounce, .balloon.bob { animation: none; }
  .balloon { animation-duration: 0.01s; }
  .celebrate.show { animation-duration: 1.9s; }
}
