:root {
  --bg: #f7fbff;
  --panel: rgba(255,255,255,.74);
  --text: #182033;
  --muted: #5b6478;
  --line: rgba(34, 48, 86, .14);
  --primary: #ff6b6b;
  --secondary: #00b8a9;
  --accent: #ffd166;
  --blue: #4d96ff;
  --green: #52b788;
  --shadow: 0 18px 50px rgba(26, 40, 80, .14);
}

[data-theme="dark"] {
  --bg: #11151f;
  --panel: rgba(29,35,52,.78);
  --text: #f6f8ff;
  --muted: #b7bfd4;
  --line: rgba(255,255,255,.16);
  --shadow: 0 18px 54px rgba(0,0,0,.34);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-rounded, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255,209,102,.42), transparent 30%),
    radial-gradient(circle at 80% 5%, rgba(77,150,255,.35), transparent 32%),
    linear-gradient(135deg, var(--bg), #eef8f3);
  min-height: 100vh;
}

button, input, textarea { font: inherit; }

.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 10;
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 8px;
}

.skip-link:focus { top: 12px; }

.nav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 14px clamp(14px, 4vw, 44px);
  backdrop-filter: blur(18px);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 900;
  margin-right: auto;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: var(--shadow);
}

.nav button, .icon-btn {
  border: 0;
  cursor: pointer;
  color: var(--text);
}

.nav-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-link, .icon-btn {
  border-radius: 999px;
  background: transparent;
  padding: 10px 12px;
}

.nav-link.active, .nav-link:hover, .icon-btn:hover {
  background: rgba(77,150,255,.14);
}

main { padding: 28px clamp(14px, 4vw, 46px) 60px; }

.view { display: none; animation: slideUp .42s ease both; }
.view.active { display: block; }

.hero {
  min-height: min(680px, calc(100vh - 120px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, .85fr);
  align-items: center;
  gap: clamp(24px, 6vw, 78px);
}

.kicker {
  color: var(--secondary);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1, h2, h3 { margin: 0; line-height: 1.05; }
h1 { font-size: clamp(3rem, 6vw, 5rem); max-width: 700px; }
h2 { font-size: clamp(1.8rem, 4vw, 3.1rem); }
h3 { font-size: 1.25rem; }
p { color: var(--muted); line-height: 1.6; }

.hero-text { max-width: 620px; font-size: 1.18rem; }

.hero-actions, .editor-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 13px 18px;
  cursor: pointer;
  font-weight: 850;
  color: var(--text);
  min-height: 48px;
}

.btn.primary {
  color: white;
  background: linear-gradient(135deg, var(--primary), #ff9f1c);
}

.hero .btn.primary { animation: pulse 2.4s infinite; }

.btn.ghost {
  background: var(--panel);
  border: 1px solid var(--line);
}

.hero-art {
  position: relative;
  min-height: 470px;
  display: grid;
  place-items: center;
}

.screen {
  width: min(100%, 460px);
  min-height: 300px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(20, 28, 48, .9);
  color: #d5fff7;
  box-shadow: var(--shadow);
  transform: rotate(-3deg);
}

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; }
.red { background: #ff6b6b; }
.yellow { background: #ffd166; }
.green { background: #52b788; }
.screen code { display: block; margin-top: 22px; font-size: 1.1rem; }

.avatar-hero {
  position: absolute;
  right: 18%;
  bottom: 46px;
  font-size: 7rem;
  filter: drop-shadow(0 20px 20px rgba(0,0,0,.2));
  animation: floaty 4s ease-in-out infinite;
}

.float-icon {
  position: absolute;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 2.2rem;
  box-shadow: var(--shadow);
  animation: floaty 5s ease-in-out infinite;
}
.icon-a { left: 2%; top: 14%; }
.icon-b { right: 4%; top: 8%; animation-delay: .8s; }
.icon-c { left: 12%; bottom: 12%; animation-delay: 1.3s; }
.icon-d { right: 12%; bottom: 28%; animation-delay: 1.7s; }

.section-head {
  margin: 24px 0 18px;
  max-width: 820px;
}

.card-grid, .badge-grid, .games-grid, .quest-layout, .stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.path-card, .badge, .game-card, .quest-card, .profile-card, .profile-stats, .lesson-panel, .path-list, .challenge-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.path-card, .badge, .game-card, .quest-card, .challenge-card {
  padding: 18px;
  transition: transform .2s ease, box-shadow .2s ease;
}

.path-card:hover, .game-card:hover, .badge.unlocked:hover {
  transform: translateY(-5px);
}

.path-icon, .game-icon {
  font-size: 2.5rem;
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: rgba(255,209,102,.25);
}

.mini-progress, .progress-bar {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(91,100,120,.18);
}

.mini-progress span, .progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--secondary), var(--blue), var(--accent));
  transition: width .5s ease;
}

.learn-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
  align-items: start;
}

.path-list, .lesson-panel { padding: 16px; }
.path-list { display: grid; gap: 10px; position: sticky; top: 88px; }
.path-choice {
  border: 1px solid var(--line);
  background: transparent;
  padding: 12px;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}
