/* ============ ML Playground — design system ============ */
:root {
  --bg: #07090f;
  --bg-elev: #0b0e17;
  --bg-panel: #0e1220;
  --bg-card: #121729;
  --bg-hover: #1a2138;
  --border: #202742;
  --border-strong: #2c3557;
  --text: #eaf0fa;
  --text-dim: #8b96b2;
  --text-faint: #5a6480;
  --text-body: #c3cde0;
  --accent: #6d8dff;
  --accent2: #b78cff;
  --cyan: #4fd6c5;
  --green: #4ade80;
  --orange: #fb923c;
  --red: #f87171;
  --yellow: #fbbf24;
  --pink: #f472b6;
  --grad: linear-gradient(120deg, #6d8dff 0%, #b78cff 55%, #4fd6c5 120%);
  --grad-soft: linear-gradient(120deg, rgba(109,141,255,0.16), rgba(183,140,255,0.16));
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-w: 292px;
  --font-ui: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-display: "Sora", "Inter", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", Consolas, monospace;
  --shadow-lg: 0 24px 60px -18px rgba(0, 0, 0, 0.65);
  --shadow-glow: 0 8px 40px -6px rgba(109, 141, 255, 0.45);
  font-size: 16px;
}

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

html { scroll-behavior: smooth; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(900px 480px at 85% -10%, rgba(109, 141, 255, 0.10), transparent 60%),
    radial-gradient(700px 420px at -10% 25%, rgba(183, 140, 255, 0.07), transparent 60%),
    radial-gradient(800px 500px at 60% 110%, rgba(79, 214, 197, 0.05), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

::selection { background: rgba(109, 141, 255, 0.35); }

/* page scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #232c4d; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #2f3a63; }

#app { display: flex; min-height: 100vh; }

/* ============ Reading progress bar ============ */
#read-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  background: var(--grad);
  z-index: 500;
  border-radius: 0 3px 3px 0;
  transition: width 0.1s linear;
}

/* ============ Sidebar ============ */
#sidebar {
  width: var(--sidebar-w);
  background: rgba(11, 14, 23, 0.88);
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-icon {
  font-size: 1.35rem;
  width: 42px; height: 42px;
  display: grid;
  place-items: center;
  background: var(--grad);
  border-radius: 12px;
  box-shadow: var(--shadow-glow);
  flex-shrink: 0;
}
.brand h1 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  background: linear-gradient(120deg, #eaf0fa, #aab8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand p { font-size: 0.72rem; color: var(--text-dim); margin-top: -2px; }

#nav { flex: 1; overflow-y: auto; padding: 12px 12px 20px; }
#nav::-webkit-scrollbar { width: 5px; }
#nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; border: none; }

.nav-section { margin-bottom: 4px; }
.nav-section-title {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-faint);
  padding: 16px 10px 6px;
  font-weight: 700;
}
.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 9px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text); }
.nav-link.active {
  background: var(--grad-soft);
  color: var(--text);
  font-weight: 600;
}
.nav-link.active::before {
  content: "";
  position: absolute;
  left: -12px; top: 20%;
  height: 60%; width: 3px;
  border-radius: 3px;
  background: var(--grad);
}
.nav-link .check {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--green);
  opacity: 0;
  transition: opacity 0.2s;
}
.nav-link.done .check { opacity: 1; }
.nav-emoji { width: 1.35em; text-align: center; font-size: 0.95em; }

.sidebar-footer {
  padding: 14px 18px 16px;
  border-top: 1px solid var(--border);
  background: rgba(7, 9, 15, 0.5);
}
#progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  width: 0%;
  background: var(--grad);
  border-radius: 3px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
#progress-text { font-size: 0.7rem; color: var(--text-dim); margin-top: 7px; font-weight: 500; }

#menu-toggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 200;
  background: rgba(18, 23, 41, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 1.15rem;
  padding: 7px 13px;
  border-radius: 10px;
  cursor: pointer;
}

