/* =========================================================
   Letter Bubble Pop — Design Tokens
   Palette: sunny sky + garden, glossy candy bubbles
   Type: rounded system font stack (no external font requests)
   ========================================================= */
:root {
  /* Sky & ground */
  --sky-top: #3FA9DC;
  --sky-mid: #74C7EA;
  --sky-low: #BFE9F7;
  --sun: #FFD966;
  --grass-back: #8FC64C;
  --grass-front: #5FA22D;

  /* Ink & surfaces */
  --ink: #223050;
  --ink-soft: #45557A;
  --paper: #FFFFFF;
  --paper-soft: #F4FBFF;
  --border-soft: rgba(34, 48, 80, 0.12);

  /* Bubble candy palette */
  --bubble-1: #FF6F61; /* coral */
  --bubble-2: #FFA630; /* tangerine */
  --bubble-3: #8BC24C; /* lime */
  --bubble-4: #3FB6E8; /* sky */
  --bubble-5: #B084F0; /* grape */
  --bubble-6: #FFD34D; /* lemon */
  --bubble-7: #FF7FB4; /* bubblegum */

  /* Feedback */
  --good: #2E9E4B;
  --good-bg: #E4F7E9;
  --bad: #E0562F;
  --bad-bg: #FDEAE3;

  /* Type */
  --font-display: ui-rounded, "SF Pro Rounded", "Segoe UI Rounded", "Nunito", system-ui, -apple-system, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", "Nunito", sans-serif;

  /* Shape */
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --shadow-soft: 0 10px 24px rgba(34, 48, 80, 0.16);
  --shadow-pop: 0 4px 0 rgba(34, 48, 80, 0.25);

  --focus-ring: 3px solid #1E3A8A;
}

/* =========================================================
   Reset & base
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 45%, var(--sky-low) 100%);
  overflow-x: hidden;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0 0 0.4em; line-height: 1.15; }
p { margin: 0 0 0.75em; line-height: 1.5; }

button { font-family: inherit; }

.visually-hidden {
  position: absolute !important;
  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: 0;
  background: var(--paper);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 999;
  font-weight: 700;
}
.skip-link:focus {
  left: 0;
}

/* Visible focus states everywhere, not relying on color alone */
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 3px;
  border-radius: 10px;
}

/* Guarantee the native `hidden` attribute always wins over any class that
   sets its own `display`, regardless of selector specificity/order. Without
   this, elements like .screen and .pause-overlay (which set display:flex /
   display:grid) can stay visible even when JS sets `hidden = true`. */
[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* =========================================================
   Ambient sky backdrop
   ========================================================= */
.sky-backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.sun {
  position: absolute;
  top: -60px; right: -40px;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #FFF3C4, var(--sun) 70%);
  box-shadow: 0 0 60px 20px rgba(255, 217, 102, 0.5);
}
.cloud {
  position: absolute;
  width: 140px; height: 46px;
  background: #FFFFFF;
  border-radius: 999px;
  opacity: 0.85;
  filter: drop-shadow(0 6px 0 rgba(255,255,255,0.5));
  animation: drift 40s linear infinite;
}
.cloud::before, .cloud::after {
  content: "";
  position: absolute;
  background: #FFFFFF;
  border-radius: 50%;
}
.cloud::before { width: 70px; height: 70px; top: -34px; left: 14px; }
.cloud::after { width: 50px; height: 50px; top: -22px; left: 74px; }
.cloud--a { top: 12%; left: -160px; animation-duration: 55s; }
.cloud--b { top: 28%; left: -260px; animation-duration: 70s; animation-delay: -20s; transform: scale(0.7); }
.cloud--c { top: 6%; left: -340px; animation-duration: 85s; animation-delay: -45s; transform: scale(0.55); }

@keyframes drift {
  from { transform: translateX(0) scale(var(--s, 1)); }
  to { transform: translateX(160vw) scale(var(--s, 1)); }
}

/* =========================================================
   Header
   ========================================================= */
.app-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(14px, 4vw, 32px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.1rem, 2.4vw, 1.5rem);
  color: var(--ink);
  background: rgba(255,255,255,0.75);
  padding: 8px 16px 8px 10px;
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
}
.brand-badge { font-size: 1.4rem; }

.header-controls { display: flex; gap: 10px; }

