/* =========================================================
   Hao Ma — shared stylesheet
   Edit here once; every page picks it up.
   ========================================================= */

/* ---------- theme ----------
   Default follows the operating system. A manual choice sets
   data-theme on <html> and wins over the system preference. */

:root,
:root[data-theme="light"] {
  --paper: #FBFCFD;
  --panel: #F2F5F8;
  --ink: #16202B;
  --ink-soft: #5A6B7A;
  --rule: #D6DEE5;
  --chip-bg: #EAF0F4;
  --h1c: #2E6F8E;
  --fig-grid: #E4EAEF;
  --logo-metal-a: #E4E9ED;
  --logo-metal-b: #95A5A6;
  --logo-lab-a: #00549E;
  --logo-lab-b: #002147;
  --logo-line: #2C3E50;
  --logo-wire: #2C3E50;
  --logo-cyan: #00E1D9;
  --logo-sensor: #FFFFFF;
  --logo-dot: #FFFFFF;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #101720;
    --panel: #18212C;
    --ink: #E3E9EE;
    --ink-soft: #93A3B1;
    --rule: #2A3644;
    --chip-bg: #1E2833;
    --h1c: #6FB6D4;
    --fig-grid: #243040;
    --logo-metal-a: #EEF2F5;
    --logo-metal-b: #9AABB6;
    --logo-lab-a: #7CC3E4;
    --logo-lab-b: #3A7FA3;
    --logo-line: #2C3E50;
    --logo-wire: #93A3B1;
    --logo-cyan: #17D8D0;
    --logo-sensor: #FFFFFF;
    --logo-dot: #101720;
  }
}

:root[data-theme="dark"] {
  --paper: #101720;
  --panel: #18212C;
  --ink: #E3E9EE;
  --ink-soft: #93A3B1;
  --rule: #2A3644;
  --chip-bg: #1E2833;
  --h1c: #6FB6D4;
  --fig-grid: #243040;
  --logo-metal-a: #EEF2F5;
  --logo-metal-b: #9AABB6;
  --logo-lab-a: #7CC3E4;
  --logo-lab-b: #3A7FA3;
  --logo-line: #2C3E50;
  --logo-wire: #93A3B1;
  --logo-cyan: #17D8D0;
  --logo-sensor: #FFFFFF;
  --logo-dot: #101720;
}

* { box-sizing: border-box }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 2rem
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 18px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* ---------- layout ---------- */
.wrap {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  grid-template-areas: "nav main";
  gap: 2.6rem;
  max-width: 1250px;
  margin: 0 auto;
  padding: 0 194px 0 1.5rem
}

.rail-l { grid-area: nav }

.main {
  grid-area: main;
  max-width: 720px;
  padding: 3.5rem 0 5rem
}

/* ---------- rails ---------- */
.rail {
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
  padding: 3.5rem 0 2rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12.5px
}

.mark {
  display: block;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: .7rem .8rem;
  margin-bottom: 1.6rem;
  background-image: linear-gradient(var(--fig-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--fig-grid) 1px, transparent 1px);
  background-size: 22px 22px
}

.mark svg { display: block; width: 100%; height: auto }

.rail-label {
  text-transform: uppercase;
  letter-spacing: .13em;
  font-size: 10.5px;
  color: var(--ink-soft);
  margin-bottom: 1.1rem
}

.site-nav { margin-bottom: 0 }

.site-nav .rail-label { display: none }

.site-nav a {
  display: block;
  margin-bottom: .18rem;
  padding: .52rem .75rem;
  font-size: 12.5px;
  letter-spacing: .02em;
  color: var(--ink);
  text-decoration: none;
  background: var(--panel);
  border: none;
  border-radius: 3px;
  line-height: 1.4;
  transition: background .12s ease, color .12s ease
}

.site-nav a:hover { background: var(--chip-bg) }

.site-nav a[aria-current="page"] {
  background: var(--h1c);
  color: var(--paper);
  font-weight: 500
}

.site-nav a.sub {
  margin-left: .9rem;
  padding: .42rem .7rem;
  font-size: 11px;
  color: var(--ink-soft);
  background: none
}

