/* NMK42003 Instrumentation — site styles */

:root {
  --paper: #f3f5f6;
  --surface: #ffffff;
  --ink: #15243a;
  --ink-2: #4a5a6e;
  --ink-3: #6f7f91;
  --rule: #d6dee4;
  --grid: #e3e9ed;
  --teal: #0b6e6e;
  --teal-strong: #085757;
  --teal-soft: #e0efee;
  --amber: #a86e00;
  --amber-soft: #fbf1dc;
  --danger: #a63d2f;
  --focus: #1a73c7;

  --serif: "IBM Plex Serif", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --measure: 68ch;
  --wrap: 1120px;
  --r-sm: 6px;
  --r-md: 10px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #0e1720;
  --surface: #15212c;
  --ink: #e6edf3;
  --ink-2: #a3b4c3;
  --ink-3: #7d90a1;
  --rule: #273645;
  --grid: #1d2a36;
  --teal: #45c4ba;
  --teal-strong: #6fd6ce;
  --teal-soft: #12302e;
  --amber: #e8b04b;
  --amber-soft: #33280f;
  --danger: #ef8a7c;
  --focus: #7cb8f2;
  color-scheme: dark;
}

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

html { scroll-behavior: smooth; scroll-padding-top: 72px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--teal); text-underline-offset: 3px; }
a:hover { color: var(--teal-strong); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; }
h2 { font-size: clamp(1.6rem, 1.2rem + 1.2vw, 2.1rem); }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 24px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }

/* ---------- Header ---------- */
.site-header {
  position: -webkit-sticky; position: sticky; top: 0; z-index: 50;
  background: var(--paper); /* fallback for browsers without color-mix */
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.2) blur(8px);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--rule);
}
.site-header .wrap { display: flex; align-items: center; gap: 24px; height: 60px; }
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-code { font-family: var(--serif); font-weight: 600; font-size: 1.1rem; }
.brand-name { color: var(--ink-2); font-size: .95rem; }
.nav { margin-left: auto; display: flex; gap: 4px; }
.nav a { color: var(--ink-2); text-decoration: none; font-size: .93rem; padding: 6px 10px; border-radius: var(--r-sm); }
.nav a:hover { color: var(--ink); background: var(--grid); }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink);
  border-radius: var(--r-sm); cursor: pointer;
}
.icon-btn:hover { border-color: var(--ink-3); }
.menu-btn { display: none; }
@media (max-width: 820px) {
  .menu-btn { display: inline-grid; margin-left: auto; }
  .nav {
    display: none; position: absolute; top: 60px; left: 0; right: 0;
    flex-direction: column; background: var(--surface); border-bottom: 1px solid var(--rule); padding: 8px 16px 16px;
  }
  .nav.open { display: flex; }
  .nav a { padding: 10px; }
  .brand-name { display: none; }
}

/* ---------- Hero ---------- */
.hero { padding: 56px 0 40px; }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 48px; align-items: start; }
@media (max-width: 900px) { .hero-grid { grid-template-columns: minmax(0, 1fr); gap: 32px; } }

.hero-kicker { color: var(--ink-2); font-size: 1rem; margin-bottom: 14px; }
.hero h1 {
  font-size: clamp(2.8rem, 1.6rem + 4.6vw, 5rem);
  letter-spacing: -0.02em;
  line-height: 1.02;
  margin-bottom: 20px;
}
/* The course name is one long word ("Instrumentation" is about 7.75em wide in IBM Plex Serif).
   Size it to fit its column so it never breaks mid-word; 8.4 leaves room for fallback fonts. */
