:root {
  --ink: #33245f;
  --purple: #7456ff;
  --pink: #ff4f91;
  --yellow: #ffd84a;
  --mint: #58e0b7;
  --sky: #63d5ff;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  font-family: ui-rounded, "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
  color: white;
  background: #241b49;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

.game {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 480px;
  isolation: isolate;
  overflow: hidden;
  background: radial-gradient(circle at 50% 25%, #5edafa, #7859ec 60%, #3f2c87);
}

.camera,
.camera-wash,
#playfield,
.flash { position: absolute; inset: 0; width: 100%; height: 100%; }

.camera {
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0;
  transition: opacity .5s ease;
}

.game.camera-ready .camera { opacity: 1; }

.camera-wash {
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 45%, transparent 20%, rgba(31, 20, 80, .12) 75%, rgba(25, 13, 60, .42)),
    linear-gradient(180deg, rgba(74, 187, 255, .20), rgba(116, 86, 255, .08));
  mix-blend-mode: multiply;
}

#playfield { z-index: 2; touch-action: none; cursor: crosshair; }

.flash { z-index: 3; pointer-events: none; opacity: 0; background: white; }
.flash.pop { animation: flash .18s ease-out; }

.topbar {
  position: absolute;
  z-index: 7;
  top: max(14px, env(safe-area-inset-top));
  left: 18px;
  right: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.brand-small {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border: 2px solid rgba(255,255,255,.48);
  border-radius: 999px;
  background: rgba(61, 42, 125, .65);
  box-shadow: 0 6px 18px rgba(38, 22, 87, .22);
  backdrop-filter: blur(10px);
  font-weight: 1000;
  letter-spacing: -.03em;
}

.controls { display: flex; gap: 9px; pointer-events: auto; }

.camera-select {
  max-width: min(250px, 32vw);
  height: 48px;
  padding: 0 34px 0 14px;
  border: 2px solid rgba(255,255,255,.58);
  border-radius: 999px;
  color: white;
  background: rgba(52, 35, 111, .82);
  box-shadow: 0 7px 18px rgba(31, 18, 72, .25);
  font: 800 13px system-ui;
  text-overflow: ellipsis;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.camera-select option { color: #251b4f; background: white; }

.round-button {
  width: 48px;
  height: 48px;
  border: 2px solid rgba(255,255,255,.58);
  border-radius: 50%;
  color: white;
  background: rgba(52, 35, 111, .68);
  box-shadow: 0 7px 18px rgba(31, 18, 72, .25);
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: transform .15s ease, background .15s ease;
}

.round-button:hover { transform: scale(1.08); background: rgba(92, 66, 190, .85); }
.round-button:active { transform: scale(.93); }

.hud {
  position: absolute;
  z-index: 6;
  top: max(70px, calc(env(safe-area-inset-top) + 66px));
  left: 20px;
  right: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  opacity: 0;
  transform: translateY(-15px);
  transition: .3s ease;
  pointer-events: none;
}

.game[data-state="playing"] .hud { opacity: 1; transform: none; }

.score-pill,
.timer-pill {
  min-width: 112px;
  padding: 10px 18px;
  border: 3px solid white;
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff, #efeaff);
  color: var(--ink);
  box-shadow: 0 7px 0 #c6b9f6, 0 12px 28px rgba(33, 21, 75, .26);
  text-align: center;
  font-size: clamp(25px, 4vw, 38px);
  font-weight: 1000;
  line-height: 1;
}

.score-pill { display: flex; align-items: center; gap: 8px; }
.score-pill.bump { animation: score-bump .28s cubic-bezier(.2,1.9,.4,1); }
.star { font-size: .8em; }
.timer-pill.danger { color: #e52c68; animation: timer-pulse .65s infinite alternate; }

.streak {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translate(-50%, -25px) rotate(-3deg) scale(.7);
  opacity: 0;
  color: var(--yellow);
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 #ff5c77;
  font-size: clamp(24px, 5vw, 52px);
  font-weight: 1000;
  white-space: nowrap;
}

.streak.show { animation: streak-in .8s cubic-bezier(.2,1.5,.4,1); }

.screen {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  transition: opacity .35s ease, visibility .35s;
}

.game:not([data-state="welcome"]) .welcome-screen,
.game:not([data-state="countdown"]) .countdown-screen,
.game:not([data-state="results"]) .results-screen {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.welcome-screen {
  background:
    radial-gradient(circle at 50% 45%, transparent 0 18%, rgba(93, 63, 205, .1) 55%),
    linear-gradient(145deg, #67dcff, #8c68f4 68%, #5d42bd);
}

.welcome-screen:after {
  content: "";
  position: absolute;
  z-index: -1;
  left: -5%;
  right: -5%;
  bottom: -10%;
  height: 36%;
  background: #67dca3;
  border-radius: 50% 50% 0 0 / 30% 30% 0 0;
  box-shadow: inset 0 20px 0 rgba(255,255,255,.15);
}

.welcome-card,
.results-card {
  position: relative;
  width: min(610px, 92vw);
  padding: clamp(28px, 5vw, 52px);
  text-align: center;
  border: 4px solid rgba(255,255,255,.92);
  border-radius: 42px;
  color: var(--ink);
  background: linear-gradient(155deg, rgba(255,255,255,.97), rgba(244,240,255,.93));
  box-shadow: 0 14px 0 rgba(69, 44, 145, .22), 0 28px 70px rgba(41, 25, 99, .32);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 4px;
  color: #7359d8;
  font-size: clamp(13px, 2vw, 17px);
  font-weight: 1000;
  letter-spacing: .13em;
  text-transform: uppercase;
}

h1 { margin: 0; line-height: .9; letter-spacing: -.07em; }
h1 span { display: block; color: var(--pink); font-size: clamp(55px, 10vw, 94px); text-shadow: 0 6px 0 #ffc1d9; }
h1 strong { color: var(--purple); font-size: clamp(66px, 12vw, 112px); text-shadow: 0 7px 0 #c8bcff; }

.intro { max-width: 470px; margin: 21px auto; font-size: clamp(17px, 2.6vw, 23px); font-weight: 750; line-height: 1.3; }

.camera-tip {
  display: flex;
  align-items: center;
  gap: 13px;
  max-width: 460px;
  margin: 0 auto 22px;
  padding: 12px 15px;
  border-radius: 18px;
  text-align: left;
  background: #ece8ff;
  color: #514278;
}

.tip-icon { font-size: 30px; }
.camera-tip strong, .camera-tip small { display: block; }
.camera-tip strong { font-size: 14px; }
.camera-tip small { margin-top: 2px; font: 600 12px system-ui; opacity: .75; }

.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  min-width: min(330px, 100%);
  margin: auto;
  padding: 17px 24px;
  border: 0;
  border-radius: 22px;
  color: white;
  background: linear-gradient(180deg, #ff719f, #f33e7d);
  box-shadow: 0 8px 0 #bd2158, 0 14px 26px rgba(214, 39, 101, .27);
  font-size: clamp(22px, 4vw, 31px);
  font-weight: 1000;
  cursor: pointer;
  transition: transform .15s ease, filter .15s ease;
}

.primary-button b { font-size: .8em; }
.primary-button:hover { transform: translateY(-2px) scale(1.025); filter: saturate(1.15); }
.primary-button:active { transform: translateY(6px); box-shadow: 0 2px 0 #bd2158; }
.primary-button:disabled { filter: grayscale(.7); cursor: wait; }

.game-switch {
  display: flex;
  align-items: center;
  gap: 11px;
  width: min(330px, 100%);
  margin: 17px auto 0;
  padding: 10px 14px;
  border: 2px solid #d8d0ff;
  border-radius: 17px;
  color: #514278;
  background: #f1eeff;
  text-align: left;
  text-decoration: none;
  transition: transform .16s ease, background .16s ease;
}
.game-switch:hover { transform: translateY(-2px); background: #e9e3ff; }
.game-switch-icon { font-size: 26px; }
.game-switch span:nth-child(2) { flex: 1; }
.game-switch strong, .game-switch small { display: block; }
.game-switch strong { font-size: 14px; }
.game-switch small { margin-top: 2px; font: 650 11px system-ui; opacity: .72; }
.game-switch b { font-size: 20px; }

.camera-status { margin: 16px 0 -16px; color: #786d91; font: 650 12px system-ui; }

.hero-balloons .css-balloon {
  position: absolute;
  width: 105px;
  height: 130px;
  border-radius: 52% 48% 48% 52%;
  background: var(--balloon);
  box-shadow: inset -18px -16px 0 rgba(74,32,99,.12), inset 14px 10px 0 rgba(255,255,255,.3), 0 15px 30px rgba(45,28,99,.18);
  animation: drift 4s ease-in-out infinite alternate;
}

.hero-balloons .css-balloon:after { content: ""; position: absolute; left: 50%; top: 99%; width: 2px; height: 150px; background: rgba(255,255,255,.65); }
.hero-balloons .pink { --balloon: #ff4f91; left: 7%; top: 18%; transform: rotate(-10deg); }
.hero-balloons .yellow { --balloon: #ffd84a; right: 7%; top: 10%; transform: rotate(10deg); animation-delay: -.8s; }
.hero-balloons .blue { --balloon: #47cfed; right: 14%; bottom: 7%; width: 78px; height: 98px; animation-delay: -1.5s; }

.cloud { position: absolute; width: 200px; height: 58px; border-radius: 99px; background: rgba(255,255,255,.25); filter: blur(.3px); }
.cloud:before, .cloud:after { content: ""; position: absolute; border-radius: 50%; background: inherit; }
.cloud:before { width: 80px; height: 80px; left: 35px; bottom: 0; }
.cloud:after { width: 110px; height: 110px; right: 20px; bottom: 0; }
.cloud-one { left: -50px; top: 12%; }
.cloud-two { right: -40px; top: 43%; transform: scale(.7); }

.countdown-screen { background: rgba(54, 34, 127, .36); backdrop-filter: blur(3px); text-align: center; }
.countdown-value {
  color: var(--yellow);
  font-size: min(44vw, 330px);
  font-weight: 1000;
  line-height: .8;
  -webkit-text-stroke: min(2vw, 15px) white;
  paint-order: stroke fill;
  filter: drop-shadow(0 14px 0 #ff5c80) drop-shadow(0 25px 18px rgba(46,25,101,.32));
  animation: count-pop .8s cubic-bezier(.15,1.4,.35,1);
}
.countdown-screen p { margin: 40px 0 0; font-size: clamp(20px, 4vw, 38px); font-weight: 1000; text-shadow: 0 4px 0 #4a338e; }

.callout {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%) rotate(-4deg) scale(.3);
  opacity: 0;
  pointer-events: none;
  color: var(--yellow);
  -webkit-text-stroke: clamp(5px, 1vw, 11px) var(--ink);
  paint-order: stroke fill;
  text-align: center;
  text-shadow: 0 9px 0 #ff4d83, 0 18px 28px rgba(37,20,78,.4);
  font-size: clamp(43px, 10vw, 108px);
  font-weight: 1000;
  line-height: .88;
  white-space: nowrap;
}
.callout.show { animation: callout 1.65s cubic-bezier(.15,1.3,.35,1); }

.results-screen { background: rgba(46, 29, 105, .44); backdrop-filter: blur(7px); }
.results-card { animation: results-in .65s cubic-bezier(.15,1.35,.35,1); }
.trophy { position: absolute; left: 50%; top: 0; transform: translate(-50%, -60%); font-size: clamp(70px, 12vw, 115px); filter: drop-shadow(0 8px 0 #d4a723); }
.results-card h2 { margin: 12px 0 -4px; color: #65568d; font-size: clamp(23px, 4vw, 36px); }
.final-score { color: var(--pink); font-size: clamp(72px, 15vw, 138px); font-weight: 1000; line-height: .95; letter-spacing: -.05em; text-shadow: 0 7px 0 #ffd0df; }
.final-score small { display: block; color: var(--purple); font-size: .25em; letter-spacing: 0; text-shadow: none; }
.best-message { display: inline-block; margin: 19px 0 5px; padding: 8px 13px; border-radius: 12px; color: #684d00; background: #ffe46b; font-weight: 1000; transform: rotate(-2deg); }
.best-message.hidden { display: none; }
.best-score { margin: 7px 0 24px; color: #756b8d; font-weight: 800; }

.camera-notice {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 20px);
  max-width: min(560px, 90vw);
  padding: 11px 17px;
  border: 2px solid rgba(255,255,255,.5);
  border-radius: 999px;
  opacity: 0;
  color: white;
  background: rgba(49, 33, 105, .82);
  box-shadow: 0 8px 25px rgba(27,15,65,.25);
  text-align: center;
  font: 700 13px system-ui;
  pointer-events: none;
  transition: .3s ease;
}
.camera-notice.show { opacity: 1; transform: translate(-50%, 0); }

.game.shake { animation: shake .25s ease-out; }
.game.mega-shake { animation: mega-shake .45s ease-out; }

@keyframes flash { 0% { opacity: .35; } 100% { opacity: 0; } }
@keyframes score-bump { 50% { transform: scale(1.22) rotate(-4deg); } }
@keyframes timer-pulse { to { transform: scale(1.08); background: #fff0f4; } }
@keyframes streak-in { 0% { opacity: 0; transform: translate(-50%,-25px) rotate(-6deg) scale(.6); } 25%,70% { opacity: 1; transform: translate(-50%,0) rotate(-3deg) scale(1); } 100% { opacity: 0; transform: translate(-50%,-15px) rotate(2deg) scale(1.12); } }
@keyframes count-pop { 0% { transform: scale(.2) rotate(-15deg); opacity: 0; } 45% { transform: scale(1.1) rotate(3deg); opacity: 1; } 100% { transform: scale(.88); opacity: 1; } }
@keyframes callout { 0% { opacity: 0; transform: translate(-50%,-50%) rotate(-8deg) scale(.25); } 20%,68% { opacity: 1; transform: translate(-50%,-50%) rotate(-3deg) scale(1); } 100% { opacity: 0; transform: translate(-50%,-70%) rotate(3deg) scale(1.2); } }
@keyframes results-in { from { transform: translateY(80px) scale(.65) rotate(-4deg); opacity: 0; } }
@keyframes drift { to { translate: 0 -25px; rotate: 5deg; } }
@keyframes shake { 25% { transform: translate(5px,-3px) rotate(.2deg); } 55% { transform: translate(-4px,2px); } }
@keyframes mega-shake { 20% { transform: translate(10px,-6px) rotate(.5deg); } 40% { transform: translate(-9px,5px) rotate(-.4deg); } 70% { transform: translate(5px,-3px); } }

@media (max-width: 700px) {
  .game { min-height: 400px; }
  .brand-small { font-size: 13px; padding: 8px 11px; }
  .round-button { width: 42px; height: 42px; }
  .camera-select { height: 42px; max-width: 42vw; font-size: 11px; }
  .topbar { left: 10px; right: 10px; top: 10px; }
  .hud { top: 63px; left: 11px; right: 11px; }
  .score-pill, .timer-pill { min-width: 88px; padding: 9px 13px; border-width: 2px; border-radius: 18px; }
  .welcome-card, .results-card { border-radius: 28px; padding: 30px 22px; }
  .hero-balloons .css-balloon, .cloud { opacity: .45; }
  .camera-tip { margin-bottom: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *:before, *:after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
