:root {
  --bg-a: #ff7eb3;
  --bg-b: #ffd86f;
  --bg-c: #7afcff;
  --accent: #ff5c8a;
  --panel: rgba(255, 255, 255, 0.84);
  --ink: #3a2a59;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  font-family: "Baloo 2", cursive;
  color: var(--ink);
  background: linear-gradient(130deg, var(--bg-a), var(--bg-b), var(--bg-c));
  background-size: 260% 260%;
  animation: bgShift 14s ease infinite;
  overflow: hidden;
}

.sky-bubble {
  position: fixed;
  border-radius: 50%;
  opacity: 0.34;
  pointer-events: none;
  z-index: 1;
}

.bubble-one {
  width: 240px;
  height: 240px;
  background: #ffffff;
  top: -60px;
  left: -40px;
  animation: drift 11s ease-in-out infinite;
}

.bubble-two {
  width: 200px;
  height: 200px;
  background: #fffba7;
  top: 26%;
  right: -70px;
  animation: drift 13s ease-in-out infinite reverse;
}

.bubble-three {
  width: 180px;
  height: 180px;
  background: #ffd7ff;
  bottom: -50px;
  left: 12%;
  animation: drift 10s ease-in-out infinite;
}

.app-shell {
  position: relative;
  z-index: 2;
  max-width: 1360px;
  margin: 0 auto;
  height: 100vh;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: minmax(280px, 0.34fr) minmax(640px, 0.66fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "hero hud"
    "play play";
  gap: 10px;
}

.card {
  background: var(--panel);
  border-radius: 18px;
  border: 3px solid #ffffff;
  box-shadow: 0 10px 24px rgba(70, 33, 99, 0.18);
  backdrop-filter: blur(6px);
}

.hero {
  grid-area: hero;
  padding: 12px 14px;
  margin-bottom: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hero h1 {
  margin: 0;
  font-family: "Fredoka", sans-serif;
  font-size: clamp(1.4rem, 2.2vw, 2rem);
  letter-spacing: 0.02em;
  line-height: 1.05;
}

.flag {
  margin-left: 6px;
}

.hero p {
  margin: 4px 0 8px;
  font-size: clamp(0.92rem, 1.4vw, 1.02rem);
  line-height: 1.15;
}

.hero-tags {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: 6px;
}

.hero-tags span {
  background: #fff7cb;
  border-radius: 999px;
  border: 2px solid #ffffff;
  padding: 4px 8px;
  font-size: 0.84rem;
  font-weight: 700;
  white-space: nowrap;
}

.hud {
  grid-area: hud;
  padding: 10px;
  margin-bottom: 0;
}

.badges {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.badge {
  background: #fff4c6;
  border-radius: 10px;
  border: 2px solid #ffffff;
  padding: 5px 7px;
  font-weight: 700;
  min-height: 34px;
  font-size: 0.84rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.1;
}

.badge.wide {
  background: #d8fff8;
}

.progress {
  margin-top: 8px;
}

.progress-label {
  font-weight: 800;
  margin-bottom: 5px;
  font-size: 0.84rem;
}

.progress-track {
  width: 100%;
  height: 13px;
  background: rgba(255, 255, 255, 0.66);
  border-radius: 999px;
  border: 2px solid #ffffff;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #52ffa5, #37d8ff);
  transition: width 280ms ease;
}

.control-strip {
  margin-top: 8px;
  display: grid;
  grid-template-columns: auto minmax(140px, 180px) repeat(4, auto);
  gap: 6px;
  align-items: center;
}

.control-strip label {
  font-weight: 700;
  white-space: nowrap;
  font-size: 0.85rem;
}

#levelSelect {
  font-family: "Baloo 2", cursive;
  font-size: 0.83rem;
  border-radius: 8px;
  border: 2px solid #ffffff;
  padding: 4px 6px;
  color: var(--ink);
  background: #ffffff;
  height: 32px;
}

.btn {
  font-family: "Baloo 2", cursive;
  font-size: 0.81rem;
  font-weight: 800;
  border: none;
  border-radius: 9px;
  padding: 5px 8px;
  white-space: nowrap;
  color: #ffffff;
  background: linear-gradient(140deg, #6a89ff, #58d7ff);
  box-shadow: 0 3px 0 rgba(33, 62, 132, 0.26);
  cursor: pointer;
  transition: transform 140ms ease, filter 160ms ease;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.07);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn.accent {
  background: linear-gradient(135deg, #ff5cb5, #ffa056);
}

.btn.primary {
  background: linear-gradient(135deg, #00c2ff, #58ff8c);
}

.play-area {
  grid-area: play;
  min-height: 0;
}

.board-card {
  padding: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-width: 1220px;
  margin: 0 auto;
}

.board-card h2 {
  margin-top: 0;
  margin-bottom: 6px;
  font-family: "Fredoka", sans-serif;
  font-size: 1.06rem;
}

.board {
  --grid-size: 8;
  display: grid;
  grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
  gap: 4px;
  padding: 8px;
  border-radius: 13px;
  background: linear-gradient(145deg, #fef2a8, #ffcad2);
  border: 3px solid #ffffff;
  touch-action: none;
  user-select: none;
  width: min(100%, calc(100vh - 360px), 620px);
  aspect-ratio: 1 / 1;
  margin: 8px auto 0;
  flex-shrink: 0;
}

.board.celebrate {
  animation: boardCelebrate 0.58s ease;
}

.cell {
  border: none;
  border-radius: 9px;
  aspect-ratio: 1 / 1;
  font-family: "Fredoka", sans-serif;
  font-size: clamp(0.82rem, 1.15vw, 1.16rem);
  color: #2f2a63;
  background: #ffffff;
  box-shadow: 0 2px 0 #f2a8bc;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, transform 120ms ease;
}

.cell.selected {
  background: #fff174;
  transform: translateY(-2px) scale(1.05);
}

.cell.found {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 3px 0 rgba(85, 16, 69, 0.34);
}

.cell.hint {
  animation: hintBlink 0.62s ease-in-out infinite alternate;
}

.word-list {
  list-style: none;
  padding: 0 2px;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 20px;
}

.word-list li {
  font-family: "Fredoka", sans-serif;
  font-size: clamp(1.02rem, 1.35vw, 1.32rem);
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #3f2f74;
  white-space: nowrap;
}

.word-list li.hit {
  animation: wordHitPop 0.68s cubic-bezier(0.24, 0.88, 0.28, 1.08);
}

.word-list li.found {
  color: #1f9b5b;
  opacity: 0.9;
  text-decoration: line-through;
  text-decoration-thickness: 3px;
}

.tip {
  margin: 6px 0 0;
  background: #e8f7ff;
  border: 2px dashed #ffffff;
  border-radius: 9px;
  padding: 5px 7px;
  font-size: 0.78rem;
  line-height: 1.2;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 10px;
  transform: translate(-50%, 120px);
  background: #ffffff;
  color: #32294d;
  border-radius: 999px;
  padding: 10px 18px;
  border: 3px solid #ffe970;
  box-shadow: 0 8px 18px rgba(52, 33, 92, 0.28);
  font-weight: 800;
  z-index: 60;
  transition: transform 220ms ease;
}

.toast.show {
  transform: translate(-50%, 0);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(36, 24, 68, 0.48);
  display: grid;
  place-items: center;
  z-index: 70;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(480px, 100%);
  border-radius: 20px;
  background: linear-gradient(145deg, #fff7cb, #ffffff);
  border: 4px solid #ffffff;
  box-shadow: 0 18px 34px rgba(39, 26, 68, 0.28);
  padding: 18px;
  text-align: center;
}

.modal-card h3 {
  margin-top: 0;
  font-family: "Fredoka", sans-serif;
  font-size: clamp(1.32rem, 4.7vw, 1.9rem);
}

.modal-card p {
  margin-top: 0;
  font-size: 1.05rem;
}

.modal-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 55;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -5vh;
  font-size: 1.25rem;
  animation: confettiFall 1.6s linear forwards;
}

.word-burst-label {
  position: fixed;
  z-index: 58;
  font-family: "Fredoka", sans-serif;
  font-size: clamp(1.15rem, 1.9vw, 1.55rem);
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 2px 0 #7f2c87, 0 6px 18px rgba(36, 22, 77, 0.45);
  transform: translate(-50%, -50%);
  animation: wordBurstLabelRise 0.9s ease-out forwards;
}

.word-burst-spark {
  position: fixed;
  z-index: 57;
  font-size: 1.15rem;
  transform: translate(-50%, -50%);
  animation: wordBurstSparkFly 0.88s cubic-bezier(0.18, 0.76, 0.34, 1) forwards;
}

.board-card.celebrate {
  animation: boardCardPulse 0.62s ease;
}

@media (max-width: 960px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
  }

  .app-shell {
    height: auto;
    display: block;
    padding: 12px 10px 24px;
  }

  .hero {
    text-align: center;
  }

  .hero-tags {
    flex-wrap: wrap;
    justify-content: center;
  }

  .play-area {
    display: block;
  }

  .badges {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-strip {
    display: flex;
    flex-wrap: wrap;
  }

  .word-list {
    gap: 8px 16px;
  }

  .board {
    width: 100%;
    max-width: 560px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px 10px 30px;
  }

  .hero {
    padding: 16px;
  }

  .hero h1 {
    font-size: clamp(1.55rem, 6.2vw, 2rem);
  }

  .hero p {
    font-size: 0.97rem;
  }

  .word-list {
    gap: 6px 12px;
  }

  .board {
    gap: 5px;
    padding: 8px;
  }

  .control-strip {
    gap: 7px;
  }

  .btn {
    font-size: 0.88rem;
    padding: 8px 10px;
  }
}

@keyframes bgShift {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

@keyframes drift {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  50% {
    transform: translateY(18px) scale(1.04);
  }
}

@keyframes hintBlink {
  from {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.65);
  }

  to {
    box-shadow: 0 0 0 8px rgba(255, 255, 255, 0);
  }
}

@keyframes confettiFall {
  to {
    transform: translateY(108vh) rotate(540deg);
    opacity: 0;
  }
}

@keyframes boardCelebrate {
  0% {
    transform: scale(1);
    filter: saturate(1);
  }

  35% {
    transform: scale(1.018);
    filter: saturate(1.18) brightness(1.05);
  }

  100% {
    transform: scale(1);
    filter: saturate(1);
  }
}

@keyframes boardCardPulse {
  0% {
    box-shadow: 0 10px 24px rgba(70, 33, 99, 0.18);
  }

  45% {
    box-shadow: 0 14px 30px rgba(254, 82, 188, 0.28), 0 10px 28px rgba(54, 156, 255, 0.24);
  }

  100% {
    box-shadow: 0 10px 24px rgba(70, 33, 99, 0.18);
  }
}

@keyframes wordHitPop {
  0% {
    transform: scale(1);
  }

  45% {
    transform: scale(1.22);
    color: #5b2bff;
  }

  100% {
    transform: scale(1);
  }
}

@keyframes wordBurstLabelRise {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.75);
  }

  20% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -130%) scale(1.05);
  }
}

@keyframes wordBurstSparkFly {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3) rotate(0deg);
  }

  25% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(1.2) rotate(240deg);
  }
}