#heroName { white-space: nowrap; }
@media (max-width: 900px) { .hero h1 { font-size: min(5rem, calc((100vw - 48px) / 8.4)); } }
@media (min-width: 901px) { .hero h1 { font-size: 5rem; } }
.chapter-hero h1 { overflow-wrap: break-word; }
.hero-code { display: block; font-family: var(--sans); font-weight: 500; font-size: max(.32em, 1rem); letter-spacing: 0; color: var(--teal); margin-bottom: .35em; }
.hero-logo { display: inline-block; background: #fff; border-radius: var(--r-sm); padding: 6px 10px; margin-bottom: 18px; line-height: 0; }
.hero-logo img { height: 56px; width: auto; }
:root[data-theme="dark"] .hero-logo { box-shadow: 0 0 0 1px var(--rule); }
.synopsis { max-width: var(--measure); color: var(--ink-2); font-size: 1.05rem; }

.facts { display: grid; grid-template-columns: minmax(0,.7fr) minmax(0,.9fr) minmax(0,1.8fr); column-gap: 20px; margin: 28px 0 0; border-top: 1px solid var(--rule); }
.facts div:first-child { grid-column: 1 / -1; }
@media (max-width: 560px) { .facts { grid-template-columns: 1fr 1fr; } .facts div:last-child { grid-column: 1 / -1; } }
.facts div { padding: 12px 0; border-bottom: 1px solid var(--rule); }
.facts dt { font-size: .82rem; color: var(--ink-3); }
.facts dd { margin: 2px 0 0; font-size: .96rem; }

/* This-week readout */
.readout {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md);
  padding: 22px 24px 24px; position: relative; overflow: hidden;
}
.readout::before { /* graticule */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .7;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.9), transparent 70%);
}
.readout > * { position: relative; }
.readout-label { font-size: .85rem; color: var(--ink-3); display: flex; align-items: center; gap: 8px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 4px var(--teal-soft); }
.readout-week { font-family: var(--serif); font-size: 3.2rem; font-weight: 600; line-height: 1; margin: 12px 0 4px; }
.readout-week small { font-family: var(--sans); font-size: .95rem; font-weight: 400; color: var(--ink-2); margin-left: 8px; }
.readout-topic { font-size: 1.12rem; font-weight: 500; margin: 10px 0 12px; }
.readout ul { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 6px; }
.readout li { font-size: .95rem; color: var(--ink-2); padding-left: 16px; position: relative; }
.readout li::before { content: ""; position: absolute; left: 0; top: .65em; width: 7px; height: 2px; background: var(--ink-3); }
.readout li.due { color: var(--amber); font-weight: 500; }
.readout li.due::before { background: var(--amber); }
.readout-next { border-top: 1px solid var(--rule); padding-top: 12px; font-size: .9rem; color: var(--ink-2); }
.progress { height: 6px; background: var(--grid); border-radius: 3px; margin: 14px 0 6px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--teal); border-radius: 3px; }
.progress-caption { font-size: .82rem; color: var(--ink-3); }

/* ---------- Sections ---------- */
section.block { padding: 56px 0; border-top: 1px solid var(--rule); }
.block-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 16px 32px; margin-bottom: 28px; }
.block-head p { color: var(--ink-2); max-width: 60ch; margin: 8px 0 0; }

/* ---------- Semester trace ---------- */
.scope {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md);
  padding: 16px 12px 8px; overflow-x: auto;
}
.scope svg { display: block; width: 100%; min-width: 760px; height: auto; }
.scope .gl { stroke: var(--grid); stroke-width: 1; }
.scope .axis { fill: var(--ink-3); font-family: var(--sans); font-size: 11px; }
.scope .trace { fill: none; stroke: var(--teal); stroke-width: 2.25; stroke-linejoin: round; }
.scope .trace-fill { fill: var(--teal-soft); opacity: .55; }
.scope .col { fill: transparent; cursor: pointer; }
.scope .col:hover { fill: var(--grid); opacity: .6; }
.scope .col.sel { fill: var(--teal-soft); opacity: .8; }
.scope .shade { fill: var(--grid); opacity: .7; }
.scope .mk { fill: var(--amber); }
.scope .mk-ring { fill: var(--surface); stroke: var(--amber); stroke-width: 2; }
.scope .now { stroke: var(--danger); stroke-width: 1.5; stroke-dasharray: 4 3; }
.scope .now-label { fill: var(--danger); font-size: 11px; font-family: var(--sans); font-weight: 500; }
.scope .wk { fill: var(--ink-2); font-size: 11px; font-family: var(--sans); }
.scope .wk.sel { fill: var(--teal); font-weight: 600; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 12px 4px 0; font-size: .85rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.sw { display: inline-block; width: 14px; height: 3px; background: var(--teal); }
.sw.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); }
.sw.dash { height: 0; border-top: 2px dashed var(--danger); background: none; }
.sw.box { width: 12px; height: 12px; background: var(--grid); }

