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

:root {
  --green-1: #4caf50;
  --green-2: #2e7d32;
  --yellow: #ffc107;
  --orange: #ff9800;
  --blue: #2196f3;
  --red: #e53935;
  --bg: #e8f5e9;
  --card: #ffffff;
  --text: #1b3a1b;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

html, body { width: 100%; height: 100%; }

body {
  font-family: 'Comic Sans MS', 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(135deg, #a8e6cf 0%, #dcedc1 50%, #ffd3b6 100%);
  color: var(--text);
  overflow-x: hidden;
}

h1 {
  font-size: clamp(22px, 3vw, 36px);
  color: var(--green-2);
  text-shadow: 2px 2px 0 #fff, 4px 4px 0 rgba(0, 0, 0, 0.1);
}

h2 {
  font-size: clamp(22px, 4vw, 32px);
  color: var(--green-2);
  margin-bottom: 16px;
  text-align: center;
}

.view {
  display: none;
}
.view.active { display: block; }

/* ============ COVER VIEW ============ */
#coverView.active {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.cover-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 15%, #fff9 0%, transparent 45%),
    radial-gradient(ellipse at 80% 30%, #fff7 0%, transparent 40%),
    linear-gradient(135deg, #87ceeb 0%, #a8e6cf 45%, #ffd166 100%);
}
.cover-floaties {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}
.cover-floaties span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  font-size: clamp(34px, 5vw, 60px);
  animation: float-around 5s ease-in-out infinite;
  animation-delay: var(--d);
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.25));
}
@keyframes float-around {
  0%, 100% { transform: translate(0, 0) rotate(-6deg); }
  50%      { transform: translate(20px, -25px) rotate(6deg); }
}

.cover-card {
  position: relative;
  z-index: 2;
  text-align: center;
  background: rgba(255,255,255,0.85);
  padding: clamp(28px, 5vw, 60px) clamp(24px, 5vw, 70px);
  border-radius: 32px;
  box-shadow: 0 12px 0 rgba(0,0,0,0.15), 0 20px 40px rgba(0,0,0,0.25);
  border: 6px solid #fff;
  backdrop-filter: blur(4px);
  animation: card-in 0.8s cubic-bezier(.34,1.56,.64,1);
  max-width: 90vw;
}
@keyframes card-in {
  0%   { transform: scale(0.5) translateY(40px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.cover-emoji {
  font-size: clamp(48px, 7vw, 90px);
  letter-spacing: 8px;
  animation: emoji-bob 2.5s ease-in-out infinite;
}
@keyframes emoji-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-12px); }
}

.cover-title {
  font-size: clamp(48px, 10vw, 110px);
  font-weight: bold;
  color: var(--green-2);
  letter-spacing: 2px;
  text-shadow:
    3px 3px 0 #fff,
    6px 6px 0 #ffd166,
    9px 12px 18px rgba(0,0,0,0.25);
  margin: 8px 0 12px;
  line-height: 1;
  animation: title-wave 3s ease-in-out infinite;
}
@keyframes title-wave {
  0%, 100% { transform: rotate(-1deg); }
  50%      { transform: rotate(1deg); }
}

.cover-subtitle {
  font-size: clamp(16px, 2.2vw, 24px);
  color: #4a5d3a;
  margin-bottom: 28px;
  font-style: italic;
}