.icon-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--paper);
  box-shadow: var(--shadow-soft);
  font-size: 1.4rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease;
}
.icon-btn:hover { transform: translateY(-2px) scale(1.04); }
.icon-btn:active { transform: translateY(1px) scale(0.97); }

.icon-btn--ghost {
  width: 46px; height: 46px;
  background: var(--paper-soft);
  box-shadow: none;
  border: 2px solid var(--border-soft);
}

#muteBtn .icon-btn__off { display: none; }
#muteBtn[aria-pressed="true"] .icon-btn__on { display: none; }
#muteBtn[aria-pressed="true"] .icon-btn__off { display: inline; }

#pauseBtn .icon-btn__pause { display: inline; }
#pauseBtn .icon-btn__play { display: none; }
#pauseBtn[aria-pressed="true"] .icon-btn__pause { display: none; }
#pauseBtn[aria-pressed="true"] .icon-btn__play { display: inline; }

/* =========================================================
   Layout shell
   ========================================================= */
main { position: relative; z-index: 2; }

.screen {
  min-height: calc(100vh - 84px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 clamp(16px, 5vw, 48px) 40px;
}

/* =========================================================
   Start screen
   ========================================================= */
.screen--start { text-align: center; }

.mascot--wave { animation: bob 2.6s ease-in-out infinite; }
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-10px) rotate(2deg); }
}

.eyebrow {
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.screen--start h2 {
  font-size: clamp(1.7rem, 5vw, 2.6rem);
  color: var(--ink);
}

.lede {
  max-width: 560px;
  color: var(--ink-soft);
  font-size: clamp(1rem, 2.4vw, 1.15rem);
  font-weight: 600;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  width: 100%;
  max-width: 920px;
  margin-top: 20px;
  list-style: none;
  padding: 0;
}

.level-card {
  background: var(--paper);
  border-radius: var(--radius-lg);
  padding: 22px 20px 24px;
  box-shadow: var(--shadow-soft);
  text-align: left;
  display: flex;
  flex-direction: column;
  border: 3px solid transparent;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.level-card:hover { transform: translateY(-4px); }
.level-card[data-locked="true"] { opacity: 0.62; }

.level-card__top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.level-card__number {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--bubble-4);
  color: #fff;
  font-weight: 800;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  flex-shrink: 0;
}
.level-card:nth-of-type(2) .level-card__number { background: var(--bubble-2); }
.level-card:nth-of-type(3) .level-card__number { background: var(--bubble-7); }

.level-card h3 { font-size: 1.25rem; }
.level-card p { color: var(--ink-soft); font-size: 0.95rem; flex-grow: 1; }

.level-card__status {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin: 4px 0 0;
}

.reset-row { margin-top: 8px; }
.btn-link {
  background: none;
  border: none;
  color: var(--ink-soft);
  text-decoration: underline;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 8px;
}

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  padding: 14px 22px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-pop);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  min-height: 52px;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(34,48,80,0.25); }

.btn--primary { background: var(--bubble-4); color: #fff; }
.btn--accent { background: var(--sun); color: var(--ink); }
.btn--ghost { background: var(--paper); color: var(--ink); box-shadow: var(--shadow-soft); }

.level-play { width: 100%; margin-top: 14px; }

/* =========================================================
   Game screen — HUD
   ========================================================= */
.screen--game { padding-top: 4px; width: 100%; align-items: stretch; }

.hud {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.hud__item {
  background: rgba(255,255,255,0.7);
  border-radius: 999px;
  padding: 4px 14px;
  text-align: center;
  min-width: 64px;
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.hud__label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--ink-soft);
}
.hud__value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--ink);
}

/* Prompt banner */
.prompt-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--paper);
  border-radius: 999px;
  max-width: 480px;
  margin: 4px auto 14px;
  padding: 14px 16px 14px 26px;
  box-shadow: var(--shadow-soft);
  border: 3px solid #FFFFFF;
}

.field-mascot { position: absolute; }
.field-mascot.happy svg { animation: happyBounce 0.5s ease; }
.field-mascot.sad svg { animation: wobble 0.5s ease; }

@keyframes happyBounce {
  0% { transform: translateY(0) rotate(0); }
  30% { transform: translateY(-12px) rotate(-8deg); }
  60% { transform: translateY(0) rotate(6deg); }
  100% { transform: translateY(0) rotate(0); }
}

