:root {
  --font: 'Fredoka', 'Chalkboard SE', 'Comic Sans MS', 'Marker Felt', 'Arial Rounded MT Bold', 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

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

body {
  position: fixed;
  inset: 0;
  font-family: var(--font);
  font-weight: 700;
  color: #fff;
  background: linear-gradient(160deg, #ffd6f5 0%, #dccbff 25%, #bfe6ff 50%, #ccffe9 75%, #fff3b8 100%);
  background-size: 300% 300%;
  animation: sky 45s ease-in-out infinite alternate;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
  cursor: default;
}

@keyframes sky {
  from { background-position: 0% 0%; }
  to   { background-position: 100% 100%; }
}

/* ---------- Sky scenery ---------- */

.sky {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.sun {
  position: absolute;
  top: -12vmin;
  right: -12vmin;
  width: 60vmin;
  height: 60vmin;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(255, 252, 215, 0.95) 0%,
    rgba(255, 236, 160, 0.6) 28%,
    rgba(255, 225, 130, 0) 68%);
  animation: sunpulse 7s ease-in-out infinite;
}

@keyframes sunpulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}

.rainbow {
  position: absolute;
  left: 50%;
  bottom: -14vmax;
  width: 170vmax;
  height: 85vmax;
  transform: translateX(-50%);
  opacity: 0.7;
  background: radial-gradient(ellipse at 50% 100%,
    transparent 0 56%,
    hsla(300, 95%, 80%, 0.7) 56.5% 60%,
    hsla(245, 95%, 80%, 0.7) 60.5% 64%,
    hsla(200, 95%, 75%, 0.7) 64.5% 68%,
    hsla(140, 85%, 74%, 0.7) 68.5% 72%,
    hsla(55, 100%, 74%, 0.75) 72.5% 76%,
    hsla(25, 100%, 74%, 0.75) 76.5% 80%,
    hsla(350, 100%, 78%, 0.75) 80.5% 84%,
    transparent 84.5%);
}

.cloud {
  position: absolute;
  width: 24vmin;
  height: 8vmin;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.85);
  filter: blur(0.5px);
  animation: drift linear infinite;
}

.cloud::before,
.cloud::after {
  content: '';
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.cloud::before { width: 11vmin; height: 11vmin; left: 3.5vmin; top: -6vmin; }
.cloud::after  { width: 8.5vmin; height: 8.5vmin; left: 11.5vmin; top: -4vmin; }

@keyframes drift {
  from { transform: translateX(-40vw); }
  to   { transform: translateX(115vw); }
}

.c1 { top: 9%;  animation-duration: 80s;  animation-delay: -10s; }
.c2 { top: 20%; animation-duration: 110s; animation-delay: -60s; scale: 0.7; }
.c3 { top: 33%; animation-duration: 95s;  animation-delay: -35s; scale: 1.15; opacity: 0.8; }
.c4 { top: 55%; animation-duration: 130s; animation-delay: -80s; scale: 0.6; opacity: 0.7; }
.c5 { top: 70%; animation-duration: 120s; animation-delay: -20s; scale: 0.85; opacity: 0.6; }

.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 24vh;
  background: linear-gradient(to top, rgba(205, 255, 225, 0.75), rgba(205, 255, 225, 0));
}

/* ---------- Particle canvas ---------- */

#fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

/* ---------- Letters ---------- */

#stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.wordrow {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  max-width: 96vw;
  line-height: 1.1;
  font-size: 22vmin;
}

.letter {
  display: inline-block;
  margin: 0 0.01em;
  animation: float 3.2s ease-in-out infinite;
  animation-delay: var(--d, 0s);
  will-change: transform;
}

