:root {
  color-scheme: light;
  --ink: #1d2440;
  --muted: #665082;
  --pink: #ff5aa5;
  --orange: #ff9f2f;
  --yellow: #ffe66d;
  --mint: #62dfad;
  --sky: #64d8ff;
  --blue: #4267ff;
  --panel: rgba(255, 255, 255, 0.88);
  --shadow: 0 18px 44px rgba(41, 34, 82, 0.24);
}

* {
  box-sizing: border-box;
}

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

body {
  display: grid;
  place-items: center;
  min-width: 820px;
  min-height: 100vh;
  overflow: hidden;
  padding: 14px;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Comic Sans MS", system-ui, sans-serif;
  background:
    radial-gradient(circle at 13% 11%, rgba(255, 230, 109, 0.92) 0 110px, transparent 112px),
    radial-gradient(circle at 86% 17%, rgba(98, 223, 173, 0.74) 0 102px, transparent 104px),
    radial-gradient(circle at 79% 88%, rgba(255, 90, 165, 0.48) 0 132px, transparent 134px),
    linear-gradient(135deg, #7ee7ff 0%, #fff08e 43%, #ffafd5 100%);
  user-select: none;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  width: min(1320px, calc(100vw - 28px));
  height: min(880px, calc(100vh - 28px));
  min-height: 650px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow,
h1,
h2,
p {
  margin: 0;
}

.eyebrow {
  color: #6b37a9;
  font-size: 0.8rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(2rem, 4.8vw, 4.7rem);
  line-height: 0.92;
  letter-spacing: 0;
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.68);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 8px 13px;
  border: 3px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow);
  color: #50306c;
  font-weight: 950;
  white-space: nowrap;
}

.mode-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 5px rgba(255, 230, 109, 0.28);
}

.mode-dot.is-live {
  background: var(--mint);
  box-shadow: 0 0 0 5px rgba(98, 223, 173, 0.28);
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 5px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  background:
    radial-gradient(circle at 20% 14%, rgba(255, 255, 255, 0.28) 0 60px, transparent 62px),
    radial-gradient(circle at 78% 74%, rgba(255, 255, 255, 0.22) 0 86px, transparent 88px),
    linear-gradient(135deg, #372770 0%, #1c4ea9 48%, #2cc7d8 100%);
  box-shadow: var(--shadow);
}

video {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.sparkle-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.sparkle {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--sparkle-color, #fff);
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.22), 0 0 20px currentColor;
  color: var(--sparkle-color, #fff);
  animation: sparklePop 780ms ease-out forwards;
}

.sparkle::before,
.sparkle::after {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 34px;
  height: 5px;
  border-radius: 999px;
  background: currentColor;
  content: "";
  transform: translate(-50%, -50%);
}

.sparkle::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(30, 24, 62, 0.18);
  backdrop-filter: blur(3px);
}

.overlay.hidden {
  display: none;
}

.overlay-panel {
  display: grid;
  justify-items: center;
  gap: 13px;
  width: min(520px, 92vw);
  padding: 28px;
  border: 4px solid rgba(255, 255, 255, 0.88);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 20px 46px rgba(32, 23, 72, 0.28);
  text-align: center;
}

.badge {
  padding: 8px 12px;
  border-radius: 999px;
  background: #fff0a6;
  color: #7d3f12;
  font-weight: 950;
}

h2 {
  font-size: clamp(2.2rem, 5vw, 4.1rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.overlay-copy {
  max-width: 28rem;
  color: var(--muted);
  font-size: 1.08rem;
  font-weight: 850;
  line-height: 1.35;
}

.primary-button,
.preset-button,
.action-button {
  border-radius: 8px;
  font-weight: 950;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.15), 0 7px 16px rgba(36, 29, 80, 0.16);
}

.primary-button {
  min-height: 58px;
  padding: 0 24px;
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--blue));
  font-size: 1.18rem;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px 320px;
  gap: 12px;
  align-items: stretch;
}

.preset-strip,
.dial-panel,
.action-row {
  min-width: 0;
  border: 4px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.preset-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 9px;
}

