:root {
  --bg: #f6f8ff;
  --card: #ffffff;
  --text: #1e2340;
  --muted: #5b6185;
  --border: #e2e6f5;
  --brand: #4f46e5;
  --brand-dark: #3730a3;
  --radius: 16px;
  --shadow: 0 6px 20px rgba(30, 35, 64, 0.08);
  --level: #4f46e5;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12142a;
    --card: #1c1f3b;
    --text: #eef0ff;
    --muted: #aab0d6;
    --border: #2d3260;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #12142a;
  --card: #1c1f3b;
  --text: #eef0ff;
  --muted: #aab0d6;
  --border: #2d3260;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 17px;
}

a { color: var(--brand); }

.container {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */
.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
}
.brand {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand span.logo { font-size: 1.5rem; }
.nav-links { display: flex; gap: 14px; flex-wrap: wrap; }
.nav-links a { text-decoration: none; color: var(--muted); font-weight: 700; font-size: 0.95rem; }
.nav-links a:hover { color: var(--brand); }

/* Hero */
.hero {
  padding: 48px 0 24px;
  text-align: center;
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  margin: 0 0 12px;
  line-height: 1.15;
}
.hero p {
  color: var(--muted);
  font-size: 1.1rem;
  max-width: 640px;
  margin: 0 auto;
}

/* Progress */
.progress-wrap {
  max-width: 520px;
  margin: 24px auto 0;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 6px;
}
.progress-bar {
  height: 12px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #3b82f6, #a855f7);
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* Level cards */
.grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin: 28px 0 48px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-top: 6px solid var(--level, var(--brand));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
a.card:hover { transform: translateY(-3px); }
.card .icon { font-size: 2.2rem; }
.card h2, .card h3 { margin: 8px 0 6px; font-size: 1.3rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.97rem; }
.card .meta {
  margin-top: 14px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--level, var(--brand));
}

.chapter-card .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--level, var(--brand));
  color: #fff;
  font-weight: 800;
  margin-bottom: 6px;
}
.chapter-card.done .num::after { content: "✓"; }
.chapter-card.done .num { font-size: 0; }
.chapter-card.done .num::after { font-size: 1rem; }

/* Level / chapter pages */
.page { padding: 28px 0 56px; }
.crumbs { font-size: 0.9rem; color: var(--muted); margin-bottom: 10px; }
.crumbs a { text-decoration: none; }
.page-title { font-size: clamp(1.7rem, 4vw, 2.4rem); margin: 0 0 8px; }
.page-sub { color: var(--muted); margin: 0 0 24px; }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}
.panel h2 { margin-top: 0; font-size: 1.3rem; }
.panel ul { padding-left: 20px; margin: 0 0 12px; }
.panel li { margin-bottom: 6px; }

.goals { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 0; }
.goals li {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.92rem;
  margin: 0;
}

pre {
  background: #0f1226;
  color: #e6e9ff;
  padding: 16px;
  border-radius: 12px;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.5;
}
code { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }

.tip {
  background: #fff7d6;
  color: #5c4500;
  border-left: 5px solid #f5b400;
  padding: 12px 16px;
  border-radius: 10px;
  margin: 14px 0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tip { background: #3a3110; color: #ffe9a6; }
}
:root[data-theme="dark"] .tip { background: #3a3110; color: #ffe9a6; }

.steps { counter-reset: step; list-style: none; padding: 0; }
.steps li {
  counter-increment: step;
  position: relative;
  padding-left: 42px;
  margin-bottom: 10px;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--level, var(--brand));
  color: #fff;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Quiz */
.quiz-options { display: grid; gap: 10px; margin-top: 10px; }
.quiz-option {
  text-align: left;
  font: inherit;
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
}
.quiz-option:hover { border-color: var(--level, var(--brand)); }
.quiz-option.correct { border-color: #22c55e; background: #e8fbef; color: #14532d; }
.quiz-option.wrong { border-color: #ef4444; background: #fdecec; color: #7f1d1d; }
:root[data-theme="dark"] .quiz-option.correct { background: #14331f; color: #bbf7d0; }
:root[data-theme="dark"] .quiz-option.wrong { background: #3a1616; color: #fecaca; }
.quiz-feedback { margin-top: 10px; font-weight: 700; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-weight: 800;
  padding: 10px 18px;
  border-radius: 999px;
  border: 2px solid var(--level, var(--brand));
  background: var(--card);
  color: var(--level, var(--brand));
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: var(--level, var(--brand)); color: #fff; }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; margin-top: 24px; }

.done-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: #dcfce7;
  color: #166534;
  font-weight: 800;
  font-size: 0.85rem;
}
:root[data-theme="dark"] .done-badge { background: #14331f; color: #bbf7d0; }

/* Assistant */
.assistant-toggle {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #4f46e5, #a855f7);
  color: #fff;
  font-size: 1.8rem;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(79, 70, 229, 0.4);
}
.assistant-panel {
  position: fixed;
  right: 18px;
  bottom: 96px;
  z-index: 50;
  width: min(380px, calc(100vw - 36px));
  height: min(520px, calc(100vh - 140px));
  display: none;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.assistant-panel.open { display: flex; }
.assistant-head {
  background: linear-gradient(135deg, #4f46e5, #a855f7);
  color: #fff;
  padding: 14px 16px;
  font-weight: 800;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.assistant-head button {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}
.assistant-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.95rem;
  white-space: pre-wrap;
}
.msg.bot { background: var(--bg); border: 1px solid var(--border); align-self: flex-start; }
.msg.user { background: var(--brand); color: #fff; align-self: flex-end; }
.msg a { color: inherit; font-weight: 800; }
.msg.bot a { color: var(--brand); }
.assistant-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
}
.assistant-form input {
  flex: 1;
  font: inherit;
  padding: 10px 12px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}
.assistant-form button {
  font: inherit;
  font-weight: 800;
  border: none;
  border-radius: 999px;
  padding: 0 16px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}
.suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 10px; }
.suggest button {
  font: inherit;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 22px 0 110px;
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
}

@media (max-width: 600px) {
  body { font-size: 16px; }
  .hero { padding-top: 32px; }
  .panel { padding: 18px; }
  .nav-links { gap: 10px; }
  .nav-links a { font-size: 0.85rem; }
}
