:root {
  --accent: #6b5fa8;      /* SNES-case lavender, used sparingly */
  --accent-dark: #4a4079;
  --ink: #24262b;
  --muted: #5a5f6b;
  --bg: #fdfcfb;
  --code-bg: #282c34;
  --code-ink: #e6e6e6;
  --border: #e4e2df;
  --table-stripe: #f5f4f2;
}

/* --accent stays the same in dark mode -- it's mostly used as a background
   under white text (th, .hero, badges), which doesn't need to change.
   --accent-dark is used as readable text/links on the page background, so
   it needs to get lighter, not stay dark. */
:root[data-theme="dark"] {
  --accent-dark: #b9adf0;
  --ink: #e7e6ea;
  --muted: #9a9ba6;
  --bg: #17181c;
  --border: #34363c;
  --table-stripe: #232429;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.65;
}

.page {
  max-width: 840px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
  margin-bottom: 2rem;
}

.top-nav a {
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 600;
}

.top-nav a:hover { text-decoration: underline; }

.top-nav-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.top-nav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.top-nav a.lang-link {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-weight: 600;
}

.top-nav a.lang-link:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, white);
}

/* pandoc's standalone template repeats the --metadata title as a visible
   header above the content; the markdown's own H1 already covers that. */
#title-block-header { display: none; }

h1, h2, h3, h4 {
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  line-height: 1.3;
}

h1 {
  font-size: 1.9rem;
  border-bottom: 3px solid var(--accent);
  padding-bottom: 0.5rem;
  margin-top: 0;
}

h2 {
  font-size: 1.35rem;
  margin-top: 2.5rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}

h3 {
  font-size: 1.1rem;
  margin-top: 1.75rem;
  color: var(--accent-dark);
}

p, li { color: var(--ink); }

a { color: var(--accent-dark); }
a:hover { color: var(--accent); }

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

code {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 0.87em;
  background: var(--table-stripe);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

pre {
  position: relative;
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 1rem 1.1rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.55;
  border-left: 4px solid var(--accent);
}

pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: 1em;
}

.copy-code-btn {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--code-ink);
  opacity: 0.45;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.copy-code-btn:hover,
.copy-code-btn:focus-visible {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.copy-code-btn svg {
  width: 1.05rem;
  height: 1.05rem;
}

.copy-code-btn .copy-icon-check {
  display: none;
}

.copy-code-btn.copied {
  opacity: 1;
  color: #4caf7d;
}

.copy-code-btn.copied .copy-icon-copy {
  display: none;
}

.copy-code-btn.copied .copy-icon-check {
  display: block;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
}

th {
  background: var(--accent);
  color: white;
}

tr:nth-child(even) td { background: var(--table-stripe); }

blockquote {
  border-left: 4px solid var(--accent);
  margin: 1rem 0;
  padding: 0.25rem 1rem;
  color: var(--muted);
  background: var(--table-stripe);
}

figure.diagram {
  margin: 1.5rem 0;
  text-align: center;
}

figure.diagram img {
  max-width: 100%;
  height: auto;
}

figure.diagram figcaption {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}

ul, ol { padding-left: 1.4rem; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0 1.5rem;
}

.bottom-nav {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

@media (max-width: 600px) {
  .page { padding: 1.5rem 1rem 3rem; }
  h1 { font-size: 1.5rem; }
}

/* ============================================================
   Homepage (index.html) only
   ============================================================ */

.site-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
}

.site-nav .brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.05rem;
}

.site-nav .brand span {
  color: var(--accent);
}

.site-nav .links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  margin-left: 1.5rem;
  font-weight: 600;
}

.site-nav .links a:hover { color: var(--accent-dark); }

.site-nav .links a.lang-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  color: var(--accent-dark);
}

.site-nav .links a.lang-pill:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, white);
}

.hero {
  background: linear-gradient(135deg, var(--accent-dark) 0%, var(--accent) 100%);
  color: #fff;
  padding: 3.5rem 1.5rem 3rem;
}

.hero-inner {
  max-width: 1000px;
  margin: 0 auto;
}

.hero-eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  font-weight: 700;
  color: rgba(255,255,255,0.75);
  margin-bottom: 0.75rem;
}

.hero h1 {
  border: none;
  color: #fff;
  font-size: 2.4rem;
  margin: 0 0 0.75rem;
  padding: 0;
  max-width: 25ch;
}

.hero p.lede {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.9);
  max-width: 58ch;
  margin: 0 0 1.75rem;
}

.hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 2rem;
}

.badge {
  display: inline-block;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

.intro-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-bottom: 3rem;
}