.preset-button {
  display: grid;
  grid-template-rows: 32px auto;
  place-items: center;
  gap: 5px;
  min-height: 76px;
  min-width: 0;
  padding: 7px 6px;
  color: #2e2650;
  background: #ffffff;
  font-size: 0.88rem;
  line-height: 1.05;
  text-align: center;
}

.preset-button.is-active {
  color: white;
  background: linear-gradient(135deg, var(--pink), var(--blue));
  transform: translateY(3px);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18), 0 3px 9px rgba(36, 29, 80, 0.14);
}

.preset-icon {
  position: relative;
  display: block;
  width: 34px;
  height: 28px;
}

.rainbow-icon {
  border: 7px solid #ff5aa5;
  border-bottom: 0;
  border-radius: 34px 34px 0 0;
  box-shadow: inset 0 5px 0 #ffe66d, inset 0 11px 0 #62dfad;
}

.bubble-icon::before,
.bubble-icon::after {
  position: absolute;
  border: 4px solid #64d8ff;
  border-radius: 50%;
  content: "";
}

.bubble-icon::before {
  inset: 2px 10px 3px 1px;
}

.bubble-icon::after {
  inset: 8px 1px 0 18px;
  border-color: #ff9f2f;
}

.eyes-icon::before,
.eyes-icon::after {
  position: absolute;
  top: 3px;
  width: 14px;
  height: 20px;
  border: 4px solid currentColor;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 55%, currentColor 0 4px, #fff 5px);
  content: "";
}

.eyes-icon::before {
  left: 0;
}

.eyes-icon::after {
  right: 0;
}

.star-icon {
  background: conic-gradient(from 18deg, #ffe66d 0 10%, transparent 10% 20%, #ff5aa5 20% 30%, transparent 30% 40%, #62dfad 40% 50%, transparent 50% 60%, #64d8ff 60% 70%, transparent 70% 80%, #ff9f2f 80% 90%, transparent 90%);
  clip-path: polygon(50% 0, 61% 33%, 96% 35%, 67% 55%, 79% 91%, 50% 69%, 21% 91%, 33% 55%, 4% 35%, 39% 33%);
}

.jelly-icon {
  border-radius: 50% 50% 42% 42%;
  background: linear-gradient(135deg, #62dfad, #4267ff);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.16);
}

.jelly-icon::after {
  position: absolute;
  right: 3px;
  bottom: -4px;
  left: 3px;
  height: 8px;
  border-radius: 50%;
  background: rgba(66, 103, 255, 0.28);
  content: "";
}

.confetti-icon {
  background:
    radial-gradient(circle at 8px 7px, #ff5aa5 0 4px, transparent 5px),
    radial-gradient(circle at 25px 9px, #ffe66d 0 4px, transparent 5px),
    radial-gradient(circle at 15px 22px, #62dfad 0 4px, transparent 5px),
    linear-gradient(45deg, transparent 0 44%, #4267ff 45% 56%, transparent 57%);
}

.dial-panel {
  display: grid;
  gap: 7px;
  padding: 10px 12px;
}

.dial-panel label {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  color: #533574;
  font-weight: 950;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--pink);
}

.action-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  padding: 9px;
}

.action-button {
  min-width: 0;
  min-height: 78px;
  padding: 9px;
  color: #2e2650;
  background: #fff;
}

.action-button.is-on,
.action-button.shuffle {
  color: #fff;
  background: linear-gradient(135deg, var(--orange), var(--pink));
}

.primary-button:active,
.preset-button:active,
.action-button:active {
  transform: translateY(4px);
}

@keyframes sparklePop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.2) rotate(0deg);
  }

  20% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -150%) scale(1.6) rotate(100deg);
  }
}

@media (max-width: 960px), (pointer: coarse) {
  body {
    min-width: 0;
    overflow: auto;
    padding: 0;
  }

  .game-shell {
    width: 100vw;
    height: 100vh;
    min-height: 0;
    padding: 18px;
  }

  .topbar,
  .controls {
    display: none;
  }

  .stage {
    min-height: 100%;
  }

  #permissionOverlay {
    display: none;
  }

  #unsupportedOverlay {
    display: grid;
  }
}
