:root {
  --bg: #0a0e24;
  --bg-2: #101739;
  --card: rgba(20, 27, 62, 0.92);
  --border: rgba(110, 130, 255, 0.22);
  --text: #e8ecff;
  --muted: #9aa5d6;
  --blue: #4f8cff;
  --purple: #8b5cf6;
  --cyan: #22d3ee;
  --green: #34d399;
  --red: #f87171;
  --yellow: #fbbf24;
  --code-bg: #0b1020;
  --radius: 16px;
}

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

html, body { min-height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at 20% 0%, var(--bg-2), var(--bg) 60%);
  color: var(--text);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  width: 420px; height: 420px;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.25;
  pointer-events: none;
  z-index: 0;
}
.bg-glow-1 { background: var(--purple); top: -120px; right: -100px; }
.bg-glow-2 { background: var(--cyan); bottom: -160px; left: -120px; }

.app {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 28px 16px 16px;
  display: flex;
  align-items: center;
}

.screen { display: none; width: 100%; }
.screen.active { display: block; animation: fadeUp 0.45s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 34px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

/* ---------- Welcome ---------- */
.welcome-card, .results-card { text-align: center; }

.badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.12);
  border: 1px solid rgba(34, 211, 238, 0.35);
  color: var(--cyan);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 18px;
}

.title {
  font-size: clamp(2rem, 6vw, 3.4rem);
  font-weight: 800;
  letter-spacing: 1px;
  line-height: 1.1;
}
.title.small { font-size: clamp(1.7rem, 5vw, 2.4rem); }
.accent {
  background: linear-gradient(90deg, var(--blue), var(--purple), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  margin-top: 12px;
  font-size: clamp(1.05rem, 2.6vw, 1.3rem);
  color: var(--cyan);
  font-weight: 600;
}
.intro {
  margin: 16px auto 0;
  max-width: 560px;
  color: var(--muted);
}

.howto {
  margin: 26px auto;
  max-width: 520px;
  text-align: left;
  background: rgba(8, 12, 32, 0.55);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
}
.howto h2 { font-size: 1rem; margin-bottom: 10px; color: var(--text); }
.howto ol { list-style: none; }
.howto li { display: flex; align-items: center; gap: 12px; padding: 5px 0; color: var(--muted); }
.step {
  flex: 0 0 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}
.howto strong { color: var(--text); }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  border: none;
  border-radius: 12px;
  padding: 14px 28px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  color: #fff;
}
.btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
.btn-primary {
  background: linear-gradient(135deg, var(--blue), var(--purple));
  box-shadow: 0 8px 22px rgba(79, 140, 255, 0.35);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(139, 92, 246, 0.45); }
