:root {
  --ink: #1c1917;
  --ink-soft: #44403c;
  --muted: #78716c;
  --paper: #f3f6f8;
  --paper-2: #e6edf2;
  --white: #fffcf7;
  --line: #cfd9e3;
  --teal: #1e4a6e;
  --teal-2: #2b6a94;
  --teal-soft: #e4eef5;
  --orange: #c45c26;
  --orange-soft: #f8e6d9;
  --gold: #b08900;
  --gold-soft: #f8efd0;
  --red: #9b2c2c;
  --red-soft: #fde8e8;
  --green: #276749;
  --green-soft: #e6f4ea;
  --code-bg: #1a2332;
  --code-fg: #e8eef6;
  --shadow: 0 10px 30px rgba(28, 25, 23, 0.08);
  --radius: 14px;
  --font: "Segoe UI", "Calibri", system-ui, sans-serif;
  --mono: Consolas, "Cascadia Code", "Courier New", monospace;
  --sidebar: 280px;
  --header: 64px;
  --header-shadow: 0 2px 12px rgba(30, 74, 110, 0.25);
  --hero-end: #122a3d;
}

body.theme-k2 {
  --teal: #1e4a6e;
  --teal-2: #2b6a94;
  --teal-soft: #e4eef5;
  --orange: #c45c26;
  --orange-soft: #f8e6d9;
  --paper: #f3f6f8;
  --paper-2: #e6edf2;
  --line: #cfd9e3;
  --gold: #9a6b12;
  --gold-soft: #f5ead0;
  --header-shadow: 0 2px 12px rgba(30, 74, 110, 0.28);
  --hero-end: #122a3d;
}

body.theme-k3 {
  --teal: #3d4a2a;
  --teal-2: #556b35;
  --teal-soft: #eef2e4;
  --orange: #b45309;
  --orange-soft: #fde8cc;
  --paper: #f4f3ec;
  --paper-2: #e8e6d8;
  --line: #d4d0be;
  --gold: #8a7010;
  --gold-soft: #f5ead0;
  --header-shadow: 0 2px 12px rgba(61, 74, 42, 0.28);
  --hero-end: #2a331c;
}

body.theme-k4 {
  --teal: #5c2438;
  --teal-2: #7a3350;
  --teal-soft: #f4e6eb;
  --orange: #c45c26;
  --orange-soft: #f8e6d9;
  --paper: #f7f1f3;
  --paper-2: #eadde2;
  --line: #dfc8d0;
  --gold: #9a6b12;
  --gold-soft: #f5ead0;
  --header-shadow: 0 2px 12px rgba(92, 36, 56, 0.28);
  --hero-end: #3a1624;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header) + 16px);
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.65;
}

a {
  color: var(--teal-2);
}

img {
  max-width: 100%;
}

.skip {
  position: absolute;
  left: -999px;
  top: 8px;
}

.skip:focus {
  left: 8px;
  z-index: 100;
  background: var(--white);
  padding: 8px 12px;
  border-radius: 8px;
}

/* Header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--teal);
  color: #fff;
  box-shadow: var(--header-shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text strong {
  font-size: 0.95rem;
}

.brand-text span {
  font-size: 0.75rem;
  opacity: 0.78;
}

.header-meta {
  font-size: 0.85rem;
  opacity: 0.85;
}

.header-nav {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.header-nav a {
  color: #fff;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.9rem;
  opacity: 0.9;
}

.header-nav a:hover,
.header-nav a[aria-current="page"] {
  background: rgba(255, 255, 255, 0.14);
  opacity: 1;
}

.nav-toggle {
  display: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
}

/* Layout */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: calc(100vh - var(--header));
}

.toc {
  position: sticky;
  top: var(--header);
  height: calc(100vh - var(--header));
  overflow: auto;
  padding: 20px 16px 40px;
  border-right: 1px solid var(--line);
  background: var(--paper-2);
}

.toc h2 {
  margin: 0 0 10px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc a {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.9rem;
}

.toc a:hover,
.toc a[aria-current="true"] {
  background: var(--white);
  color: var(--teal);
}

.toc .sub a {
  padding-left: 20px;
  font-size: 0.82rem;
}

.content {
  padding: 32px 28px 80px;
}

.page {
  max-width: 860px;
  margin: 0 auto;
}

/* Home */

.hero {
  background: linear-gradient(160deg, var(--teal) 0%, var(--hero-end) 100%);
  color: #fff;
  border-radius: 22px;
  padding: 40px 36px;
  margin-bottom: 28px;
  box-shadow: var(--shadow);
}

.hero p {
  max-width: 62ch;
  opacity: 0.92;
}

.hero a {
  color: #f3c39a;
}

.kicker {
  display: inline-block;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--orange);
  margin: 0 0 8px;
}

.hero .kicker {
  color: #f3c39a;
}

