/* =========================================================
   Python 速成 · 工科版
   Design tokens
   ========================================================= */
:root {
  --paper: #f4f4ee;
  --surface: #fffefa;
  --surface-soft: #eeefe8;
  --surface-raised: #ffffff;
  --ink: #131c26;
  --ink-soft: #34434f;
  --muted: #60707c;
  --line: #dde0d8;
  --line-strong: #c8cec4;

  --blue: #1f5f8b;
  --blue-strong: #164a6e;
  --blue-tint: #e8f1f6;
  --amber: #e7b02b;
  --amber-tint: #fbf2d8;
  --green: #2c7a58;
  --green-tint: #e7f3ed;
  --red: #b8433a;
  --red-tint: #fbeae8;

  --code-bg: #0d1726;
  --code-panel: #122136;
  --code-line: #22344c;
  --code-text: #dbe7f3;

  --shadow-sm: 0 1px 2px rgba(19, 28, 38, 0.05);
  --shadow: 0 1px 2px rgba(19, 28, 38, 0.04), 0 16px 40px rgba(19, 28, 38, 0.07);
  --radius: 14px;
  --radius-sm: 9px;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", "SF Mono", ui-monospace, Menlo, Consolas,
    "Liberation Mono", monospace;

  --sidebar-w: 286px;
}

html[data-theme="dark"] {
  --paper: #0a1119;
  --surface: #101a26;
  --surface-soft: #16222f;
  --surface-raised: #14202d;
  --ink: #e9eff6;
  --ink-soft: #c5d0db;
  --muted: #93a3b2;
  --line: #22303e;
  --line-strong: #34485c;

  --blue: #72b6e2;
  --blue-strong: #9bcfee;
  --blue-tint: #142a3b;
  --amber: #f0c14b;
  --amber-tint: #312817;
  --green: #68c39b;
  --green-tint: #132c24;
  --red: #ef9186;
  --red-tint: #331b1a;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 18px 46px rgba(0, 0, 0, 0.36);
}

/* =========================================================
   Base
   ========================================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.78;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.18;
  -webkit-mask-image: radial-gradient(ellipse at 75% -10%, #000 0%, transparent 62%);
  mask-image: radial-gradient(ellipse at 75% -10%, #000 0%, transparent 62%);
}

html[data-theme="dark"] body::before {
  opacity: 0.22;
}

::selection {
  background: var(--amber);
  color: #1a1a1a;
}

h1,
h2,
h3,
h4 {
  line-height: 1.22;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-weight: 700;
}

p {
  margin: 0 0 1.05em;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

code,
kbd,
pre,
samp {
  font-family: var(--mono);
}

:not(pre) > code {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.08em 0.38em;
  font-size: 0.87em;
  color: var(--ink-soft);
  white-space: normal;
  overflow-wrap: anywhere;
}

html[data-theme="dark"] :not(pre) > code {
  color: var(--ink);
}

strong {
  font-weight: 650;
}

button {
  font-family: inherit;
  font-size: inherit;
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: -100px;
  left: 16px;
  z-index: 200;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

/* =========================================================
   Reading progress + layout
   ========================================================= */
.reading-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  z-index: 120;
  background: transparent;
}

.reading-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--blue), var(--amber));
  transition: width 0.1s linear;
}

.layout {
  position: relative;
  z-index: 1;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-right: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  z-index: 80;
}

.sidebar-head {
  padding: 26px 22px 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: linear-gradient(150deg, var(--blue) 0%, var(--blue-strong) 100%);
  color: #fff;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.06em;
  box-shadow: 0 6px 16px rgba(31, 95, 139, 0.28);
}

.brand-mark::after {
  content: "";
  position: absolute;
  right: -3px;
  top: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--amber);
  border: 2px solid var(--surface);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.35;
  min-width: 0;
}

.brand-text strong {
  font-size: 15px;
  letter-spacing: 0.01em;
}

