/* Bubble Pop Math — layout and colour.
 *
 * One rule shapes most of this file: a child of five has to be able to hit
 * anything they can see. Every interactive element is at least 48px, the
 * bubbles are sized from the available space rather than fixed, and nothing
 * depends on hover.
 */

:root {
  --sky: #4db8ff;
  --aqua: #3cc9b0;
  --leaf: #5bc98c;
  --sun: #ffd166;
  --coral: #ff8a5b;
  --rose: #ff6fa5;
  --plum: #9c8cff;
  --deep: #0b4f6c;
  --foam: #eaf7ff;
  --snow: #ffffff;
  --ink: #12303f;
  --ink-soft: #5a7386;
  --stone: #b6c6d1;

  --radius: 18px;
  --tap: 48px;
  --shadow: 0 6px 18px rgba(11, 79, 108, 0.16);
  --font-head: 'Fredoka', 'Trebuchet MS', sans-serif;
  --font-body: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 4%, rgba(255, 209, 102, 0.3), transparent 28%),
    radial-gradient(circle at 88% 12%, rgba(60, 201, 176, 0.2), transparent 34%),
    linear-gradient(180deg, #dff6ff 0%, var(--foam) 52%, #d8f4f0 100%);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--snow);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  z-index: 50;
}
.skip-link:focus { left: 8px; }

#particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

#app {
  display: block;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem;
  min-height: calc(100dvh - 64px);
  position: relative;
}

/* --- shared chrome ------------------------------------------------------ */

.screen { display: flex; flex-direction: column; gap: 0.9rem; }

.screen-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.screen-title {
  font-family: var(--font-head);
  font-size: clamp(1.3rem, 4vw, 1.9rem);
  margin: 0;
  color: var(--deep);
}

.btn {
  font-family: var(--font-head);
  font-size: 1rem;
  min-height: var(--tap);
  padding: 0.65rem 1.1rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--snow);
  color: var(--deep);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.48rem;
  border: 1px solid rgba(11, 79, 108, 0.08);
}
.btn svg { width: 22px; height: 22px; flex: none; }
.btn.primary { background: linear-gradient(135deg, var(--sky), #278dd1); color: var(--snow); box-shadow: 0 7px 18px rgba(39, 141, 209, 0.28); }
.btn.big { font-size: 1.2rem; min-height: 60px; padding: 0.8rem 1.6rem; }
.btn.ghost { background: transparent; box-shadow: none; text-decoration: underline; }
.btn.danger { color: #b3261e; }
.btn:focus-visible, .tier-chip:focus-visible, .bubble:focus-visible, .icon-btn:focus-visible {
  outline: 4px solid var(--coral);
  outline-offset: 3px;
}

.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  font-size: 1.35rem;
  border: 0;
  border-radius: 50%;
  background: var(--snow);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  color: var(--deep);
  border: 1px solid rgba(11, 79, 108, 0.1);
}
.icon-btn svg { width: 25px; height: 25px; }
.icon-btn:hover { color: #167f9e; background: #effbff; }

/* --- the Bay ------------------------------------------------------------ */

.hero {
  position: relative;
  min-height: clamp(310px, 41vw, 440px);
  overflow: hidden;
  isolation: isolate;
  border-radius: 30px;
  background: #063a54;
  box-shadow: 0 20px 48px rgba(6, 58, 84, 0.23);
}
.hero-art,
.hero-shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.hero-art { object-fit: cover; object-position: center; }
.hero-shade {
  z-index: 1;
  background:
    linear-gradient(90deg, rgba(3, 42, 61, 0.97) 0%, rgba(3, 42, 61, 0.88) 38%, rgba(3, 42, 61, 0.18) 67%, transparent 100%),
    linear-gradient(0deg, rgba(2, 31, 47, 0.26), transparent 60%);
}
.hero-copy {
  position: relative;
  z-index: 2;
  width: min(55%, 590px);
  min-height: inherit;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(26px, 5vw, 56px);
  color: #fff;
  text-align: left;
  text-shadow: 0 2px 12px rgba(0, 24, 36, 0.34);
}
.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  font-family: var(--font-head);
  font-size: 0.82rem;
  letter-spacing: 0.045em;
  text-transform: uppercase;
}
.hero-eyebrow svg { width: 19px; height: 19px; }
.hero-title {
  font-family: var(--font-head);
  font-size: clamp(2.35rem, 5vw, 4.25rem);
  line-height: 0.95;
  letter-spacing: -0.035em;
  margin: 0;
  color: #fff;
}
.hero-sub { margin: 0.7rem 0 1rem; color: rgba(255, 255, 255, 0.92); font-size: clamp(1.05rem, 1.8vw, 1.28rem); }
.hero-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.hero-chips li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--deep);
  text-shadow: none;
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 31, 47, 0.14);
}
.hero-chips svg { width: 18px; height: 18px; color: #e36f75; }

.bay-heading { text-align: center; padding: 0.25rem 1rem 0; }
.bay-heading h2 { margin: 0; font-family: var(--font-head); color: var(--deep); font-size: clamp(1.55rem, 4vw, 2.1rem); }
.bay-heading p { margin: 0.25rem 0 0; color: var(--ink-soft); }

.bay {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  padding: clamp(0.5rem, 2vw, 1rem);
  border-radius: 28px;
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 255, 255, 0.72), transparent 30%),
    linear-gradient(145deg, rgba(184, 234, 255, 0.62), rgba(219, 248, 241, 0.72));
  border: 1px solid rgba(11, 79, 108, 0.08);
}

