:root {
  --berry: #FF6B9D;
  --sun: #FFD93D;
  --sun-dark: #e6a800;
  --grass: #6BCB77;
  --grass-dark: #4CAF50;
  --sky-light: #B0E0FF;
  --text-dark: #2D3436;
  --text-mid: #636E72;
  --cell: 30px;
}

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

body {
  font-family: 'Baloo 2', cursive;
  min-height: 100vh;
  background: linear-gradient(180deg, #87CEEB 0%, #B8E4FF 55%, #D4F1C4 100%);
  overflow-x: hidden;
}

/* ── Floating clouds ── */
.cloud {
  position: fixed;
  background: white;
  border-radius: 50px;
  opacity: 0.7;
  z-index: 0;
  animation: floatCloud linear infinite;
}
.cloud::before, .cloud::after {
  content: '';
  position: absolute;
  background: white;
  border-radius: 50%;
}
.c1 { width: 110px; height: 36px; top: 6%;  animation-duration: 38s; animation-delay: -8s; }
.c1::before { width: 55px; height: 55px; top: -28px; left: 14px; }
.c1::after  { width: 38px; height: 38px; top: -18px; left: 52px; }
.c2 { width: 160px; height: 50px; top: 18%; animation-duration: 52s; animation-delay: -26s; opacity: 0.45; }
.c2::before { width: 75px; height: 75px; top: -38px; left: 18px; }
.c2::after  { width: 52px; height: 52px; top: -26px; left: 76px; }
.c3 { width: 90px;  height: 30px; top: 4%;  animation-duration: 44s; animation-delay: -14s; opacity: 0.6; }
.c3::before { width: 45px; height: 45px; top: -22px; left: 10px; }
.c3::after  { width: 32px; height: 32px; top: -16px; left: 42px; }
@keyframes floatCloud {
  from { transform: translateX(-250px); }
  to   { transform: translateX(110vw); }
}

/* ── Ground ── */
.ground {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 56px;
  background: linear-gradient(180deg, #7CC56A, #5BA04A);
  z-index: 0;
}
.ground::before {
  content: '';
  position: absolute;
  top: -14px; left: 0; right: 0; height: 22px;
  background: radial-gradient(ellipse 28px 18px at center, #7CC56A 60%, transparent 100%);
  background-size: 56px 22px;
  background-repeat: repeat-x;
}

/* ── Page layout ── */
.page {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 6px 12px 58px;
  gap: 6px;
}

/* ── Title ── */
.title-badge {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #FF6B9D, #FF9A3C);
  border-radius: 50px;
  padding: 5px 20px;
  box-shadow: 0 4px 0 #C4386A, 0 6px 20px rgba(255,107,157,0.3);
}
.title-badge h1 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.45rem;
  color: white;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.15);
  line-height: 1;
  white-space: nowrap;
}
.title-badge .sub {
  font-size: 0.7rem;
  font-weight: 600;
  color: rgba(255,255,255,0.88);
  letter-spacing: 0.3px;
  white-space: nowrap;
  border-left: 1.5px solid rgba(255,255,255,0.4);
  padding-left: 10px;
}

/* ── Score row ── */
.score-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.pill {
  background: white;
  border-radius: 50px;
  padding: 3px 12px;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text-dark);
  box-shadow: 0 3px 0 rgba(0,0,0,0.1), 0 4px 12px rgba(0,0,0,0.07);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.pill .val { font-size: 0.9rem; font-weight: 800; }
.pill .val.green  { color: var(--grass-dark); }
.pill .val.orange { color: #FF9A3C; }
.pill .val.pink   { color: var(--berry); }

/* ── Game area ── */
.game-area {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  max-width: 960px;
}

/* ── Grid card ── */
.grid-card {
  background: white;
  border-radius: 20px;
  padding: 10px;
  box-shadow: 0 7px 0 #b8dfa8, 0 12px 32px rgba(0,0,0,0.15);
  flex-shrink: 0;
  position: relative;
}

#word-grid {
  display: grid;
  grid-template-columns: repeat(12, var(--cell));
  grid-template-rows:    repeat(12, var(--cell));
  gap: 2px;
  position: relative;
  user-select: none;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Baloo 2', cursive;
  font-size: calc(var(--cell) * 0.55);
  font-weight: 700;
  text-transform: uppercase;
  color: #3a3a3a;
  border-radius: calc(var(--cell) * 0.22);
  cursor: pointer;
  transition: transform 0.1s, background 0.12s;
  background: #f7f5ff;
  position: relative;
  z-index: 1;
}
.cell:hover:not(.found) {
  transform: scale(1.13);
  background: rgba(255,217,61,0.28);
  z-index: 5;
}
.cell.selecting {
  background: var(--sun) !important;
  color: #2D3436;
  z-index: 4;
  box-shadow: 0 0 0 2px var(--sun-dark);
}
.cell.found {
  font-weight: 800;
  background: #BBEFBC !important;
  color: #1A4D1C;
}

/* ── SVG line overlay ── */
#lines-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}
.found-line {
  stroke-linecap: round;
  opacity: 0.38;
  stroke-dasharray: 2000;
  stroke-dashoffset: 2000;
  animation: drawLine 0.35s ease forwards;
}
@keyframes drawLine { to { stroke-dashoffset: 0; } }

/* ── Right panel ── */
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 250px;
  flex-shrink: 0;
}