.brand-text small {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.theme-toggle {
  position: absolute;
  top: 26px;
  right: 18px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.15s;
}

.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

html[data-theme="light"] .theme-toggle .icon-sun,
html[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

.sidebar-label {
  padding: 18px 24px 8px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 2px 12px 20px;
  scrollbar-width: thin;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.4;
  text-decoration: none;
  transition: background 0.14s, color 0.14s;
}

.nav a:hover {
  background: var(--surface-soft);
  color: var(--ink);
  text-decoration: none;
}

.nav a.active {
  background: var(--blue-tint);
  color: var(--blue-strong);
  font-weight: 600;
}

.nav-num {
  flex: 0 0 auto;
  width: 22px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.nav a.active .nav-num {
  color: var(--blue);
}

.nav-title {
  flex: 1;
  min-width: 0;
}

.nav-check {
  flex: 0 0 auto;
  font-size: 10px;
  color: var(--green);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.15s, transform 0.15s;
}

.nav a.done .nav-check {
  opacity: 1;
  transform: none;
}

.sidebar-foot {
  padding: 16px 18px 20px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, var(--paper));
}

.version-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 13px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--line);
  font-size: 10.5px;
  color: var(--muted);
}

.version-switch a {
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.version-switch a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.progress-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 7px;
}

.progress-top strong {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink);
  font-weight: 600;
}

.progress-track {
  height: 6px;
  border-radius: 99px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  overflow: hidden;
}

.progress-track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), #4f9c7b);
  transition: width 0.35s ease;
}

.sidebar-foot-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 11px;
}

.env-state {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 10.5px;
  color: var(--muted);
}

.env-dot {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background 0.2s, box-shadow 0.2s;
}

.env-state.ready .env-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 18%, transparent);
}

.env-state.loading .env-dot {
  background: var(--amber);
  animation: blink 1s ease-in-out infinite;
}

.link-btn {
  border: 0;
  padding: 0;
  background: none;
  color: var(--muted);
  font-size: 10.5px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-btn:hover {
  color: var(--red);
}

/* =========================================================
   Mobile bar
   ========================================================= */
.mobilebar {
  display: none;
  position: fixed;
  inset: 0 0 auto 0;
  height: 58px;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  z-index: 90;
}

.menu-btn,
.mobile-theme {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.menu-btn svg,
.mobile-theme svg {
  width: 18px;
  height: 18px;
}

.mobilebar-title {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobilebar-title span {
  display: block;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 15, 23, 0.45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 70;
}

/* =========================================================
   Main content
   ========================================================= */
.main {
  margin-left: var(--sidebar-w);
  min-width: 0;
}

.content {
  max-width: 920px;
  margin: 0 auto;
  padding: 48px 48px 120px;
}

.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(250px, 0.65fr);
  gap: 40px;
  align-items: center;
  padding: 34px 0 52px;
  border-bottom: 1px solid var(--line);
}

.hero-kicker {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 20px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--blue);
  text-transform: uppercase;
}

.hero-kicker::before {
  content: "";
  width: 24px;
  height: 1px;
  background: var(--blue);
}

.hero h1 {
  margin: 0 0 20px;
  font-size: clamp(2.35rem, 4.6vw, 3.65rem);
  line-height: 1.08;
  letter-spacing: -0.045em;
  font-weight: 750;
}

.hero h1 em {
  font-style: normal;
  color: var(--blue);
  position: relative;
  white-space: nowrap;
}

.hero h1 em::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.04em;
  height: 0.22em;
  background: var(--amber);
  opacity: 0.38;
  z-index: -1;
  border-radius: 2px;
}

.hero-sub {
  max-width: 56ch;
  margin: 0 0 24px;
  font-size: 16.5px;
  color: var(--muted);
  line-height: 1.75;
}

.hero-sub strong {
  color: var(--ink);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 0 0 26px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 5px 4px 9px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.chip::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--blue);
}

.chip.warm::before {
  background: var(--amber);
}

.chip.green::before {
  background: var(--green);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.4;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s, border-color 0.15s;
}

.btn:hover {
  text-decoration: none;
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--ink);
  color: var(--surface);
  box-shadow: 0 8px 20px rgba(19, 28, 38, 0.16);
}

html[data-theme="dark"] .btn-primary {
  background: var(--blue);
  color: #071018;
}

.btn-primary:hover {
  background: var(--blue-strong);
  color: #fff;
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn-ghost:hover {
  border-color: var(--ink);
}

.btn svg {
  width: 15px;
  height: 15px;
}

.hero-meta {
  margin-top: 18px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.hero-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  transform: rotate(0.6deg);
}

.hero-card-head {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.hero-card-head .dots {
  display: inline-flex;
  gap: 4px;
  margin-right: 3px;
}

.hero-card-head .dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-strong);
}

.hero-list {
  list-style: none;
  margin: 0;
  padding: 8px 14px;
}

.hero-list li {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 7px 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-soft);
  border-bottom: 1px dashed var(--line);
}

