:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #475569;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --tip-bg: #ecfdf5;
  --tip-border: #10b981;
  --warn-bg: #fffbeb;
  --warn-border: #f59e0b;
}

html.dark {
  --bg: #020617;
  --panel: #0f172a;
  --border: #1e293b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #818cf8;
  --accent-soft: #1e1b4b;
  --code-bg: #020617;
  --code-text: #e2e8f0;
  --tip-bg: #022c22;
  --tip-border: #10b981;
  --warn-bg: #3b2a05;
  --warn-border: #f59e0b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

a { color: var(--accent); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.crumbs { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; flex-wrap: wrap; }
.crumbs a { text-decoration: none; font-weight: 600; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { color: var(--muted); }
.crumbs .here { color: var(--muted); font-weight: 600; }

.btn-small {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.btn-small:hover { background: var(--accent-soft); }

.bar-actions { display: flex; gap: 0.5rem; align-items: center; }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 3rem;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
}

h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.15; margin: 0 0 0.75rem; letter-spacing: -0.02em; }
h2 { font-size: 1.4rem; margin: 2.5rem 0 0.75rem; letter-spacing: -0.01em; }
h3 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }
p { margin: 0.75rem 0; }
.lead { font-size: 1.1rem; color: var(--muted); }

ul, ol { padding-left: 1.4rem; }
li { margin: 0.3rem 0; }

code {
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 0.88em;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.1em 0.4em;
  border-radius: 4px;
}

pre {
  position: relative;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1rem 0;
  line-height: 1.5;
}
pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: 0.85rem;
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font: inherit;
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #cbd5e1;
  cursor: pointer;
}
.copy-btn:hover { background: #334155; }

.callout {
  border-left: 4px solid var(--tip-border);
  background: var(--tip-bg);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin: 1.25rem 0;
}
.callout.warn { border-left-color: var(--warn-border); background: var(--warn-bg); }
.callout strong:first-child { display: block; margin-bottom: 0.15rem; }

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.92rem;
  background: var(--panel);
  border-radius: 10px;
  overflow: hidden;
}
th, td { text-align: left; padding: 0.55rem 0.8rem; border: 1px solid var(--border); vertical-align: top; }
th { background: var(--accent-soft); }

.exercise {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
}
.exercise h3 { margin-top: 0; }

.diagram {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin: 1rem 0;
  overflow-x: auto;
}
.diagram svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  flex-wrap: wrap;
}
.pager a {
  flex: 1 1 220px;
  display: block;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
}
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--muted); font-weight: 500; font-size: 0.75rem; }
.pager .next { text-align: right; }

footer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 0.8rem;
  padding: 1.5rem;
  text-align: center;
}
footer a { color: inherit; }

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.module-card {
  display: block;
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.2s, transform 0.2s;
}
.module-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.module-card .num { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.module-card h3 { margin: 0.2rem 0 0.4rem; font-size: 1.05rem; }
.module-card p { margin: 0; font-size: 0.82rem; color: var(--muted); }