.glyph,
.rainbow-text {
  display: inline-block;
  padding: 0.12em 0.03em;
  background: linear-gradient(135deg,
    hsl(var(--h, 320) 100% 62%) 0%,
    hsl(calc(var(--h, 320) + 55) 100% 60%) 35%,
    hsl(calc(var(--h, 320) + 120) 95% 58%) 70%,
    hsl(calc(var(--h, 320) + 190) 100% 66%) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  /* Fredoka has overlapping contours, so text-stroke shows seams; shadows make the sticker edge instead. */
  filter: drop-shadow(0 0 0.012em #fff)
          drop-shadow(0 0.05em 0 rgba(255, 255, 255, 0.95))
          drop-shadow(0 0.1em 0.12em rgba(255, 100, 190, 0.45));
}

.glyph {
  animation: popin 0.7s ease-out both;
}

@keyframes popin {
  0%   { transform: scale(0) rotate(-25deg); opacity: 0; }
  55%  { transform: scale(1.28) rotate(7deg); opacity: 1; }
  80%  { transform: scale(0.94) rotate(-3deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50%      { transform: translateY(-0.08em) rotate(3deg); }
}

.letter.bye {
  animation: bye 0.35s ease-in forwards;
}

/* Word hunt: a wrong key in the no-hints mode gives the row a small shake */

.wordrow.shake {
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-1.2vmin); }
  50%      { transform: translateX(1vmin); }
  75%      { transform: translateX(-0.6vmin); }
}

/* Word hunt: the slots still to be found, the next one pulsing */

.letter.ghost {
  padding: 0.12em 0.03em; /* same box as .glyph so the row does not shift when a slot fills */
  color: #fff;
  opacity: 0.5;
  filter: drop-shadow(0 0.05em 0.1em rgba(176, 90, 160, 0.35));
}

.letter.ghost.want {
  animation: want 1s ease-in-out infinite;
}

@keyframes want {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50%      { transform: scale(1.15); opacity: 1; }
}

@keyframes bye {
  to { transform: scale(0) rotate(35deg); opacity: 0; }
}

/* The celebrated word: a clone that wiggles and floats away */

.flyaway {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: flyaway 2.5s ease-in forwards;
}

@keyframes flyaway {
  0%   { transform: scale(1) rotate(0deg); opacity: 1; }
  12%  { transform: scale(1.22) rotate(-5deg); }
  24%  { transform: scale(1.18) rotate(5deg); }
  36%  { transform: scale(1.22) rotate(-3deg); }
  50%  { transform: scale(1.15) rotate(0deg); opacity: 1; }
  100% { transform: translateY(-75vh) scale(0.45); opacity: 0; }
}

/* The clone must not replay the letters' pop-in, or the word blinks out first. */
.flyaway .glyph { animation: none; }

.wordemoji {
  line-height: 1;
  margin-top: 0.1em;
  animation: popin 0.6s ease-out both;
}

/* ---------- Idle hint ---------- */

#hint {
  position: absolute;
  left: 50%;
  bottom: 16vh;
  transform: translateX(-50%);
  text-align: center;
  transition: opacity 0.5s;
  pointer-events: none;
}

#hint.hidden { opacity: 0; }

.hint-inner {
  animation: bounce 1.3s ease-in-out infinite;
}

.hint-emoji {
  display: block;
  font-size: 13vmin;
}

.hint-text {
  font-size: 5.5vmin;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3vmin); }
}

/* ---------- Word hunt prompt ---------- */

#guide {
  position: absolute;
  top: 3vh;
  left: 50%;
  transform: translateX(-50%);
  max-width: 96vw;
  transition: opacity 0.4s;
  pointer-events: none;
}

#guide.hidden { opacity: 0; }

.guide-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.5vmin;
  padding: 1vmin 4vmin;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.45);
  box-shadow: 0 1vmin 3vmin rgba(255, 120, 200, 0.25);
}

.guide-inner.wiggle {
  animation: wiggle 0.6s ease-in-out;
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg) scale(1); }
  20%      { transform: rotate(-4deg) scale(1.06); }
  50%      { transform: rotate(4deg) scale(1.06); }
  80%      { transform: rotate(-2deg) scale(1.02); }
}

