:root {
  --bg: #0f1115;
  --bg-elev: #151821;
  --bg-elev-2: #1c2030;
  --border: #262b3a;
  --text: #e6e8ef;
  --text-dim: #9aa3b8;
  --accent: #7c9eff;
  --accent-2: #a78bfa;
  --accent-glow: rgba(124, 158, 255, 0.18);
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --code-bg: #0b0d13;
  --challenge: #f59e0b;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  --radius: 14px;
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", Consolas, Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

/* ===== Background glow ===== */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 800px 500px at 10% -10%, var(--accent-glow), transparent 60%),
    radial-gradient(ellipse 600px 400px at 90% 110%, rgba(167, 139, 250, 0.1), transparent 60%);
  pointer-events: none;
  z-index: -1;
}

/* ===== Navigation ===== */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  background: color-mix(in oklab, var(--bg) 70%, transparent);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-decoration: none;
}
.nav-links {
  display: flex;
  gap: 6px;
  margin-left: auto;
  align-items: center;
}
.nav-links a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
}
.nav-links a:hover { color: var(--text); background: var(--bg-elev); }
.nav-links a.active { color: var(--accent); background: var(--accent-glow); }

.icon-btn {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  position: relative;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Admin panel dropdown */
.admin-wrap { position: relative; }
.admin-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 260px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: none;
  z-index: 100;
}
.admin-panel.open { display: block; }
.admin-panel h4 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
}
.admin-panel label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.admin-panel small {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 8px;
  line-height: 1.5;
}

/* Hide solutions when admin disables them */
body.hide-solutions .sol-toggle,
body.hide-solutions .solution { display: none !important; }

/* ===== Layout ===== */
main {
  max-width: 820px;
  margin: 0 auto;
  padding: 60px 24px 120px;
}
main.wide { max-width: 1100px; }

/* ===== Hero (landing page) ===== */
.hero {
  text-align: center;
  padding: 80px 20px 40px;
}
.hero h1 {
  font-size: clamp(38px, 6vw, 64px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin: 0 0 20px;
  background: linear-gradient(135deg, var(--text) 30%, var(--accent) 70%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p {
  font-size: 19px;
  color: var(--text-dim);
  max-width: 580px;
  margin: 0 auto;
}
.chapters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin: 80px auto 0;
  max-width: 980px;
}
.chapter-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  display: block;
  position: relative;
  overflow: hidden;
}
.chapter-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent-glow), transparent 60%);
  opacity: 0;
  transition: opacity 0.25s;
}
.chapter-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.chapter-card:hover::before { opacity: 1; }
.chapter-card > * { position: relative; }
.chapter-num {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.08em;
}
.chapter-card h2 {
  font-size: 22px;
  margin: 8px 0 10px;
  letter-spacing: -0.01em;
}
.chapter-card p {
  color: var(--text-dim);
  font-size: 14px;
  margin: 0;
}

