.bubble-hero {
  position: relative;
  isolation: isolate;
  display: grid;
  width: 100%;
  min-height: 106px;
  margin-block: 14px 0;
  align-content: center;
  justify-items: start;
  gap: 5px;
  overflow: hidden;
  padding: 16px clamp(16px, 4.5vw, 34px);
  padding-inline-end: clamp(72px, 22vw, 160px);
  border: 1px solid #715497;
  border-radius: 22px;
  color: #fff8ff;
  background: linear-gradient(122deg, #342454 12%, #4e326e 65%, #623f87);
  box-shadow: 0 4px 0 #dbc9ee;
  text-align: left;
}

.bubble-hero::before,
.bubble-hero::after {
  position: absolute;
  z-index: -1;
  content: '';
  pointer-events: none;
}

.bubble-hero::before {
  inset: 0;
  background:
    radial-gradient(circle at 77% 29%, #fff3c5 0 2px, transparent 3px),
    radial-gradient(circle at 86% 79%, #efd8fe 0 2px, transparent 3px),
    radial-gradient(circle at 97% 18%, #fff3c5 0 1px, transparent 3px),
    radial-gradient(circle at 80% 70%, #ad8ad7 0 1px, transparent 3px),
    radial-gradient(circle at 95% 78%, #ad8ad7 0 2px, transparent 4px);
}

.bubble-hero::after {
  top: 50%;
  right: clamp(14px, 9%, 94px);
  width: clamp(39px, 11vw, 72px);
  aspect-ratio: 1;
  transform: translateY(-50%);
  border: 1px solid #f8e5ff;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, #fff8ff 0 7%, #f4d6ff 13%, #cab0f3 53%, #9272c7 95%);
  box-shadow: 16px 17px 0 -9px #efda9a, -13px -14px 0 -9px #ecb9e5;
}

.bubble-hero:hover { border-color: #cc9af5; }
.bubble-hero-copy { display: grid; gap: 4px; }
.bubble-hero strong { font-size: clamp(23px, 5vw, 35px); font-weight: 900; line-height: 1.12; letter-spacing: -.055em; }
.bubble-hero small { color: #f1dff9; font-size: clamp(12px, 2.7vw, 15px); font-weight: 670; line-height: 1.35; word-break: keep-all; }
.bubble-hero-arrow { position: absolute; inset: 50% 12px auto auto; transform: translateY(-50%); font-size: 18px; font-weight: 800; }

#bubbles { max-width: 780px; margin-inline: auto; }
.bubble-header { display: grid; gap: 4px; margin-bottom: 12px; }
.bubble-header h1 { font-size: clamp(24px, 5vw, 36px); line-height: 1.15; letter-spacing: -.045em; }
.bubble-header p { color: #61496f; font-size: 14px; line-height: 1.45; word-break: keep-all; }
.bubble-header .bubble-identity { justify-self: start; padding: 5px 10px; border-radius: 999px; background: #eee0f6; color: #51376c; font-size: 13px; font-weight: 800; }
.bubble-header .bubble-identity[data-team='yellow'] { background: #fff0ae; color: #62462e; }
.bubble-setup { display: grid; gap: 16px; max-width: 640px; padding: clamp(14px, 5vw, 26px); border: 1px solid #dfcdeb; border-radius: 20px; background: #fffaff; }
.bubble-setup > button { justify-self: start; }
.bubble-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.bubble-setup fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.bubble-setup p { color: #61496f; font-size: 14px; line-height: 1.45; word-break: keep-all; }
.bubble-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.bubble-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.bubble-options label { display: grid; min-width: 0; gap: 5px; color: #50345f; font-size: 13px; font-weight: 750; }
.bubble-options select { width: 100%; min-height: 42px; padding: 5px 6px; border: 1px solid #c6a9d7; border-radius: 8px; color: inherit; background: #fff; font: inherit; }
.bubble-levels { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(5px, 2vw, 10px); }
.bubble-levels label {
  display: grid;
  min-height: 79px;
  align-content: center;
  justify-items: center;
  gap: 4px;
  padding: 7px 3px;
  border: 1px solid #d7bce7;
  border-radius: 13px;
  background: #fcf5ff;
  color: #50345f;
  cursor: pointer;
  text-align: center;
}
.bubble-levels label:hover { border-color: #9860bd; }
.bubble-levels label:focus-within { outline: 2px solid #7944a2; outline-offset: 2px; }
.bubble-levels label:has(input:checked) { border-color: #8a51b5; background: #f1e1fc; box-shadow: inset 0 0 0 1px #8a51b5; }
.bubble-levels input { accent-color: #7944a2; margin: 0; }
.bubble-levels strong { font-size: 16px; font-weight: 850; }
.bubble-levels span { font-size: 12px; font-weight: 680; line-height: 1.25; word-break: keep-all; }

.bubble-board {
  position: relative;
  isolation: isolate;
  min-width: 0;
  padding: clamp(11px, 3vw, 24px);
  border: 1px solid #715497;
  border-radius: clamp(16px, 5vw, 26px);
  background: #2c1c49 radial-gradient(ellipse at 48% 95%, #4c2f6e, transparent 72%);
  color: #fff9ff;
}
.bubble-board::before {
  position: absolute;
  z-index: -1;
  inset: 0;
  content: '';
  border-radius: inherit;
  background:
    radial-gradient(circle at 11% 33%, #ba9bdc 0 1px, transparent 2px),
    radial-gradient(circle at 48% 64%, #ceb4ea 0 1px, transparent 2px),
    radial-gradient(circle at 86% 57%, #d9b9eb 0 1px, transparent 2px),
    radial-gradient(circle at 16% 62%, #ad8ad8 0 1px, transparent 2px),
    radial-gradient(circle at 93% 39%, #e7c9f8 0 1px, transparent 2px),
    radial-gradient(circle at 37% 82%, #ad8ad8 0 1px, transparent 2px);
  pointer-events: none;
}
.bubble-board-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 7px clamp(6px, 2vw, 13px);
  min-height: 65px;
  padding-bottom: 9px;
  text-align: center;
}
.bubble-hud { display: grid; justify-items: center; gap: 3px; line-height: 1.12; }
.bubble-hud span { color: #f0dff7; font-size: clamp(10px, 2.5vw, 13px); font-weight: 720; }
.bubble-hud strong { font-size: clamp(18px, 4vw, 25px); font-variant-numeric: tabular-nums; font-weight: 900; }
.bubble-time[data-urgent='true'] #bubble-seconds { color: #ffc1d9; }
.bubble-time[data-penalty='true'] #bubble-seconds { color: #ffe4eb; background: #914667; padding: 0 5px; border-radius: 6px; }
#bubble-equation {
  grid-column: 1 / -1;
  justify-self: center;
  color: #fff7ec;
  font-size: clamp(22px, 5vw, 41px);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  letter-spacing: -.05em;
  line-height: 1.17;
  text-align: center;
  white-space: nowrap;
}
#bubble-equation:focus { outline: none; }
#bubble-equation:focus-visible { outline-color: #fff1a4; }
#bubble-seconds, #bubble-score { color: #fff3b2; font-variant-numeric: tabular-nums; font-weight: 900; }
.bubble-meter { height: 5px; overflow: hidden; border-radius: 999px; background: #674884; }
.bubble-meter i { display: block; width: 100%; height: 100%; border-radius: inherit; background: #f7d88a; transform-origin: left center; }

.bubble-field {
  --bubble-size: clamp(54px, 17vw, 92px);
  --bubble-number-size: clamp(19px, 5vw, 34px);
  --arena-min-height: 282px;
  position: relative;
  width: 100%;
  height: clamp(var(--arena-min-height), 47vh, 385px);
  margin-block: 7px;
}
.bubble-field[data-level='easy'] {
  --bubble-size: clamp(64px, 20vw, 108px);
  --bubble-number-size: clamp(21px, 5.5vw, 40px);
  --arena-min-height: 274px;
}
.bubble-field[data-level='hard'] {
  --bubble-size: clamp(54px, 16vw, 84px);
  --arena-min-height: 294px;
}
.bubble-field[data-level='expert'] {
  --bubble-size: clamp(52px, 15vw, 80px);
  --bubble-number-size: clamp(18px, 4.8vw, 31px);
  --arena-min-height: 306px;
}
.bubble-field > .answer-bubble {
  --bubble-surface: #f0d9ff;
  --bubble-rim: #a67dcf;
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  user-select: none;
  width: var(--bubble-size);
  height: var(--bubble-size);
  place-content: center;
  justify-items: center;
  gap: 2px;
  padding: 2px;
  border: 2px solid var(--bubble-rim);
  border-radius: 50%;
  background: radial-gradient(circle at 33% 20%, #fffafd 4%, var(--bubble-surface) 63%);
  box-shadow: inset 0 -4px 0 #6c45892d, 0 3px 0 #10062068;
  color: #372047;
}
.bubble-field > .answer-bubble:nth-child(6n + 2) { --bubble-surface: #ffebbd; --bubble-rim: #ce9f63; }
.bubble-field > .answer-bubble:nth-child(6n + 3) { --bubble-surface: #d5f3e3; --bubble-rim: #78bfa8; }
.bubble-field > .answer-bubble:nth-child(6n + 4) { --bubble-surface: #ffdbe8; --bubble-rim: #d68eb7; }
.bubble-field > .answer-bubble:nth-child(6n + 5) { --bubble-surface: #dceaff; --bubble-rim: #819fd2; }
.bubble-field > .answer-bubble:nth-child(6n + 6) { --bubble-surface: #ffe0ce; --bubble-rim: #cd9279; }
.answer-bubble strong { font-size: var(--bubble-number-size); font-variant-numeric: tabular-nums; font-weight: 900; letter-spacing: -.035em; line-height: 1; white-space: nowrap; }
.answer-bubble small { min-width: 15px; padding: 1px 3px; border: 1px solid #41245b32; border-radius: 5px; color: #50375b; font-size: 9px; font-weight: 780; line-height: 1; }
.bubble-field[data-motion='on'] > .answer-bubble { will-change: transform; }
.answer-bubble:focus-visible { z-index: 1; outline: 3px solid #fff1a4; outline-offset: 2px; }
.answer-bubble:disabled { cursor: default; }
.bubble-field > .answer-bubble[data-state='wrong'] { border-color: #cb7698; background: #f6bccc; text-decoration: line-through; }
.bubble-field > .answer-bubble[data-state='correct'] { z-index: 1; border-color: #c3ec9f; outline: 3px double #c3ec9f; outline-offset: 3px; background: #e0f5cb; }
.answer-bubble[data-caught]::after { position: absolute; inset: -4px; border: 2px solid #ecffb4; border-radius: inherit; content: ''; pointer-events: none; animation: bubble-pop 350ms ease-out both; }
.bubble-field > .answer-bubble[data-state='missed'] { border-style: dashed; }

@keyframes bubble-pop {
  from { transform: scale(1); opacity: 1; }
  to { transform: scale(1.25); opacity: 0; }
}

.bubble-footer { display: grid; justify-items: center; gap: 4px; padding: 4px; text-align: center; }
.bubble-footer .button:focus-visible { outline-color: #fff1a4; }
.bubble-feedback {
  min-height: 30px;
  color: #f6e7fe;
  font-size: 13px;
  font-weight: 680;
  line-height: 1.36;
  text-align: center;
  word-break: keep-all;
}
.bubble-feedback span { display: block; margin-top: 3px; }
.bubble-feedback[data-state='correct'] { color: #d7f3b8; }
.bubble-feedback[data-state='wrong'], .bubble-feedback[data-state='missed'] { color: #ffd6e6; }
.bubble-result { display: grid; justify-items: center; gap: 12px; min-height: 232px; align-content: center; padding: 15px 8px; text-align: center; }
.bubble-result > div { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 8px; }
.bubble-result p { color: #61496f; font-size: 14px; line-height: 1.45; word-break: keep-all; }
.bubble-result #bubble-final-score { color: #563483; font-size: clamp(29px, 7vw, 53px); font-weight: 900; letter-spacing: -.06em; line-height: 1.1; }
.bubble-key-guide { margin-top: 8px; color: #61496f; font-size: 12px; line-height: 1.45; text-align: center; }
.bubble-board .button.light { border-color: #f0ddfc; }

@media (hover: hover) {
  .answer-bubble:not(:disabled, :focus-visible):hover { z-index: 1; outline: 2px solid #fff1a4; outline-offset: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .bubble-field[data-motion='on'] > .answer-bubble { will-change: auto; }
  .answer-bubble[data-caught]::after { content: none; }
}

@media (max-height: 460px) and (orientation: landscape) {
  .shell[data-screen='bubbles'] .masthead { min-height: 49px; }
  #bubbles { max-width: 650px; }
  .bubble-header { margin-bottom: 6px; }
  .bubble-header h1 { font-size: 21px; }
  .bubble-header p { font-size: 12px; }
  .bubble-board { padding-block: 6px; }
  .bubble-board-head { min-height: 47px; gap: 4px 8px; padding-bottom: 6px; }
  .bubble-field { height: clamp(206px, calc(100vh - 164px), 290px); margin-block: 5px; }
  .bubble-field, .bubble-field[data-level] {
    --bubble-size: 58px;
    --bubble-number-size: 20px;
  }
  .bubble-feedback { min-height: 28px; }
}

@media (min-width: 515px) and (max-height: 460px) and (orientation: landscape) {
  .bubble-board-head { grid-template-columns: minmax(0, 1fr) minmax(0, 4fr) repeat(2, minmax(0, 1fr)); }
  .bubble-board-head > :nth-child(2) { grid-area: 1 / 3; }
  .bubble-board-head > :nth-child(3) { grid-area: 1 / 4; }
  #bubble-equation { grid-area: 1 / 2; font-size: clamp(22px, 4.8vw, 38px); }
}