.intro-grid h3 {
  margin-top: 0;
  color: var(--accent-dark);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.intro-grid p { color: var(--muted); font-size: 0.95rem; }

.part-heading {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin: 3rem 0 1.25rem;
}

.part-heading h2 {
  border: none;
  margin: 0;
  padding: 0;
  font-size: 1.3rem;
}

.part-heading .part-label {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: #ece9f5;
  background: color-mix(in srgb, var(--accent) 12%, white);
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
}

.lesson-grid {
  display: grid;
  gap: 1rem;
}

.lesson-card {
  display: flex;
  gap: 1.1rem;
  align-items: flex-start;
  padding: 1.1rem 1.3rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

a.lesson-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(74, 64, 121, 0.12);
}

.lesson-card.disabled {
  opacity: 0.6;
  cursor: default;
}

.lesson-num {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 8px;
  background: var(--table-stripe);
  color: var(--accent-dark);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.lesson-card.available .lesson-num {
  background: var(--accent);
  color: #fff;
}

.lesson-body { flex: 1; }

.lesson-title {
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.2rem;
  font-size: 1rem;
}

.lesson-desc {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.resources-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem 2rem;
}

.resources-list a {
  font-weight: 600;
}

.resources-list span {
  color: var(--muted);
  font-size: 0.88rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 700px) {
  .intro-grid { grid-template-columns: 1fr; }
  .resources-list { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.9rem; }
}

.exercise-answer {
  display: inline;
}

.exercise-answer > summary {
  display: inline;
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 600;
  list-style: none;
  margin-left: 0.35em;
  white-space: nowrap;
}

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

.exercise-answer > summary:hover {
  text-decoration: underline;
}

.exercise-answer .hide-label {
  display: none;
}

.exercise-answer[open] > summary .show-label {
  display: none;
}

.exercise-answer[open] > summary .hide-label {
  display: inline;
}

.exercise-answer .answer-body {
  margin-top: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--table-stripe);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}

.exercise-answer .answer-body > :first-child {
  margin-top: 0;
}

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

/* Overrides pandoc's per-page embedded <style> (String: #bf0303) at equal
   specificity -- this file loads after that block in every page's <head>,
   so it wins on source order. Applies in both light and dark mode. */
code span.st {
  color: darkturquoise;
}

/* ============================================================
   Dark mode: theme toggle button + the few spots that hardcode
   a light-mode color instead of using a variable.
   ============================================================ */

.theme-toggle {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  background: transparent;
  color: var(--accent-dark);
}

/* .top-nav-right spaces its children via flex gap, but .site-nav .links
   only puts margin-left on <a> tags -- the button needs it spelled out. */
.site-nav .links .theme-toggle {
  margin-left: 1.5rem;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.theme-toggle .to-light {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .to-dark {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .to-light {
  display: inline;
}

:root[data-theme="dark"] .top-nav a.lang-link:hover,
:root[data-theme="dark"] .site-nav .links a.lang-pill:hover {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}

:root[data-theme="dark"] .lesson-card {
  background: #1d1e23;
}

:root[data-theme="dark"] .part-heading .part-label {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

/* The syntax-highlighted lesson code blocks (div.sourceCode) get their
   colors from a per-page pandoc-generated <style> block hardcoded for a
   light background. These overrides mirror the same per-token color
   scheme (comment grey, builtin/function purple, string turquoise, etc.)
   at higher specificity, so they win without editing pandoc's output --
   only for the token classes actually used in this tutorial's code. */
:root[data-theme="dark"] div.sourceCode {
  background-color: var(--code-bg);
}

:root[data-theme="dark"] code span {
  color: var(--code-ink);
}

:root[data-theme="dark"] code span.co { color: #8b91a3; }    /* Comment */
:root[data-theme="dark"] code span.bn { color: #e0a64c; }    /* BaseN (hex/binary literals) */
:root[data-theme="dark"] code span.dv { color: #e0a64c; }    /* DecVal */
:root[data-theme="dark"] code span.dt { color: #6fb3ff; }    /* DataType */
:root[data-theme="dark"] code span.bu { color: var(--accent-dark); }  /* BuiltIn (instructions) */
:root[data-theme="dark"] code span.fu { color: var(--accent-dark); }  /* Function (labels) */
:root[data-theme="dark"] code span.st { color: darkturquoise; }  /* String -- needs restating here: the
   catch-all "code span" rule above is (0,1,3) specificity, which already beats the plain
   "code span.st" rule's (0,1,2), so without this it falls back to --code-ink instead of turquoise. */
:root[data-theme="dark"] code span.ex { color: #4fc3f7; }    /* Extension */
:root[data-theme="dark"] code span.pp { color: #6bcf8f; }    /* Preprocessor */