/* ============ Main content ============ */
#content {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  padding: 40px clamp(20px, 5vw, 72px) 0;
  max-width: calc(var(--sidebar-w) + 1120px);
  animation: pageIn 0.45s cubic-bezier(0.25, 0.6, 0.3, 1) both;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* scroll reveal */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.25, 0.6, 0.3, 1); }
.reveal.visible { opacity: 1; transform: none; }

/* ============ Lesson pages ============ */
.lesson-header { margin-bottom: 26px; }
.lesson-breadcrumb {
  font-size: 0.72rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 700;
  margin-bottom: 8px;
}
.lesson-header h2 {
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 3.4vw, 2.3rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}
.level-badge {
  display: inline-block;
  font-size: 0.64rem;
  font-weight: 800;
  font-family: var(--font-ui);
  padding: 4px 12px;
  border-radius: 20px;
  margin-left: 12px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.level-Beginner { background: rgba(74, 222, 128, 0.13); color: var(--green); border: 1px solid rgba(74, 222, 128, 0.3); }
.level-Intermediate { background: rgba(251, 191, 36, 0.12); color: var(--yellow); border: 1px solid rgba(251, 191, 36, 0.3); }
.level-Advanced { background: rgba(251, 146, 60, 0.12); color: var(--orange); border: 1px solid rgba(251, 146, 60, 0.3); }
.level-Expert { background: rgba(248, 113, 113, 0.12); color: var(--red); border: 1px solid rgba(248, 113, 113, 0.3); }

.lesson-body h3 {
  margin: 40px 0 12px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: -0.01em;
  color: var(--text);
  position: relative;
  padding-left: 16px;
}
.lesson-body h3::before {
  content: "";
  position: absolute;
  left: 0; top: 0.28em;
  width: 4px; height: 1em;
  border-radius: 3px;
  background: var(--grad);
}
.lesson-body p { margin: 11px 0; color: var(--text-body); }
.lesson-body strong { color: var(--text); }
.lesson-body em { color: var(--text); }
.lesson-body ul, .lesson-body ol { margin: 10px 0 10px 24px; color: var(--text-body); }
.lesson-body li { margin: 5px 0; }
.lesson-body code {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.82em;
  color: var(--cyan);
}

.formula {
  background: linear-gradient(120deg, rgba(18, 23, 41, 0.9), rgba(22, 20, 40, 0.9));
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent2);
  border-radius: var(--radius-sm);
  padding: 15px 20px;
  margin: 16px 0;
  font-family: "Cambria Math", Georgia, serif;
  font-size: 1.05rem;
  overflow-x: auto;
  white-space: nowrap;
  color: var(--text-body);
}

.callout {
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin: 18px 0;
  border: 1px solid;
  font-size: 0.92rem;
  color: var(--text-body);
}
.callout-tip { background: rgba(74, 222, 128, 0.06); border-color: rgba(74, 222, 128, 0.28); }
.callout-warn { background: rgba(251, 191, 36, 0.06); border-color: rgba(251, 191, 36, 0.28); }
.callout-info { background: rgba(109, 141, 255, 0.07); border-color: rgba(109, 141, 255, 0.3); }
.callout .callout-title { font-weight: 700; margin-bottom: 5px; color: var(--text); }