/* ===== Chapter header ===== */
.chapter-header {
  margin-bottom: 40px;
  padding-bottom: 30px;
  border-bottom: 1px solid var(--border);
}
.chapter-header .eyebrow {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.chapter-header h1 {
  font-size: clamp(34px, 5vw, 48px);
  letter-spacing: -0.025em;
  margin: 10px 0 16px;
  line-height: 1.1;
}
.chapter-header p { color: var(--text-dim); font-size: 17px; margin: 0; }

/* ===== Content typography ===== */
main h2 {
  font-size: 26px;
  letter-spacing: -0.015em;
  margin: 60px 0 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
main h2:first-of-type { border-top: none; padding-top: 0; }
main p { margin: 16px 0; }
main a { color: var(--accent); }
main strong { color: var(--text); }

/* Inline code */
code {
  font-family: var(--mono);
  font-size: 0.92em;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--bg-elev-2);
  color: var(--accent);
  border: 1px solid var(--border);
}

/* Block code */
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.6;
  position: relative;
}
pre code {
  background: none;
  border: none;
  padding: 0;
  color: #e6e8ef;
  font-size: inherit;
}
pre .lang {
  position: absolute;
  top: 10px;
  right: 14px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Syntax tokens */
.tok-kw { color: #c084fc; }
.tok-def { color: #7dd3fc; }
.tok-str { color: #86efac; }
.tok-num { color: #fbbf24; }
.tok-com { color: #64748b; font-style: italic; }
.tok-fn  { color: #60a5fa; }
.tok-op  { color: #e6e8ef; }

/* ===== Exercise card ===== */
.exercise {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 28px 30px;
  margin: 28px 0;
  box-shadow: var(--shadow);
}
.exercise.challenge {
  border-left-color: var(--challenge);
}
.exercise-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.badge {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 20px;
  background: var(--accent-glow);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.badge.challenge {
  background: rgba(245, 158, 11, 0.15);
  color: var(--challenge);
}
.exercise h3 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.01em;
  flex: 1;
}

.exercise-body > *:first-child { margin-top: 0; }
.exercise-body > *:last-child { margin-bottom: 0; }
.exercise img {
  max-width: 100%;
  border-radius: 10px;
  margin: 10px 0;
}
.exercise img.float-right {
  float: right;
  padding-left: 16px;
  margin: 0 0 10px 10px;
}

/* ===== Pick list (interactive checkboxes) ===== */
.pick-list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  display: grid;
  gap: 8px;
}
.pick-list li { margin: 0; }
.pick-list label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.pick-list label:hover { border-color: var(--accent); }
.pick-list input[type="checkbox"] { flex-shrink: 0; }
.pick-list input.correct + code,
.pick-list input.incorrect + code { font-weight: 600; }
.pick-list label:has(input.correct) {
  border-color: var(--success);
  background: rgba(52, 211, 153, 0.08);
}
.pick-list label:has(input.incorrect) {
  border-color: var(--danger);
  background: rgba(248, 113, 113, 0.08);
}

/* ===== Tables ===== */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 15px;
}
th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  font-weight: 600;
  color: var(--text-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
td input[type="number"],
td input[type="text"] { width: 100%; max-width: 160px; }

/* ===== Form inputs ===== */
input[type="number"],
input[type="text"] {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 11px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 14px;
  width: 110px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="number"]:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input[type="text"].wide { width: 100%; max-width: 100%; }
input[type="radio"],
input[type="checkbox"] {
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
  vertical-align: middle;
}
input.correct {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
}
input.incorrect {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18);
}

/* ===== Buttons ===== */
button.check,
button.sol-toggle {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 18px;
  border-radius: 9px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  margin-top: 14px;
  margin-right: 10px;
}
button.check:hover,
button.sol-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
button.check {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border: none;
}
button.check:hover {
  filter: brightness(1.1);
  color: white;
  transform: translateY(-1px);
}

.check-feedback {
  display: inline-block;
  margin-left: 10px;
  font-size: 14px;
  font-weight: 600;
}
.check-feedback.ok { color: var(--success); }
.check-feedback.bad { color: var(--danger); }

/* ===== WebTigerPython embed ===== */
.wtp-wrap { margin: 14px 0 4px; }
.wtp-open {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 9px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.12s, filter 0.12s, box-shadow 0.12s;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.25);
}
.wtp-open:hover { filter: brightness(1.08); transform: translateY(-1px); }
.wtp-open .wtp-icon { font-size: 11px; }
.wtp-frame {
  display: none;
  margin-top: 14px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--code-bg);
}
.wtp-wrap.open .wtp-frame { display: block; }
.wtp-frame iframe {
  width: 100%;
  height: 620px;
  border: 0;
  display: block;
}

/* ===== Solution ===== */
.solution {
  display: none;
  margin-top: 18px;
  padding: 18px 22px;
  background: rgba(52, 211, 153, 0.06);
  border: 1px solid rgba(52, 211, 153, 0.25);
  border-radius: 10px;
}
.solution.open { display: block; }
.solution-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--success);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.solution > *:last-child { margin-bottom: 0; }

/* ===== Info / tip blocks ===== */
.tip, .info, .warn {
  padding: 14px 18px;
  border-radius: 10px;
  margin: 20px 0;
  border-left: 3px solid var(--accent);
  background: var(--bg-elev-2);
  font-size: 15px;
}
.tip::before { content: "💡 "; }
.warn { border-left-color: var(--warning); }
.warn::before { content: "⚠️ "; }

/* ===== Footer ===== */
footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

/* ===== Chapter pager ===== */
.pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 80px;
  padding-top: 30px;
  border-top: 1px solid var(--border);
}
.pager a {
  flex: 1;
  padding: 16px 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: all 0.2s;
}
.pager a:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.pager .dir { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.pager .title { font-weight: 600; margin-top: 4px; }
.pager a.next { text-align: right; }
.pager .disabled { visibility: hidden; }

@media (max-width: 640px) {
  main { padding: 30px 16px 80px; }
  .exercise { padding: 22px 20px; }
  .hero { padding: 40px 16px 20px; }
  td input[type="number"], td input[type="text"] { max-width: 100%; }
}
