:root {
  /* Playful child-friendly colors */
  --primary-color: #4cc9f0;
  /* Bright Blue */
  --primary-hover: #4895ef;
  --secondary-color: #f72585;
  /* Vibrant Pink */
  --accent-color: #ffbe0b;
  /* Sunny Yellow */
  --success-color: #4ade80;
  /* Soft Green */
  --error-color: #f87171;
  /* Soft Red */

  --bg-main: #f0f9ff;
  /* Very light blue background */
  --bg-gradient: linear-gradient(135deg, #a2d2ff 0%, #ffafcc 100%);

  --text-main: #1e293b;
  /* Dark slate for readability */
  --text-muted: #475569;

  /* Softer Glassmorphism for kids */
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.5);
  --glass-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);

  /* Animations */
  --transition-fast: 0.2s ease;
  --transition-medium: 0.4s ease;
  --transition-bounce: 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Nunito', sans-serif;
}

body {
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  /* No manual scrolling */
}

#app {
  width: 100vw;
  height: 100vh;
  /* Fixed height for absolute children */
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 10;
  overflow: hidden;
}

/* Header - Single Column */
.game-header {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-bottom: 2rem;
  padding: 1rem;
  text-align: center;
  position: relative;
  z-index: 100;
  width: 100%;
}

.stats {
  display: none;
  /* Hide global stats as we move it into cards */
}