.mode-card {
  background: linear-gradient(160deg, #fff 0%, color-mix(in srgb, var(--card-tone) 8%, #fff) 100%);
  border-radius: 22px;
  box-shadow: 0 8px 22px rgba(11, 79, 108, 0.12);
  padding: 1rem;
  border: 1px solid color-mix(in srgb, var(--card-tone) 22%, #fff);
  border-top: 6px solid var(--card-tone, var(--sky));
  transition: transform 150ms ease, box-shadow 150ms ease;
}
.mode-card:hover { transform: translateY(-3px); box-shadow: 0 13px 28px rgba(11, 79, 108, 0.17); }
.mode-card.tone-sky { --card-tone: var(--sky); }
.mode-card.tone-aqua { --card-tone: var(--aqua); }
.mode-card.tone-sun { --card-tone: var(--sun); }
.mode-card.tone-rose { --card-tone: var(--rose); }
.mode-card.tone-plum { --card-tone: var(--plum); }

.mode-head { display: flex; align-items: center; gap: 0.6rem; }
.mode-emoji {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 17px;
  background: color-mix(in srgb, var(--card-tone) 14%, #fff);
  color: color-mix(in srgb, var(--card-tone) 74%, var(--deep));
}
.mode-emoji svg { width: 42px; height: 42px; }
.mode-title {
  font-family: var(--font-head);
  font-size: 1.25rem;
  margin: 0;
  flex: 1;
}
.mode-stars { display: inline-flex; align-items: center; gap: 0.2rem; color: var(--ink-soft); }

.tier-chips { display: flex; gap: 0.5rem; margin-top: 0.7rem; flex-wrap: wrap; }

.tier-chip {
  flex: 1 1 30%;
  min-width: 96px;
  min-height: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.5rem 0.4rem;
  border: 2px solid var(--foam);
  border-radius: 14px;
  background: var(--foam);
  cursor: pointer;
  font-family: var(--font-body);
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
.tier-chip:hover { transform: translateY(-3px); box-shadow: 0 7px 16px rgba(11, 79, 108, 0.12); }
.chip-label { font-family: var(--font-head); font-size: 0.98rem; }
.chip-stars { display: inline-flex; }
.chip-best { color: var(--ink-soft); font-size: 0.76rem; }

.bay-rail {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0.35rem;
}

/* --- the run ------------------------------------------------------------ */

.run-screen { height: calc(100dvh - 90px); gap: 0.5rem; }

.hud {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.hud-progress {
  font-family: var(--font-head);
  font-size: 1.05rem;
  background: var(--snow);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.hud-score {
  font-family: var(--font-head);
  /* Tabular figures so the number does not jitter as it climbs. */
  font-variant-numeric: tabular-nums;
  font-size: 1.2rem;
  background: var(--sun);
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
}
.hud-combo { display: inline-flex; gap: 2px; align-items: center; min-height: 16px; }
.hud-actions { margin-left: auto; display: flex; gap: 0.4rem; }

.question-banner {
  text-align: center;
  background: linear-gradient(135deg, rgba(255,255,255,0.98), rgba(234,247,255,0.96));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.6rem 1rem;
}
.question-text {
  font-family: var(--font-head);
  font-variant-numeric: tabular-nums;
  font-size: clamp(2rem, 9vw, 3.2rem);
  color: var(--deep);
  letter-spacing: 0.02em;
}

.field-stage {
  flex: 1;
  min-height: 260px;
  position: relative;
  overflow: hidden;
  border-radius: 24px;
  background:
    linear-gradient(rgba(0, 84, 119, 0.24), rgba(0, 66, 92, 0.38)),
    url('/bubble-pop-math/assets/images/bubble-pop-math-hero.webp') center / cover;
  box-shadow: inset 0 0 50px rgba(3, 42, 61, 0.18), var(--shadow);
}

.bubble-field {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 24px;
}

/* Real buttons, absolutely positioned, moved only by transform. Everything the
 * rAF loop writes is composited; nothing here triggers layout. */
.bubble {
  position: absolute;
  top: 0;
  left: 0;
  min-width: var(--tap);
  min-height: var(--tap);
  border: 0;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  will-change: transform;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0) 42%),
    radial-gradient(circle at 50% 50%, var(--bubble-color, var(--sky)) 60%, rgba(0, 0, 0, 0.12) 100%);
  box-shadow: 0 4px 14px rgba(11, 79, 108, 0.25), inset 0 -6px 12px rgba(0, 0, 0, 0.12);
}

.bubble-sheen { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.bubble-value {
  font-family: var(--font-head);
  font-variant-numeric: tabular-nums;
  /* Sized from the bubble, so a big bubble on desktop is not a small number in
   * a large circle. */
  font-size: clamp(1.4rem, 42%, 2.6rem);
  color: var(--snow);
  text-shadow: 0 2px 4px rgba(11, 79, 108, 0.55);
  pointer-events: none;
  position: relative;
}

/* --- overlays ----------------------------------------------------------- */

.overlay {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(92%, 480px);
  text-align: center;
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 30;
  font-size: 1.05rem;
}

.wave-card {
  top: 40%;
  background: var(--plum);
  color: var(--snow);
  font-family: var(--font-head);
  font-size: 1.4rem;
}

.explain-toast {
  top: 96px;
  background: var(--snow);
  color: var(--ink);
  border: 3px solid var(--sun);
}

.pause-sheet {
  top: 30%;
  background: var(--snow);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 260px;
}
.pause-sheet h3 { font-family: var(--font-head); margin: 0 0 0.3rem; }

/* --- round complete ----------------------------------------------------- */

.done { display: flex; flex-direction: column; align-items: center; gap: 0.7rem; text-align: center; }
.done-stars { display: flex; gap: 0.4rem; }

.done-grid {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.35rem 1.4rem;
  background: var(--snow);
  padding: 1rem 1.4rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 0;
}
.done-grid dt { color: var(--ink-soft); text-align: right; margin: 0; }
.done-grid dd {
  margin: 0;
  font-family: var(--font-head);
  font-variant-numeric: tabular-nums;
  font-size: 1.2rem;
  text-align: left;
}

.done-flash { color: var(--coral); font-family: var(--font-head); font-size: 1.15rem; margin: 0; }
.done-pearls, .done-streak, .done-earned { margin: 0; color: var(--ink-soft); }
.done-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; justify-content: center; }

/* --- collection, settings, parents -------------------------------------- */

.collection, .settings, .parents, .daily, .tutorial {
  background: var(--snow);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.pearl-count { display: flex; align-items: center; gap: 0.35rem; margin: 0; font-size: 1.1rem; }

.sticker-grid, .badge-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
}
.sticker, .badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.5rem;
  border-radius: 14px;
  background: var(--foam);
  text-align: center;
  position: relative;
}
.sticker-emoji { font-size: 1.9rem; }
.badge-emoji { font-size: 1.3rem; position: absolute; top: 1.1rem; }
.sticker small, .badge small { color: var(--ink-soft); font-size: 0.74rem; }
.sticker:not(.owned), .badge:not(.owned) { opacity: 0.55; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--tap);
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--foam);
}
.setting-row input[type='checkbox'] { width: 28px; height: 28px; }
.setting-row select { min-height: var(--tap); font-size: 1rem; border-radius: 10px; padding: 0 0.6rem; }

.topic-list { list-style: none; margin: 0; padding: 0; }
.topic-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--foam);
}