.prompt-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.15rem, 3.2vw, 1.5rem);
  margin: 0;
  color: #223050;
}
#promptLetter {
  color: #2C6FD1;
  font-size: 1.35em;
}

.speaker-btn {
  flex-shrink: 0;
  width: 50px; height: 50px;
  border-radius: 50%;
  border: none;
  background: #4B93E0;
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 0 #2C6FD1;
  transition: transform 0.12s ease;
}
.speaker-btn:hover { transform: translateY(-2px); }
.speaker-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #2C6FD1; }

/* Play field */
.play-field {
  position: relative;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  height: min(58vh, 560px);
  min-height: 340px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255,255,255,0.15), rgba(255,255,255,0.35));
  overflow: hidden;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.5);
}

.ground {
  max-width: 1000px;
  margin: -10px auto 0;
  width: 100%;
  height: 26px;
  position: relative;
}
.ground__grass {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--grass-back), var(--grass-front));
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.ground::before, .ground::after {
  content: "";
  position: absolute;
  bottom: 20px;
  width: 14px; height: 14px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(45deg);
}
.ground::before { left: 6%; background: #FF9EC4; }
.ground::after { right: 8%; background: #FFD34D; }

/* In-field mascot, bottom-left, decorative and non-interactive */
.field-mascot {
  left: clamp(6px, 2%, 20px);
  bottom: 0;
  width: clamp(90px, 22%, 150px);
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 6px 6px rgba(34,48,80,0.18));
}
.field-mascot svg { display: block; width: 100%; height: auto; }

.deco-bubble {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.95), rgba(190,231,245,0.55));
  border: 1.5px solid rgba(255,255,255,0.8);
  opacity: 0;
  animation: decoFloat 3.6s ease-in infinite;
}
.deco-bubble--1 { width: 14px; height: 14px; right: 6%; top: 30%; animation-delay: 0s; }
.deco-bubble--2 { width: 9px; height: 9px; right: 0%; top: 40%; animation-delay: 1.1s; }
.deco-bubble--3 { width: 11px; height: 11px; right: 10%; top: 22%; animation-delay: 2.2s; }

@keyframes decoFloat {
  0% { opacity: 0; transform: translate(0, 0) scale(0.6); }
  15% { opacity: 0.9; }
  100% { opacity: 0; transform: translate(14px, -70px) scale(1); }
}

.field-flower {
  position: absolute;
  bottom: 6px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #FF9EC4;
  box-shadow: 6px 0 0 -2px #FFD34D, -6px 0 0 -2px #B084F0;
  opacity: 0.85;
  pointer-events: none;
}
.field-flower--1 { left: 3%; }
.field-flower--2 { right: 4%; }

.scroll-hint {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.85);
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  box-shadow: var(--shadow-soft);
  animation: bob 1.8s ease-in-out infinite;
  pointer-events: none;
}

/* =========================================================
   Bubbles
   ========================================================= */
.bubble {
  position: absolute;
  width: var(--bubble-size, 84px);
  height: var(--bubble-size, 84px);
  border-radius: 50%;
  bottom: 0;
  left: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  border: none;
  padding: 0;
  color: #fff;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: calc(var(--bubble-size, 84px) * 0.42);
  text-shadow: 0 2px 3px rgba(0,0,0,0.25);
  box-shadow:
    inset -8px -10px 0 rgba(0,0,0,0.08),
    inset 8px 10px 18px rgba(255,255,255,0.55),
    0 8px 14px rgba(34,48,80,0.28);
  will-change: transform;
  animation: sway 2.4s ease-in-out infinite;
  transform-origin: 50% 100%;
}
.bubble:focus-visible { outline: var(--focus-ring); outline-offset: 4px; }

.bubble::after {
  content: "";
  position: absolute;
  top: 14%; left: 20%;
  width: 26%; height: 16%;
  background: rgba(255,255,255,0.75);
  border-radius: 50%;
  transform: rotate(-25deg);
}

@keyframes sway {
  0%, 100% { transform: translateX(0) rotate(-2deg); }
  50% { transform: translateX(6px) rotate(2deg); }
}

