/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #FFF8E1;
  --primary: #7C4DFF;
  --secondary: #FF6D00;
  --accent-green: #00E676;
  --accent-pink: #FF4081;
  --accent-blue: #40C4FF;
  --accent-yellow: #FFD600;
  --text: #3E2723;
  --text-light: #5D4037;
  --error: #FF1744;
  --success: #00C853;
  --card-bg: #FFFFFF;
  --card-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@400;600;700;800&display=swap');

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

body {
  font-family: 'Nunito', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100%;
  -webkit-user-select: none;
  user-select: none;
}

/* === Floating eggs background === */
.bg-eggs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.bg-egg {
  position: absolute;
  width: 30px;
  height: 40px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  opacity: 0.15;
  animation: float-egg var(--duration, 6s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

@keyframes float-egg {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-25px) rotate(10deg); }
}

/* === Screens === */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 70px 16px 24px;
  position: relative;
  z-index: 1;
  overflow-y: auto;
  min-height: 100vh;
}

.screen.active {
  display: flex;
}

/* === Top Bar === */
#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: transform 0.3s;
}

#top-bar.hidden {
  transform: translateY(-100%);
  pointer-events: none;
}

/* === Timer === */
.timer {
  font-family: 'Fredoka One', 'Courier New', monospace;
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 700;
  letter-spacing: 2px;
  transition: color 0.3s;
}

.timer-green { color: var(--accent-green); }
.timer-yellow { color: #FFA000; }
.timer-orange { color: var(--secondary); }
.timer-red { color: var(--error); animation: pulse 1s ease-in-out infinite; }
.timer-critical { color: var(--error); font-size: clamp(1.6rem, 6vw, 2.4rem); animation: pulse 0.5s ease-in-out infinite; }

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

/* === Language toggle === */
.lang-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 6px 16px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s;
}

.lang-btn:hover {
  background: #651FFF;
}

/* === Progress bar === */
.progress-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-light);
}

.progress-egg {
  width: 18px;
  height: 22px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: #E0E0E0;
  transition: background 0.3s, transform 0.3s;
  display: inline-block;
}

.progress-egg.completed {
  background: var(--accent-green);
}

.progress-egg.current {
  background: var(--primary);
  animation: egg-bounce 1s ease-in-out infinite;
}

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

/* === Intro Screen === */
.intro-content {
  text-align: center;
  max-width: 500px;
}

.intro-title {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(2rem, 8vw, 3.5rem);
  color: var(--primary);
  margin-bottom: 8px;
  line-height: 1.2;
}

.intro-subtitle {
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  color: var(--secondary);
  font-weight: 700;
  margin-bottom: 16px;
}

.intro-desc {
  font-size: clamp(0.95rem, 3vw, 1.1rem);
  color: var(--text-light);
  margin-bottom: 32px;
  line-height: 1.6;
}

.start-btn {
  background: linear-gradient(135deg, var(--primary), var(--accent-pink));
  color: white;
  border: none;
  border-radius: 50px;
  padding: 16px 48px;
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1.2rem, 4vw, 1.5rem);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 15px rgba(124, 77, 255, 0.4);
}

.start-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(124, 77, 255, 0.5);
}

.start-btn:active {
  transform: scale(0.98);
}

.intro-lang-btn {
  margin-top: 24px;
}

/* === Puzzle screens === */
.puzzle-icon {
  font-size: clamp(3rem, 12vw, 5rem);
  margin-bottom: 8px;
}

.puzzle-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 24px;
  max-width: 500px;
  width: 100%;
  box-shadow: var(--card-shadow);
  margin-bottom: 20px;
}

.puzzle-title {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1.2rem, 5vw, 1.8rem);
  color: var(--primary);
  margin-bottom: 12px;
  text-align: center;
}

.puzzle-clue {
  font-size: clamp(0.95rem, 3vw, 1.1rem);
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 12px;
}

.puzzle-detail {
  background: #F3E5F5;
  border-radius: 12px;
  padding: 12px;
  font-weight: 700;
  text-align: center;
  font-size: clamp(1rem, 3.5vw, 1.2rem);
  color: var(--primary);
  margin-bottom: 8px;
}

