/* structure.css -- all layout and behaviour. Colour, type, and spacing come
   entirely from custom properties defined in the theme files. Nothing in this
   file hard-codes a colour or a font: if it does, it is a bug, because it would
   not respond to a theme switch. A few layout elements are gated on properties
   with a fallback (--ruler, --hero-size, --section-rule, --h2-rule) so a
   theme can opt in without touching this file. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-variant-numeric: var(--numeric, normal);
  text-rendering: optimizeLegibility;
}

.wrap { max-width: var(--page-max); margin: 0 auto; padding: 0 var(--gutter); }
.prose { max-width: var(--measure); }

/* ---------- ruler ---------- */
.ruler { display: var(--ruler, none); height: 14px;
  background-image:
    repeating-linear-gradient(90deg, var(--muted) 0 1px, transparent 1px 1ch),
    repeating-linear-gradient(90deg, var(--rule-color) 0 1px, transparent 1px 10ch);
  background-size: 1ch 5px, 10ch 14px;
  background-repeat: repeat-x;
  background-position: left bottom, left bottom; }

/* ---------- navigation header ---------- */
.nav { background: var(--bg-alt);
       border-top: var(--rule) solid var(--rule-color);
       border-bottom: var(--rule) solid var(--rule-color); }
.nav .wrap { display: flex; align-items: stretch; flex-wrap: wrap;
             gap: 0 calc(var(--unit) * 1.5); }
.nav .brand { font-family: var(--font-head); font-weight: var(--head-weight);
              letter-spacing: var(--head-spacing); text-decoration: none;
              color: var(--fg); padding: calc(var(--unit) * 0.7) 0; margin-right: auto; }
.nav .brand:hover { color: var(--accent); }
.nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; }
.nav li a { display: block; font-family: var(--font-head); font-size: var(--fs-base);
            text-transform: var(--nav-transform, none); letter-spacing: var(--head-spacing);
            text-decoration: none; color: var(--fg);
            padding: calc(var(--unit) * 0.8) calc(var(--unit) * 0.7);
            border-bottom: 3px solid transparent; }
.nav li a:hover { color: var(--accent); }
.nav li a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent);
                                 font-weight: var(--head-weight); }
.nav li.ext { margin-left: calc(var(--unit) * 0.6); padding-left: calc(var(--unit) * 0.6);
              border-left: var(--rule) solid var(--rule-faint); }
.nav li.ext a::after { content: " \2197"; color: var(--muted); }

/* ---------- links ---------- */
a { color: var(--link); text-underline-offset: 0.15em;
    text-decoration-thickness: from-font; }
a:visited { color: var(--link-visited, var(--link)); }
a:hover { color: var(--accent); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- hero (home page) ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 320px);
        gap: calc(var(--unit) * 3); align-items: end;
        padding: calc(var(--unit) * 3) 0 calc(var(--unit) * 3.5); }
.hero h1 { font-family: var(--font-head); font-size: var(--hero-size, var(--fs-h1));
           font-weight: var(--head-weight); line-height: 0.95;
           letter-spacing: var(--hero-spacing, var(--head-spacing));
           text-transform: none; margin: 0 0 calc(var(--unit) * 1.5);
           text-wrap: balance; }
.hero h1 a { text-decoration: none; color: inherit; }
.facts { display: grid; grid-template-columns: 8ch minmax(0, 1fr); gap: 0.15rem 2ch;
         margin: 0; max-width: var(--measure); }
.facts dt { color: var(--muted); text-transform: var(--nav-transform, none); }
.facts dd { margin: 0; }
.facts address { font-style: normal; }
.portrait { margin: 0; }
.portrait img { width: 100%; height: auto; display: block;
                border-bottom: var(--rule) solid var(--rule-color); }

/* ---------- sections ---------- */
section { margin: 0 0 calc(var(--unit) * 3); border-top: var(--section-rule, 0);
          padding-top: var(--section-pad, 0); }
h2 { font-family: var(--font-head); font-size: var(--fs-h2);
     font-weight: var(--head-weight); letter-spacing: var(--head-spacing);
     text-transform: var(--head-transform); line-height: var(--lh-head);
     margin: 0 0 var(--unit); padding-bottom: calc(var(--unit) * 0.3);
     border-bottom: var(--h2-rule, var(--rule) solid var(--rule-color)); }
h3 { font-family: var(--font-head); font-size: var(--fs-h3);
     font-weight: var(--head-weight); margin: calc(var(--unit) * 1.5) 0 calc(var(--unit) * 0.4); }
.page-title { font-family: var(--font-head); font-size: var(--fs-h1);
              font-weight: var(--head-weight); line-height: var(--lh-head);
              letter-spacing: var(--head-spacing); text-transform: none;
              margin: calc(var(--unit) * 2) 0 calc(var(--unit) * 0.5); text-wrap: balance; }