/* Selecting bar */
.sel-bar {
  background: white;
  border-radius: 10px;
  padding: 4px 10px;
  box-shadow: 0 3px 0 #b8dfa8, 0 4px 10px rgba(0,0,0,0.07);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.sel-bar .lbl {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-mid);
  flex-shrink: 0;
}
.sel-bar .word {
  font-family: 'Fredoka One', cursive;
  font-size: 1.15rem;
  color: var(--berry);
  letter-spacing: 2px;
}

/* Progress card */
.prog-card {
  background: white;
  border-radius: 12px;
  padding: 6px 12px;
  box-shadow: 0 3px 0 #b8dfa8, 0 4px 10px rgba(0,0,0,0.07);
  flex-shrink: 0;
}
.prog-top {
  display: flex;
  justify-content: space-between;
  font-family: 'Fredoka One', cursive;
  font-size: 0.82rem;
  color: var(--text-mid);
  margin-bottom: 5px;
}
.prog-top span { color: var(--grass-dark); }
.prog-bg {
  background: #eee;
  border-radius: 50px;
  height: 10px;
  overflow: hidden;
}
.prog-fill {
  height: 100%;
  border-radius: 50px;
  background: linear-gradient(90deg, var(--grass), #4EC9F0);
  width: 0%;
  transition: width 0.55s cubic-bezier(.36,.07,.19,.97);
}

/* Words card */
.words-card {
  background: white;
  border-radius: 14px;
  padding: 7px 8px 5px;
  box-shadow: 0 3px 0 #b8dfa8, 0 4px 10px rgba(0,0,0,0.07);
}
.words-title {
  font-family: 'Fredoka One', cursive;
  font-size: 0.95rem;
  color: var(--berry);
  text-align: center;
  margin-bottom: 6px;
}
.word-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.word-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 50px;
  background: #F5F2FF;
  border: 2px solid #DDD4FF;
  font-weight: 700;
  font-size: 0.76rem;
  color: #555;
  letter-spacing: 0.1px;
  transition: all 0.35s cubic-bezier(.36,.07,.19,.97);
}
.check {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid #CCC;
  background: white;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  color: transparent;
  transition: all 0.3s;
}
.word-item.done {
  background: linear-gradient(135deg, #EAFFEA, #D4F7D4);
  border-color: var(--grass-dark);
  color: #1A5C1E;
  animation: wFound 0.5s ease;
}
.word-item.done .check {
  background: var(--grass-dark);
  border-color: var(--grass-dark);
  color: white;
}
.word-item.done .wt {
  text-decoration: line-through;
  text-decoration-color: var(--grass-dark);
  text-decoration-thickness: 2px;
}
@keyframes wFound {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.07) translateX(3px); }
  65%  { transform: scale(0.97) translateX(-2px); }
  100% { transform: scale(1); }
}

