/* ============================================================
   KIDS MATH QUIZ GAME — Main Stylesheet
   ============================================================ */

/* ---------- Google Font ---------- */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

/* ---------- Design Tokens ---------- */
:root {
  --clr-bg: #1a1040;
  --clr-bg2: #2a1a60;
  --clr-primary: #f7c948;
  --clr-secondary: #ff6b9d;
  --clr-accent: #4dd9ac;
  --clr-purple: #8b5cf6;
  --clr-blue: #38bdf8;
  --clr-card: rgba(255, 255, 255, 0.07);
  --clr-card-border: rgba(255, 255, 255, 0.14);
  --clr-text: #ffffff;
  --clr-muted: rgba(255, 255, 255, 0.55);
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --transition: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
  font-size: 16px;
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--clr-bg);
  color: var(--clr-text);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ---------- Back Button ---------- */
.back-btn {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--bdr);
  color: var(--muted);
  font-family: 'Nunito', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
  backdrop-filter: blur(10px);
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

/* ---------- Animated Starfield Background ---------- */
.bg-stars {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(139, 92, 246, 0.25) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(56, 189, 248, 0.2) 0%, transparent 60%),
    radial-gradient(ellipse at 50% 50%, rgba(77, 217, 172, 0.1) 0%, transparent 70%);
}

.star {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  animation: twinkle var(--dur, 3s) ease-in-out infinite alternate;
  opacity: 0;
}

@keyframes twinkle {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }

  100% {
    opacity: var(--op, 0.8);
    transform: scale(1.2);
  }
}

/* ---------- Layout ---------- */
#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

/* ---------- Screens ---------- */
.screen {
  display: none;
  width: 100%;
  max-width: 560px;
  animation: fadeUp 0.5s ease both;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }

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

/* ---------- Card ---------- */
.card {
  width: 100%;
  background: var(--clr-card);
  border: 1px solid var(--clr-card-border);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(20px);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

/* ---------- Home Screen ---------- */
.home-mascot {
  font-size: 96px;
  line-height: 1;
  animation: bounce 2s ease-in-out infinite;
  filter: drop-shadow(0 8px 24px rgba(247, 201, 72, 0.4));
}

@keyframes bounce {

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

  50% {
    transform: translateY(-12px) rotate(3deg);
  }
}

.home-title {
  font-size: 2.4rem;
  font-weight: 900;
  text-align: center;
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-secondary), var(--clr-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.home-sub {
  font-size: 1.05rem;
  color: var(--clr-muted);
  text-align: center;
}

.ops-badge {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.op-chip {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50px;
  padding: 6px 18px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--clr-primary);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 50px;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0);
  transition: background 0.2s;
}

.btn:hover::after {
  background: rgba(255, 255, 255, 0.12);
}

.btn:active {
  transform: scale(0.95);
}

.btn-lg {
  padding: 16px 40px;
  font-size: 1.2rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.btn-md {
  padding: 11px 24px;
  font-size: 1rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.btn-sm {
  padding: 7px 16px;
  font-size: 0.85rem;
}

.btn-primary {
  background: linear-gradient(135deg, var(--clr-primary), #f59e0b);
  color: #1a1040;
}

.btn-secondary {
  background: linear-gradient(135deg, var(--clr-secondary), #e44d8a);
  color: #fff;
}

.btn-accent {
  background: linear-gradient(135deg, var(--clr-accent), #15b888);
  color: #1a1040;
}

.btn-purple {
  background: linear-gradient(135deg, var(--clr-purple), #6d28d9);
  color: #fff;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--clr-muted);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
}

.btn-full {
  width: 100%;
}

/* ---------- Quiz Screen ---------- */
.quiz-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.lives-display {
  display: flex;
  gap: 4px;
  font-size: 1.4rem;
}

.score-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.score-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--clr-muted);
  font-weight: 700;
}

.score-value {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--clr-primary);
  line-height: 1;
}

/* ---------- Timer ---------- */
.timer-ring-wrap {
  position: relative;
  width: 64px;
  height: 64px;
}

.timer-ring {
  transform: rotate(-90deg);
}

.timer-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 5;
}

.timer-arc {
  fill: none;
  stroke: var(--clr-accent);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 163;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.5s;
}

.timer-arc.warning {
  stroke: var(--clr-primary);
}

.timer-arc.danger {
  stroke: var(--clr-secondary);
}

.timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 900;
}

/* ---------- Progress Bar ---------- */
.progress-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--clr-muted);
  font-weight: 700;
}

.progress-bar {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--clr-purple), var(--clr-blue));
  border-radius: 99px;
  transition: width 0.5s ease;
}

/* ---------- Question Card ---------- */
.question-number {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--clr-muted);
  font-weight: 700;
  text-align: center;
}

.question-text {
  font-size: 3rem;
  font-weight: 900;
  text-align: center;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #fff, var(--clr-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  padding: 12px 0;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Answer Input ---------- */
.answer-wrap {
  width: 100%;
  position: relative;
}

.answer-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  font-family: 'Nunito', sans-serif;
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  text-align: center;
  outline: none;
  transition: border-color 0.3s, background 0.3s;
  -moz-appearance: textfield;
}