.cover-start {
  background: linear-gradient(180deg, #66bb6a 0%, #43a047 100%);
  color: #fff;
  border: none;
  padding: 16px 40px;
  font-size: clamp(20px, 2.5vw, 28px);
  font-weight: bold;
  font-family: inherit;
  border-radius: 32px;
  cursor: pointer;
  box-shadow: 0 6px 0 #2e7d32, 0 10px 20px rgba(0,0,0,0.3);
  transition: transform 0.1s, box-shadow 0.1s;
  letter-spacing: 1px;
  animation: button-pulse 1.6s ease-in-out infinite;
}
.cover-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #2e7d32, 0 14px 24px rgba(0,0,0,0.3);
}
.cover-start:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #2e7d32, 0 4px 8px rgba(0,0,0,0.3);
}
@keyframes button-pulse {
  0%, 100% { box-shadow: 0 6px 0 #2e7d32, 0 10px 20px rgba(0,0,0,0.3), 0 0 0 0 rgba(102,187,106,0.6); }
  50%      { box-shadow: 0 6px 0 #2e7d32, 0 10px 20px rgba(0,0,0,0.3), 0 0 0 14px rgba(102,187,106,0); }
}

.cover-authors {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}
.cover-by {
  font-size: clamp(13px, 1.6vw, 16px);
  color: #777;
  text-transform: uppercase;
  letter-spacing: 3px;
}
.cover-names {
  font-size: clamp(16px, 2.2vw, 22px);
  font-weight: bold;
  color: var(--green-2);
}

/* ============ FULLSCREEN MAP VIEW ============ */
#mapView.active {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.map-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: linear-gradient(180deg, rgba(255,255,255,0.85), rgba(255,255,255,0.5));
  border-bottom: 2px solid rgba(0,0,0,0.05);
  z-index: 5;
  flex-shrink: 0;
}
.map-stats {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: bold;
  color: var(--green-2);
}
.map-stats > #totalStars {
  background: #fff;
  padding: 6px 14px;
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.map-container {
  position: relative;
  flex: 1;
  width: 100%;
  background:
    radial-gradient(ellipse at 20% 10%, #fff8 0%, transparent 40%),
    radial-gradient(ellipse at 80% 20%, #fff7 0%, transparent 35%),
    linear-gradient(180deg,
      #87ceeb 0%,
      #b6e3ff 25%,
      #c5e9a4 55%,
      #95d171 80%,
      #7fb95a 100%);
  overflow: hidden;
}

.map-path {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.map-decorations {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.deco {
  position: absolute;
  filter: drop-shadow(2px 3px 2px rgba(0,0,0,0.15));
  user-select: none;
  transform: translate(-50%, -50%);
}

.worlds-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
}

.world-node {
  position: absolute;
  transform: translate(-50%, -50%);
  width: clamp(70px, 7vw, 100px);
  height: clamp(70px, 7vw, 100px);
  background: var(--card);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 6px 0 rgba(0,0,0,0.25), 0 8px 14px rgba(0,0,0,0.25);
  border: 5px solid #fff;
  font-family: inherit;
  padding: 0;
}
.world-node:hover:not(.locked) {
  transform: translate(-50%, -55%) scale(1.06);
  box-shadow: 0 8px 0 rgba(0,0,0,0.25), 0 10px 18px rgba(0,0,0,0.3);
}
.world-node .node-emoji {
  font-size: clamp(32px, 3.5vw, 48px);
  line-height: 1;
}
.world-node .node-num {
  position: absolute;
  top: -10px;
  left: -10px;
  background: var(--red);
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  border: 3px solid #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.world-node .node-name {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.92);
  color: var(--green-2);
  font-weight: bold;
  font-size: 13px;
  padding: 3px 10px;
  border-radius: 12px;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.world-node .grade-badge {
  position: absolute;
  top: -10px;
  right: -10px;
  background: var(--yellow);
  color: #333;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 16px;
  border: 3px solid #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.world-node .grade-badge.gold { background: #ffd700; }

.world-node.locked {
  filter: grayscale(0.8) brightness(0.7);
  cursor: not-allowed;
}
.world-node.locked .node-emoji { opacity: 0.4; }
.world-node.locked::after {
  content: '🔒';
  position: absolute;
  font-size: 32px;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.4));
}

.world-node.current {
  animation: bounce 1.2s ease-in-out infinite;
  border-color: #ffd700;
  box-shadow: 0 6px 0 rgba(0,0,0,0.25), 0 8px 14px rgba(0,0,0,0.25), 0 0 0 4px #ffd70080;
}
@keyframes bounce {
  0%, 100% { transform: translate(-50%, -50%); }
  50%      { transform: translate(-50%, -58%); }
}

.player-marker {
  position: absolute;
  transform: translate(-50%, -120%);
  font-size: 36px;
  z-index: 4;
  pointer-events: none;
  transition: top 0.5s ease, left 0.5s ease;
  filter: drop-shadow(0 4px 3px rgba(0,0,0,0.4));
  animation: floaty 2s ease-in-out infinite;
}
@keyframes floaty {
  0%, 100% { transform: translate(-50%, -120%); }
  50%      { transform: translate(-50%, -130%); }
}

/* ============ GAME / RESULT VIEW ============ */
#gameView.active, #resultView.active {
  display: block;
  max-width: 1100px;
  margin: 16px auto;
  padding: 24px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.back-btn {
  background: transparent;
  border: 2px solid var(--green-2);
  color: var(--green-2);
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 16px;
  font-family: inherit;
  margin-bottom: 12px;
}
.back-btn:hover { background: var(--green-2); color: #fff; }

.game-progress-top {
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  color: var(--green-2);
  margin-bottom: 8px;
}

.progress-bar {
  height: 14px;
  background: #ddd;
  border-radius: 8px;
  overflow: hidden;
  margin: 12px 0 20px;
}
#progressFill {
  height: 100%;
  background: linear-gradient(90deg, var(--green-1), var(--yellow));
  width: 0%;
  transition: width 0.3s;
}

#gameArea {
  background: var(--card);
  padding: 24px;
  border-radius: 16px;
  min-height: 280px;
}

.question {
  font-size: 22px;
  margin-bottom: 20px;
  text-align: center;
  font-weight: bold;
  color: var(--green-2);
}

.big-emoji {
  font-size: 110px;
  text-align: center;
  display: block;
  margin: 12px 0;
}

.options {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.option-btn {
  padding: 16px;
  background: #fff;
  border: 3px solid #ccc;
  border-radius: 12px;
  font-size: 18px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.option-btn:hover:not(:disabled) {
  border-color: var(--blue);
  transform: translateY(-2px);
}
.option-btn.correct { background: #c8e6c9; border-color: var(--green-1); }
.option-btn.wrong { background: #ffcdd2; border-color: var(--red); }
.option-btn:disabled { cursor: not-allowed; }

.fill-blank {
  font-size: 22px;
  text-align: center;
  margin: 16px 0;
}
.fill-input {
  font-size: 22px;
  padding: 8px 12px;
  border: 3px solid #ccc;
  border-radius: 10px;
  font-family: inherit;
  text-align: center;
  width: 200px;
  outline: none;
}
.fill-input:focus { border-color: var(--blue); }

.primary-btn, .secondary-btn {
  padding: 14px 28px;
  border-radius: 24px;
  border: none;
  font-size: 18px;
  cursor: pointer;
  font-family: inherit;
  font-weight: bold;
  margin: 8px;
}
.primary-btn { background: var(--green-1); color: #fff; }
.primary-btn:hover { background: var(--green-2); }
.secondary-btn { background: #fff; color: var(--green-2); border: 2px solid var(--green-2); }
.secondary-btn:hover { background: #e8f5e9; }

.feedback {
  text-align: center;
  font-size: 20px;
  margin-top: 16px;
  min-height: 30px;
  font-weight: bold;
  padding: 14px;
  border-radius: 14px;
  background: transparent;
  transition: background 0.2s;
}
.feedback.correct {
  color: var(--green-2);
  background: #e8f5e9;
  border: 2px solid var(--green-1);
}
.feedback.wrong {
  color: var(--red);
  background: #ffebee;
  border: 2px solid var(--red);
}
.feedback .next-btn {
  display: block;
  margin: 14px auto 0;
}

.image-input-wrap { text-align: center; margin: 16px 0; }

.result-card {
  background: var(--card);
  padding: 32px;
  border-radius: 20px;
  text-align: center;
  max-width: 500px;
  margin: 0 auto;
  box-shadow: var(--shadow);
}
.grade-big {
  font-size: 100px;
  font-weight: bold;
  color: var(--green-1);
  margin: 12px 0;
}
.result-buttons {
  text-align: center;
  margin-top: 24px;
}
.game-breakdown {
  margin: 16px 0;
  text-align: left;
  display: inline-block;
  font-size: 16px;
}
.game-breakdown div { padding: 4px 0; }

/* Word search */
.wordsearch-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
}
.ws-grid {
  display: grid;
  gap: 2px;
  background: #999;
  padding: 2px;
  border-radius: 8px;
  user-select: none;
  touch-action: none;
}
.ws-cell {
  width: 34px;
  height: 34px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 16px;
  cursor: pointer;
  border-radius: 4px;
}
.ws-cell.selected { background: #ffe082; }
.ws-cell.found { background: #a5d6a7; color: #1b5e20; }
.ws-cell.hint { outline: 3px solid var(--orange); }

.ws-words {
  background: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 160px;
}
.ws-words h3 { margin-bottom: 8px; color: var(--green-2); font-size: 16px; }
.ws-words ul { list-style: none; }
.ws-words li { padding: 4px 0; font-size: 16px; }
.ws-words li.found { text-decoration: line-through; color: #888; }
.small-btn {
  background: #fff;
  border: 2px solid #ccc;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
.small-btn:hover { background: #f0f0f0; }

@media (max-width: 500px) {
  .options { grid-template-columns: 1fr; }
  .ws-cell { width: 28px; height: 28px; font-size: 14px; }
}

/* ============ CELEBRATION ANIMATION ============ */
.celebration-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(ellipse at center,
              rgba(255,255,200,0.95) 0%,
              rgba(255,200,100,0.85) 50%,
              rgba(0,0,0,0.5) 100%);
}
.celebration-overlay.active {
  display: flex;
  animation: fade-in 0.3s ease;
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.celebration-burst {
  position: absolute;
  width: 800px;
  height: 800px;
  background:
    repeating-conic-gradient(
      from 0deg,
      rgba(255,215,0,0.5) 0deg 12deg,
      transparent 12deg 24deg
    );
  border-radius: 50%;
  animation: spin-burst 8s linear infinite;
  filter: blur(2px);
}
@keyframes spin-burst {
  from { transform: rotate(0); }
  to   { transform: rotate(360deg); }
}

.celebration-content {
  position: relative;
  text-align: center;
  z-index: 5;
  animation: pop-in 0.7s cubic-bezier(.34,1.56,.64,1);
}
@keyframes pop-in {
  0%   { transform: scale(0) rotate(-180deg); opacity: 0; }
  60%  { transform: scale(1.25) rotate(10deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.celebration-emoji {
  font-size: clamp(100px, 18vw, 220px);
  filter: drop-shadow(0 10px 16px rgba(0,0,0,0.5));
  animation: trophy-bounce 1.2s ease-in-out infinite;
}
@keyframes trophy-bounce {
  0%, 100% { transform: scale(1) rotate(-6deg); }
  50%      { transform: scale(1.1) rotate(6deg); }
}

.celebration-title {
  font-size: clamp(34px, 6vw, 78px);
  font-weight: bold;
  color: #fff;
  letter-spacing: 2px;
  text-shadow:
    3px 3px 0 #ff6b00,
    6px 6px 0 #c63800,
    8px 12px 16px rgba(0,0,0,0.4);
  margin-top: 8px;
  animation: title-wobble 1s ease-in-out infinite;
}
@keyframes title-wobble {
  0%, 100% { transform: rotate(-2deg) scale(1); }
  50%      { transform: rotate(2deg)  scale(1.04); }
}

.celebration-sub {
  font-size: clamp(20px, 3vw, 32px);
  font-weight: bold;
  color: var(--green-2);
  background: #fff;
  display: inline-block;
  padding: 8px 20px;
  border-radius: 20px;
  margin-top: 18px;
  box-shadow: 0 6px 0 rgba(0,0,0,0.2);
  animation: sub-pop 0.6s ease 0.4s backwards;
}
@keyframes sub-pop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.confetti-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.confetti {
  position: absolute;
  top: -10vh;
  animation: confetti-fall linear forwards;
  user-select: none;
}
@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(115vh) rotate(720deg); opacity: 0.9; }
}

.celebration-skip {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  background: rgba(255,255,255,0.9);
  border: 2px solid var(--green-2);
  color: var(--green-2);
  padding: 10px 22px;
  border-radius: 24px;
  font-family: inherit;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  animation: sub-pop 0.6s ease 1.5s backwards;
}
.celebration-skip:hover { background: #fff; }
