*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0d0020;
  --glow-a: #a855f7;
  --glow-b: #3b82f6;
  --app-height: 100dvh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html,
body {
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: "Fredoka One", cursive;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  cursor: none;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html {
  height: 100%;
}

body {
  min-height: var(--app-height);
}

#bg-gradient {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 40%, #2d0060 0%, transparent 70%),
    radial-gradient(ellipse 60% 50% at 80% 20%, #003060 0%, transparent 70%),
    radial-gradient(ellipse 70% 60% at 50% 90%, #1a004a 0%, #0d0020 80%);
  animation: bg-shift 8s ease-in-out infinite alternate;
}

@keyframes bg-shift {
  0% { filter: hue-rotate(0deg) brightness(1); }
  100% { filter: hue-rotate(40deg) brightness(1.2); }
}

#canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

#stars {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.star {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  animation: twinkle var(--d, 3s) ease-in-out infinite var(--dl, 0s);
}

@keyframes twinkle {
  0%, 100% { opacity: 0.1; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.8); }
}

#flash {
  position: fixed;
  inset: 0;
  z-index: 99;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.05s;
}

#flash.on {
  opacity: 0.22;
  transition: opacity 0s;
}

.ripple {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 5;
  transform: translate(-50%, -50%) scale(0);
  animation: ripple-out 0.7s ease-out forwards;
}

@keyframes ripple-out {
  to {
    transform: translate(-50%, -50%) scale(8);
    opacity: 0;
  }
}

#stage {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: var(--app-height);
  padding:
    calc(var(--safe-top) + 24px)
    calc(var(--safe-right) + 20px)
    calc(var(--safe-bottom) + 24px)
    calc(var(--safe-left) + 20px);
}

#big-char {
  font-family: "Fredoka One", cursive;
  font-size: clamp(140px, 30vw, 340px);
  line-height: 1;
  text-align: center;
  color: #fff;
  will-change: transform;
  animation: idle-bob 3.2s ease-in-out infinite;
  filter: drop-shadow(0 0 30px var(--glow-a)) drop-shadow(0 6px 0 rgba(0, 0, 0, 0.45));
}

@keyframes idle-bob {
  0%, 100% { transform: translateY(0) rotate(-1.5deg) scale(1); }
  50% { transform: translateY(-14px) rotate(1.5deg) scale(1.03); }
}

@keyframes pop-in {
  0% { transform: scale(0.2) rotate(-15deg); opacity: 0; }
  55% { transform: scale(1.35) rotate(5deg); opacity: 1; }
  75% { transform: scale(0.92) rotate(-2deg); }
  90% { transform: scale(1.04) rotate(1deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  20% { transform: translateX(-12px) rotate(-4deg); }
  40% { transform: translateX(12px) rotate(4deg); }
  60% { transform: translateX(-8px) rotate(-2deg); }
  80% { transform: translateX(8px) rotate(2deg); }
}

@keyframes spin-pop {
  0% { transform: scale(0) rotate(-360deg); opacity: 0; }
  60% { transform: scale(1.3) rotate(20deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.anim-pop { animation: pop-in 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important; }
.anim-shake { animation: shake 0.4s ease-in-out forwards !important; }
.anim-spin { animation: spin-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important; }

#word-label {
  font-family: "Nunito", sans-serif;
  font-weight: 900;
  font-size: clamp(18px, 3vw, 36px);
  color: rgba(255, 255, 255, 0.75);
  letter-spacing: 3px;
  text-align: center;
  min-height: 46px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  transition: opacity 0.15s;
}

#combo {
  font-family: "Fredoka One", cursive;
  font-size: clamp(16px, 2.5vw, 28px);
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 2px;
  min-height: 36px;
  transition: all 0.2s;
}

#combo.fire {
  color: #ffe66d;
  text-shadow: 0 0 20px #f97316;
}

#theme-badge {
  position: fixed;
  top: calc(var(--safe-top) + 20px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  font-family: "Nunito", sans-serif;
  font-weight: 900;
  font-size: clamp(12px, 1.8vw, 18px);
  color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 20px;
  border-radius: 100px;
  backdrop-filter: blur(8px);
  letter-spacing: 2px;
  pointer-events: none;
  transition: opacity 0.4s;
}

#exit-hint {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  right: calc(var(--safe-right) + 12px);
  z-index: 200;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0);
  transition: background 0.3s;
  cursor: default;
}

#exit-progress {
  position: fixed;
  top: calc(var(--safe-top) + 8px);
  right: calc(var(--safe-right) + 8px);
  z-index: 201;
  width: 52px;
  height: 52px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

#exit-progress circle {
  fill: none;
  stroke: #fff;
  stroke-width: 3;
  stroke-dasharray: 145;
  stroke-dashoffset: 145;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  transition: stroke-dashoffset 0.1s linear;
}

.floater {
  position: fixed;
  pointer-events: none;
  z-index: 15;
  animation: float-up var(--dur, 1.4s) cubic-bezier(0.22, 1, 0.36, 1) forwards;
  will-change: transform, opacity;
}

@keyframes float-up {
  0% { transform: translateY(0) scale(0.4) rotate(0deg); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translateY(var(--dy, -280px)) scale(1.5) rotate(var(--rot, 30deg)); opacity: 0; }
}