/* ============ Demo panels ============ */
.demo {
  position: relative;
  background: linear-gradient(160deg, rgba(16, 20, 36, 0.95), rgba(11, 14, 23, 0.95));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin: 24px 0;
  box-shadow: var(--shadow-lg);
}
.demo::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(140deg, rgba(109, 141, 255, 0.35), transparent 30%, transparent 70%, rgba(79, 214, 197, 0.25));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.demo-title {
  font-weight: 700;
  font-family: var(--font-display);
  font-size: 0.98rem;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.demo-title::before { content: "🎛️"; font-size: 0.9em; }
.demo-hint { font-size: 0.82rem; color: var(--text-dim); margin-bottom: 15px; }

.demo canvas {
  display: block;
  width: 100%;
  border-radius: var(--radius-sm);
  background: #05070c;
  border: 1px solid var(--border);
  touch-action: none;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
  align-items: center;
  margin-top: 16px;
}
.control { display: flex; align-items: center; gap: 9px; font-size: 0.84rem; }
.control label { color: var(--text-dim); white-space: nowrap; font-weight: 500; }
.control .val {
  font-family: var(--font-mono);
  color: var(--cyan);
  min-width: 3.5em;
  font-size: 0.82rem;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 140px;
  height: 5px;
  background: var(--border-strong);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: linear-gradient(140deg, #6d8dff, #b78cff);
  cursor: grab;
  border: 2px solid #05070c;
  box-shadow: 0 0 10px rgba(109, 141, 255, 0.5);
  transition: transform 0.12s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: #6d8dff;
  border: 2px solid #05070c;
  cursor: grab;
}

button.btn {
  background: var(--grad);
  background-size: 150% 150%;
  color: #fff;
  border: none;
  padding: 9px 20px;
  border-radius: 10px;
  font-family: var(--font-ui);
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 4px 18px -4px rgba(109, 141, 255, 0.55);
  transition: transform 0.13s, box-shadow 0.2s, background-position 0.3s;
}
button.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 24px -4px rgba(109, 141, 255, 0.65); background-position: 100% 50%; }
button.btn:active { transform: translateY(0) scale(0.98); }
button.btn.secondary {
  background: rgba(26, 33, 56, 0.7);
  border: 1px solid var(--border-strong);
  color: var(--text);
  box-shadow: none;
}
button.btn.secondary:hover { background: var(--bg-hover); border-color: #3a4670; box-shadow: none; }
button.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

select, input[type="text"] {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  font-family: var(--font-ui);
  font-size: 0.84rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select:focus, input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 141, 255, 0.18);
}

.stat-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.stat {
  background: rgba(18, 23, 41, 0.8);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat b {
  display: block;
  font-size: 1.08rem;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--cyan);
  letter-spacing: 0;
  text-transform: none;
  margin-top: 1px;
}

/* Cards grid (inside lessons) */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin: 18px 0; }
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: border-color 0.2s, transform 0.2s;
}
.card:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.card .card-icon { font-size: 1.55rem; margin-bottom: 8px; }
.card h4 { font-size: 0.95rem; margin-bottom: 5px; font-family: var(--font-display); }
.card p { font-size: 0.82rem; color: var(--text-dim); margin: 0; }

