/* Math Balloon Shooter – styles for HUD, controls and menu overlay.
   The sky, balloons and effects are drawn on the canvas (see game.js). */

:root {
  --ink: #17325c;
  --ink-soft: #4a628a;
  --good: #06c08a;
  --bad: #ef476f;
  --warn: #ff9f1c;
  --accent: #ff6b9a;
  --accent-2: #ffb347;
  --card: #ffffff;
  --chip: #eef4ff;
  --chip-on: #ffd166;
  --shadow: 0 8px 24px rgba(20, 50, 100, 0.25);
  --font: 'Fredoka', 'Trebuchet MS', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  color: var(--ink);
  /* fallback sky in case the canvas is not ready yet */
  background: linear-gradient(180deg, #4fb6f5 0%, #9fdcff 55%, #fff2d0 100%);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}
body.aiming #canvas { cursor: none; }

/* ===== HUD ===== */
#hud {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 2;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 0;
  pointer-events: none;
}

#timebar {
  height: 12px;
  margin: 0 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}
#timebar.off { visibility: hidden; }
#timefill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: hsl(140 75% 48%);
  transform-origin: left center;
  transition: transform 0.12s linear;
}
#timebar.low #timefill { animation: pulse-bar 0.5s ease-in-out infinite alternate; }
@keyframes pulse-bar { to { filter: brightness(1.35); } }

#hudRow {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 10px;
}

.badge {
  background: rgba(255, 255, 255, 0.88);
  border: 3px solid #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 6px 14px;
}

#lives {
  justify-self: start;
  display: flex;
  gap: 2px;
  font-size: clamp(22px, 4.2vw, 30px);
  line-height: 1.1;
  padding: 6px 10px;
}
.heart {
  display: inline-block;
  color: #ff4d6d;
  text-shadow: 0 2px 0 #c9184a;
  transition: color 0.3s, opacity 0.3s;
}
.heart.empty { color: #c7d2e6; text-shadow: none; opacity: 0.8; }
.heart.lost { animation: heart-lost 0.6s ease-out; }
.heart.gained { animation: heart-gained 0.7s ease-out; }
@keyframes heart-lost {
  0% { transform: scale(1.5); color: #ff4d6d; }
  40% { transform: scale(0.6) rotate(-20deg); }
  100% { transform: scale(1); }
}
@keyframes heart-gained {
  0% { transform: scale(0.3); }
  60% { transform: scale(1.6); }
  100% { transform: scale(1); }
}

#problem {
  justify-self: center;
  font-size: clamp(30px, 6.5vw, 56px);
  font-weight: 700;
  line-height: 1.1;
  padding: 6px 22px 8px;
  white-space: nowrap;
  text-align: center;
  min-width: 4em;
}
#problem.enter { animation: problem-enter 0.5s cubic-bezier(.2, 1.6, .4, 1); }
#problem.solved { color: var(--good); animation: problem-solved 0.6s ease-out; }
#problem.reveal { color: var(--warn); animation: problem-solved 0.6s ease-out; }
#problem.shake { animation: shake 0.4s linear; }
#problem.small { font-size: clamp(20px, 4.5vw, 32px); }
@keyframes problem-enter {
  0% { transform: translateY(-40px) scale(0.5); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
@keyframes problem-solved {
  0% { transform: scale(1); }
  35% { transform: scale(1.18) rotate(-2deg); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-12px) rotate(-2deg); }
  40% { transform: translateX(10px) rotate(2deg); }
  60% { transform: translateX(-7px); }
  80% { transform: translateX(4px); }
}

#scoreBox {
  justify-self: end;
  text-align: right;
  padding: 4px 14px 6px;
}
#score {
  font-size: clamp(24px, 4.5vw, 34px);
  font-weight: 700;
  line-height: 1.05;
  display: inline-block;
}
#score.bump { animation: bump 0.35s ease-out; }
#best { font-size: 14px; font-weight: 600; color: var(--ink-soft); }
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); color: var(--good); }
  100% { transform: scale(1); }
}

#streak {
  display: block;
  width: max-content;
  margin: 8px auto 0;
  padding: 4px 14px;
  border-radius: 999px;
  font-size: clamp(16px, 3.4vw, 22px);
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg, #ff7b00, #ff3d77);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.25s, transform 0.25s;
}
#streak.show { opacity: 1; transform: scale(1); }
#streak.bump { animation: streak-bump 0.4s ease-out; }
@keyframes streak-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.35) rotate(3deg); }
  100% { transform: scale(1); }
}

/* Narrow screens: lives + score on the first row, problem on its own row */
@media (max-width: 640px) {
  #hudRow {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "lives score" "problem problem";
    gap: 8px;
  }
  #lives { grid-area: lives; }
  #scoreBox { grid-area: score; }
  #problem { grid-area: problem; }
}

/* ===== Big centred praise text ===== */
#callout {
  position: fixed;
  left: 50%;
  top: 42%;
  z-index: 3;
  transform: translate(-50%, -50%);
  font-size: clamp(42px, 11vw, 92px);
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  -webkit-text-stroke: 3px #ff3d77;
  paint-order: stroke fill;
  text-shadow: 0 6px 0 #c9184a, 0 10px 24px rgba(0, 0, 0, 0.3);
}
#callout.warn { -webkit-text-stroke-color: #f77f00; text-shadow: 0 6px 0 #d45d00, 0 10px 24px rgba(0, 0, 0, 0.3); }
#callout.show { animation: callout 1.3s ease-out forwards; }
@keyframes callout {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-8deg); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(3deg); }
  30% { transform: translate(-50%, -50%) scale(1) rotate(0); }
  75% { opacity: 1; transform: translate(-50%, -55%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -75%) scale(0.9); }
}