/* Decoder ring for puzzle 3 */
.decoder-ring {
  background: linear-gradient(135deg, #EDE7F6, #F3E5F5);
  border-radius: 16px;
  padding: 16px;
  margin: 12px 0;
}

.decoder-title {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  color: var(--primary);
  text-align: center;
  margin-bottom: 12px;
}

.decoder-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.decoder-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
}

.decoder-symbol {
  font-size: 1.5rem;
}

.decoder-equals {
  color: var(--text-light);
}

.decoder-number {
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
  color: var(--primary);
}

/* === Input area === */
.input-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 500px;
}

.puzzle-input {
  width: 100%;
  max-width: 300px;
  text-align: center;
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1.3rem, 5vw, 1.8rem);
  padding: 12px 20px;
  border: 3px solid #E0E0E0;
  border-radius: 16px;
  background: white;
  color: var(--text);
  outline: none;
  transition: border-color 0.3s, box-shadow 0.3s;
  letter-spacing: 4px;
}

.puzzle-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(124, 77, 255, 0.15);
}

.puzzle-input.input-shake {
  animation: shake 0.4s ease-in-out;
  border-color: var(--error);
}

.puzzle-input.input-correct {
  border-color: var(--success);
  background: #E8F5E9;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.check-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50px;
  padding: 12px 36px;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: clamp(1rem, 3.5vw, 1.2rem);
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.check-btn:hover {
  background: #651FFF;
  transform: scale(1.03);
}

.check-btn:active {
  transform: scale(0.97);
}

.feedback {
  min-height: 24px;
  font-weight: 700;
  font-size: 1rem;
  text-align: center;
  transition: color 0.3s;
}

.feedback.correct { color: var(--success); }
.feedback.wrong { color: var(--error); }

/* === Hints === */
.hint-btn {
  display: none;
  background: none;
  border: 2px dashed var(--secondary);
  border-radius: 12px;
  padding: 8px 20px;
  color: var(--secondary);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
  margin-top: 8px;
}

.hint-btn:hover {
  background: #FFF3E0;
}

.hint {
  display: none;
  background: #FFF3E0;
  border-left: 4px solid var(--secondary);
  border-radius: 0 12px 12px 0;
  padding: 12px 16px;
  margin-top: 8px;
  font-size: 0.95rem;
  color: var(--text-light);
  max-width: 500px;
  width: 100%;
  animation: fadeIn 0.5s;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Victory screen === */
.victory-content {
  text-align: center;
  position: relative;
  z-index: 2;
}

.victory-title {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(2rem, 8vw, 3.5rem);
  color: var(--primary);
  margin-bottom: 8px;
  animation: victoryBounce 0.8s ease-out;
}

@keyframes victoryBounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.victory-subtitle {
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  color: var(--accent-green);
  font-weight: 800;
  margin-bottom: 16px;
}

.victory-message {
  font-size: clamp(1rem, 3vw, 1.2rem);
  color: var(--text-light);
  margin-bottom: 16px;
  line-height: 1.6;
}

.victory-time {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  color: var(--primary);
  margin-bottom: 24px;
}

/* === Time up screen === */
.timeup-content {
  text-align: center;
}

.timeup-title {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1.8rem, 7vw, 3rem);
  color: var(--secondary);
  margin-bottom: 16px;
}

.timeup-message {
  font-size: clamp(1rem, 3.5vw, 1.3rem);
  color: var(--text-light);
  margin-bottom: 24px;
  line-height: 1.6;
}

.timeup-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.btn-secondary {
  background: white;
  color: var(--primary);
  border: 3px solid var(--primary);
  border-radius: 50px;
  padding: 12px 36px;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--primary);
  color: white;
}

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

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}

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

/* === Responsive === */
@media (max-width: 480px) {
  .screen {
    padding: 64px 12px 16px;
  }

  .puzzle-card {
    padding: 16px;
    border-radius: 16px;
  }

  .puzzle-input {
    max-width: 100%;
  }

  .decoder-grid {
    grid-template-columns: 1fr;
  }

  #top-bar {
    height: 48px;
    padding: 0 10px;
  }

  .setup-modal-content {
    padding: 16px;
    border-radius: 16px;
  }
}

@media (min-width: 768px) {
  .puzzle-card {
    padding: 32px;
  }

  .intro-content {
    max-width: 600px;
  }
}