/* Tables */
table.info-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 16px 0;
  font-size: 0.86rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.info-table th, .info-table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
}
.info-table th:last-child, .info-table td:last-child { border-right: none; }
.info-table tr:last-child td { border-bottom: none; }
.info-table th {
  background: rgba(109, 141, 255, 0.08);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.info-table td { color: var(--text-body); }
.info-table tr:hover td { background: rgba(109, 141, 255, 0.03); }

/* Lesson footer navigation */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 52px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.lesson-nav a {
  color: var(--text);
  text-decoration: none;
  padding: 15px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  font-size: 0.9rem;
  font-weight: 600;
  max-width: 48%;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.lesson-nav a:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 10px 30px -10px rgba(109, 141, 255, 0.35);
}
.lesson-nav a span { display: block; font-size: 0.68rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 3px; }

/* ============ Code blocks ============ */
.code-block {
  background: #070a12;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 16px 0;
  overflow: hidden;
}
.code-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 23, 41, 0.6);
}
.code-dots { display: inline-flex; gap: 5px; }
.code-dots i { width: 9px; height: 9px; border-radius: 50%; background: #2c3557; }
.code-dots i:first-child { background: #f8717155; }
.code-dots i:nth-child(2) { background: #fbbf2455; }
.code-dots i:nth-child(3) { background: #4ade8055; }
.code-body {
  margin: 0;
  padding: 13px 16px;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  line-height: 1.7;
  color: #dbe4f5;
  overflow-x: auto;
}
.code-ln {
  display: inline-block;
  width: 2.1em;
  color: #3a4262;
  user-select: none;
}
.py-kw { color: #c792ea; }
.py-fn { color: #82aaff; }
.py-str { color: #7cd9c8; }
.py-num { color: #f7b96d; }
.py-com { color: #546084; font-style: italic; }
.code-output {
  border-top: 1px dashed var(--border);
  padding: 10px 16px 12px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #9ae6b4;
  white-space: pre-wrap;
  background: rgba(74, 222, 128, 0.03);
}
.code-out-label {
  display: block;
  font-size: 0.66rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 2px;
}

/* ============ Real-world examples ============ */
.examples {
  background: linear-gradient(135deg, rgba(251, 146, 60, 0.06), rgba(74, 222, 128, 0.05));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin: 40px 0 8px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.examples::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, rgba(251, 146, 60, 0.5), transparent 40%, transparent 60%, rgba(74, 222, 128, 0.4));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.examples-head { margin-bottom: 18px; position: relative; z-index: 1; }
.examples-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--orange);
  background: rgba(251, 146, 60, 0.14);
  border: 1px solid rgba(251, 146, 60, 0.35);
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 8px;
}
.examples-head h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: -0.01em;
  color: var(--text);
  padding-left: 0 !important;
  margin: 6px 0 0 !important;
}
.examples-head h3::before { display: none !important; }
.examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  position: relative;
  z-index: 1;
}
.example-card {
  display: flex;
  gap: 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.example-card:hover {
  transform: translateY(-2px);
  border-color: rgba(251, 146, 60, 0.4);
  box-shadow: 0 12px 30px -12px rgba(251, 146, 60, 0.25);
}
.example-icon {
  width: 44px; height: 44px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  border-radius: 12px;
  background: linear-gradient(140deg, rgba(251, 146, 60, 0.18), rgba(74, 222, 128, 0.12));
  border: 1px solid rgba(251, 146, 60, 0.3);
}
.example-body { flex: 1; min-width: 0; }
.example-body h4 {
  font-family: var(--font-display);
  font-size: 0.96rem;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}
.example-story {
  font-size: 0.85rem;
  color: var(--text-body);
  line-height: 1.6;
  margin: 0 0 10px !important;
}
.example-story code {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.8em;
  color: var(--cyan);
}
.example-connect {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  line-height: 1.5;
}
.example-connect .connect-arrow { color: var(--orange); font-weight: 800; margin-right: 4px; }

/* ============ Games highlight (homepage) ============ */
.games-highlight {
  background: linear-gradient(135deg, rgba(244, 114, 182, 0.08), rgba(109, 141, 255, 0.06));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin: 46px 0 10px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.games-highlight::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, rgba(244, 114, 182, 0.5), transparent 40%, transparent 60%, rgba(109, 141, 255, 0.4));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.games-highlight-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  position: relative;
  z-index: 1;
}
.games-highlight-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--pink);
  background: rgba(244, 114, 182, 0.13);
  border: 1px solid rgba(244, 114, 182, 0.35);
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 8px;
}
.games-highlight-head h3 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  color: var(--text);
}
.games-highlight-head p { font-size: 0.85rem; color: var(--text-dim); margin: 4px 0 0; max-width: 480px; }
.games-highlight-all {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.86rem;
  white-space: nowrap;
}
.games-highlight-all:hover { text-decoration: underline; }

/* ============ Quiz ============ */
.quiz {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin: 40px 0 8px;
  box-shadow: var(--shadow-lg);
}
.quiz-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.quiz-head h3 { font-family: var(--font-display); font-size: 1.15rem; }
.quiz-score { font-size: 0.8rem; color: var(--text-dim); font-weight: 600; }
.quiz-q { margin-top: 20px; }
.quiz-question { font-weight: 600; margin-bottom: 10px; color: var(--text); font-size: 0.94rem; }
.quiz-opts { display: flex; flex-direction: column; gap: 8px; }
.quiz-opt {
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text-body);
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 0.87rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.quiz-opt:hover:not(.locked) { border-color: var(--accent); background: var(--bg-hover); transform: translateX(3px); }
.quiz-opt.locked { cursor: default; opacity: 0.75; }
.quiz-opt.correct {
  background: rgba(74, 222, 128, 0.12) !important;
  border-color: var(--green) !important;
  color: var(--green);
  font-weight: 700;
  opacity: 1;
}
.quiz-opt.correct::after { content: "  ✓"; }
.quiz-opt.wrong {
  background: rgba(248, 113, 113, 0.10) !important;
  border-color: var(--red) !important;
  color: var(--red);
  opacity: 1;
}
.quiz-opt.wrong::after { content: "  ✗"; }
.quiz-why {
  display: none;
  margin-top: 10px;
  font-size: 0.84rem;
  color: var(--text-dim);
  background: rgba(109, 141, 255, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 10px 14px;
}
.quiz-why.show { display: block; animation: pageIn 0.3s both; }

/* ============ Newsletter signup ============ */
.newsletter {
  margin-top: 30px;
  padding: 22px 24px;
  background: linear-gradient(135deg, rgba(109, 141, 255, 0.09), rgba(183, 140, 255, 0.06));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  gap: 18px;
  align-items: flex-start;
  position: relative;
  overflow: hidden;
}
.newsletter::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, rgba(109, 141, 255, 0.5), transparent 40%, transparent 60%, rgba(183, 140, 255, 0.45));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.newsletter.newsletter-pending { opacity: 0.9; }
.nl-icon {
  width: 46px; height: 46px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  border-radius: 12px;
  background: var(--grad-soft);
  border: 1px solid rgba(109, 141, 255, 0.3);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.nl-body { flex: 1; min-width: 0; position: relative; z-index: 1; }
.nl-body h4 { font-family: var(--font-display); font-size: 1rem; margin-bottom: 4px; color: var(--text); letter-spacing: -0.01em; }
.nl-body p { font-size: 0.82rem; color: var(--text-dim); margin: 0 0 12px !important; }
.nl-form { display: flex; gap: 8px; flex-wrap: wrap; }
.nl-input {
  flex: 1;
  min-width: 200px;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-family: var(--font-ui);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.nl-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109, 141, 255, 0.18); }
.nl-submit {
  background: var(--grad);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 10px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 18px -4px rgba(109, 141, 255, 0.55);
  transition: transform 0.13s, box-shadow 0.2s;
  white-space: nowrap;
}
.nl-submit:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 24px -4px rgba(109, 141, 255, 0.65); }
.nl-submit:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.nl-status { margin-top: 8px; font-size: 0.78rem; min-height: 1em; }
.nl-status.ok { color: var(--green); }
.nl-status.err { color: var(--red); }

/* ============ Comments section (Giscus) ============ */
.comments {
  background: linear-gradient(135deg, rgba(79, 214, 197, 0.06), rgba(109, 141, 255, 0.05));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 24px 16px;
  margin: 40px 0 8px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.comments::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, rgba(79, 214, 197, 0.45), transparent 40%, transparent 60%, rgba(109, 141, 255, 0.4));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.comments-head { position: relative; z-index: 1; margin-bottom: 18px; }
.comments-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan);
  background: rgba(79, 214, 197, 0.12);
  border: 1px solid rgba(79, 214, 197, 0.35);
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 8px;
}
.comments-head h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: -0.01em;
  color: var(--text);
  padding-left: 0 !important;
  margin: 6px 0 6px !important;
}
.comments-head h3::before { display: none !important; }
.comments-sub {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0 !important;
  line-height: 1.55;
}
.comments-body { position: relative; z-index: 1; min-height: 60px; }
.comments-body .giscus, .comments-body .giscus-frame {
  width: 100%;
  min-height: 200px;
  border: none;
  color-scheme: auto;
}
.comments-fallback {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  background: var(--bg-card);
  border: 1px dashed var(--border-strong);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 11px 20px;
  border-radius: 10px;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.comments-fallback:hover {
  border-color: var(--cyan);
  border-style: solid;
  transform: translateY(-1px);
  background: var(--bg-hover);
}
.comments-fallback .arrow { color: var(--cyan); font-weight: 800; }

.complete-row { text-align: center; margin-top: 36px; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 0.77rem; color: var(--text-dim); }
.legend .chip { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; box-shadow: 0 0 6px currentColor; }

/* ============ HOME PAGE ============ */
.hero {
  position: relative;
  margin: -40px calc(-1 * clamp(20px, 5vw, 72px)) 0;
  padding: clamp(70px, 10vh, 120px) clamp(20px, 5vw, 72px) 70px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
#hero-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.85;
}
.hero-inner { position: relative; z-index: 2; max-width: 780px; }
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(109, 141, 255, 0.1);
  border: 1px solid rgba(109, 141, 255, 0.35);
  padding: 6px 16px;
  border-radius: 30px;
  margin-bottom: 22px;
  letter-spacing: 0.03em;
  backdrop-filter: blur(4px);
}
.hero-badge .pulse-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
}
.hero h2 {
  font-family: var(--font-display);
  font-size: clamp(2.3rem, 5.5vw, 3.9rem);
  line-height: 1.06;
  letter-spacing: -0.03em;
  margin-bottom: 20px;
  font-weight: 800;
}
.hero h2 .grad-text {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero .hero-sub {
  color: var(--text-dim);
  font-size: clamp(0.98rem, 1.6vw, 1.13rem);
  max-width: 620px;
  margin-bottom: 32px;
  line-height: 1.7;
}
.hero-cta { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 44px; }
.cta-primary, .cta-ghost {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 14px 30px;
  border-radius: 13px;
  transition: transform 0.15s, box-shadow 0.25s;
}
.cta-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 10px 34px -8px rgba(109, 141, 255, 0.65);
}
.cta-primary:hover { transform: translateY(-2px); box-shadow: 0 16px 44px -8px rgba(109, 141, 255, 0.75); }
.cta-ghost {
  background: rgba(18, 23, 41, 0.6);
  color: var(--text);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(6px);
}
.cta-ghost:hover { transform: translateY(-2px); border-color: var(--accent); }