.week-detail {
  margin-top: 16px; display: grid; grid-template-columns: 150px minmax(0,1fr); gap: 20px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 18px 22px;
}
@media (max-width: 640px) { .week-detail { grid-template-columns: minmax(0, 1fr); gap: 8px; } }
.wd-num { font-family: var(--serif); font-size: 1.8rem; font-weight: 600; line-height: 1.1; }
.wd-dates { font-size: .88rem; color: var(--ink-3); }
.wd-topic { font-weight: 600; font-size: 1.08rem; margin-bottom: 4px; }
.wd-sub { color: var(--ink-2); margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .8rem; padding: 3px 9px; border-radius: 999px; background: var(--grid); color: var(--ink-2); }
.chip.due { background: var(--amber-soft); color: var(--amber); font-weight: 500; }
.chip.note { background: transparent; border: 1px solid var(--rule); }

/* ---------- Topics ---------- */
.search { position: relative; }
.search input {
  width: min(320px, 100%); height: 40px; padding: 0 12px 0 36px; font: inherit; font-size: .95rem;
  border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--surface); color: var(--ink);
}
.search input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }

.topic-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.topic {
  display: grid; grid-template-columns: 64px minmax(0,1fr) auto; gap: 8px 24px; align-items: start;
  padding: 22px 0; border-bottom: 1px solid var(--rule);
}
.topic-no { font-family: var(--serif); font-size: 2rem; font-weight: 600; color: var(--ink-3); line-height: 1; padding-top: 2px; }
.topic.featured .topic-no { color: var(--teal); }
.topic h3 a { color: var(--ink); text-decoration: none; }
.topic h3 a:hover { color: var(--teal); text-decoration: underline; }
.topic-summary { color: var(--ink-2); margin: 6px 0 8px; max-width: var(--measure); font-size: .98rem; }
.topic-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: .86rem; color: var(--ink-3); }
.badge { font-size: .78rem; font-weight: 500; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--rule); color: var(--ink-2); }
.badge.building { border-color: transparent; background: var(--teal-soft); color: var(--teal); }
.badge.interactive { border-color: transparent; background: var(--teal); color: var(--surface); }
.study-toggle {
  display: inline-flex; align-items: center; gap: 8px; font: inherit; font-size: .86rem; color: var(--ink-2);
  background: none; border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 6px 10px; cursor: pointer; white-space: nowrap;
}
.study-toggle:hover { border-color: var(--ink-3); }
.study-toggle .box { width: 14px; height: 14px; border: 1.5px solid var(--ink-3); border-radius: 3px; display: grid; place-items: center; }
.study-toggle[aria-pressed="true"] { color: var(--teal); border-color: var(--teal); }
.study-toggle[aria-pressed="true"] .box { background: var(--teal); border-color: var(--teal); }
.study-toggle[aria-pressed="true"] .box::after { content: ""; width: 7px; height: 4px; border: 2px solid var(--surface); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px,-1px); }
.topic-empty { padding: 24px 0; color: var(--ink-2); }
.study-summary { font-size: .9rem; color: var(--ink-2); margin-top: 14px; }
@media (max-width: 640px) {
  .topic { grid-template-columns: 44px minmax(0,1fr); }
  .topic-no { font-size: 1.5rem; }
  .topic .study-toggle { grid-column: 2; justify-self: start; }
}

