/* Graph theory, from scratch — shared stylesheet */
:root {
  --paper: #F8F9FB;
  --ink: #1A2440;
  --slate: #59647D;
  --rule: #D9DFE8;
  --wash: #EDF1F6;
  --teal: #0E8A8C;
  --teal-soft: #D5EEEE;
  --magenta: #BF3A6A;
  --magenta-soft: #F6DFE8;
  --amber: #D98E1F;
  --amber-soft: #FBEFD9;
  --blue: #2E5AA6;
  --sans: "Avenir Next", Avenir, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --measure: 40rem;
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.7;
}

a { color: var(--teal); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--magenta); }
:focus-visible { outline: 3px solid var(--magenta); outline-offset: 3px; border-radius: 3px; }

h1, h2, h3, h4 { font-family: var(--sans); line-height: 1.15; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: clamp(2.3rem, 6vw, 4.1rem); font-weight: 700; letter-spacing: -0.025em; }
h2 { font-size: clamp(1.6rem, 3.4vw, 2.05rem); font-weight: 700; margin-top: 4.5rem; margin-bottom: 1rem; scroll-margin-top: 1.5rem; }
h3 { font-size: 1.25rem; font-weight: 600; margin-top: 2.4rem; margin-bottom: 0.5rem; scroll-margin-top: 1.5rem; }
p { margin: 0 0 1.1rem; }
ul, ol { padding-left: 1.3rem; margin: 0 0 1.1rem; }
li { margin-bottom: 0.35rem; }
strong { font-weight: 700; }
var, .v { font-family: var(--serif); font-style: italic; }
sub { font-size: 0.7em; }

/* ---------- Site header ---------- */
.site-head {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  max-width: 72rem; margin: 0 auto; padding: 1.1rem 1.5rem;
  font-family: var(--sans); font-size: 0.95rem;
}
.brand { display: inline-flex; align-items: center; gap: 0.6rem; color: var(--ink); text-decoration: none; font-weight: 700; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.site-head .where { color: var(--slate); }

/* ---------- Hero (unit pages) ---------- */
.unit-hero { max-width: 72rem; margin: 0 auto; padding: 2.5rem 1.5rem 1rem; }
.unit-hero .kicker { font-family: var(--sans); color: var(--teal); font-weight: 600; margin-bottom: 0.9rem; }
.unit-hero h1 { max-width: 16ch; }
.unit-hero .lede { font-size: 1.3rem; line-height: 1.55; max-width: 36rem; color: var(--slate); margin-top: 1.4rem; }
.route { width: 100%; max-width: 46rem; height: auto; margin-top: 2rem; display: block; }

/* ---------- Page layout with route-line contents ---------- */
.layout {
  max-width: 72rem; margin: 0 auto; padding: 1rem 1.5rem 5rem;
  display: grid; grid-template-columns: 15rem minmax(0, 1fr); gap: 4rem;
}
.layout > article { max-width: var(--measure); min-width: 0; }

.toc { position: sticky; top: 1.5rem; align-self: start; font-family: var(--sans); font-size: 0.92rem; margin-top: 4.6rem; }
.toc summary { list-style: none; cursor: pointer; font-weight: 700; margin-bottom: 0.8rem; }
.toc summary::-webkit-details-marker { display: none; }
.stations { list-style: none; padding: 0; margin: 0; position: relative; }
.stations::before { content: ""; position: absolute; left: 7px; top: 10px; bottom: 10px; width: 4px; background: var(--teal); border-radius: 2px; }
.stations li { position: relative; padding-left: 1.9rem; margin: 0 0 0.85rem; line-height: 1.35; }
.stations li::before {
  content: ""; position: absolute; left: 0; top: 0.12rem; width: 18px; height: 18px; border-radius: 50%;
  background: var(--paper); border: 4px solid var(--teal);
}
.stations a { color: var(--ink); text-decoration: none; }
.stations a:hover { color: var(--teal); text-decoration: underline; }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .layout > article { margin: 0 auto; width: 100%; }
  .toc { position: static; margin: 1rem auto 0; width: 100%; max-width: var(--measure); background: var(--wash); border-radius: 10px; padding: 1rem 1.2rem 0.4rem; }
  .toc summary::after { content: " (tap to open)"; font-weight: 400; color: var(--slate); }
  .toc[open] summary::after { content: ""; }
}