.hero-stats { display: flex; flex-wrap: wrap; gap: 0; }
.hero-stat {
  padding: 0 28px;
  border-left: 1px solid var(--border-strong);
}
.hero-stat:first-child { padding-left: 0; border-left: none; }
.hero-stat b {
  display: block;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 800;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.2;
}
.hero-stat span { font-size: 0.76rem; color: var(--text-dim); font-weight: 600; }

/* feature trio */
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin: 44px 0 10px;
}
.feature {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s, transform 0.2s;
}
.feature:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.feature .f-icon {
  width: 42px; height: 42px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  border-radius: 12px;
  background: var(--grad-soft);
  border: 1px solid rgba(109, 141, 255, 0.3);
}
.feature h4 { font-family: var(--font-display); font-size: 0.94rem; margin-bottom: 3px; }
.feature p { font-size: 0.8rem; color: var(--text-dim); margin: 0; line-height: 1.55; }

/* curriculum sections */
.home-sections { margin-top: 54px; }
.home-section-block { margin-bottom: 46px; }
.section-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 18px;
}
.section-head .sec-num {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(109, 141, 255, 0.1);
  border: 1px solid rgba(109, 141, 255, 0.3);
  padding: 3px 11px;
  border-radius: 20px;
}
.section-head h3 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}
.section-head .sec-line { flex: 1; height: 1px; background: linear-gradient(90deg, var(--border-strong), transparent); }