.answer-input::-webkit-inner-spin-button,
.answer-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.answer-input:focus {
  border-color: var(--clr-purple);
  background: rgba(139, 92, 246, 0.12);
}

.answer-input.correct {
  border-color: var(--clr-accent);
  background: rgba(77, 217, 172, 0.12);
}

.answer-input.wrong {
  border-color: var(--clr-secondary);
  background: rgba(255, 107, 157, 0.12);
  animation: shake 0.4s ease;
}

@keyframes shake {

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

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

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

/* ---------- Feedback Bubble ---------- */
.feedback-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: 50px;
  font-size: 1.05rem;
  font-weight: 800;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.3s, transform 0.3s var(--transition);
  pointer-events: none;
}

.feedback-bubble.show {
  opacity: 1;
  transform: scale(1);
}

.feedback-bubble.correct-fb {
  background: rgba(77, 217, 172, 0.2);
  border: 1px solid var(--clr-accent);
  color: var(--clr-accent);
}

.feedback-bubble.wrong-fb {
  background: rgba(255, 107, 157, 0.2);
  border: 1px solid var(--clr-secondary);
  color: var(--clr-secondary);
}


/* ---------- Code Editor Panel ---------- */
.editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 6, 30, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
}

.editor-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.editor-panel {
  width: 100%;
  max-width: 780px;
  max-height: 88vh;
  background: #0f0a24;
  border-top: 2px solid var(--clr-purple);
  border-radius: 24px 24px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.34, 1.2, 0.64, 1);
  overflow: hidden;
}

.editor-overlay.open .editor-panel {
  transform: translateY(0);
}

.editor-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.editor-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  font-weight: 800;
}

.editor-title-icon {
  font-size: 1.4rem;
}

.editor-badge {
  background: rgba(139, 92, 246, 0.25);
  border: 1px solid var(--clr-purple);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.72rem;
  color: var(--clr-purple);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.editor-close-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: var(--clr-muted);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1rem;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  transition: background 0.2s, color 0.2s;
}

.editor-close-btn:hover {
  background: rgba(255, 107, 157, 0.15);
  color: var(--clr-secondary);
}

.editor-hint {
  padding: 10px 20px;
  font-size: 0.82rem;
  color: var(--clr-muted);
  background: rgba(247, 201, 72, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  line-height: 1.5;
}

.editor-hint strong {
  color: var(--clr-primary);
}

/* CodeMirror overrides */
.CodeMirror {
  font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace !important;
  font-size: 0.88rem !important;
  line-height: 1.65 !important;
  background: #0f0a24 !important;
  color: #e2d9f3 !important;
  height: auto !important;
  min-height: 200px;
  max-height: 42vh;
}

.CodeMirror-scroll {
  max-height: 42vh;
}

.CodeMirror-gutters {
  background: #0f0a24 !important;
  border-right: 1px solid rgba(255, 255, 255, 0.07) !important;
}

.CodeMirror-linenumber {
  color: rgba(255, 255, 255, 0.25) !important;
}

.CodeMirror-cursor {
  border-left-color: var(--clr-primary) !important;
}

.editor-actions {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  background: #0b0820;
  flex-wrap: wrap;
}

/* ---------- Output Console ---------- */
.console-wrap {
  padding: 10px 20px 4px;
  flex-shrink: 0;
}

.console-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--clr-muted);
  font-weight: 700;
  margin-bottom: 4px;
}

.console-output {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  color: var(--clr-accent);
  min-height: 73px;
  max-height: 150px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.console-output.error {
  color: var(--clr-secondary);
}

/* ---------- Results Screen ---------- */
.result-emoji {
  font-size: 80px;
  animation: pop 0.5s var(--transition) both;
}

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

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

.result-title {
  font-size: 2rem;
  font-weight: 900;
  text-align: center;
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.result-score-big {
  font-size: 4.5rem;
  font-weight: 900;
  color: var(--clr-primary);
  line-height: 1;
}

.result-score-label {
  font-size: 0.9rem;
  color: var(--clr-muted);
  font-weight: 700;
}

.result-stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-box {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 16px 12px;
  text-align: center;
}

.stat-num {
  font-size: 1.8rem;
  font-weight: 900;
  line-height: 1;
}

.stat-lbl {
  font-size: 0.72rem;
  color: var(--clr-muted);
  font-weight: 700;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---------- Confetti Canvas ---------- */
#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
}

/* ---------- Floating Code Button (during quiz) ---------- */
.fab-code {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 50;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.fab-code.visible {
  display: flex;
}

.fab-code-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--clr-purple), #6d28d9);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(139, 92, 246, 0.5);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.fab-code-btn:hover {
  transform: scale(1.12) rotate(-5deg);
}

.fab-code-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--clr-muted);
  letter-spacing: 0.5px;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .home-mascot {
    font-size: 72px;
  }

  .home-title {
    font-size: 1.8rem;
  }

  .question-text {
    font-size: 2.2rem;
  }

  .result-score-big {
    font-size: 3.5rem;
  }

  .editor-panel {
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
  }

  .editor-actions {
    flex-direction: column;
  }

  .CodeMirror {
    font-size: 0.8rem !important;
  }

  .CodeMirror-scroll {
    max-height: 34vh;
  }
}