.hero-list li:last-child {
  border-bottom: 0;
}

.hero-list .num {
  font-size: 9px;
  color: var(--muted);
}

.hero-list .ok {
  margin-left: auto;
  color: var(--green);
  font-weight: 700;
}

.hero-card-foot {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--blue-tint);
  font-size: 10px;
  color: var(--blue-strong);
  font-weight: 600;
}

.pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 45%, transparent);
  animation: pulse 2.2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 40%, transparent);
  }
  70% {
    box-shadow: 0 0 0 7px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

@keyframes blink {
  50% {
    opacity: 0.25;
  }
}

/* ---------- how to use ---------- */
.howto {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 30px 0 8px;
}

.howto-card {
  padding: 16px 16px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.howto-step {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  color: var(--blue);
  text-transform: uppercase;
}

.howto-step b {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: var(--blue-tint);
  font-size: 10px;
  color: var(--blue-strong);
}

.howto-card strong {
  display: block;
  font-size: 14px;
  margin-bottom: 3px;
}

.howto-card p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--muted);
}

.env-note {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 24px 0 0;
  padding: 13px 16px;
  border: 1px solid color-mix(in srgb, var(--amber) 42%, var(--line));
  border-radius: 10px;
  background: var(--amber-tint);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--ink-soft);
}

.env-note svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  color: #a97c10;
}

html[data-theme="dark"] .env-note svg {
  color: var(--amber);
}

.env-note strong {
  color: var(--ink);
}

/* =========================================================
   Chapters & prose
   ========================================================= */
.chapter {
  padding-top: 30px;
  margin-top: 30px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 24px;
}

.chapter:first-of-type {
  border-top: 0;
}

.chapter-head {
  margin-bottom: 26px;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--blue);
}

.eyebrow::after {
  content: "";
  height: 1px;
  width: 34px;
  background: var(--line-strong);
}

.chapter h2 {
  margin: 0 0 12px;
  font-size: clamp(1.7rem, 2.8vw, 2.15rem);
  letter-spacing: -0.035em;
}

.chapter .lede {
  max-width: 68ch;
  margin: 0;
  font-size: 15.5px;
  color: var(--muted);
  line-height: 1.78;
}

.chapter h3 {
  position: relative;
  margin: 2.35em 0 0.7em;
  padding-left: 17px;
  font-size: 1.16rem;
  letter-spacing: -0.015em;
}

.chapter h3::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.42em;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--amber);
}

.chapter h4 {
  margin: 1.8em 0 0.5em;
  font-size: 1rem;
  color: var(--ink-soft);
}

.chapter p,
.chapter ul,
.chapter ol {
  max-width: 74ch;
}

.chapter ul,
.chapter ol {
  margin: 0 0 1.1em;
  padding-left: 1.35em;
}

.chapter li {
  margin: 0.28em 0;
}

.chapter li::marker {
  color: var(--blue);
}

.chapter strong {
  color: var(--ink);
}

.lead-in {
  font-size: 15.5px;
}

/* inline kbd */
kbd {
  display: inline-block;
  padding: 0.1em 0.42em;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  font-size: 0.78em;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* =========================================================
   Callouts
   ========================================================= */
.callout {
  position: relative;
  margin: 24px 0;
  padding: 15px 18px 15px 18px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--blue);
  border-radius: 0 10px 10px 0;
  background: var(--blue-tint);
  font-size: 14px;
  line-height: 1.72;
}

.callout p {
  margin: 0;
}

.callout p + p {
  margin-top: 0.65em;
}

.callout-label {
  display: block;
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue-strong);
}

.callout.warn {
  border-left-color: var(--amber);
  background: var(--amber-tint);
}

.callout.warn .callout-label {
  color: #9a6d06;
}

html[data-theme="dark"] .callout.warn .callout-label {
  color: var(--amber);
}

.callout.tip {
  border-left-color: var(--green);
  background: var(--green-tint);
}

.callout.tip .callout-label {
  color: var(--green);
}

.callout code {
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}

/* =========================================================
   Tables
   ========================================================= */
.table-wrap {
  margin: 24px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-x: auto;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  line-height: 1.6;
}

thead th {
  padding: 10px 14px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  color: var(--ink-soft);
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: color-mix(in srgb, var(--blue-tint) 45%, transparent);
}

tbody td:first-child {
  color: var(--ink);
  font-weight: 550;
}

td code,
th code {
  white-space: nowrap;
}