.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.lesson-card {
  position: relative;
  display: block;
  text-decoration: none;
  color: var(--text);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  overflow: hidden;
  transition: transform 0.22s cubic-bezier(0.25, 0.6, 0.3, 1), border-color 0.22s, box-shadow 0.22s;
}
.lesson-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(300px 160px at 20% 0%, rgba(109, 141, 255, 0.12), transparent 70%);
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}
.lesson-card:hover {
  transform: translateY(-4px);
  border-color: rgba(109, 141, 255, 0.55);
  box-shadow: 0 18px 44px -14px rgba(109, 141, 255, 0.35);
}
.lesson-card:hover::after { opacity: 1; }
.lesson-card .lc-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.lesson-card .lc-emoji {
  width: 44px; height: 44px;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.lesson-card .lc-num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-faint);
}
.lesson-card h4 { margin: 0 0 5px; font-size: 0.99rem; font-family: var(--font-display); letter-spacing: -0.01em; }
.lesson-card p { font-size: 0.8rem; color: var(--text-dim); margin: 0 0 12px; line-height: 1.55; }
.lesson-card .lc-foot { display: flex; align-items: center; justify-content: space-between; }
.lesson-card .lc-arrow {
  font-size: 0.85rem;
  color: var(--accent);
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 0.2s, transform 0.2s;
}
.lesson-card:hover .lc-arrow { opacity: 1; transform: none; }
.lesson-card .lc-done { color: var(--green); font-size: 0.72rem; font-weight: 700; }
.lesson-card .level-badge { margin-left: 0; }