.site-nav a.sub:hover {
  background: var(--panel);
  color: var(--ink)
}

.toc a {
  display: block;
  padding: .44rem 0 .44rem .85rem;
  color: var(--ink-soft);
  text-decoration: none;
  border-left: 2px solid var(--rule);
  line-height: 1.55
}

.toc a:hover { color: var(--ink) }
.toc a.lvl2 { padding-left: 1.7rem }

.toc a.on {
  color: var(--h1c);
  border-left-color: var(--h1c)
}

.site-nav a:focus-visible,
.toc a:focus-visible {
  outline: 2px solid var(--h1c);
  outline-offset: 2px
}

/* ---------- type ---------- */
.eyebrow {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 1.1rem
}

h1 {
  font-family: Fraunces, serif;
  font-weight: 600;
  font-size: 2.55rem;
  line-height: 1.14;
  letter-spacing: -.015em;
  margin: 0 0 .9rem
}

.standfirst {
  color: var(--ink-soft);
  font-size: 1.06rem;
  margin: 0 0 1.4rem
}

.standfirst.solo {
  margin-bottom: 2.4rem;
  padding-bottom: 2.4rem;
  border-bottom: 1px solid var(--rule)
}

h2 {
  font-family: Fraunces, serif;
  font-weight: 600;
  font-size: 1.2rem;
  letter-spacing: -.005em;
  margin: 2.3rem 0 .7rem
}

h3 {
  font-family: Fraunces, serif;
  font-weight: 400;
  font-size: 1.06rem;
  margin: 1.6rem 0 .5rem
}

h2 .num,
h3 .num {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 400;
  color: var(--h1c);
  font-size: .72em;
  margin-right: .6em
}

p { margin: 0 0 .9rem }
a { color: var(--h1c) }

ul { margin: 0 0 .9rem; padding-left: 1.15rem }
li { margin-bottom: .38rem }

/* ---------- contact strip ---------- */
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  margin: 0 0 .6rem;
  padding-bottom: 0
}

.meta span,
.meta a {
  background: var(--chip-bg);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: .22em .6em;
  color: var(--ink-soft);
  text-decoration: none;
  letter-spacing: .02em
}

.meta a { color: var(--h1c) }
.meta a:hover { border-color: var(--h1c) }

.meta .key {
  opacity: .75;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-size: .85em
}

/* ---------- homepage introduction ---------- */
.intro {
  font-size: 1.06rem;
  line-height: 1.72;
  margin-bottom: 2rem
}

.intro p:last-child { margin-bottom: 0 }

/* ---------- note under the homepage feature ---------- */
.feature-note {
  font-size: .92rem;
  line-height: 1.6;
  color: var(--ink-soft);
  margin: -.4rem 0 0
}

.feature-note ul {
  margin: .2rem 0 .5rem;
  padding-left: 1.1rem
}

.feature-note li { margin-bottom: .2rem }

/* ---------- tutorial series list ---------- */
.series {
  display: block;
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  color: inherit
}

.series:first-of-type { padding-top: .2rem }

.series .top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap
}

.series .name {
  font-family: Fraunces, serif;
  font-size: 1.16rem;
  font-weight: 600;
  line-height: 1.3
}

a.series .name { color: var(--h1c) }
a.series:hover .name { text-decoration: underline }

.series .what {
  color: var(--ink-soft);
  font-size: .95em;
  margin-top: .25rem
}

.series.soon .name { color: var(--ink-soft); font-weight: 400 }

/* ---------- homepage feature slot ---------- */
.feature {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.4rem;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--rule);
  border-left: 4px solid var(--h1c);
  border-radius: 0 5px 5px 0;
  background: var(--panel);
  padding: 1.15rem 1.3rem;
  margin: 0 0 1.4rem;
  text-decoration: none;
  color: inherit;
  transition: border-color .15s ease, background .15s ease, transform .15s ease
}

.feature:hover {
  border-color: var(--h1c);
  background: var(--chip-bg);
  transform: translateX(2px)
}

.feature:focus-visible {
  outline: 2px solid var(--h1c);
  outline-offset: 3px
}