.tutorial-title { margin: 0 0 0.15rem; text-align: center; font-family: var(--font-head); color: var(--deep); }
.tutorial-step { display: flex; align-items: center; gap: 0.8rem; padding: 0.7rem; border-radius: 16px; background: var(--foam); }
.tutorial-emoji {
  flex: 0 0 50px;
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: #fff;
  color: #178dad;
  box-shadow: 0 4px 12px rgba(11, 79, 108, 0.1);
}
.tutorial-emoji svg { width: 34px; height: 34px; }
.tutorial-step p { margin: 0; font-size: 1.1rem; }

/* --- responsive --------------------------------------------------------- */

@media (max-width: 480px) {
  #app { padding: 0.5rem; }
  .bay { grid-template-columns: 1fr; }
  .hud-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
  .done-grid { grid-template-columns: auto auto; padding: 0.8rem 1rem; }
  .hero { min-height: 350px; border-radius: 24px; }
  .hero-art { object-position: 60% center; }
  .hero-shade { background: linear-gradient(90deg, rgba(3, 42, 61, 0.96), rgba(3, 42, 61, 0.8) 68%, rgba(3, 42, 61, 0.23)); }
  .hero-copy { width: 100%; padding: 24px 20px; justify-content: flex-end; }
  .hero-title { max-width: 270px; font-size: 2.7rem; }
  .hero-sub { max-width: 260px; margin-block: 0.55rem 0.8rem; }
  .hero-chips { max-width: 285px; }
  .hero-chips li { padding: 6px 8px; font-size: 0.73rem; }
  .bay { padding: 0.55rem; }
}

@media (min-width: 1025px) {
  .field-stage { min-height: 420px; }
}

/* --- high contrast ------------------------------------------------------ */

body.high-contrast {
  background: #ffffff;
}
body.high-contrast .bubble {
  background: var(--bubble-color, var(--sky));
  border: 4px solid var(--ink);
  box-shadow: none;
}
body.high-contrast .bubble-value {
  color: #ffffff;
  text-shadow: 0 0 3px #000, 0 2px 4px #000;
}
body.high-contrast .bubble-sheen { display: none; }
body.high-contrast .mode-card,
body.high-contrast .question-banner { border: 2px solid var(--ink); }