/* footer */
.site-footer {
  margin: 70px calc(-1 * clamp(20px, 5vw, 72px)) 0;
  padding: 40px clamp(20px, 5vw, 72px) 46px;
  border-top: 1px solid var(--border);
  background: rgba(7, 9, 15, 0.6);
}
.site-footer .foot-grid { display: flex; flex-wrap: wrap; gap: 30px 60px; justify-content: space-between; align-items: flex-start; }
.site-footer .foot-brand { max-width: 320px; }
.site-footer .foot-brand h4 { font-family: var(--font-display); font-size: 1rem; margin-bottom: 6px; }
.site-footer p { font-size: 0.8rem; color: var(--text-dim); }
.site-footer .foot-links { display: flex; gap: 50px; flex-wrap: wrap; }
.site-footer .foot-col h5 {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.site-footer .foot-col a {
  display: block;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.82rem;
  padding: 3px 0;
  transition: color 0.15s;
}
.site-footer .foot-col a:hover { color: var(--accent); }
.site-footer .foot-bottom {
  margin-top: 34px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-faint);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

/* ============ Responsive ============ */
@media (max-width: 900px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); box-shadow: 0 0 60px rgba(0, 0, 0, 0.7); }
  #menu-toggle { display: block; }
  #content { margin-left: 0; padding-top: 66px; }
  .hero { margin-top: -66px; padding-top: 110px; }
  .hero-stat { padding: 0 18px; }
  .lesson-nav { flex-direction: column; }
  .lesson-nav a { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}

/* =====================================================================
   THEMING — light "study mode" + dark "focus mode" (toggle in sidebar)
   Dark is the default (:root above). Light overrides the variables.
   The interactive demos, code blocks and hero stay framed-dark islands.
   ===================================================================== */
html, body { transition: background-color 0.25s ease, color 0.25s ease; }