.feature .kicker {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-soft)
}

.feature .name {
  font-family: Fraunces, serif;
  font-size: 1.42rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--h1c);
  margin: .35rem 0 .3rem
}

.feature:hover .name { text-decoration: underline }

.feature .go {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--ink-soft)
}

.feature .arrow {
  justify-self: end;
  width: 2.1rem;
  height: 2.1rem;
  border: 1px solid var(--h1c);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 15px;
  color: var(--h1c);
  transition: transform .15s ease, background .15s ease
}

.feature:hover .arrow {
  transform: translateX(3px);
  background: var(--h1c);
  color: var(--paper)
}

@media (prefers-reduced-motion: reduce) {
  .feature,
  .feature .arrow { transition: none }

  .feature:hover,
  .feature:hover .arrow { transform: none }
}


/* ---------- contents, top right: always visible, deliberately quiet ---------- */
.toc-panel {
  position: fixed;
  top: 3.5rem;
  right: 1.25rem;
  width: 152px;
  z-index: 15;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px
}

.toc-panel .rail-label {
  font-size: 9.5px;
  letter-spacing: .14em;
  margin-bottom: .5rem;
  opacity: .8
}

.toc-panel .toc a {
  padding: .26rem 0 .26rem .6rem;
  font-size: 11px;
  line-height: 1.45;
  border-left-width: 1px
}

/* ---------- theme switch ---------- */
.theme-toggle {
  position: fixed;
  top: 1.15rem;
  right: 1.25rem;
  z-index: 20;
  width: 54px;
  height: 27px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--chip-bg);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease
}

.theme-toggle:hover { border-color: var(--h1c) }

.theme-toggle:focus-visible {
  outline: 2px solid var(--h1c);
  outline-offset: 3px
}

.theme-toggle .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s ease
}

.theme-toggle[aria-checked="true"] .knob { transform: translateX(27px) }

.theme-toggle .knob svg {
  width: 12px;
  height: 12px;
  display: block
}

.theme-toggle .knob .moon { display: none }
.theme-toggle[aria-checked="true"] .knob .sun { display: none }
.theme-toggle[aria-checked="true"] .knob .moon { display: block }

@media (prefers-reduced-motion: reduce) {
  .theme-toggle .knob { transition: none }
}

@media (max-width: 1040px) {
  .theme-toggle {
    top: .8rem;
    right: .9rem
  }
}

/* ---------- chips ---------- */
.chip {
  font-family: "IBM Plex Mono", monospace;
  font-size: .74em;
  white-space: nowrap;
  background: var(--chip-bg);
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: .12em .45em;
  letter-spacing: .02em;
  vertical-align: .08em
}

.chip.hot {
  color: var(--h1c);
  border-color: var(--h1c)
}

/* ---------- collapsible cards ---------- */
details.card {
  background: var(--panel);
  border-left: 3px solid var(--h1c);
  border-radius: 0 4px 4px 0;
  margin: 1.2rem 0
}

details.card > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: .95rem 1.3rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--h1c)
}

details.card > summary::-webkit-details-marker { display: none }

details.card > summary::after {
  content: "+";
  font-size: 15px;
  color: var(--ink-soft)
}

details.card[open] > summary::after { content: "−" }

details.card > summary:focus-visible {
  outline: 2px solid var(--h1c);
  outline-offset: -2px
}

.card-body {
  padding: 0 1.3rem 1.1rem;
  font-size: .96em
}

.card-body > *:first-child { margin-top: 0 }

h4, .card-body h4 {
  font-family: Fraunces, serif;
  font-weight: 600;
  font-size: 1.02rem;
  margin: 1.5rem 0 .5rem
}

/* ---------- callout ---------- */
.note-box {
  border-left: 3px solid var(--h1c);
  border-radius: 0 4px 4px 0;
  background: var(--panel);
  padding: 1rem 1.2rem;
  margin: 1.8rem 0;
  font-size: .95em
}

.note-box b {
  display: block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--h1c);
  margin-bottom: .3rem
}

.note-box > *:last-child { margin-bottom: 0 }