/* Hint button */
.hint-btn {
  background: linear-gradient(135deg, #FFD93D, #FF9A3C);
  border: none;
  border-radius: 10px;
  padding: 5px 0;
  width: 100%;
  font-family: 'Fredoka One', cursive;
  font-size: 0.85rem;
  color: white;
  cursor: pointer;
  box-shadow: 0 3px 0 #CC7700;
  transition: all 0.14s;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.12);
  flex-shrink: 0;
}
.hint-btn:hover  { transform: translateY(-2px); box-shadow: 0 6px 0 #CC7700; }
.hint-btn:active { transform: translateY(2px);  box-shadow: 0 2px 0 #CC7700; }
.hint-btn:disabled { opacity: 0.45; cursor: default; transform: none; }

/* ── Animations ── */
.shake { animation: shake 0.38s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
.cell.hint-glow { animation: hintPulse 1.5s ease 3; }
@keyframes hintPulse {
  0%,100% { box-shadow: none; }
  50% { box-shadow: 0 0 0 3px var(--sun), 0 0 14px var(--sun); background: rgba(255,217,61,0.55) !important; }
}

/* ── Sparkles ── */
.sparkle {
  position: fixed;
  pointer-events: none;
  z-index: 500;
  font-size: 20px;
  animation: sparkleBurst 0.65s ease forwards;
}
@keyframes sparkleBurst {
  0%   { transform: scale(0) rotate(0deg);   opacity: 1; }
  60%  { transform: scale(1.4) rotate(180deg); opacity: 1; }
  100% { transform: scale(0.7) rotate(360deg) translateY(-36px); opacity: 0; }
}

/* ── Win screen ── */
.celebration {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
  background: rgba(0,0,0,0.18);
}
.celebration.active { opacity: 1; pointer-events: all; }
.celebration.active .win-card { pointer-events: all; }
.confetti-piece {
  position: absolute;
  animation: cFall linear forwards;
  border-radius: 2px;
}
@keyframes cFall {
  0%   { transform: translateY(-40px) rotate(0deg);   opacity: 1; }
  100% { transform: translateY(110vh)  rotate(720deg); opacity: 0; }
}
.win-card {
  background: white;
  border-radius: 28px;
  padding: clamp(20px,5vw,40px) clamp(20px,8vw,60px);
  text-align: center;
  box-shadow: 0 16px 50px rgba(0,0,0,0.22), 0 6px 0 #b8dfa8;
  animation: popIn 0.45s cubic-bezier(.36,.07,.19,.97);
  pointer-events: none;
  z-index: 1;
  max-width: 88vw;
}
@keyframes popIn {
  0%  { transform: scale(0.3); opacity: 0; }
  70% { transform: scale(1.05); }
  100%{ transform: scale(1);   opacity: 1; }
}
.win-card h2 {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(2rem, 6vw, 3.2rem);
  background: linear-gradient(135deg,#FF6B9D,#FF9A3C);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}
.win-card p { font-size: 1rem; color: var(--text-mid); margin-bottom: 20px; }
.again-btn {
  background: linear-gradient(135deg,#FF6B9D,#FF9A3C);
  border: none;
  border-radius: 16px;
  padding: 12px 36px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.2rem;
  color: white;
  cursor: pointer;
  box-shadow: 0 5px 0 #C4386A;
  transition: all 0.14s;
}
.again-btn:hover  { transform: translateY(-2px); box-shadow: 0 7px 0 #C4386A; }
.again-btn:active { transform: translateY(2px);  box-shadow: 0 3px 0 #C4386A; }

/* ── Responsive ── */
@media (max-width: 680px) {
  .game-area {
    flex-direction: column;
    align-items: center;
  }
  .grid-card { width: 100%; display: flex; justify-content: center; }
  .right-panel {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
  }
  .sel-bar, .prog-card, .hint-btn { flex: 1 1 140px; }
  .words-card { flex: 1 1 100%; }
  .word-list { flex-direction: row; flex-wrap: wrap; }
  .word-item { flex: 0 0 auto; padding: 4px 10px; font-size: 0.8rem; }
}