.caption {
  margin: -14px 0 24px;
  font-size: 11.5px;
  color: var(--muted);
  font-family: var(--mono);
}

/* =========================================================
   Code blocks
   ========================================================= */
.codeblock,
.runner {
  position: relative;
  margin: 22px 0;
  border: 1px solid #1c2b40;
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(6, 12, 21, 0.12);
}

.code-head,
.runner-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 37px;
  padding: 7px 12px;
  background: var(--code-panel);
  border-bottom: 1px solid var(--code-line);
  font-family: var(--mono);
  font-size: 10px;
  color: #8da2b8;
  user-select: none;
}

.dots {
  display: inline-flex;
  gap: 5px;
  margin-right: 4px;
}

.dots i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #33465c;
}

.dots i:nth-child(1) {
  background: #ff5f57;
}

.dots i:nth-child(2) {
  background: #febc2e;
}

.dots i:nth-child(3) {
  background: #28c840;
}

.filename {
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.code-tag {
  margin-left: auto;
  padding: 2px 7px;
  border: 1px solid var(--code-line);
  border-radius: 99px;
  font-size: 8.5px;
  letter-spacing: 0.1em;
  color: #7f95ab;
  text-transform: uppercase;
}

.copy-btn,
.run-btn {
  margin-left: auto;
  border: 1px solid var(--code-line);
  border-radius: 6px;
  background: #16263b;
  color: #a9bed2;
  font-family: var(--mono);
  font-size: 10px;
  padding: 4px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.copy-btn:hover {
  background: #1c304a;
  color: #e3edf7;
}

.copy-btn.copied {
  color: #8ce0b0;
  border-color: #2f6f55;
}

.codeblock pre {
  margin: 0;
  padding: 16px 18px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.codeblock code {
  display: block;
  font-size: 13px;
  line-height: 1.68;
  color: var(--code-text);
  tab-size: 4;
  white-space: pre;
}

/* token colors */
.tok-kw {
  color: #c9a0f0;
}

.tok-str {
  color: #a8d98b;
}

.tok-num {
  color: #f2c177;
}

.tok-com {
  color: #6d8299;
  font-style: italic;
}

.tok-bi {
  color: #7cc4fa;
}

.tok-dec {
  color: #f0a6ca;
}

.tok-op {
  color: #9fb3c8;
}

/* =========================================================
   Runnable example
   ========================================================= */
.runner-head {
  min-height: 41px;
}

.runner-head .filename {
  color: #9db2c8;
}

.run-hint {
  margin-left: auto;
  font-size: 9px;
  color: #637a91;
  letter-spacing: 0.02em;
}

.run-btn {
  margin-left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 13px;
  border: 1px solid #d6a01c;
  background: var(--amber);
  color: #241a02;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset;
}

.run-btn:hover {
  background: #f3c64e;
}

.run-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.run-btn.running::before {
  content: "";
  width: 9px;
  height: 9px;
  border: 2px solid rgba(36, 26, 2, 0.3);
  border-top-color: #241a02;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.run-btn.running .run-icon {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.runner textarea {
  display: block;
  width: 100%;
  min-height: 140px;
  padding: 16px 18px;
  border: 0;
  outline: 0;
  resize: none;
  overflow: hidden;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.68;
  tab-size: 4;
  caret-color: var(--amber);
  white-space: pre;
}

.runner textarea::selection {
  background: rgba(231, 176, 43, 0.28);
}

.runner-output {
  display: none;
  border-top: 1px dashed var(--code-line);
  background: #0a1421;
  padding: 13px 18px 15px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  color: #b9cadc;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 340px;
  overflow-y: auto;
}

.runner-output.visible {
  display: block;
}

.runner-output::before {
  content: "OUTPUT";
  display: block;
  margin-bottom: 5px;
  font-size: 8px;
  letter-spacing: 0.16em;
  color: #5e7692;
}

.runner-output.is-error {
  color: #ffb4a8;
  background: #170f14;
}

.runner-output.is-error::before {
  content: "ERROR";
  color: #d97b70;
}

.runner-output.is-status {
  color: #8da2b8;
}

.runner-output.is-status::before {
  content: "PYTHON";
}

.runner-output .out-prompt {
  color: #5e7692;
}

.runner-plot {
  display: none;
  margin: 0;
  padding: 14px 18px 16px;
  border-top: 1px dashed var(--code-line);
  background: #0a1421;
  text-align: center;
}

.runner-plot.visible {
  display: block;
}

.runner-plot img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 6px;
  background: #fff;
}

.runner-plot figcaption {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: #5e7692;
  text-transform: uppercase;
}

/* =========================================================
   Quiz
   ========================================================= */
.quiz {
  margin: 26px 0;
  padding: 18px 20px 19px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.quiz-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
}

.quiz-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--amber-tint);
  border: 1px solid color-mix(in srgb, var(--amber) 38%, var(--line));
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.11em;
  color: #9a6d06;
  text-transform: uppercase;
}