/* ---------- entries ---------- */
.entry {
  padding: .8rem 0;
  border-bottom: 1px solid var(--rule)
}

.entry .top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap
}

.entry .what { font-weight: 600 }
.entry .where, .entry .note { color: var(--ink-soft) }

.entry .note {
  font-size: .94em;
  margin-top: .3rem
}

/* ---------- publication list ---------- */
.pubs {
  list-style: none;
  margin: 0;
  padding: 0
}

.pubs li {
  display: grid;
  grid-template-columns: 3.6rem minmax(0, 1fr);
  gap: 1rem;
  padding: .75rem 0;
  border-bottom: 1px solid var(--rule);
  font-size: .96em
}

.pubs .yr {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--ink-soft);
  padding-top: .35rem
}

.pubs .ttl { font-weight: 600 }

.pubs .src {
  display: block;
  color: var(--ink-soft);
  font-size: .93em;
  margin-top: .15rem
}

/* ---------- course table ---------- */
table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.4rem 0;
  font-size: .92em
}

th, td {
  border-bottom: 1px solid var(--rule);
  padding: .55rem .7rem .55rem 0;
  text-align: left;
  vertical-align: top
}

th {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-soft)
}

/* ---------- footer ---------- */
footer {
  margin-top: 5rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--rule);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11.5px;
  line-height: 1.9;
  color: var(--ink-soft)
}

footer a { color: var(--ink-soft) }

/* ---------- responsive ---------- */
@media (max-width: 1040px) {
  .wrap {
    grid-template-columns: 1fr;
    grid-template-areas: "nav" "toc" "main";
    gap: 0;
    padding: 0 1.5rem
  }

  .rail {
    position: static;
    max-height: none;
    overflow: visible
  }

  .toc-panel {
    position: static;
    width: auto;
    grid-area: toc;
    padding-bottom: 1.4rem;
    border-bottom: 1px solid var(--rule)
  }

  .wrap.no-toc .rail-l { border-bottom: 1px solid var(--rule) }

  .toc-panel { font-size: 12.5px }

  .toc-panel .rail-label {
    font-size: 10.5px;
    margin-bottom: 1.1rem
  }

  .toc-panel .toc a {
    padding: .44rem 0 .44rem .85rem;
    font-size: 12.5px;
    line-height: 1.55;
    border-left-width: 2px
  }

  .rail-l { padding: 2rem 0 1.4rem }

  .rail-r {
    padding: 0 0 1.4rem;
    border-bottom: 1px solid var(--rule)
  }

  .mark {
    max-width: 168px;
    margin-bottom: 1.1rem
  }

  .ident {
    margin-top: 1rem;
    padding-bottom: 1.1rem
  }

  .site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-bottom: 0
  }

  .site-nav a {
    margin-bottom: 0;
    padding: .32rem .68rem
  }

  .site-nav a.sub {
    margin-left: 0;
    padding: .32rem .68rem;
    background: var(--panel)
  }

  .toc {
    columns: 2;
    column-gap: 1.2rem
  }

  .toc .rail-label {
    column-span: all;
    margin-top: 1.4rem
  }

  .main { padding-top: 2rem }
}

@media (max-width: 700px) {
  h1 { font-size: 2rem }
  body { font-size: 17px }

  .toc { columns: 1 }

  .pubs li {
    grid-template-columns: 1fr;
    gap: .2rem
  }
}


/* ---------- identity block in the left rail ---------- */
.ident {
  margin-top: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--rule)
}

.ident .who {
  display: block;
  font-family: Fraunces, serif;
  font-size: 1.18rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.01em;
  color: var(--ink);
  text-decoration: none;
  margin: 0 0 .35rem
}

.ident .who:hover { color: var(--h1c) }

.ident .line {
  display: block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11.5px;
  line-height: 2.05;
  color: var(--ink-soft)
}

.ident a.line { color: var(--h1c); text-decoration: none }
.ident a.line:hover { text-decoration: underline }

.ident .aff {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  line-height: 1.7;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: .7rem
}

.main > h2:first-child { margin-top: 0 }