.burst-word {
  position: fixed;
  pointer-events: none;
  z-index: 15;
  font-family: "Fredoka One", cursive;
  font-size: clamp(22px, 4vw, 48px);
  font-weight: 900;
  white-space: nowrap;
  animation: burst-word-anim 0.9s ease-out forwards;
}

@keyframes burst-word-anim {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  40% { transform: translate(-50%, -50%) scale(1.2); }
  100% { transform: translate(-50%, -120%) scale(0.8); opacity: 0; }
}

#start {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  background: radial-gradient(ellipse at 50% 50%, #1e0050 0%, #0d0020 100%);
  transition: opacity 0.7s ease, transform 0.7s ease;
  min-height: var(--app-height);
  padding:
    calc(var(--safe-top) + 24px)
    calc(var(--safe-right) + 20px)
    calc(var(--safe-bottom) + 24px)
    calc(var(--safe-left) + 20px);
}

#start.gone {
  opacity: 0;
  transform: scale(1.08);
  pointer-events: none;
}

.start-emojis {
  font-size: clamp(28px, 5.5vw, 60px);
  letter-spacing: 10px;
  animation: idle-bob 2.4s ease-in-out infinite;
}

#start-title {
  font-family: "Fredoka One", cursive;
  font-size: clamp(52px, 11vw, 130px);
  color: #fff;
  text-align: center;
  line-height: 1.05;
  text-shadow: 0 0 80px #a855f7, 0 6px 0 rgba(0, 0, 0, 0.4);
  animation: idle-bob 3s ease-in-out infinite;
}

.start-sub {
  font-family: "Nunito", sans-serif;
  font-weight: 800;
  font-size: clamp(14px, 2.5vw, 26px);
  color: rgba(255, 255, 255, 0.55);
  text-align: center;
  max-width: 760px;
  text-wrap: balance;
}

.seo-copy {
  font-family: "Nunito", sans-serif;
  font-weight: 800;
  font-size: clamp(14px, 2.1vw, 22px);
  color: rgba(255, 255, 255, 0.72);
  text-align: center;
  max-width: 760px;
  line-height: 1.45;
  text-wrap: pretty;
}

#play-btn {
  font-family: "Fredoka One", cursive;
  font-size: clamp(24px, 4vw, 48px);
  color: #fff;
  background: linear-gradient(135deg, #a855f7, #3b82f6, #06b6d4);
  background-size: 200% 200%;
  animation: btn-gradient 3s ease infinite, pulse-shadow 2s ease-in-out infinite;
  border: none;
  outline: none;
  padding: 22px 70px;
  border-radius: 100px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: transform 0.15s;
}

#play-btn:hover { transform: scale(1.06); }
#play-btn:active { transform: scale(0.96); }

@keyframes btn-gradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes pulse-shadow {
  0%, 100% { box-shadow: 0 8px 40px rgba(168, 85, 247, 0.5), 0 0 0 4px rgba(255, 255, 255, 0.1); }
  50% { box-shadow: 0 8px 70px rgba(59, 130, 246, 0.7), 0 0 0 10px rgba(255, 255, 255, 0.15); }
}

.start-features {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 600px;
}

.feat-chip {
  font-family: "Nunito", sans-serif;
  font-weight: 800;
  font-size: clamp(12px, 1.8vw, 16px);
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 7px 16px;
  border-radius: 100px;
  letter-spacing: 1px;
}

.start-hint {
  font-size: 13px;
  opacity: 0.35;
  margin-top: 4px;
}

.noscript-message {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 999;
  padding: 14px 16px;
  border-radius: 16px;
  font-family: "Nunito", sans-serif;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  background: rgba(10, 10, 20, 0.92);
}

body.theme-ocean { --bg: #001830; }
body.theme-forest { --bg: #001a05; }
body.theme-candy { --bg: #1a0030; }
body.theme-fire { --bg: #1a0500; }

#milestone {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 300;
  pointer-events: none;
  font-family: "Fredoka One", cursive;
  font-size: clamp(32px, 7vw, 90px);
  color: #ffe66d;
  text-shadow: 0 0 60px #f97316, 0 0 120px #f97316, 0 6px 0 rgba(0, 0, 0, 0.4);
  white-space: nowrap;
  text-align: center;
  opacity: 0;
}

#milestone.show {
  animation: milestone-pop 2.2s ease forwards;
}

@keyframes milestone-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  25% { transform: translate(-50%, -50%) scale(0.95); }
  40%, 70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.8); }
}

@media (prefers-reduced-motion: reduce) {
  #bg-gradient,
  #big-char,
  .star,
  .floater,
  .burst-word,
  #play-btn,
  #milestone.show {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  #flash,
  #theme-badge,
  #start {
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 768px) {
  #stage {
    gap: 12px;
  }

  #theme-badge {
    width: min(calc(100vw - 32px - var(--safe-left) - var(--safe-right)), 420px);
    text-align: center;
    padding: 8px 14px;
    letter-spacing: 1.2px;
  }

  #start {
    gap: 20px;
  }

  .start-emojis {
    letter-spacing: 6px;
  }

  #play-btn {
    width: min(100%, 360px);
    padding: 18px 24px;
  }

  .start-features {
    gap: 12px;
    max-width: 100%;
  }

  .feat-chip {
    font-size: 13px;
    padding: 8px 12px;
  }

  #word-label {
    min-height: 40px;
    letter-spacing: 2px;
  }
}