html[data-theme="dark"] .quiz-tag {
  color: var(--amber);
}

.quiz-q {
  margin: 0 0 12px;
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--ink);
}

.quiz-options {
  display: grid;
  gap: 7px;
}

.quiz-opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-soft);
  text-align: left;
  font-size: 13.5px;
  line-height: 1.55;
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s, transform 0.14s;
}

.quiz-opt:hover:not(:disabled) {
  border-color: var(--blue);
  background: var(--blue-tint);
  transform: translateX(2px);
}

.quiz-opt .opt-key {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 21px;
  height: 21px;
  border-radius: 5px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  margin-top: 1px;
}

.quiz-opt code {
  font-size: 12.5px;
}

.quiz-opt.correct {
  border-color: var(--green);
  background: var(--green-tint);
  color: var(--ink);
}

.quiz-opt.correct .opt-key {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.quiz-opt.wrong {
  border-color: var(--red);
  background: var(--red-tint);
  color: var(--ink);
  animation: shake 0.3s ease;
}

.quiz-opt.wrong .opt-key {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.quiz-opt:disabled {
  cursor: default;
}

@keyframes shake {
  25% {
    transform: translateX(-3px);
  }
  50% {
    transform: translateX(3px);
  }
  75% {
    transform: translateX(-2px);
  }
}

.quiz-feedback {
  margin-top: 11px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.68;
  background: var(--blue-tint);
  color: var(--ink-soft);
  border-left: 2px solid var(--blue);
}

.quiz-feedback:empty {
  display: none;
}

.quiz-feedback.wrong {
  border-left-color: var(--amber);
  background: var(--amber-tint);
}

.quiz-feedback.correct {
  border-left-color: var(--green);
  background: var(--green-tint);
}

.quiz-feedback strong {
  color: var(--ink);
}

.quiz-explain[hidden] {
  display: none;
}

/* =========================================================
   Split code, exercise, chapter foot
   ========================================================= */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 22px 0;
}

.split .codeblock {
  margin: 0;
}

.split .codeblock code {
  font-size: 12px;
}

.exercise {
  margin: 18px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.exercise summary {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 17px;
  cursor: pointer;
  list-style: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  user-select: none;
}

.exercise summary::-webkit-details-marker {
  display: none;
}

.exercise summary::after {
  content: "+";
  margin-left: auto;
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 400;
  color: var(--muted);
  transition: transform 0.2s;
}

.exercise[open] summary {
  border-bottom: 1px solid var(--line);
}

.exercise[open] summary::after {
  content: "−";
}

.exercise summary:hover {
  background: var(--surface-soft);
}

.ex-number {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--blue-tint);
  color: var(--blue-strong);
  font-family: var(--mono);
  font-size: 10px;
}

.exercise-body {
  padding: 15px 18px 18px;
  font-size: 14px;
}

.exercise-body p:last-child {
  margin-bottom: 0;
}

.exercise-body .codeblock {
  margin-bottom: 0;
}

.chapter-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-top: 34px;
  padding-top: 18px;
  border-top: 1px dashed var(--line);
  font-size: 12px;
  color: var(--muted);
}

.complete-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.complete-btn:hover {
  border-color: var(--green);
  color: var(--green);
}

.complete-btn.done {
  border-color: var(--green);
  background: var(--green-tint);
  color: var(--green);
}

.complete-btn svg {
  width: 13px;
  height: 13px;
  opacity: 0.55;
}

.complete-btn.done svg {
  opacity: 1;
}

/* =========================================================
   Cheat sheet & misc
   ========================================================= */
.sheet {
  margin: 22px 0;
}

.sheet h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 24px 0 8px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.sheet h4::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.pitfalls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 22px 0;
  padding: 0;
  list-style: none;
}

.pitfalls li {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  font-size: 12.5px;
  line-height: 1.62;
  color: var(--ink-soft);
}

.pitfalls li strong {
  display: block;
  margin-bottom: 2px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.04em;
  color: var(--red);
}