/* Screen flash on wrong answer / celebration */
#flash {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
}
#flash.bad { background: radial-gradient(ellipse at center, transparent 45%, rgba(239, 71, 111, 0.55)); animation: flash 0.5s ease-out; }
#flash.good { background: radial-gradient(ellipse at center, transparent 50%, rgba(255, 214, 102, 0.5)); animation: flash 0.6s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ===== Bottom-left controls ===== */
#controls {
  position: fixed;
  left: 12px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 2;
  display: flex;
  gap: 10px;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  color: var(--ink);
  touch-action: manipulation;
}
button:focus-visible, .chip input:focus-visible + span, select:focus-visible, input[type="range"]:focus-visible {
  outline: 3px solid #2b7cff;
  outline-offset: 2px;
}

.round {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid #fff;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.round:hover { transform: scale(1.08); }
.round:active { transform: scale(0.92); }
.round:disabled { opacity: 0.45; cursor: default; transform: none; }

/* ===== Menu / pause / game-over overlay ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(30, 70, 140, 0.18);
  /* the backdrop lets taps through, so the demo balloons can be popped */
  pointer-events: none;
}
.overlay[hidden] { display: none; }

.card {
  pointer-events: auto;
  width: min(540px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--card);
  border-radius: 28px;
  border: 4px solid #fff;
  box-shadow: 0 18px 50px rgba(20, 50, 100, 0.35);
  padding: 20px 22px 18px;
  text-align: center;
  animation: card-in 0.45s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes card-in {
  0% { transform: translateY(30px) scale(0.85); opacity: 0; }
  100% { transform: none; opacity: 1; }
}

.title {
  margin: 0;
  font-size: clamp(30px, 7.5vw, 46px);
  font-weight: 700;
  line-height: 1.05;
  color: #ff3d77;
  text-shadow: 0 3px 0 #ffd0de;
}
.title .b1 { color: #ff9f1c; }
.title .b2 { color: #2bb3ff; }
.sub {
  margin: 6px 0 12px;
  font-size: 18px;
  color: var(--ink-soft);
}

.results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 4px 0 14px;
}
.results[hidden] { display: none; }
.res {
  background: var(--chip);
  border-radius: 16px;
  padding: 6px 4px;
}
.res span { display: block; font-size: 14px; color: var(--ink-soft); }
.res strong { font-size: 28px; }
.record {
  grid-column: 1 / -1;
  font-size: 22px;
  font-weight: 700;
  color: #d48800;
  animation: problem-solved 0.8s ease-out infinite alternate;
}
.record[hidden] { display: none; }

.actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.big {
  font-size: 26px;
  font-weight: 700;
  padding: 12px 34px;
  min-height: 60px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(180deg, #ff8fb1, #ff3d77);
  box-shadow: 0 6px 0 #c9184a, 0 12px 24px rgba(201, 24, 74, 0.35);
  transition: transform 0.12s, box-shadow 0.12s;
  animation: wiggle 2.4s ease-in-out infinite;
}
.big:hover { transform: translateY(-2px) scale(1.04); }
.big:active { transform: translateY(4px); box-shadow: 0 2px 0 #c9184a; animation: none; }
@keyframes wiggle {
  0%, 85%, 100% { transform: rotate(0); }
  90% { transform: rotate(-3deg) scale(1.04); }
  95% { transform: rotate(3deg) scale(1.04); }
}
.ghost {
  font-size: 20px;
  font-weight: 600;
  padding: 10px 22px;
  min-height: 60px;
  border-radius: 999px;
  background: var(--chip);
  box-shadow: 0 4px 0 #c9d7f0;
}
.ghost:active { transform: translateY(3px); box-shadow: 0 1px 0 #c9d7f0; }
.ghost[hidden] { display: none; }

/* Settings */
.settings {
  text-align: left;
  border-top: 2px dashed #dbe5f5;
  padding-top: 10px;
}
.settings h2 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 600;
  color: var(--ink-soft);
}
.ops {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.chip { position: relative; cursor: pointer; }
.chip input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.chip span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 600;
  background: var(--chip);
  color: var(--ink-soft);
  border: 2px solid transparent;
  transition: background 0.15s, transform 0.15s;
}
.chip span b { font-size: 22px; }
.chip input:checked + span {
  background: var(--chip-on);
  color: var(--ink);
  border-color: #f4b400;
}
.chip:active span { transform: scale(0.95); }
.chip.nope span { animation: shake 0.4s linear; }

.sliders {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}
.slider {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-soft);
}
.slider output { color: var(--ink); font-weight: 700; }
.slider input[type="range"] {
  width: 100%;
  height: 34px;
  accent-color: #ff3d77;
}
.slider select {
  font-family: inherit;
  font-size: 17px;
  min-height: 42px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 2px solid #dbe5f5;
  background: var(--chip);
  color: var(--ink);
}
.tip {
  margin: 10px 0 2px;
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.35;
}
.keys { margin: 4px 0 0; font-size: 13px; color: #8a9bb8; }

@media (max-width: 420px) {
  .sliders { grid-template-columns: 1fr; }
  .card { padding: 16px 14px 14px; }
  .chip span { font-size: 15px; padding: 6px 11px; }
}
@media (hover: none) {
  .keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .big { animation: none; }
  #problem.shake, .chip.nope span { animation-duration: 0.2s; }
}