/* ---------- Figures ---------- */
figure { margin: 2.2rem 0; }
figure svg { display: block; width: 100%; height: auto; }
figcaption { font-family: var(--sans); font-size: 0.9rem; line-height: 1.5; color: var(--slate); margin-top: 0.75rem; }
figcaption b { color: var(--ink); }
.fig-wide { margin-left: 0; margin-right: 0; }
@media (min-width: 1200px) { .fig-wide { margin-right: -6rem; } }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: end; }
.pair > div > p { font-family: var(--sans); font-size: 0.9rem; text-align: center; color: var(--slate); margin: 0.4rem 0 0; }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.6rem 1.2rem; }
.gallery.five { grid-template-columns: repeat(5, 1fr); }
.gallery > div { text-align: center; }
.gallery p { font-family: var(--sans); font-size: 0.86rem; line-height: 1.35; margin: 0.4rem 0 0; color: var(--slate); }
.gallery p b { display: block; color: var(--ink); font-size: 0.95rem; }
@media (max-width: 560px) {
  .gallery { grid-template-columns: repeat(2, 1fr); }
  .gallery.five { grid-template-columns: repeat(3, 1fr); }
}

/* Graph drawing vocabulary (inline SVG) */
.g .e { stroke: var(--ink); stroke-width: 2.5; fill: none; stroke-linecap: round; }
.g .e.faint { stroke: var(--rule); stroke-dasharray: 5 6; }
.g .e.hi { stroke: var(--teal); stroke-width: 4.5; }
.g .e.arc { stroke-width: 2.2; }
.g circle.v { fill: #fff; stroke: var(--ink); stroke-width: 2.5; }
.g circle.v.hi { fill: var(--teal); stroke: var(--teal); }
.g circle.v.faint { stroke: var(--rule); }
.g .vl { font-family: var(--sans); font-weight: 600; fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.g circle.v.hi + .vl { fill: #fff; }
.g circle.v.faint + .vl { fill: #9AA4B8; }
.g .w { font-family: var(--sans); font-weight: 700; font-size: 15px; fill: var(--blue); text-anchor: middle; dominant-baseline: central; paint-order: stroke; stroke: var(--paper); stroke-width: 6px; stroke-linejoin: round; }
.g .end { fill: var(--magenta); }
.g .note { font-family: var(--sans); font-size: 14px; fill: var(--slate); }
.g .note-line { stroke: var(--slate); stroke-width: 1.2; fill: none; }
.g .cross { fill: none; stroke: var(--amber); stroke-width: 2.5; }
.g .mini circle.v { stroke-width: 2.5; }

/* Interactive vertices: hover or tap (focus) to light up edges and show the degree */
.g .star { cursor: pointer; outline: none; }
.g .star .hl { stroke: transparent; stroke-width: 6; stroke-linecap: round; pointer-events: none; transition: stroke 0.15s; }
.g .star .badge { opacity: 0; transition: opacity 0.15s; pointer-events: none; }
.g .star .badge circle { fill: var(--magenta); }
.g .star .badge text { font-family: var(--sans); font-weight: 700; font-size: 13px; fill: #fff; text-anchor: middle; dominant-baseline: central; }
.g .star:hover .hl, .g .star:focus .hl { stroke: var(--magenta); }
.g .star:hover circle.v, .g .star:focus circle.v { fill: var(--magenta); stroke: var(--magenta); }
.g .star:hover .vl, .g .star:focus .vl { fill: #fff; }
.g .star:hover .badge, .g .star:focus .badge { opacity: 1; }
.hint { font-family: var(--sans); font-size: 0.85rem; color: var(--magenta); font-weight: 600; }

/* ---------- Teaching blocks ---------- */
.def { position: relative; margin: 1.8rem 0; padding: 0.2rem 0 0.2rem 1.4rem; border-left: 4px solid var(--teal); }
.def::before { content: ""; position: absolute; left: -11px; top: 0.25rem; width: 18px; height: 18px; border-radius: 50%; background: var(--paper); border: 4px solid var(--teal); }
.def h4 { font-size: 1rem; color: var(--teal); margin-bottom: 0.3rem; }
.def p:last-child { margin-bottom: 0; }

.note-box { margin: 1.8rem 0; padding: 1rem 1.2rem; background: var(--amber-soft); border-radius: 10px; }
.note-box h4 { font-size: 1rem; color: #8A5608; margin-bottom: 0.3rem; }
.note-box p:last-child { margin-bottom: 0; }

.formula {
  font-family: var(--serif); font-size: clamp(1.25rem, 3.4vw, 1.6rem); text-align: center;
  margin: 1.8rem 0; padding: 1.2rem 1rem; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.formula small { display: block; font-family: var(--sans); font-size: 0.85rem; color: var(--slate); margin-top: 0.5rem; }

.example { margin: 1.6rem 0; padding-left: 1.4rem; border-left: 2px dotted var(--slate); }
.example h4 { font-size: 1rem; margin-bottom: 0.35rem; }
.example p:last-child { margin-bottom: 0; }

.try { margin: 2rem 0; padding: 1.1rem 1.25rem 0.9rem; background: var(--magenta-soft); border-radius: 10px; }
.try > p:first-child { margin-bottom: 0.7rem; }
.try .lead { font-family: var(--sans); font-weight: 700; color: var(--magenta); }
.try details { border-top: 1px solid rgba(191, 58, 106, 0.25); padding-top: 0.6rem; }
.try summary { font-family: var(--sans); font-weight: 600; font-size: 0.95rem; cursor: pointer; color: var(--magenta); }
.try details[open] summary { margin-bottom: 0.6rem; }
.try details > *:last-child { margin-bottom: 0.3rem; }
.try svg { max-width: 220px; display: block; margin: 0.5rem 0 0.8rem; }
.try ol, .try ul { margin-bottom: 0.6rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 1.6rem 0; }
table { border-collapse: collapse; font-family: var(--sans); font-size: 0.95rem; width: 100%; }
th, td { text-align: left; padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
thead th { border-bottom: 2px solid var(--ink); font-weight: 700; }
tbody th { font-weight: 600; }

.matrix { width: auto; font-variant-numeric: tabular-nums; }
.matrix th, .matrix td { text-align: center; width: 2.6rem; height: 2.6rem; padding: 0; border: none; }
.matrix thead th { border: none; color: var(--slate); }
.matrix tbody th { color: var(--slate); }
.matrix td { border: 1px solid var(--rule); background: #fff; color: #A9B2C3; }
.matrix td.one { background: var(--teal); color: #fff; font-weight: 700; }
.matrix td.sum { background: none; border: none; color: var(--magenta); font-weight: 700; }

.reps { display: grid; grid-template-columns: 1.1fr 1fr; gap: 2rem; align-items: start; margin: 2rem 0; }
.reps h4 { font-size: 1rem; margin-bottom: 0.6rem; }
.adjlist { list-style: none; padding: 0; font-family: var(--sans); font-size: 1rem; }
.adjlist li { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.45rem; }
.adjlist .key { display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; border: 2.5px solid var(--ink); font-weight: 700; background: #fff; flex: none; }
.adjlist .chip { padding: 0.15rem 0.6rem; border-radius: 1rem; background: var(--teal-soft); font-weight: 600; }
@media (max-width: 640px) { .reps { grid-template-columns: 1fr; } }

/* ---------- Summary ---------- */
.takeaways { list-style: none; padding: 0; counter-reset: t; }
.takeaways li { position: relative; padding-left: 2.6rem; margin-bottom: 1rem; counter-increment: t; }
.takeaways li::before {
  content: counter(t); position: absolute; left: 0; top: 0.05rem; width: 1.8rem; height: 1.8rem; border-radius: 50%;
  background: var(--teal); color: #fff; font-family: var(--sans); font-weight: 700; font-size: 0.9rem; display: grid; place-items: center;
}
dl.glossary { display: grid; grid-template-columns: max-content 1fr; gap: 0.6rem 1.4rem; margin: 1.5rem 0; }
dl.glossary dt { font-family: var(--sans); font-weight: 700; }
dl.glossary dd { margin: 0; }
@media (max-width: 560px) { dl.glossary { grid-template-columns: 1fr; gap: 0.1rem; } dl.glossary dd { margin-bottom: 0.8rem; } }

.next {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin-top: 4rem; padding-top: 1.5rem; border-top: 4px solid var(--teal); font-family: var(--sans);
}
.next .soon { color: var(--slate); }

/* ---------- Home page ---------- */
.home-hero {
  max-width: 72rem; margin: 0 auto; padding: 3rem 1.5rem 2rem;
  display: grid; grid-template-columns: 1fr 1.05fr; gap: 3rem; align-items: center;
}
.home-hero .lede { font-size: 1.3rem; line-height: 1.55; color: var(--slate); margin-top: 1.5rem; max-width: 30rem; }
.home-hero figure { margin: 0; }
.cta { display: inline-block; margin-top: 1.6rem; padding: 0.8rem 1.4rem; background: var(--teal); color: #fff; border-radius: 2rem; font-family: var(--sans); font-weight: 700; text-decoration: none; }
.cta:hover { background: var(--ink); color: #fff; }
@media (max-width: 860px) { .home-hero { grid-template-columns: 1fr; gap: 1.5rem; } }

.home-section { max-width: 72rem; margin: 0 auto; padding: 2rem 1.5rem; }
.home-section > h2 { margin-top: 1.5rem; }
.home-section > p { max-width: var(--measure); }

.method { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5rem; margin-top: 1.5rem; font-family: var(--sans); }
.method div { border-top: 4px solid var(--teal); padding-top: 0.8rem; }
.method h3 { font-size: 1.05rem; margin: 0 0 0.3rem; }
.method p { font-family: var(--serif); font-size: 1rem; line-height: 1.55; color: var(--slate); margin: 0; }
@media (max-width: 760px) { .method { grid-template-columns: 1fr 1fr; } }

.syllabus { list-style: none; padding: 0; margin: 2rem 0 0; position: relative; max-width: 46rem; }
.syllabus::before { content: ""; position: absolute; left: 21px; top: 22px; bottom: 30px; width: 6px; background: var(--teal); border-radius: 3px; }
.syllabus li { position: relative; padding: 0 0 1.9rem 4.4rem; margin: 0; }
.syllabus .num {
  position: absolute; left: 0; top: 0; width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; background: var(--paper); border: 5px solid var(--rule);
  font-family: var(--sans); font-weight: 700; color: var(--slate);
}
.syllabus li.open .num { border-color: var(--teal); background: var(--teal); color: #fff; }
.syllabus h3 { margin: 0.55rem 0 0.25rem; font-size: 1.2rem; }
.syllabus h3 a { color: var(--ink); text-decoration: none; }
.syllabus h3 a:hover { color: var(--teal); text-decoration: underline; }
.syllabus p { margin: 0; color: var(--slate); font-size: 1.02rem; line-height: 1.55; }
.syllabus .status { font-family: var(--sans); font-size: 0.85rem; font-weight: 600; color: var(--slate); }
.syllabus li.open .status { color: var(--teal); }

.site-foot { max-width: 72rem; margin: 0 auto; padding: 2rem 1.5rem 3rem; font-family: var(--sans); font-size: 0.9rem; color: var(--slate); border-top: 1px solid var(--rule); }
.table-wrap.flush { margin: 0; }
.fig-small svg { max-width: 380px; }
.arr { font-family: var(--sans); }
@media (max-width: 560px) {
  .site-head, .unit-hero, .layout, .home-hero, .home-section, .site-foot { padding-left: 1.1rem; padding-right: 1.1rem; }
  body { font-size: 1.0625rem; }
}
.site-head a.where { color: var(--slate); text-decoration: none; } .site-head a.where:hover { color: var(--teal); } include-fragment { display: block; }

/* ---------- Units 2-11 additions ---------- */
.route .rl { stroke: #D9DFE8; stroke-width: 6; stroke-linecap: round; }
.route .rl.rd { stroke: #0E8A8C; }
.route circle { fill: #F8F9FB; stroke: #D9DFE8; stroke-width: 5; }
.route circle.done { stroke: #0E8A8C; }
.route circle.here { fill: #0E8A8C; stroke: #0E8A8C; }
.route text { font-family: var(--sans); font-size: 14px; fill: #59647D; text-anchor: middle; }
.route text.here { fill: #0E8A8C; font-weight: 700; }
.route a:hover circle { stroke: #BF3A6A; }

.g circle.v.done { fill: var(--teal-soft); stroke: var(--teal); }
.g circle.v.cur { fill: var(--magenta); stroke: var(--magenta); }
.g circle.v.cur + .vl { fill: #fff; }
.g circle.v.front { fill: var(--amber-soft); stroke: var(--amber); stroke-width: 3.5; }
.g circle.v.dark { fill: var(--ink); stroke: var(--ink); }
.g circle.v.dark + .vl { fill: #fff; }
.g circle.v.c1 { fill: #9FD8D8; }
.g circle.v.c2 { fill: #F2B5CB; }
.g circle.v.c3 { fill: #F7D08A; }
.g circle.v.c4 { fill: #B9CBEC; }
.g .e.hi2 { stroke: var(--magenta); stroke-width: 4.5; }
.g .e.amb { stroke: var(--amber); stroke-width: 4.5; }
.g .e.blu { stroke: var(--blue); stroke-width: 4.5; }
.g .e.thin { stroke-width: 1.6; }
.g .e.arc.hi, .g .e.arc.hi2, .g .e.arc.amb, .g .e.arc.blu { stroke-width: 3; }
.g .e.dash { stroke-dasharray: 6 6; }
.g .e.gone { stroke: var(--rule); stroke-dasharray: 3 6; }
.g .tag { font-family: var(--sans); font-weight: 700; font-size: 14px; fill: var(--blue); text-anchor: middle; dominant-baseline: central; paint-order: stroke; stroke: var(--paper); stroke-width: 5px; stroke-linejoin: round; }
.g .tag.m { fill: var(--magenta); }
.g .tag.t { fill: var(--teal); }
.g .tag.s { fill: var(--slate); font-weight: 600; }
.g .w.m { fill: var(--magenta); }
.g .w.t { fill: var(--teal); }
.g .w.s { fill: var(--slate); font-weight: 600; }
.g .cutline { fill: none; stroke: var(--magenta); stroke-width: 3; stroke-dasharray: 9 7; }
.g .face1 { fill: #DDF0F0; } .g .face2 { fill: #FBE6EE; } .g .face3 { fill: #FCF0D8; } .g .face4 { fill: #E3EAF7; }
.g .land { fill: #E9E2D2; stroke: #CBBFA5; stroke-width: 1.5; }
.g .river { fill: #CFE2F0; }
.g .bridge { stroke: #8A6F3F; stroke-width: 7; stroke-linecap: round; }
.g .lbl { font-family: var(--sans); font-size: 14px; fill: var(--slate); text-anchor: middle; dominant-baseline: central; }
.g .lbl.b { font-weight: 700; fill: var(--ink); }
.g .grid { fill: #fff; stroke: var(--rule); stroke-width: 1; }
.g .wall { fill: var(--ink); }
.g .bar { fill: var(--teal); }
.g .bar.m { fill: var(--magenta); }
.g .axis { stroke: var(--slate); stroke-width: 1.2; }

.steps-hint { font-family: var(--sans); font-size: 0.85rem; color: var(--slate); margin: 1.6rem 0 0.4rem; }
.steps { display: flex; gap: 1rem; overflow-x: auto; scroll-snap-type: x mandatory; padding: 0.2rem 0 0.9rem; margin: 0 0 1.6rem; -webkit-overflow-scrolling: touch; }
.steps > .step { flex: 0 0 min(86%, 25rem); scroll-snap-align: start; background: #fff; border: 1px solid var(--rule); border-radius: 12px; padding: 0.9rem 1rem 1rem; }
.step h4 { font-size: 0.95rem; color: var(--teal); margin: 0 0 0.4rem; }
.step svg { display: block; width: 100%; height: auto; }
.step p { font-family: var(--sans); font-size: 0.9rem; line-height: 1.45; margin: 0.5rem 0 0; }

.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; font-family: var(--sans); font-size: 0.85rem; color: var(--slate); margin: 0.6rem 0 0; }
.legend span::before { content: ""; display: inline-block; width: 0.85rem; height: 0.85rem; border-radius: 50%; margin-right: 0.35rem; vertical-align: -0.1rem; border: 2.5px solid var(--ink); background: #fff; }
.legend .l-done::before { background: var(--teal-soft); border-color: var(--teal); }
.legend .l-cur::before { background: var(--magenta); border-color: var(--magenta); }
.legend .l-front::before { background: var(--amber-soft); border-color: var(--amber); }
.legend .l-edge::before { border-radius: 2px; height: 0.3rem; border: none; background: var(--teal); vertical-align: 0.15rem; width: 1.2rem; }
.legend .l-edge2::before { border-radius: 2px; height: 0.3rem; border: none; background: var(--magenta); vertical-align: 0.15rem; width: 1.2rem; }

table.compact td, table.compact th { padding: 0.4rem 0.55rem; font-size: 0.9rem; }
td.hl, th.hl { background: var(--teal-soft); }
td.hm { background: var(--magenta-soft); }
.prevnext { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.history { font-family: var(--sans); font-size: 0.95rem; line-height: 1.6; color: var(--slate); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 0.9rem 0; margin: 1.8rem 0; }
.history b { color: var(--ink); }