.btn-secondary {
  background: rgba(79, 140, 255, 0.15);
  border: 1px solid var(--blue);
  color: var(--text);
}
.btn-secondary:hover { background: rgba(79, 140, 255, 0.28); transform: translateY(-2px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.btn-large { padding: 18px 48px; font-size: 1.2rem; }
.btn-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }

/* ---------- Game ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.q-counter { font-weight: 700; font-size: 1.05rem; }
.difficulty {
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border: 1px solid;
}
.difficulty.easy   { color: var(--green);  border-color: var(--green);  background: rgba(52, 211, 153, 0.1); }
.difficulty.medium { color: var(--yellow); border-color: var(--yellow); background: rgba(251, 191, 36, 0.1); }
.difficulty.hard   { color: var(--red);    border-color: var(--red);    background: rgba(248, 113, 113, 0.1); }
.score-pill { color: var(--muted); font-weight: 600; font-size: 0.95rem; }

.progress {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 22px;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--cyan), var(--blue), var(--purple));
  border-radius: 999px;
  transition: width 0.5s ease;
}

.question-text { font-size: clamp(1.15rem, 3vw, 1.45rem); margin-bottom: 14px; }

.editor {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 20px;
}
.editor-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid var(--border);
}
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.red { background: #ff5f57; } .dot.yellow { background: #febc2e; } .dot.green { background: #28c840; }
.file-name { margin-left: 8px; font-size: 0.8rem; color: var(--muted); font-family: Consolas, "Courier New", monospace; }

.code {
  padding: 16px 18px;
  overflow-x: auto;
  font-family: Consolas, "Fira Code", "Courier New", monospace;
  font-size: clamp(0.95rem, 2.6vw, 1.15rem);
  line-height: 1.7;
  color: #d6deff;
  tab-size: 4;
}
.tok-kw  { color: #c792ea; font-weight: 600; }
.tok-fn  { color: #5ccfe6; }
.tok-str { color: #a5e075; }
.tok-num { color: #ffb86c; }
.tok-cm  { color: #6b7aa8; font-style: italic; }

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

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  background: rgba(8, 12, 32, 0.6);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.option:hover:not(:disabled) { border-color: var(--blue); transform: translateY(-2px); }
.option:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.option .letter {
  flex: 0 0 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(79, 140, 255, 0.2);
  color: var(--cyan);
  font-weight: 800;
}
.option .text {
  font-family: Consolas, "Courier New", monospace;
  font-size: 1.05rem;
  white-space: pre-line;
  word-break: break-word;
}
.option.selected { border-color: var(--cyan); background: rgba(34, 211, 238, 0.1); }
.option.selected .letter { background: var(--cyan); color: #06222a; }
.option.correct { border-color: var(--green); background: rgba(52, 211, 153, 0.15); }
.option.correct .letter { background: var(--green); color: #052b1c; }
.option.wrong { border-color: var(--red); background: rgba(248, 113, 113, 0.15); }
.option.wrong .letter { background: var(--red); color: #3a0a0a; }
.option:disabled { cursor: default; }
.option:disabled:not(.correct):not(.wrong) { opacity: 0.55; }

#btn-submit { display: block; margin: 0 auto; min-width: 220px; }

/* ---------- Feedback ---------- */
.feedback {
  margin-top: 22px;
  padding: 20px;
  border-radius: var(--radius);
  background: rgba(8, 12, 32, 0.6);
  border: 1px solid var(--border);
  animation: fadeUp 0.35s ease;
}
.feedback.hidden { display: none; }
.feedback.is-correct { border-color: var(--green); }
.feedback.is-wrong { border-color: var(--red); }
.feedback-title { font-size: 1.3rem; font-weight: 800; margin-bottom: 14px; }
.is-correct .feedback-title { color: var(--green); }
.is-wrong .feedback-title { color: var(--red); }

.output-label, .explain-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}
.output-box {
  background: #05070f;
  border-left: 4px solid var(--cyan);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 1.1rem;
  color: var(--cyan);
  white-space: pre-wrap;
}
.output-box::before { content: ">>> "; color: var(--muted); }
.explanation { color: var(--text); margin-bottom: 18px; }
.explanation code {
  font-family: Consolas, "Courier New", monospace;
  background: rgba(79, 140, 255, 0.18);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--cyan);
}
#btn-next { display: block; margin: 0 auto; min-width: 220px; }

/* ---------- Results ---------- */
.score-circle {
  width: 150px; height: 150px;
  margin: 20px auto 10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2.4rem;
  font-weight: 800;
  background: radial-gradient(circle, var(--bg-2) 58%, transparent 60%),
              conic-gradient(var(--cyan) var(--pct, 0%), rgba(255, 255, 255, 0.1) 0);
}
.res-score { font-size: 1.2rem; font-weight: 700; margin-bottom: 18px; }
.stats { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }
.stat {
  min-width: 130px;
  padding: 14px 20px;
  border-radius: 14px;
  display: flex; flex-direction: column;
  background: rgba(8, 12, 32, 0.6);
  border: 1px solid var(--border);
}
.stat-num { font-size: 2rem; font-weight: 800; }
.stat.good .stat-num { color: var(--green); }
.stat.bad .stat-num { color: var(--yellow); }
.stat-label { color: var(--muted); font-size: 0.9rem; }
.res-message { max-width: 480px; margin: 0 auto; color: var(--muted); font-size: 1.1rem; }

/* ---------- Footer ---------- */
.footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 16px;
  font-size: 0.82rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: rgba(6, 9, 24, 0.7);
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .card { padding: 20px 16px; border-radius: 18px; }
  .options { grid-template-columns: 1fr; }
  .app { padding-top: 16px; }
  .btn-large { padding: 16px 32px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