.logo {
  font-size: 1.8rem;
  font-weight: 900;
  background: linear-gradient(to right, #a855f7, #ec4899, #f43f5e);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}

/* Main Container - Centered and Full Height */
.game-container {
  flex: 1;
  width: 100%;
  position: relative;
  overflow: hidden;
  min-height: 400px;
}

.screen {
  width: 100vw;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.8s ease;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  padding: 1rem 0;
}

.screen.active {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.screen.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

/* Transitions */
.slide-out-left {
  transform: translateX(-100vw) !important;
  opacity: 0 !important;
  visibility: hidden !important;
}

.slide-in-right {
  transform: translateX(100vw) !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Level cards should also snap */
.game-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  /* Better spacing between items */
  width: 100%;
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.game-panel.inactive {
  opacity: 0.3;
  pointer-events: none;
  transform: scale(0.9);
}

.level-card {
  width: 90%;
  max-width: 1000px;
  margin: 0 auto;
}

.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 4px solid var(--glass-border);
  border-radius: 40px;
  padding: 1rem 2rem;
  box-shadow: var(--glass-shadow);
  width: 95%;
  max-width: 1100px;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  color: var(--text-main);
  box-sizing: border-box;
  overflow-y: auto;
  /* Allow scrolling if content is too tall for container */
}

/* Score and Timer Bar inside card */
.card-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 1rem;
}

.level-score-pill {
  background: white;
  color: #1e293b;
  padding: 0.5rem 1rem;
  border-radius: 99px;
  font-weight: 800;
  font-size: 1.1rem;
  border: 2px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 4px 0px #cbd5e1;
}

.timer-pill {
  background: var(--accent-color);
  color: #000;
  padding: 0.5rem 1rem;
  border-radius: 99px;
  font-weight: 900;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 0px #d97706;
}

.timer-warning {
  animation: shake 0.5s infinite;
  background: var(--error-color);
  color: white;
}

/* Image Containers */
.scene-image-container {
  width: 100%;
  height: clamp(100px, 15vh, 160px);
  flex-shrink: 0;
  margin-bottom: 0.5rem;
  border-radius: 20px;
  overflow: hidden;
  border: 4px solid var(--glass-border);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  position: relative;
  background: #cbd5e1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.robot-face {
  position: absolute;
  top: 5px;
  right: 5px;
  font-size: 2.2rem;
  background: white;
  width: 55px;
  height: 55px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  border: 4px solid var(--primary-color);
  z-index: 20;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.robot-face.pop {
  animation: pop 0.5s ease-out;
}

@keyframes pop {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }

  70% {
    transform: scale(1.2);
  }

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

.scene-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.scene-image:hover {
  transform: scale(1.05);
}

/* Typography elements */
h2 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  text-align: center;
  color: #1e3a8a;
  font-weight: 900;
  text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.5);
}

p {
  font-size: 1.15rem;
  line-height: 1.4;
  margin-bottom: 0.75rem;
  color: #334155;
  /* Dark Slate Gray */
  font-weight: 600;
}

strong {
  color: #1e293b;
  font-weight: 800;
}

/* Welcome Screen Specifics */
.input-group {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

label {
  font-size: 1.2rem;
  font-weight: 600;
}

input[type="text"] {
  width: 100%;
  max-width: 400px;
  padding: 1rem 1.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  border-radius: 9999px;
  border: 3px solid var(--primary-color);
  background: white;
  color: #1e293b;
  outline: none;
  transition: all var(--transition-fast);
  text-align: center;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

input[type="text"]::placeholder {
  color: #64748b;
}

input[type="text"]:focus {
  border-color: var(--secondary-color);
  box-shadow: 0 0 0 4px rgba(236, 72, 153, 0.2);
}

/* Buttons */
.primary-btn {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  border: none;
  padding: 1rem 2rem;
  font-size: 1.25rem;
  font-weight: 800;
  border-radius: 9999px;
  cursor: pointer;
  transition: all var(--transition-bounce);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.primary-btn:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
}

.primary-btn:active {
  transform: translateY(2px);
}

.pulse-animation {
  animation: pulse 2s infinite;
}

/* Game Screen Specifics */
.game-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.progress-bar-container {
  width: 100%;
  height: 8px;
  background: var(--glass-bg);
  border-radius: 999px;
  margin-bottom: 2rem;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #34d399);
  /* Emerald green */
  border-radius: 999px;
  width: 0%;
  transition: width 0.5s ease;
}

.story-text {
  font-size: 1.1rem;
  line-height: 1.4;
  color: #0f172a;
  font-weight: 700;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

/* Choices List - Strictly one column */
.choices-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding-bottom: 0.5rem;
}

.choice-btn {
  width: 100%;
  display: block;
  background: white;
  border: 2px solid #e2e8f0;
  color: var(--text-main);
  padding: 0.75rem 1.25rem;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: left;
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 5px 0px #cbd5e1;
}

.choice-btn:hover {
  background: #f8fafc;
  border-color: var(--primary-color);
  transform: translateY(-2px);
  box-shadow: 0 8px 0px #38bdf8;
}

.choice-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0px #38bdf8;
}

.choice-btn.correct {
  background: #dcfce7;
  border-color: var(--success-color);
  box-shadow: 0 6px 0px #22c55e;
}

.choice-btn.wrong {
  background: #fee2e2;
  border-color: var(--error-color);
  box-shadow: 0 6px 0px #ef4444;
}

/* Feedback Message */
.feedback {
  padding: 1rem 2rem;
  border-radius: 16px;
  font-size: 1.1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  animation: slideUp var(--transition-fast);
  margin-top: 0.5rem;
}

.feedback.success {
  background: rgba(34, 197, 94, 0.2);
  border: 3px solid #16a34a;
  color: #111827;
  /* Near black for contrast */
  font-weight: 800;
}

.feedback.error {
  background: rgba(239, 68, 68, 0.2);
  border: 3px solid #dc2626;
  color: #111827;
  /* Near black for contrast */
  font-weight: 800;
}

.feedback.hidden {
  display: none;
}

.winner-panel {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  position: relative;
  width: 100%;
  height: 100%;
}

.end-actions {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.final-score {
  font-size: 1.2rem;
  margin: 0.5rem 0;
  /* Minimal margin */
  background: rgba(0, 0, 0, 0.2);
  padding: 0.5rem 1.5rem;
  border-radius: 99px;
}

.highlight {
  font-size: 1.8rem;
  /* Slightly smaller highlight */
  color: var(--accent-color);
  font-weight: 900;
  margin-left: 0.5rem;
}

/* Balloon Animation */
.balloon-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}

.balloon {
  position: absolute;
  bottom: -100px;
  width: 40px;
  height: 55px;
  border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  box-shadow: inset -5px -5px 15px rgba(0, 0, 0, 0.1);
  animation: balloonFloat 6s linear infinite;
}

.balloon::after {
  content: '';
  position: absolute;
  bottom: -15px;
  left: 50%;
  width: 2px;
  height: 20px;
  background: rgba(0, 0, 0, 0.1);
  transform: translateX(-50%);
}

@keyframes balloonFloat {
  0% {
    transform: translateY(0) translateX(0) rotate(0deg);
    opacity: 1;
  }

  100% {
    transform: translateY(-120vh) translateX(50px) rotate(20deg);
    opacity: 0;
  }
}


/* Keyframes */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(236, 72, 153, 0.7);
  }

  70% {
    box-shadow: 0 0 0 15px rgba(236, 72, 153, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(236, 72, 153, 0);
  }
}

@keyframes float {
  0% {
    transform: translateY(0) rotate(0deg);
  }

  50% {
    transform: translateY(-30px) rotate(10deg);
  }

  100% {
    transform: translateY(0) rotate(0deg);
  }
}

@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

/* --- Responsive Design & Mobile Optimization --- */

/* For Tablets and Mobile */
@media (max-width: 900px) {
  .glass-panel {
    width: 100%;
    padding: 1.5rem;
    border-radius: 20px;
  }
}

@media (max-width: 600px) {
  #app {
    padding: 0.5rem;
  }

  .game-header {
    padding: 0.5rem;
    margin-bottom: 0.75rem;
  }

  .logo {
    font-size: 1.3rem;
  }

  .score-pill {
    font-size: 1rem;
    padding: 0.3rem 0.6rem;
  }

  h2 {
    font-size: 1.6rem;
    margin-bottom: 1rem;
  }

  p,
  .story-text {
    font-size: 1.1rem;
    line-height: 1.4;
    min-height: auto;
  }

  .scene-image-container {
    height: 180px;
    margin-bottom: 1rem;
  }

  .choices-grid {
    gap: 0.75rem;
  }

  .choice-btn {
    padding: 0.8rem 1rem;
    font-size: 1rem;
    border-radius: 12px;
  }

  .primary-btn {
    padding: 0.8rem 1.5rem;
    font-size: 1.1rem;
    width: 100%;
  }
}

/* Landscape Mode / Short Screens */
@media (max-height: 600px) {
  .scene-image-container {
    height: 120px;
  }

  h2 {
    font-size: 1.4rem;
    margin-bottom: 0.5rem;
  }

  .game-panel {
    gap: 1rem;
  }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--secondary-color);
}