.path-choice.active { background: rgba(0,184,169,.16); }

.module-list { display: grid; gap: 12px; margin-top: 16px; }
.module {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.lesson-detail {
  margin-top: 18px;
}

.lesson-card {
  display: grid;
  gap: 16px;
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(255,255,255,.7), rgba(77,150,255,.13));
}

.lesson-topline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--secondary);
  font-weight: 900;
}

.lesson-big {
  font-size: 1.08rem;
  max-width: 850px;
}

.lesson-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.lesson-steps div,
.mission-box,
.lesson-quiz {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.44);
}

.lesson-steps strong {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
}

.code-example pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  border-radius: 8px;
  background: #101828;
  color: #d5fff7;
}

.answer.correct {
  border-color: var(--green);
  background: rgba(82,183,136,.22);
}

.answer.wrong {
  border-color: var(--primary);
  background: rgba(255,107,107,.18);
}

.lesson-feedback {
  min-height: 28px;
  font-weight: 800;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: .55;
  filter: grayscale(.35);
}

.profile-shell {
  display: grid;
  grid-template-columns: minmax(240px, 340px) 1fr;
  gap: 18px;
  align-items: stretch;
}
.profile-card, .profile-stats { padding: 22px; }
.profile-avatar { font-size: 6rem; text-align: center; }
.name-label { display: block; margin: 12px 0 6px; color: var(--muted); }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255,255,255,.55);
  color: var(--text);
}
.level-ring {
  margin: 18px auto 0;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--accent), var(--primary), var(--secondary), var(--accent));
  color: white;
}
.level-ring strong { font-size: 3rem; line-height: 1; }
.level-ring span { font-weight: 800; margin-top: -34px; }

.stat {
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.stat strong { display: block; font-size: 1.7rem; }

.badge { opacity: .54; text-align: center; }
.badge.unlocked { opacity: 1; }
.badge.unlocked .badge-icon { animation: badgeSpin .9s ease; }
.badge-icon { font-size: 2rem; }

.challenge-zone { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.answer-list { display: grid; gap: 10px; margin-top: 12px; }
.answer {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255,255,255,.45);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}
.editor-tabs, .editor-actions { grid-column: 1 / -1; }
.tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.tab.active { background: rgba(255,107,107,.16); }
textarea {
  min-height: 360px;
  font-family: "Cascadia Code", Consolas, monospace;
  line-height: 1.5;
  resize: vertical;
}

.code-pane {
  position: relative;
  min-height: 360px;
}

.code-pane pre,
.code-pane textarea {
  position: absolute;
  inset: 0;
  min-height: 360px;
  margin: 0;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: .95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow: auto;
}

#code-highlight {
  padding: 12px;
  pointer-events: none;
  color: #25314d;
  background: rgba(255,255,255,.6);
}

#code-input {
  color: transparent;
  background: transparent;
  caret-color: var(--primary);
}

.tok-key { color: #8a3ffc; font-weight: 800; }
.tok-tag { color: #0077b6; font-weight: 800; }
.tok-str { color: #2d9d78; }
.tok-fn { color: #d9480f; }

[data-theme="dark"] #code-highlight {
  color: #dce6ff;
  background: rgba(12, 18, 32, .72);
}
iframe, #python-output {
  min-height: 360px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}
#python-output {
  display: none;
  padding: 16px;
  overflow: auto;
  background: #101828;
  color: #d5fff7;
}

.game-play {
  min-height: 170px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  margin: 12px 0;
}
.bug { font-size: 2.4rem; cursor: crosshair; }
.memory-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; }
.memory-card {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: rgba(77,150,255,.18);
  color: var(--text);
  cursor: pointer;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: grid;
  gap: 10px;
}
.toast {
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
}
.level-up {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 30;
  padding: 28px 36px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  font-weight: 950;
  font-size: clamp(2rem, 6vw, 4rem);
  animation: levelPop 1.8s ease forwards;
}
.confetti-piece {
  position: fixed;
  top: -20px;
  z-index: 25;
  width: 12px;
  height: 18px;
  border-radius: 3px;
  animation: sparkle 1.4s linear forwards;
}

@media (max-width: 860px) {
  .nav { align-items: flex-start; }
  .nav-links { width: 100%; order: 3; justify-content: flex-start; }
  .hero, .learn-layout, .profile-shell, .editor-layout { grid-template-columns: 1fr; }
  .hero { min-height: auto; padding-top: 12px; gap: 10px; }
  .path-list { position: static; }
  .hero-art { min-height: 300px; }
  .screen { min-height: 220px; }
}

@media (max-width: 520px) {
  main { padding-inline: 12px; }
  .nav-link { padding: 9px 10px; }
  h1 { font-size: 2.65rem; }
  .float-icon { width: 58px; height: 58px; font-size: 1.65rem; }
  .avatar-hero { font-size: 5.2rem; }
  .module { grid-template-columns: 1fr; }
}