.bubble--c1 { background: #E6DBFB; color: #6A3FCB; }
.bubble--c2 { background: #FFE9B8; color: #E07A1F; }
.bubble--c3 { background: #D8F3DD; color: #2E9E4B; }
.bubble--c4 { background: #DCEEFF; color: #2C6FD1; }
.bubble--c5 { background: #FCE0EE; color: #D63384; }
.bubble--c6 { background: #FFF3C4; color: #D98A00; }
.bubble--c7 { background: #DFF6F5; color: #1B9E96; }

.bubble--c1, .bubble--c2, .bubble--c3, .bubble--c4, .bubble--c5, .bubble--c6, .bubble--c7 {
  text-shadow: none;
  border: 4px solid rgba(255,255,255,0.9);
}

.bubble--target {
  --bubble-size: var(--target-bubble-size, 104px);
  width: var(--bubble-size);
  height: var(--bubble-size);
  font-size: calc(var(--bubble-size) * 0.46);
  background: #FFE18A;
  color: #E0691F;
  border: 5px solid #FFFFFF;
  box-shadow:
    inset -8px -10px 0 rgba(0,0,0,0.06),
    inset 8px 10px 18px rgba(255,255,255,0.7),
    0 0 0 6px rgba(255, 217, 102, 0.35),
    0 10px 18px rgba(34,48,80,0.32);
  z-index: 2;
}

.bubble.is-popping {
  animation: popAway 0.35s ease forwards;
  pointer-events: none;
}
@keyframes popAway {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}

.bubble.is-wrong {
  animation: wobble 0.45s ease;
}
@keyframes wobble {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-8px) rotate(-6deg); }
  40% { transform: translateX(8px) rotate(6deg); }
  60% { transform: translateX(-6px) rotate(-4deg); }
  80% { transform: translateX(6px) rotate(4deg); }
}

.bubble.is-fading {
  transition: opacity 0.4s ease, transform 0.4s ease;
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

/* Little correctness marks so we never rely on color alone */
.bubble .mark {
  position: absolute;
  top: -10px; right: -10px;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: none;
  place-items: center;
  font-size: 1.1rem;
  background: #fff;
  box-shadow: var(--shadow-soft);
}
.bubble.is-popping .mark--good { display: grid; }
.bubble.is-wrong .mark--bad { display: grid; }

/* Pop particle burst */
.pop-burst {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 50%;
  pointer-events: none;
  animation: burst 0.5s ease-out forwards;
}
@keyframes burst {
  to { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

/* Feedback toast */
.feedback-toast {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--good-bg);
  color: var(--good);
  font-weight: 800;
  padding: 10px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  z-index: 6;
  white-space: nowrap;
}
.feedback-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.feedback-toast.bad { background: var(--bad-bg); color: var(--bad); }

/* Pause overlay */
.pause-overlay {
  position: fixed;
  inset: 0;
  background: rgba(34, 48, 80, 0.55);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 20px;
}
.pause-card {
  background: var(--paper);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow-soft);
}
.pause-card .btn { width: 100%; margin-top: 10px; }

/* =========================================================
   Result screen
   ========================================================= */
.screen--result { justify-content: center; }
.result-card {
  background: var(--paper);
  border-radius: var(--radius-lg);
  padding: 36px 28px;
  max-width: 440px;
  text-align: center;
  box-shadow: var(--shadow-soft);
}
.result-mascot { font-size: 3rem; animation: happyBounce 0.9s ease; }
.result-sub { color: var(--ink-soft); font-weight: 700; }

.stars {
  font-size: 2.2rem;
  color: #E3E8F0;
  margin: 10px 0;
  letter-spacing: 6px;
}
.stars .star.filled { color: var(--sun); text-shadow: 0 2px 2px rgba(0,0,0,0.15); }

.result-score { font-size: 1.1rem; }
.result-message { color: var(--ink-soft); font-weight: 600; }

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}
.result-actions .btn { width: 100%; }

/* =========================================================
   Footer
   ========================================================= */
.app-footer {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 20px 20px 34px;
  color: rgba(34, 48, 80, 0.75);
  font-size: 0.85rem;
  max-width: 720px;
  margin: 0 auto;
}
.app-footer a { color: var(--ink); font-weight: 700; }

/* =========================================================
   Responsive tweaks
   ========================================================= */
@media (max-width: 480px) {
  .play-field { height: min(52vh, 460px); min-height: 300px; }
  .prompt-banner { padding: 8px 14px; gap: 8px; }
  .icon-btn { width: 46px; height: 46px; font-size: 1.2rem; }
}

@media (min-width: 900px) {
  .play-field { height: min(62vh, 620px); }
}
