/* Word Search — big letters, big word list, and everything works by finger.
   Sibling to the ABC, 123 and Shapes games and shares their look. */

:root {
  --bg: #fff7ed;
  --ink: #2b2b45;
  --muted: #6b6b8a;
  --card: #ffffff;
  --tile-shadow: 0 5px 0 rgba(43, 43, 69, 0.14);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: "Baloo 2", "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 0%, #fffdf8, var(--bg) 60%);
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

/* --- Top bar --- */
#bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px clamp(10px, 3vw, 28px);
}

#stars {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 800;
  min-width: 4.5ch;
}

#pack {
  margin-left: auto;
  margin-right: auto;
  font-size: clamp(1rem, 3vw, 1.4rem);
  font-weight: 800;
  color: var(--muted);
}

.icon-btn {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(43, 43, 69, 0.08);
  color: var(--ink);
  display: grid;
  place-items: center;
  flex: none;
}

.icon-btn:active {
  transform: scale(0.92);
}

.pill {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  font-size: clamp(1rem, 2.6vw, 1.25rem);
  padding: 16px 30px;
  border-radius: 999px;
  background: #ffb066;
  color: var(--ink);
  box-shadow: 0 6px 0 #ef8a30;
  min-height: 60px;
}

.pill:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #ef8a30;
}

.pill.big {
  font-size: clamp(1.3rem, 5vw, 2rem);
  padding: 22px 60px;
}

#screen {
  padding: 0 clamp(8px, 3vw, 28px) 40px;
}

/* --- The letter grid --- */
/* touch-action: none stops the page scrolling while a finger drags a word. */
#grid {
  display: grid;
  gap: clamp(3px, 1vw, 7px);
  width: min(92vw, 520px);
  margin: 0 auto;
  touch-action: none;
}

.cell {
  border: 0;
  font-family: inherit;
  font-weight: 800;
  font-size: clamp(1rem, 4.4vw, 1.7rem);
  cursor: pointer;
  aspect-ratio: 1;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--card);
  box-shadow: var(--tile-shadow);
  touch-action: none;
  user-select: none;
}

/* The letters the finger is on right now. */
.cell.picked {
  background: #ffd9a8;
  transform: scale(0.94);
}

/* The very first letter, when it was chosen with a single tap. */
.cell.anchor {
  background: #ffc078;
}

/* A word that has been found keeps its own colour for the rest of the game. */
.cell.found {
  background: hsl(var(--h) 78% 72%);
  color: #23233a;
  box-shadow: 0 5px 0 hsl(var(--h) 60% 55%);
}

.cell.wrong {
  animation: shake 380ms ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  60% { transform: translateX(6px); }
}

/* --- The word list --- */
#words {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(8px, 2vw, 14px);
  max-width: 560px;
  margin: clamp(14px, 3vh, 26px) auto 0;
}

.word {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  font-size: clamp(1rem, 3.4vw, 1.35rem);
  letter-spacing: 0.04em;
  padding: 12px 20px;
  min-height: 52px;
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--tile-shadow);
}

.word:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(43, 43, 69, 0.14);
}

.word.done {
  background: hsl(var(--h) 78% 72%);
  box-shadow: 0 5px 0 hsl(var(--h) 60% 55%);
  text-decoration: line-through;
}

/* --- Well done screen --- */
#done {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(43, 43, 69, 0.55);
  padding: 18px;
}

#done-inner {
  background: var(--card);
  border-radius: 32px;
  padding: clamp(24px, 6vw, 44px);
  text-align: center;
  width: min(440px, 100%);
  animation: pop 320ms ease;
}

#done-face {
  font-size: clamp(3.5rem, 16vw, 6rem);
  line-height: 1;
}

#done-word {
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 800;
  margin: 10px 0 24px;
}

@keyframes pop {
  0% { transform: scale(0.8); }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* --- Title screen --- */
#start {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 20%, #fffdf8, #ffd9a8 70%);
  text-align: center;
  padding: 20px;
}

#start h1 {
  font-size: clamp(3.2rem, 19vw, 8rem);
  margin: 0;
  line-height: 1;
  letter-spacing: 0.06em;
}

#start h1 span {
  color: hsl(var(--h) 78% 52%);
  display: inline-block;
  animation: bob 2.4s ease-in-out infinite;
}

#start h1 span:nth-child(2) { animation-delay: 0.15s; }
#start h1 span:nth-child(3) { animation-delay: 0.3s; }
#start h1 span:nth-child(4) { animation-delay: 0.45s; }

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-14px) rotate(3deg); }
}

#start p {
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  color: var(--muted);
  margin: 10px 0 32px;
}

/* --- Confetti --- */
#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}

#confetti span {
  position: absolute;
  font-size: 1.8rem;
  animation: fall 1.5s linear forwards;
}

@keyframes fall {
  0% { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(540deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