.checklist {
  margin: 22px 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.checklist li {
  position: relative;
  margin: 0;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  font-size: 13.5px;
}

.checklist li::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 50%;
  width: 13px;
  height: 7px;
  border-left: 2px solid var(--green);
  border-bottom: 2px solid var(--green);
  transform: translateY(-60%) rotate(-45deg);
}

.next-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 24px 0;
}

.next-card {
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.next-card .k {
  display: block;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--blue);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.next-card strong {
  display: block;
  font-size: 13.5px;
  margin-bottom: 3px;
}

.next-card span {
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

/* =========================================================
   Footer + back to top + toast
   ========================================================= */
.footer {
  margin-top: 48px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.footer-top {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.footer strong {
  color: var(--ink);
}

.footer a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer a:hover {
  color: var(--blue);
}

.footer-note {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.03em;
}

.back-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-soft);
  box-shadow: var(--shadow);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.back-top.visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.back-top:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.back-top svg {
  width: 16px;
  height: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 150;
  transform: translate(-50%, 16px);
  padding: 9px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
}

html[data-theme="dark"] .toast {
  background: var(--surface-raised);
  color: var(--ink);
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1120px) {
  .content {
    padding-left: 38px;
    padding-right: 38px;
  }

  .hero {
    gap: 28px;
  }
}

@media (max-width: 980px) {
  .sidebar {
    transform: translateX(-102%);
    transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.22);
    width: 292px;
  }

  body.nav-open .sidebar {
    transform: none;
  }

  body.nav-open .sidebar-backdrop {
    display: block;
  }

  body.nav-open {
    overflow: hidden;
  }

  .mobilebar {
    display: flex;
  }

  .main {
    margin-left: 0;
    padding-top: 58px;
  }

  .content {
    padding: 28px 24px 100px;
  }

  .chapter {
    scroll-margin-top: 74px;
  }

  .hero {
    grid-template-columns: 1fr;
    padding-top: 14px;
    gap: 24px;
  }

  .hero-card {
    transform: none;
    max-width: 420px;
  }

  .hero h1 {
    font-size: clamp(2.2rem, 8vw, 3.1rem);
  }

  .howto {
    grid-template-columns: 1fr;
  }

  .howto-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0 12px;
    align-items: baseline;
  }

  .howto-step {
    grid-row: span 2;
    margin: 0;
  }

  .howto-card p {
    grid-column: 2;
  }

  .next-steps {
    grid-template-columns: 1fr;
  }

  .back-top {
    right: 16px;
    bottom: 16px;
  }
}

@media (max-width: 720px) {
  .content {
    padding: 22px 17px 92px;
  }

  .chapter h2 {
    font-size: 1.62rem;
  }

  .split {
    grid-template-columns: 1fr;
  }

  .pitfalls {
    grid-template-columns: 1fr;
  }

  .hero-card {
    display: none;
  }

  .hero {
    padding-bottom: 34px;
  }

  .hero-sub {
    font-size: 15px;
  }

  .run-hint {
    display: none;
  }

  .quiz {
    padding: 15px 15px 16px;
  }

  .chapter-foot {
    flex-direction: column;
    align-items: flex-start;
  }

  .complete-btn {
    width: 100%;
    justify-content: center;
  }

  .table-wrap {
    border-radius: 9px;
  }

  thead th,
  tbody td {
    padding: 8px 10px;
  }

  .callout {
    padding: 13px 14px;
  }

  .runner textarea {
    font-size: 12.5px;
    padding: 14px;
  }

  .codeblock code {
    font-size: 12px;
  }

  .toast {
    max-width: calc(100vw - 32px);
    white-space: normal;
    text-align: center;
    border-radius: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* =========================================================
   Print
   ========================================================= */
@media print {
  body::before,
  .sidebar,
  .mobilebar,
  .reading-progress,
  .back-top,
  .toast,
  .hero-card,
  .run-btn,
  .copy-btn {
    display: none !important;
  }

  .main {
    margin-left: 0;
    padding-top: 0;
  }

  .content {
    max-width: none;
    padding: 0;
  }

  .chapter {
    break-before: page;
  }

  .codeblock,
  .quiz,
  .runner {
    break-inside: avoid;
  }

  .runner-output,
  .runner-plot {
    display: block;
  }

  body {
    background: #fff;
    font-size: 11pt;
  }

  a {
    color: inherit;
  }
}