/* labelled sections: heading in a left column, content on the right */
.sec { display: grid; grid-template-columns: 14ch minmax(0, 1fr); gap: 0 3ch;
       border-top: var(--rule) solid var(--rule-color);
       padding: calc(var(--unit) * 1.2) 0 calc(var(--unit) * 2.2); margin: 0; }
.sec > h2 { border: 0; padding: 0; margin: 0; }
.sec h2 .sub { display: block; color: var(--muted); font-weight: normal;
               font-size: var(--fs-small); text-transform: none; letter-spacing: 0;
               margin-top: calc(var(--unit) * 0.2); }
.sec h2 .sub time { white-space: nowrap; }
.sec > .prose { margin-top: 0; }

/* ---------- publication list ---------- */
.pubs { list-style: none; margin: 0; padding: 0; }
.pubs > li { display: grid; grid-template-columns: 5ch 4ch minmax(0, 1fr);
             gap: 0 2ch; align-items: baseline;
             padding: calc(var(--unit) * 0.6) 0;
             border-bottom: 1px solid var(--rule-faint); }
.pubs > li:last-child { border-bottom: 0; }
.pub-year { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pub-venue-short { color: var(--accent); font-size: var(--fs-small); white-space: nowrap; }
.pub-body { min-width: 0; }
.pub-title { font-weight: var(--pub-title-weight, 600); }
.pub-title a { text-decoration: none; }
.pub-meta { color: var(--muted); font-size: var(--fs-small);
            margin-top: calc(var(--unit) * 0.15); }
.pub-venue { font-style: var(--venue-style, italic); }
.linkrow { margin-top: calc(var(--unit) * 0.3); font-size: var(--fs-small);
           display: flex; flex-wrap: wrap; gap: 0 calc(var(--unit) * 0.75); }
.linkrow a, .linkrow .disabled {
  font-family: var(--font-mono); font-size: 0.92em;
  text-decoration: none; white-space: nowrap; }
.linkrow a::before { content: var(--bracket-open, "["); }
.linkrow a::after  { content: var(--bracket-close, "]"); }
.linkrow .disabled { color: var(--muted); opacity: 0.6; }

/* abstracts: <details>, so no JavaScript is involved */
.pubs details { margin-top: calc(var(--unit) * 0.4); }
.pubs summary { cursor: pointer; font-size: var(--fs-small);
                font-family: var(--font-mono); color: var(--muted);
                list-style: none; display: inline-block; }
.pubs summary::-webkit-details-marker { display: none; }
.pubs summary::before { content: "[abstract]"; }
.pubs details[open] summary::before { content: "[hide]"; }
.pubs details > p { max-width: var(--measure); margin: calc(var(--unit) * 0.5) 0 0;
                    padding-left: calc(var(--unit) * 0.75);
                    border-left: 2px solid var(--rule-color);
                    color: var(--fg-soft, var(--fg)); }

.status { font-family: var(--font-mono); font-size: 0.82em;
          text-transform: uppercase; letter-spacing: 0.06em;
          color: var(--accent); border: 1px solid var(--rule-color);
          padding: 0.05em 0.4em; border-radius: var(--radius); white-space: nowrap; }
.todo { background: var(--todo-bg, #ffe8a3); color: #5a4300;
        font-family: var(--font-mono); font-size: 0.82em;
        padding: 0.05em 0.4em; border-radius: var(--radius); }

/* ---------- now block ---------- */
.now ul { margin: 0; padding-left: 2ch; max-width: var(--measure); }
.now li { margin: 0 0 calc(var(--unit) * 0.5); }
.now li:last-child { margin-bottom: 0; }

/* ---------- link grid (elsewhere, footer) ---------- */
.links { display: grid; grid-template-columns: repeat(auto-fill, minmax(20ch, 1fr));
         gap: calc(var(--unit) * 0.3) 2ch; margin: 0; padding: 0; list-style: none; }
.links .wide { grid-column: 1 / -1; color: var(--muted); font-size: var(--fs-small);
               margin-top: calc(var(--unit) * 0.5); }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: var(--fs-small);
        font-variant-numeric: var(--numeric, normal); }
th, td { text-align: left; padding: calc(var(--unit) * 0.35) calc(var(--unit) * 0.5);
         border-bottom: 1px solid var(--rule-faint); vertical-align: top; }
th { font-family: var(--font-head); font-weight: var(--head-weight);
     text-transform: var(--head-transform); letter-spacing: var(--head-spacing);
     border-bottom: var(--rule) solid var(--rule-color); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--bg-alt); }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: " \2195"; opacity: 0.35; }
th[aria-sort="ascending"]::after  { content: " \2191"; opacity: 1; }
th[aria-sort="descending"]::after { content: " \2193"; opacity: 1; }

/* ---------- notes ---------- */
.note-header { border-bottom: var(--rule) solid var(--rule-color);
               padding-bottom: var(--unit); margin-bottom: calc(var(--unit) * 1.5); }
.note-header .page-title { margin-top: calc(var(--unit) * 0.5); }
.note-series { font-family: var(--font-mono); font-size: var(--fs-small);
               color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em;
               margin: calc(var(--unit) * 2) 0 0; }
