:root {
  --ink: #39255d;
  --purple: #6f45e8;
  --purple-dark: #5832c4;
  --cream: #fffdf5;
  --sky: #dff7ff;
  --pink: #ff71b8;
}

* { box-sizing: border-box; }

html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 14%, rgba(255,255,255,.95) 0 4px, transparent 5px),
    radial-gradient(circle at 87% 22%, rgba(255,255,255,.85) 0 6px, transparent 7px),
    linear-gradient(160deg, #bceeff 0%, #e7d9ff 52%, #ffd4ec 100%);
  font-family: ui-rounded, "Arial Rounded MT Bold", Nunito, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

button, .luna {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.game-shell {
  width: min(980px, 100%);
  height: 100%;
  min-height: 0;
  max-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  overscroll-behavior: none;
  padding: max(16px, env(safe-area-inset-top)) clamp(16px, 4vw, 42px) max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 12px;
  position: relative;
}

@supports (height: 100dvh) {
  body { height: 100dvh; }
}

header { display: flex; align-items: center; justify-content: space-between; z-index: 3; }
.brand { display: flex; align-items: center; gap: 9px; }
.brand h1 { margin: 0; font-size: clamp(1.15rem, 3.5vw, 1.65rem); letter-spacing: -.03em; }
.mini-star { color: #f5af18; font-size: 1.7rem; filter: drop-shadow(0 2px 0 #fff); }

.sound-button {
  width: 50px; height: 50px; border: 3px solid rgba(57,37,93,.12); border-radius: 50%;
  color: var(--purple-dark); background: rgba(255,255,255,.8); box-shadow: 0 5px 0 rgba(88,50,196,.13);
  font-size: 1.5rem; cursor: pointer;
}
.sound-button:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(88,50,196,.13); }

.play-area {
  min-height: 300px;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(240px, .88fr);
  align-items: center;
  gap: clamp(8px, 4vw, 42px);
  position: relative;
}

.character-wrap { min-height: 280px; height: min(46vh, 440px); position: relative; display: grid; place-items: center; }
.luna {
  width: min(100%, 430px); max-height: 100%; object-fit: contain; position: relative; z-index: 2;
  filter: drop-shadow(0 18px 20px rgba(77,39,139,.2)); transform-origin: 50% 90%;
  animation: float 3.3s ease-in-out infinite; cursor: pointer; touch-action: manipulation; user-select: none;
}
.luna:focus-visible { outline: 5px solid #fff; outline-offset: 4px; border-radius: 42%; }
.luna.happy-reaction { animation: lunaHappy .72s ease both; }
.luna.sad-reaction { animation: lunaSad .68s ease both; }
.rainbow-arc {
  position: absolute; width: min(88%, 380px); aspect-ratio: 1; border-radius: 50%;
  background: conic-gradient(from 210deg, #ff596d, #ffbd3e, #67d47e, #52b9f6, #9771ef, #ff72b6, #ff596d);
  opacity: .28; filter: blur(1px); mask: radial-gradient(circle, transparent 0 53%, #000 54% 63%, transparent 64%);
  transform: rotate(-30deg);
}

.prompt-card {
  position: relative; z-index: 4; text-align: center; background: rgba(255,253,245,.93); border: 4px solid #fff;
  border-radius: 30px 30px 30px 10px; padding: clamp(22px, 5vw, 38px); box-shadow: 0 14px 34px rgba(67,38,118,.18);
}
.prompt-button {
  width: 100%; margin: 0 0 20px; padding: 0; border: 0; color: inherit; background: transparent;
  font-size: clamp(1.45rem, 5vw, 2.35rem); font-weight: 900; line-height: 1.15;
}
.prompt-button:not(:disabled) { cursor: pointer; }
.prompt-button:not(:disabled):active { transform: scale(.97); }
.prompt-button:disabled { opacity: 1; }
.restart {
  min-height: 60px; border: 0; border-radius: 999px; padding: 12px 28px; color: #fff;
  background: linear-gradient(180deg, #875eff, var(--purple)); box-shadow: 0 7px 0 #4f2cb5, 0 12px 24px rgba(92,53,188,.25);
  font-weight: 900; font-size: clamp(1.15rem, 3vw, 1.4rem); cursor: pointer;
}
.restart:active { transform: translateY(5px); box-shadow: 0 2px 0 #4f2cb5; }

.mode-menu { display: grid; gap: 11px; }
.mode-button {
  min-height: 58px; border: 3px solid #fff; border-radius: 18px; padding: 9px 15px;
  display: grid; grid-template-columns: 58px 1fr; align-items: center; text-align: left;
  background: #f8f4ff; color: var(--ink); box-shadow: 0 5px 0 #d6c7f7;
  font-size: clamp(1rem, 2.8vw, 1.18rem); font-weight: 900; cursor: pointer;
}
.mode-button:nth-child(2) { background: #fff3d4; box-shadow-color: #efd18a; }
.mode-button:nth-child(3) { background: #ddf8ff; box-shadow-color: #99dbe9; }
.mode-button span { font-size: 1.55rem; color: var(--purple); text-align: center; }
.mode-button:nth-child(2) span { color: #ef6f57; }
.mode-button:nth-child(3) span { color: #167b99; font-size: 1.05rem; letter-spacing: -.08em; }
.mode-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #d6c7f7; }

.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(10px, 2vw, 18px); z-index: 4; }
.color-choice, .shape-choice, .count-choice {
  min-height: clamp(82px, 15vw, 120px); border: 5px solid rgba(255,255,255,.95); border-radius: 28px;
  box-shadow: 0 8px 0 color-mix(in srgb, var(--color), #37205f 35%), 0 12px 22px rgba(57,37,93,.17);
  background: var(--color); cursor: pointer; position: relative; transition: transform .15s ease;
}
.color-choice::after { content: "★"; color: rgba(255,255,255,.94); font-size: clamp(2.3rem, 7vw, 4rem); text-shadow: 0 3px 0 rgba(0,0,0,.1); }
.shape-choice, .count-choice { --color: #d7c8fa; background: rgba(255,253,245,.94); display: grid; place-items: center; }
.shape-symbol { color: var(--shape-color); font-size: clamp(3rem, 10vw, 5.3rem); line-height: .85; text-shadow: 0 4px 0 rgba(57,37,93,.13); }
.count-choice { grid-auto-flow: column; justify-content: center; gap: clamp(0px, .5vw, 5px); padding: 6px; }
.count-star { color: #ffc42f; font-size: clamp(1.05rem, 3.5vw, 2.2rem); line-height: 1; text-shadow: 0 3px 0 #e99722; }
.color-choice:hover, .shape-choice:hover, .count-choice:hover { transform: translateY(-3px) rotate(-1deg); }
.color-choice:active, .shape-choice:active, .count-choice:active { transform: translateY(6px); box-shadow: 0 2px 0 color-mix(in srgb, var(--color), #37205f 35%); }
.color-choice.wiggle, .shape-choice.wiggle, .count-choice.wiggle { animation: wiggle .42s ease; }
.color-choice.correct, .shape-choice.correct, .count-choice.correct { animation: pop .62s ease; outline: 7px solid #fff8a8; }

footer { min-height: 38px; display: flex; align-items: center; justify-content: center; gap: 18px; z-index: 4; }
.progress { display: flex; justify-content: center; gap: 9px; }
.dot { width: 16px; height: 16px; border-radius: 50%; border: 3px solid rgba(57,37,93,.3); background: rgba(255,255,255,.45); }
.dot.done { border-color: #7151d5; background: #fff; box-shadow: inset 0 0 0 3px #8c6cf0; }
.end-actions { display: flex; gap: 10px; align-items: center; }
.restart { font-size: 1rem; min-height: 48px; box-shadow: 0 5px 0 #4f2cb5; }
.change-game { min-height: 48px; border: 3px solid #fff; border-radius: 999px; padding: 9px 18px; background: #fff; color: var(--purple-dark); font-weight: 900; cursor: pointer; box-shadow: 0 5px 0 #d3c2f6; }
.change-game:active { transform: translateY(3px); box-shadow: 0 2px 0 #d3c2f6; }

.sparkles i { position: absolute; color: #fff; font-style: normal; font-size: 1.4rem; animation: twinkle 2.1s ease-in-out infinite; }
.sparkles i:nth-child(1) { left: 2%; top: 18%; }.sparkles i:nth-child(2) { left: 40%; top: 8%; animation-delay: .5s; }
.sparkles i:nth-child(3) { right: 4%; top: 5%; animation-delay: 1s; }.sparkles i:nth-child(4) { right: 32%; bottom: 8%; animation-delay: 1.4s; }

.celebration { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.confetti { position: absolute; top: -30px; font-size: 26px; animation: fall 1.4s ease-in forwards; }

button:focus-visible { outline: 5px solid #fff; outline-offset: 4px; }
[hidden] { display: none !important; }

@keyframes float { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-10px) rotate(1deg); } }
@keyframes lunaHappy { 0%,100% { transform: translateY(0) rotate(-1deg) scale(1); } 45% { transform: translateY(-16px) rotate(2deg) scale(1.055); } 70% { transform: translateY(-5px) rotate(-2deg) scale(1.02); } }
@keyframes lunaSad { 0%,100% { transform: translateY(0) rotate(-1deg); } 45% { transform: translateY(7px) rotate(-3deg) scale(.98); } }
@keyframes twinkle { 0%,100% { opacity: .25; transform: scale(.7); } 50% { opacity: 1; transform: scale(1.25); } }
@keyframes wiggle { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px) rotate(-3deg); } 75% { transform: translateX(8px) rotate(3deg); } }
@keyframes pop { 50% { transform: scale(1.12) rotate(4deg); } }
@keyframes fall { to { transform: translateY(110vh) rotate(480deg); opacity: .5; } }

@media (max-width: 650px) {
  .game-shell { gap: 8px; }
  .play-area { grid-template-columns: 1fr; align-content: center; gap: 0; }
  .character-wrap { height: min(38vh, 330px); min-height: 220px; }
  .prompt-card { margin-top: -18px; padding: 18px 20px; border-radius: 24px 24px 24px 8px; }
  .prompt-button { margin-bottom: 14px; }
  .choices { gap: 9px; }
  .color-choice { border-width: 4px; border-radius: 22px; }
  .shape-choice, .count-choice { border-width: 4px; border-radius: 22px; }
}

@media (max-height: 690px) and (max-width: 650px) {
  .character-wrap { height: 235px; min-height: 190px; }
  .prompt-card { padding: 14px 18px; }
  .prompt-button { font-size: 1.35rem; margin-bottom: 10px; }
  .color-choice { min-height: 68px; }
  .shape-choice, .count-choice { min-height: 68px; }
  .mode-button { min-height: 50px; }
}

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