.guide-emoji {
  font-size: 12vmin;
  line-height: 1;
  animation: bounce 1.6s ease-in-out infinite;
}

.guide-msg {
  white-space: pre-wrap;
  text-align: center;
  font-size: 5.5vmin;
  line-height: 1;
  color: #b05aa0;
}

.guide-letter {
  font-size: 2.4em;
}

/* ---------- Word garden (previously typed words) ---------- */

#garden {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2vh;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.2vmin;
  padding: 0 2vw;
  pointer-events: none;
  z-index: 3;
}

.chip {
  max-width: 34vw;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 0.6vmin 2.4vmin;
  border: 0.4vmin solid #fff;
  border-radius: 99px;
  font-size: 3.4vmin;
  color: hsl(var(--h, 320) 70% 38%);
  background: hsl(var(--h, 320) 100% 90%);
  box-shadow: 0 0.6vmin 0 rgba(255, 255, 255, 0.6), 0 1vmin 2vmin rgba(255, 120, 200, 0.25);
  animation: popin 0.5s ease-out both;
  /* The garden itself lets clicks through; the chips take them so a tap says the word. */
  pointer-events: auto;
  cursor: pointer;
}

/* ---------- Flying unicorns ---------- */

#flyers {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 6;
}

.unicorn {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 13vmin;
  line-height: 1;
  will-change: transform;
  filter: drop-shadow(0 0.4vmin 1vmin rgba(255, 120, 220, 0.55));
}

/* ---------- Controls (music, full screen) ---------- */

#controls {
  position: absolute;
  top: 1.5vmin;
  right: 1.5vmin;
  display: flex;
  gap: 1vmin;
  z-index: 10;
}

#controls button {
  width: 7vmin;
  height: 7vmin;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  font-size: 3.4vmin;
  line-height: 1;
  color: #b05aa0;
  cursor: pointer;
  opacity: 0.8;
  box-shadow: 0 3px 10px rgba(255, 120, 200, 0.3);
  -webkit-tap-highlight-color: transparent;
}

#controls button:focus { outline: none; }

#controls button.on {
  opacity: 1;
  background: #fff;
  box-shadow: 0 0 0 0.7vmin rgba(255, 120, 220, 0.45), 0 3px 10px rgba(255, 120, 200, 0.3);
}

body.is-full #btn-full { display: none; }

/* ---------- Mode and language pickers (start screen only) ---------- */

.modes,
.langs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4vmin 1.2vmin;
  margin-top: 1.5vmin;
}

.modes { margin-top: 5vmin; }

.mode,
.lang {
  padding: 0.8vmin 1.6vmin;
  border: 0;
  border-radius: 99px;
  background: none;
  color: rgba(176, 90, 160, 0.55);
  font-family: inherit;
  font-weight: 600;
  font-size: 2.2vmin;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mode:hover,
.lang:hover { color: #b05aa0; }

.mode:focus,
.lang:focus { outline: none; }

.mode.on,
.lang.on {
  color: #e0489a;
  background: rgba(255, 255, 255, 0.6);
}

/* ---------- Start overlay ---------- */

#start {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.6s;
}

#start.gone {
  opacity: 0;
  pointer-events: none;
}

.start-card { text-align: center; }

.start-unicorn {
  font-size: 26vmin;
  line-height: 1;
  animation: bounce 1.6s ease-in-out infinite;
}

.start-card h1 {
  margin: 0;
  font-size: 11vmin;
  line-height: 1.1;
  --h: 300;
}

.start-card p {
  margin: 2vmin 0 0;
  font-size: 4vmin;
  color: #b05aa0;
}

/* ---------- Hidden input for touch keyboards ---------- */

#touch-input {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px; /* 16px stops iOS from zooming on focus */
  pointer-events: none;
}