.chapter-grid {
  display: grid;
  gap: 16px;
}

.chapter-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 16px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
}

.chapter-card:hover {
  border-color: var(--teal-2);
}

.class-pick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 18px;
}

.class-pick {
  display: block;
  text-decoration: none;
  color: #fff;
  border-radius: 22px;
  padding: 32px 28px;
  min-height: 220px;
  box-shadow: var(--shadow);
}

.class-pick.k2 {
  background: linear-gradient(160deg, #1e4a6e 0%, #122a3d 100%);
}

.class-pick.k3 {
  background: linear-gradient(160deg, #3d4a2a 0%, #2a331c 100%);
}

.class-pick.k4 {
  background: linear-gradient(160deg, #5c2438 0%, #3a1624 100%);
}

.class-pick .kicker {
  color: #f3c39a;
}

.class-pick.k3 .kicker {
  color: #d4e0a8;
}

.class-pick.k4 .kicker {
  color: #f0c4d2;
}

.class-pick h2 {
  margin: 8px 0 10px;
  color: #fff;
  font-size: 1.45rem;
}

.class-pick p {
  margin: 0;
  opacity: 0.92;
}

.chapter-num {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  background: var(--teal-soft);
  color: var(--teal);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 800;
}

.chapter-card h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.chapter-card p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.muted-card {
  opacity: 0.72;
}

.muted-card .chapter-num {
  background: var(--paper-2);
  color: var(--muted);
}

/* Article */

.article-head {
  margin-bottom: 28px;
}

.article-head h1 {
  margin: 0 0 10px;
  font-size: clamp(1.7rem, 3vw, 2.2rem);
  line-height: 1.2;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

h2 {
  margin: 2.2em 0 0.6em;
  font-size: 1.45rem;
  color: var(--teal);
}

h3 {
  margin: 1.5em 0 0.5em;
  font-size: 1.1rem;
}

p {
  margin: 0 0 1em;
}

.lead {
  font-size: 1.12rem;
  color: var(--ink-soft);
}

ul,
ol {
  margin: 0 0 1.1em;
  padding-left: 1.2em;
}

li + li {
  margin-top: 0.28em;
}

figure {
  margin: 0 0 1.4em;
}

figcaption {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  border-radius: 12px;
  overflow: hidden;
  margin: 0 0 1.3em;
  font-size: 0.95rem;
}

th,
td {
  border: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--teal-soft);
  color: var(--teal);
}

.goals {
  background: var(--white);
  border: 1px solid var(--line);
  border-left: 5px solid var(--teal);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 0 0 24px;
}

.goals h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.callout {
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 0 0 1.2em;
  border: 1px solid transparent;
}

.callout strong {
  display: block;
  margin-bottom: 4px;
}

.callout.note {
  background: var(--teal-soft);
  border-color: #c5d8e6;
}

.callout.exam {
  background: var(--gold-soft);
  border-color: #ead89a;
}

.callout.warn {
  background: var(--orange-soft);
  border-color: #f0c9ad;
}

.callout.def {
  background: var(--white);
  border-color: var(--line);
  border-left: 5px solid var(--orange);
}

.callout.try {
  background: var(--green-soft);
  border-color: #c5e4cf;
}

.demo {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 1.3em;
}

.demo h3 {
  margin-top: 0;
}

.demo-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

button,
.btn {
  font: inherit;
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  background: var(--teal);
  color: #fff;
}

button.secondary {
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line);
}

.console {
  background: var(--code-bg);
  color: #d7e3c4;
  font-family: var(--mono);
  font-size: 0.88rem;
  border-radius: 10px;
  padding: 12px;
  min-height: 72px;
  white-space: pre-wrap;
}

pre,
.code {
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 12px;
  padding: 14px 16px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0 0 1.2em;
}

code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--paper-2);
  padding: 0.08em 0.35em;
  border-radius: 5px;
}

pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.kw { color: #7dc4ff; }
.fn { color: #f0c674; }
.str { color: #c3e88d; }
.cm { color: #8b9bb4; }
.tag { color: #f78c6c; }
.attr { color: #c792ea; }
.num { color: #f78c6c; }

.timeline {
  border-left: 3px solid var(--teal);
  margin: 0 0 1.4em 8px;
  padding-left: 18px;
}

.timeline-item {
  margin: 0 0 16px;
}

.timeline-item time {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--orange);
}

.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 0 0 1.3em;
}

.compare article {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.compare.thirds {
  grid-template-columns: 1fr 1fr 1fr;
}

/* Flowcharts */

.flow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin: 0 0 1.4em;
  padding: 20px 12px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.flow-node {
  min-width: 160px;
  max-width: 280px;
  text-align: center;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
}

.flow-node.start,
.flow-node.stop {
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
}

.flow-node.process {
  border-radius: 8px;
  background: var(--teal-soft);
  color: var(--teal);
  border: 2px solid var(--teal-2);
}

.flow-node.io {
  background: var(--orange-soft);
  color: #7a3510;
  border: 2px solid var(--orange);
  transform: skewX(-16deg);
}

.flow-node.io span {
  display: block;
  transform: skewX(16deg);
}

.flow-node.decision {
  width: 168px;
  min-width: 168px;
  height: 112px;
  padding: 0 28px;
  display: grid;
  place-items: center;
  background: var(--gold-soft);
  color: #6b4e00;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  border: 0;
  font-size: 0.85rem;
}

.flow-arrow {
  width: 2px;
  height: 22px;
  background: var(--teal);
  position: relative;
}

.flow-arrow::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -1px;
  width: 0;
  height: 0;
  border: 6px solid transparent;
  border-top-color: var(--teal);
  transform: translateX(-50%);
}

.flow-branch {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px 12px;
  align-items: start;
  width: min(100%, 520px);
  margin-top: 4px;
}

.flow-branch .decision-wrap {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.flow-branch .arm {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.flow-branch .arm-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--orange);
}

.flow-join {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 1.2em;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}

.legend-item .swatch {
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.legend-item .swatch.start {
  border-radius: 999px;
  background: var(--teal);
}

.legend-item .swatch.process {
  border-radius: 6px;
  background: var(--teal-soft);
  border: 2px solid var(--teal-2);
}

.legend-item .swatch.io {
  background: var(--orange-soft);
  border: 2px solid var(--orange);
  transform: skewX(-16deg);
}

.legend-item .swatch.decision {
  width: 36px;
  height: 36px;
  background: var(--gold-soft);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

.exercise {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 0 0 14px;
}

.exercise h3 {
  margin: 0 0 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.level {
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--paper-2);
  color: var(--ink-soft);
}

.level.l2 { background: #edf2f7; }
.level.l3 { background: #e6f4ea; color: var(--green); }
.level.l4 { background: var(--teal-soft); color: var(--teal); }
.level.l5 { background: var(--gold-soft); color: #7a5b00; }
.level.l6 { background: var(--orange-soft); color: var(--orange); }

.hint {
  margin-top: 10px;
}

.hint-body {
  display: none;
  margin-top: 8px;
  background: var(--paper);
  border-radius: 8px;
  padding: 10px 12px;
}

.hint.open .hint-body {
  display: block;
}

.checklist {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 8px 16px 12px;
}

.checklist label {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.checklist label:last-child {
  border-bottom: 0;
}

.quiz-item {
  margin-bottom: 14px;
}

.quiz-item fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  padding: 12px 14px;
}

.quiz-item label {
  display: block;
  padding: 4px 0;
  cursor: pointer;
}

.home {
  display: block;
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.quiz-result {
  margin-top: 8px;
  font-weight: 600;
}

.footer-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.footer-nav a,
.footer-nav span {
  text-decoration: none;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.footer-nav span {
  color: var(--muted);
}

.flow-svg {
  display: block;
  width: min(100%, 340px);
  margin: 0 auto;
  height: auto;
}

.site-footer {
  max-width: 860px;
  margin: 24px auto 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.glossary-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin: 0 0 22px;
}

.glossary-tools input {
  font: inherit;
  flex: 1 1 220px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
}

.letter-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 28px;
}

.letter-nav a {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--white);
  border: 1px solid var(--line);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
}

.glossary-item {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 0 0 12px;
}

.glossary-item h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.glossary-item p {
  margin: 0;
  color: var(--ink-soft);
}

.glossary-item .also {
  margin-top: 8px;
  font-size: 0.88rem;
  color: var(--muted);
}

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .nav-toggle {
    display: inline-flex;
  }

  .brand-text span {
    display: none;
  }

  .header-meta {
    display: none;
  }

  .toc {
    position: fixed;
    top: var(--header);
    left: 0;
    width: min(86vw, 320px);
    transform: translateX(-110%);
    transition: transform 0.2s ease;
    z-index: 30;
    box-shadow: var(--shadow);
  }

  .toc.open {
    transform: none;
  }

  .content {
    padding: 20px 16px 64px;
  }

  .compare,
  .compare.thirds,
  .chapter-card,
  .class-pick-grid {
    grid-template-columns: 1fr;
  }

  .chapter-num {
    width: 52px;
    height: 52px;
  }

  .flow-branch {
    grid-template-columns: 1fr;
  }
}

@media print {
  .site-header,
  .toc,
  .nav-toggle,
  .demo,
  .footer-nav,
  .hint button {
    display: none !important;
  }

  .layout,
  .content,
  .page {
    display: block;
    max-width: none;
    padding: 0;
  }

  body {
    background: #fff;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  pre {
    white-space: pre-wrap;
  }
}