/* ---------- Schedule table ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filter {
  font: inherit; font-size: .88rem; padding: 6px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink-2);
}
.filter:hover { border-color: var(--ink-3); }
.filter[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--surface); }
table.sched { width: 100%; border-collapse: collapse; font-size: .93rem; min-width: 720px; }
.sched th { text-align: left; font-weight: 500; color: var(--ink-3); font-size: .82rem; padding: 12px 16px; border-bottom: 1px solid var(--rule); }
.sched td { padding: 14px 16px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.sched tr:last-child td { border-bottom: 0; }
.sched .c-week { width: 120px; }
.sched .wnum { font-weight: 600; }
.sched .wdate { display: block; font-size: .8rem; color: var(--ink-3); }
.sched .t-topic { font-weight: 500; }
.sched .t-sub { display: block; color: var(--ink-2); font-size: .88rem; margin-top: 2px; }
.sched tr.muted td { color: var(--ink-3); background: color-mix(in srgb, var(--grid) 45%, transparent); }
.sched tr.current td { background: var(--teal-soft); }
.sched tr.current .wnum::after { content: "This week"; margin-left: 8px; font-size: .72rem; font-weight: 500; color: var(--teal); }
.sched tr.flash td { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: var(--amber-soft); } }
@media (prefers-reduced-motion: reduce) { .sched tr.flash td { animation: none; } }

/* ---------- Assessment ---------- */
.assess-grid { display: grid; grid-template-columns: minmax(0,1.1fr) minmax(0,1fr); gap: 48px; }
@media (max-width: 900px) { .assess-grid { grid-template-columns: minmax(0, 1fr); gap: 36px; } }
.split { display: flex; justify-content: space-between; font-size: .88rem; color: var(--ink-2); margin-bottom: 8px; }
.bar { display: flex; height: 52px; border-radius: var(--r-sm); overflow: hidden; gap: 2px; }
.seg {
  border: 0; padding: 0 10px; cursor: pointer; font: inherit; font-size: .85rem; font-weight: 600;
  display: flex; align-items: center; justify-content: flex-start; white-space: nowrap; overflow: hidden;
  transition: filter .15s; min-width: 0;
}
.seg:hover { filter: brightness(1.08); }
.seg[aria-pressed="true"] { box-shadow: inset 0 -4px 0 var(--ink); }
.seg.final   { background: #15243a; color: #fff; }
.seg.lab     { background: #0b6e6e; color: #fff; }
.seg.quiz    { background: #3f9a93; color: #fff; }
.seg.project { background: #8fc5bf; color: #0d2a2a; }
.seg.test    { background: #d9b45f; color: #3a2a00; }
:root[data-theme="dark"] .seg.final { background: #4d6581; }
.assess-detail { margin-top: 18px; padding: 16px 18px; border-left: 3px solid var(--teal); background: var(--surface); border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.assess-detail strong { font-size: 1.05rem; }
.assess-detail p { margin: 4px 0 0; color: var(--ink-2); }
.assess-list { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 6px; font-size: .92rem; }
.assess-list li { display: flex; justify-content: space-between; border-bottom: 1px dotted var(--rule); padding: 4px 0; color: var(--ink-2); }

.co-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0; border-top: 1px solid var(--rule); }
.co { padding: 16px 0; border-bottom: 1px solid var(--rule); display: grid; grid-template-columns: 64px minmax(0,1fr); gap: 16px; }
.co-id { font-family: var(--serif); font-weight: 600; font-size: 1.15rem; color: var(--teal); }
.co p { margin: 0 0 4px; }
.co-meta { font-size: .84rem; color: var(--ink-3); }

/* ---------- Labs & references ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 48px; }
@media (max-width: 820px) { .two-col { grid-template-columns: minmax(0, 1fr); gap: 36px; } }
.plain-list { list-style: none; padding: 0; margin: 16px 0 0; border-top: 1px solid var(--rule); }
.plain-list li { padding: 12px 0; border-bottom: 1px solid var(--rule); display: flex; justify-content: space-between; gap: 16px; }
.plain-list .muted { color: var(--ink-3); font-size: .88rem; white-space: nowrap; }
.plain-list li.lab-link { display: block; padding: 8px 0; }
.lab-link a { display: grid; gap: 4px; text-decoration: none; color: var(--ink); background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--teal); border-radius: var(--r-md); padding: 12px 14px; }
.lab-link a:hover { border-color: var(--teal); }
.ll-top { display: flex; justify-content: space-between; gap: 16px; }
.ll-title { font-weight: 600; }
.ll-sum { color: var(--ink-2); font-size: .92rem; }
.ll-go { color: var(--teal); font-weight: 600; font-size: .92rem; }
.oe { font-size: .75rem; color: var(--teal); border: 1px solid var(--teal); border-radius: 999px; padding: 0 7px; margin-left: 6px; white-space: nowrap; }
ol.refs { margin: 16px 0 0; padding-left: 1.3em; color: var(--ink-2); }
ol.refs li { padding: 8px 0 8px 4px; font-family: var(--serif); }

/* ---------- Team ---------- */
.team { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 20px; }
.person > div:last-child { min-width: 0; }
.person-links a { overflow-wrap: anywhere; }
.person { display: flex; gap: 18px; align-items: center; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 20px; }
.avatar {
  flex: none; width: 112px; height: 112px; border-radius: 50%; display: grid; place-items: center;
  background: var(--teal-soft); color: var(--teal); font-family: var(--serif); font-weight: 600; font-size: 1.4rem; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
@media (max-width: 480px) { .avatar { width: 84px; height: 84px; } .person { gap: 14px; padding: 16px; } }
.person-role { font-size: .85rem; color: var(--teal); font-weight: 500; }
.person-name { font-family: var(--serif); font-weight: 600; font-size: 1.1rem; line-height: 1.3; margin: 2px 0 6px; }
.person-links { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .9rem; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--rule); padding: 36px 0 48px; margin-top: 24px; font-size: .9rem; color: var(--ink-2); }
.foot-grid { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px 40px; }
.foot-dev strong { color: var(--ink); font-weight: 500; }
.foot-dev { flex: 1 1 320px; }
.foot-logo { flex: none; background: #fff; border-radius: var(--r-sm); padding: 5px 8px; line-height: 0; align-self: flex-start; }
.foot-logo img { height: 36px; width: auto; }
:root[data-theme="dark"] .foot-logo { box-shadow: 0 0 0 1px var(--rule); }
.live-dot.waiting { background: var(--amber); box-shadow: 0 0 0 4px var(--amber-soft); }
.readout-first { font-size: .95rem; color: var(--ink-2); margin: 0 0 12px; }
.foot-meta { color: var(--ink-3); }

/* ---------- Chapter placeholder page ---------- */
.chapter-hero { padding-top: 48px; padding-bottom: 32px; }
.crumb { font-size: .9rem; margin-bottom: 24px; display: inline-block; }
.chapter-no { font-family: var(--serif); color: var(--teal); font-size: 1.1rem; font-weight: 600; }
.chapter-hero h1 { font-size: clamp(2rem, 1.3rem + 2.6vw, 3.2rem); margin: 6px 0 14px; max-width: 22ch; }
.chapter-body { padding-bottom: 48px; }
.chapter-body > * { max-width: var(--measure); }
.notice { background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--teal); border-radius: 0 var(--r-md) var(--r-md) 0; padding: 18px 22px; margin: 24px 0; }
.notice h2 { font-size: 1.15rem; margin-bottom: 6px; }
.chapter-body ul { padding-left: 1.2em; color: var(--ink-2); }
.chapter-body li { margin-bottom: 6px; }
.pager { display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid var(--rule); padding: 20px 0 8px; margin-top: 32px; font-size: .95rem; }
.pager a { text-decoration: none; }
.pager small { display: block; color: var(--ink-3); font-size: .8rem; }

.readout-links { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .92rem; margin: 0 0 14px; }
.assess-list .key { display: inline-block; width: 12px; height: 12px; padding: 0; border-radius: 3px; margin-right: 10px; vertical-align: -1px; cursor: default; }
@media (max-width: 560px) { .readout-week small { display: block; margin: 8px 0 0; } }

/* ======== Multi-page layout (home + menu cards + section pages) ======== */
.nav a[aria-current="page"] { color: var(--ink); background: var(--grid); font-weight: 500; }

/* Home hero */
.hero { padding: 56px 0 48px; }
.hero .synopsis { font-size: 1.08rem; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 28px 0 0; max-width: 760px; }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 14px 16px; display: flex; flex-direction: column-reverse; }
.stat dt { font-size: .82rem; color: var(--ink-3); }
.stat dd { margin: 0 0 2px; font-family: var(--serif); font-size: 1.7rem; font-weight: 600; line-height: 1.1; color: var(--ink); }
.hero-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 16px 0 0; font-size: .88rem; color: var(--ink-3); max-width: 900px; }

/* This-week strip inside "The semester at a glance" */
.readout.strip { display: grid; grid-template-columns: minmax(0, 280px) minmax(0, 1fr); gap: 8px 32px; margin-bottom: 16px; padding: 20px 24px; }
.readout.strip .ro-b { border-left: 1px solid var(--rule); padding-left: 28px; }
.readout.strip .readout-week { font-size: 2.6rem; margin: 10px 0 2px; }
.readout.strip .readout-topic { margin-top: 0; }
@media (max-width: 760px) { .readout.strip { grid-template-columns: minmax(0, 1fr); } .readout.strip .ro-b { border-left: 0; padding-left: 0; border-top: 1px solid var(--rule); padding-top: 12px; } }

/* Menu cards */
.menu-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .menu-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .menu-cards { grid-template-columns: minmax(0, 1fr); } }
.mcard {
  display: flex; flex-direction: column; gap: 8px; min-height: 196px; padding: 22px 22px 18px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; color: var(--ink); text-decoration: none;
  box-shadow: 0 1px 2px rgba(21, 36, 58, .04); transition: transform .18s ease, box-shadow .18s ease;
}
.mcard:hover, .mcard:focus-visible { transform: translateY(-3px); border-color: var(--teal); box-shadow: 0 10px 24px rgba(21, 36, 58, .10); color: var(--ink); }
:root[data-theme="dark"] .mcard:hover, :root[data-theme="dark"] .mcard:focus-visible { box-shadow: 0 10px 24px rgba(0, 0, 0, .35); }
.mc-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--teal-soft); color: var(--teal); margin-bottom: 4px; }
.mc-title { font-family: var(--serif); font-weight: 600; font-size: 1.2rem; line-height: 1.25; }
.mc-desc { color: var(--ink-2); font-size: .93rem; flex: 1; }
.mc-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.mc-badge { font-size: .8rem; font-weight: 500; color: var(--ink-2); background: var(--grid); border-radius: 999px; padding: 3px 10px; }
.mc-go { color: var(--teal); font-size: 1.2rem; transition: transform .18s ease; }
.mcard:hover .mc-go { transform: translateX(4px); }
.mcard.now { background: var(--teal); border-color: var(--teal); color: #fff; }
.mcard.now .mc-icon { background: rgba(255, 255, 255, .16); color: #fff; }
.mcard.now .mc-desc { color: rgba(255, 255, 255, .88); }
.mcard.now .mc-badge { background: rgba(255, 255, 255, .18); color: #fff; }
.mcard.now .mc-go { color: #fff; }
:root[data-theme="dark"] .mcard.now { background: #12403d; border-color: var(--teal); }
@media (prefers-reduced-motion: reduce) { .mcard, .mc-go { transition: none; } .mcard:hover { transform: none; } .mcard:hover .mc-go { transform: none; } }

/* Section pages */
.page-hero { padding-top: 40px; padding-bottom: 8px; }
.page-hero h1 { font-size: clamp(2rem, 1.3rem + 2.4vw, 3rem); margin: 4px 0 10px; }
.page-lead { color: var(--ink-2); font-size: 1.05rem; max-width: var(--measure); }
.page-body { padding: 16px 0 48px; }
.page-tools { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
h2.h3 { font-size: 1.3rem; margin-bottom: 12px; }
.page-body .two-col > div { scroll-margin-top: 80px; }

/* Chapter cards */
.topic-list.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 16px; border-top: 0; }
.topic-list.cards .topic { grid-template-columns: 52px minmax(0, 1fr); background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; padding: 20px; transition: box-shadow .18s ease; }
.topic-list.cards .topic:hover { border-color: var(--teal); box-shadow: 0 8px 20px rgba(21, 36, 58, .08); }
.topic-list.cards .topic .study-toggle { grid-column: 2; justify-self: start; margin-top: 4px; }
.topic-list.cards .topic-empty { grid-column: 1 / -1; }
.readout.strip .readout-week small { display: block; margin: 6px 0 0; }

/* ======== UX additions ======== */
.hero .synopsis { text-align: justify; -webkit-hyphens: auto; hyphens: auto; max-width: 72ch; }
.hero-prog { color: var(--ink-2); font-size: .98rem; font-weight: 500; margin: -6px 0 18px; }

/* One-line "now" note and "continue" link */
.now-note { display: flex; align-items: flex-start; gap: 10px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 12px 16px; margin: 0 0 8px; font-size: .96rem; color: var(--ink-2); }
.now-note .live-dot { flex: none; margin-top: .45em; }
.now-note strong { color: var(--ink); font-weight: 600; }
.now-note .due { color: var(--amber); font-weight: 600; }
.continue-note { font-size: .92rem; color: var(--ink-2); margin: 0 0 14px 4px; }
.continue-note[hidden] { display: none; }
.now-note + .continue-note[hidden] + .scope, .now-note + .scope { margin-top: 14px; }
.week-detail[hidden] { display: none; }

/* Wide Chapters card */
.mcard.wide { grid-column: span 2; }
@media (max-width: 560px) { .mcard.wide { grid-column: auto; } }
.mc-pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 4px; }
.mc-pills .pill { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font: 600 .85rem var(--sans); background: var(--grid); color: var(--ink-3); }
.mc-pills .pill.on { background: var(--teal-soft); color: var(--teal); }

/* Exercise progress on chapter cards */
.ex-prog { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: .84rem; color: var(--ink-3); }
.ex-bar { flex: 0 0 110px; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.ex-bar i { display: block; height: 100%; background: var(--teal); border-radius: 3px; }

/* Back to top */
.to-top {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center;
  background: var(--teal); color: #fff; box-shadow: 0 6px 18px rgba(21, 36, 58, .22);
  opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .2s ease, transform .2s ease;
}
.to-top.show { opacity: .92; pointer-events: auto; transform: none; }
.to-top:hover { opacity: 1; }
:root[data-theme="dark"] .to-top { color: #0e1720; }
@media (min-width: 821px) { .to-top { right: 24px; bottom: 24px; } }

/* Reading progress on chapter pages */
.read-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 70; background: var(--teal); transform-origin: 0 50%; transform: scaleX(0); pointer-events: none; }

/* Header hides while scrolling down on phones, returns on scroll up */
@media (max-width: 820px) {
  .site-header { transition: transform .25s ease; }
  html.hdr-hide .site-header { transform: translateY(-100%); }
  .lab-nav { transition: top .25s ease; }
  html.hdr-hide .lab-nav { top: 0; }
  html.hdr-hide .ex-nav { top: 50px; }
}
@media (prefers-reduced-motion: reduce) { .to-top, .site-header, .lab-nav { transition: none; } }

/* Printing a chapter */
@media print {
  .site-header, .lab-nav, .toc-chips, .pl, .pv-pl, .ex-nav, .to-top, .read-progress, .skip, .code-copy, .tone-host, .crumb,
  .site-footer .foot-logo, .study-toggle, noscript, .ex-actions button[data-reveal], .menu-cards { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .ex-track { display: block !important; height: auto !important; overflow: visible !important; }
  .ex, .circuit, .working, figure, .callout, table { break-inside: avoid; }
  .ex { margin: 12px 0 !important; }
  .scene-scroll, .ckt-wrap, .table-wrap, .scope { overflow: visible !important; }
  .scene, .ckt, .scope svg { min-width: 0 !important; }
  .diagram { position: static !important; }
  a { color: inherit; }
  .lab-group, section.block { padding: 12px 0; }
}

/* Header: keep each menu item on one line; on mid-width screens drop the subtitle to make room */
.nav a { white-space: nowrap; }
@media (min-width: 821px) and (max-width: 980px) { .brand-name { display: none; } .nav a { padding: 6px 8px; } }

/* a week the lecturer changed (schedule.js) */
.chip.upd { background: var(--teal-soft); color: var(--teal); font-weight: 600; }