.note-abstract { max-width: var(--measure); background: var(--bg-alt);
                 padding: var(--unit); border-left: 3px solid var(--rule-color);
                 margin: var(--unit) 0 calc(var(--unit) * 2); }
.note-abstract h2 { font-size: var(--fs-small); text-transform: uppercase;
                    letter-spacing: 0.08em; border: 0; margin-bottom: calc(var(--unit) * 0.4); }
.note-body { max-width: var(--measure); }
.note-body h2 { counter-increment: sec; }
.note-body h2::before { content: counter(sec) ".\00a0"; color: var(--muted); }
.note-body { counter-reset: sec; }
.note-body pre { overflow-x: auto; background: var(--bg-alt);
                 padding: var(--unit); font-size: 0.88em;
                 border-left: 3px solid var(--rule-color); }
.note-body code { font-family: var(--font-mono); font-size: 0.92em; }
.note-body blockquote { margin: var(--unit) 0; padding-left: var(--unit);
                        border-left: 3px solid var(--rule-color); color: var(--muted); }
.refs { font-size: var(--fs-small); }
.refs li { margin-bottom: calc(var(--unit) * 0.4); }

/* ---------- software ---------- */
.sw-group { margin-bottom: calc(var(--unit) * 2.5); }
.sw-item { padding: calc(var(--unit) * 0.7) 0; border-bottom: 1px solid var(--rule-faint); }
.sw-name { font-family: var(--font-mono); font-weight: 600; }
.sw-badges { font-size: var(--fs-small); color: var(--muted); }
.sw-install { font-family: var(--font-mono); font-size: 0.85em;
              background: var(--bg-alt); padding: calc(var(--unit) * 0.4);
              overflow-x: auto; white-space: pre; margin-top: calc(var(--unit) * 0.4);
              border-left: 3px solid var(--rule-color); }

/* ---------- footer ---------- */
footer { border-top: var(--rule) solid var(--rule-color);
         margin-top: calc(var(--unit) * 4); padding: calc(var(--unit) * 1.4) 0 calc(var(--unit) * 3);
         font-size: var(--fs-small); color: var(--muted); }
footer .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
               gap: var(--unit) 3ch; }
footer address { font-style: normal; }
footer p { margin: 0; }
footer strong { color: var(--fg); }
footer ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap;
            gap: 0 2ch; }
footer a { color: var(--muted); }
footer .built { margin-top: calc(var(--unit) * 0.8); }

/* ---------- theme switcher (staging only) ---------- */
.themebar { position: sticky; top: 0; z-index: 10; background: var(--bg-alt);
            border-bottom: var(--rule) solid var(--rule-color);
            padding: calc(var(--unit) * 0.4) 0; font-size: var(--fs-small); }
.themebar .wrap { display: flex; flex-wrap: wrap; align-items: center;
                  gap: calc(var(--unit) * 0.4); }
.themebar strong { font-family: var(--font-mono); text-transform: uppercase;
                   letter-spacing: 0.08em; font-size: 0.85em; margin-right: var(--unit); }
.themebar button { font: inherit; font-family: var(--font-mono); font-size: 0.85em;
                   background: var(--bg); color: var(--fg); cursor: pointer;
                   border: 1px solid var(--rule-color); border-radius: var(--radius);
                   padding: 0.15em 0.5em; }
.themebar button[aria-pressed="true"] { background: var(--accent); color: var(--bg);
                                        border-color: var(--accent); }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: var(--gutter); top: 0.5rem; background: var(--bg);
              padding: 0.5em; z-index: 20; }

/* ---------- responsive ---------- */
@media (max-width: 52rem) {
  .hero { grid-template-columns: 1fr; gap: calc(var(--unit) * 2); }
  .portrait { max-width: 280px; }
  .sec { grid-template-columns: 1fr; gap: calc(var(--unit) * 0.6) 0; }
}
@media (max-width: 34rem) {
  :root { --fs-base: 1rem; }
  .nav .wrap { gap: 0 1ch; }
  .nav li a { padding: calc(var(--unit) * 0.6) calc(var(--unit) * 0.5); }
  .hero { padding-top: calc(var(--unit) * 2); }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dt { margin-top: calc(var(--unit) * 0.5); }
  .pubs > li { grid-template-columns: 5ch minmax(0, 1fr); }
  .pub-venue-short { display: none; }
}

/* ---------- print ---------- */
@media print {
  .nav, .themebar, .skip, .linkrow, .ruler, footer .built { display: none; }
  body { background: #fff; color: #000; font-size: 10.5pt; }
  .wrap { max-width: none; padding: 0; }
  a { color: #000; text-decoration: none; }
  .pubs details { display: block; }
  .pubs details > p { border-left: 0; padding-left: 0; }
  .pubs summary { display: none; }
  h2 { break-after: avoid; }
  .pubs > li, .sw-item { break-inside: avoid; }
}