:root[data-theme="light"] {
  --bg: #f5f7fc;
  --bg-elev: #ffffff;
  --bg-panel: #ffffff;
  --bg-card: #eef1f9;
  --bg-hover: #e7ebf6;
  --border: #e0e5f1;
  --border-strong: #ccd4e6;
  --text: #161d33;
  --text-dim: #5a6480;
  --text-faint: #949cb4;
  --text-body: #38425c;
  --accent: #4d5fe0;
  --accent2: #8b5cf6;
  --cyan: #0e9384;
  --grad-soft: linear-gradient(120deg, rgba(77, 95, 224, 0.12), rgba(139, 92, 246, 0.12));
  --shadow-lg: 0 18px 44px -20px rgba(35, 45, 95, 0.25);
  --shadow-glow: 0 8px 30px -8px rgba(77, 95, 224, 0.4);
}

/* light-mode surface fixes for elements with hard-coded dark colours */
:root[data-theme="light"] #sidebar { background: rgba(255, 255, 255, 0.9); }
:root[data-theme="light"] .sidebar-footer { background: rgba(245, 247, 252, 0.7); }
:root[data-theme="light"] .brand h1 {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
:root[data-theme="light"] #menu-toggle { background: rgba(255, 255, 255, 0.92); }
:root[data-theme="light"] ::-webkit-scrollbar-thumb { background: #c8d0e4; border-color: var(--bg); }
:root[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #b3bdd8; }
:root[data-theme="light"] .formula {
  background: linear-gradient(120deg, #eef1fc, #f3effc);
}
:root[data-theme="light"] .site-footer { background: #eef1f9; }
:root[data-theme="light"] .info-table th { background: rgba(77, 95, 224, 0.07); }
:root[data-theme="light"] .lesson-body code { background: #eef1f9; color: #0e7c70; }
:root[data-theme="light"] select, :root[data-theme="light"] input[type="text"] { background: #ffffff; }

/* Framed-dark islands: demos, code blocks and the hero keep the dark palette
   in BOTH themes by re-declaring the neutral variables locally. */
.demo, .code-block, .hero {
  --bg: #07090f;
  --bg-elev: #0b0e17;
  --bg-panel: #0e1220;
  --bg-card: #121729;
  --bg-hover: #1a2138;
  --border: #202742;
  --border-strong: #2c3557;
  --text: #eaf0fa;
  --text-dim: #8b96b2;
  --text-faint: #5a6480;
  --text-body: #c3cde0;
  --cyan: #4fd6c5;
  --accent: #6d8dff;
  --shadow-lg: 0 24px 60px -18px rgba(0, 0, 0, 0.5);
}

/* Hero becomes an explicit gradient banner so it reads intentionally in light mode */
.hero {
  color: var(--text); /* pinned light — keeps headline readable on the dark banner */
  background:
    radial-gradient(720px 380px at 82% -12%, rgba(109, 141, 255, 0.24), transparent 60%),
    radial-gradient(620px 360px at 4% 120%, rgba(79, 214, 197, 0.14), transparent 60%),
    linear-gradient(135deg, #0a0e1e 0%, #0f1030 55%, #0a1b26 100%);
}
.hero h2 { color: var(--text); }

/* ============ Concept cross-links (auto-generated) ============ */
.concept-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px dashed rgba(109, 141, 255, 0.55);
  border-bottom: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 2px;
  padding: 0 1px;
  transition: background 0.15s, border-color 0.15s;
}
.concept-link:hover {
  background: rgba(109, 141, 255, 0.14);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-bottom-color: var(--accent);
  border-bottom-style: solid;
}
.info-table .concept-link { white-space: nowrap; }

/* ============ Theme toggle ============ */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 12px;
  cursor: pointer;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
}
.theme-toggle:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.theme-toggle .tt-track {
  position: relative;
  width: 34px; height: 18px;
  border-radius: 20px;
  background: var(--border-strong);
  flex-shrink: 0;
  transition: background 0.2s;
}
.theme-toggle .tt-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--grad);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
:root[data-theme="light"] .theme-toggle .tt-thumb { transform: translateX(16px); }
.theme-toggle .tt-icon { font-size: 0.9rem; }
