/* ===== Φ / Φ* project wiki — self-contained ===== */
:root {
  --bg: #ffffff;
  --bg-alt: #f7f8fa;
  --bg-card: #ffffff;
  --fg: #16191d;
  --fg-muted: #5b6472;
  --border: #dfe3e9;
  --border-soft: #edf0f4;
  --accent: #0b6e81;
  --accent-soft: #e6f2f4;
  --code-bg: #f2f4f7;
  --serif: Georgia, "Times New Roman", Times, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215; --bg-alt: #151a20; --bg-card: #161c22;
    --fg: #e7ecf2; --fg-muted: #9aa7b6;
    --border: #29323c; --border-soft: #1f262e;
    --accent: #5cbccd; --accent-soft: #12262c;
    --code-bg: #1b2229;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 70px; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--sans); font-size: 16px; line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); background: var(--code-bg);
  padding: .1em .36em; border-radius: 4px; font-size: .86em; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 60;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: .55rem 1.25rem;
  display: flex; align-items: center; gap: .75rem;
}
.topbar .title {
  font-family: var(--serif); font-weight: 700; font-size: 1.02rem;
  letter-spacing: -.01em; margin-right: auto;
}
.topbar .title span { color: var(--fg-muted); font-weight: 400; font-size: .82rem;
  font-family: var(--sans); margin-left: .5rem; }
.icon-link { color: var(--fg-muted); display: inline-flex; }
.icon-link:hover { color: var(--accent); }
.toc-toggle {
  display: none; background: none; border: 1px solid var(--border);
  color: var(--fg); border-radius: 6px; padding: .3rem .6rem;
  font-size: .8rem; cursor: pointer;
}

/* ---------- layout ---------- */
.layout {
  max-width: 1240px; margin: 0 auto; padding: 0 1.25rem;
  display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 2.75rem;
  align-items: start;
}

/* ---------- sidebar contents ---------- */
.sidebar {
  position: sticky; top: 62px; align-self: start;
  max-height: calc(100vh - 80px); overflow-y: auto;
  padding: 1.5rem 0 2rem; font-size: .84rem;
  border-right: 1px solid var(--border-soft);
}
.sidebar h2 {
  font-family: var(--sans); font-size: .68rem; text-transform: uppercase;
  letter-spacing: .11em; color: var(--fg-muted); margin: 0 0 .7rem;
  border: none; padding: 0;
}
.sidebar ol { list-style: none; margin: 0; padding: 0; counter-reset: sec; }
.sidebar > ol > li { counter-increment: sec; margin-bottom: .1rem; }
.sidebar > ol > li > a::before {
  content: counter(sec) ". "; color: var(--fg-muted); font-variant-numeric: tabular-nums;
}
.sidebar a {
  display: block; padding: .22rem .5rem .22rem .55rem;
  color: var(--fg-muted); border-left: 2px solid transparent; border-radius: 0 4px 4px 0;
}
.sidebar a:hover { color: var(--accent); background: var(--bg-alt); text-decoration: none; }
.sidebar a.active { color: var(--accent); border-left-color: var(--accent);
  background: var(--accent-soft); font-weight: 600; }
.sidebar ol ol { margin: 0 0 .3rem .85rem; counter-reset: sub; }
.sidebar ol ol li { counter-increment: sub; }
.sidebar ol ol a { font-size: .8rem; padding-top: .12rem; padding-bottom: .12rem; }

/* ---------- article ---------- */
.content { padding: 1.9rem 0 3rem; min-width: 0; }
.page-title {
  font-family: var(--serif); font-size: clamp(1.9rem, 4vw, 2.5rem);
  line-height: 1.2; letter-spacing: -.015em; margin: 0 0 .35rem;
}
.page-sub {
  color: var(--fg-muted); font-size: .92rem; padding-bottom: 1rem;
  border-bottom: 1px solid var(--border); margin-bottom: 1.6rem;
}
section { scroll-margin-top: 70px; }
h2 {
  font-family: var(--serif); font-size: 1.6rem; font-weight: 700;
  letter-spacing: -.01em; margin: 2.8rem 0 .8rem; padding-bottom: .3rem;
  border-bottom: 1px solid var(--border);
}
h3 { font-family: var(--serif); font-size: 1.16rem; margin: 1.9rem 0 .4rem; }
h2 .num, h3 .num { color: var(--fg-muted); font-weight: 400; margin-right: .45rem; }
p { margin: .75rem 0; }
ul, ol.body { margin: .75rem 0; padding-left: 1.3rem; }
li { margin: .3rem 0; }

/* ---------- infobox ---------- */
.infobox {
  float: right; width: 290px; margin: .2rem 0 1.2rem 1.6rem;
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: 8px; font-size: .82rem; overflow: hidden;
}
.infobox .ib-head {
  background: var(--accent-soft); padding: .55rem .8rem; font-weight: 700;
  font-family: var(--serif); font-size: .95rem;
  border-bottom: 1px solid var(--border);
}
.infobox dl { margin: 0; padding: .5rem .8rem .7rem; }
.infobox dt { color: var(--fg-muted); font-size: .72rem; text-transform: uppercase;
  letter-spacing: .06em; margin-top: .55rem; }
.infobox dd { margin: .1rem 0 0; }
@media (max-width: 720px) { .infobox { float: none; width: 100%; margin: 1rem 0; } }

/* ---------- callout ---------- */
.note {
  background: var(--bg-alt); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 6px;
  padding: .8rem 1rem; margin: 1.3rem 0; font-size: .9rem;
}

/* ---------- figures ---------- */
figure {
  margin: 1.5rem 0; padding: .75rem; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 8px;
}
figure img { border-radius: 4px; background: #fff; }
/* Tall diagrams (e.g. vertical flowcharts) would otherwise render metres high at
   full content width; cap them by height and centre. Click to view full size. */
figure.fig-tall img { max-height: 680px; width: auto; margin-left: auto; margin-right: auto; }
figure.fig-tall a { display: block; }
figcaption { font-size: .82rem; color: var(--fg-muted); margin-top: .6rem; line-height: 1.55; }
figcaption .fnum { font-weight: 700; color: var(--fg); }
.grid2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }
.grid3 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
.grid2 figure, .grid3 figure { margin: 0; }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; margin: 1.2rem 0; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; min-width: 500px; }
caption { caption-side: top; text-align: left; font-size: .82rem;
  color: var(--fg-muted); padding-bottom: .45rem; }
caption .fnum { font-weight: 700; color: var(--fg); }
th, td { text-align: left; padding: .5rem .65rem; border: 1px solid var(--border); vertical-align: top; }
thead th { background: var(--bg-alt); font-weight: 700; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- contact form ---------- */
.form { max-width: 560px; margin: 1.2rem 0; }
.field { margin-bottom: .85rem; }
.field label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: .28rem; }
.field input, .field textarea {
  width: 100%; padding: .55rem .7rem; font: inherit; font-size: .9rem;
  color: var(--fg); background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 6px;
}
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { min-height: 120px; resize: vertical; }
.btn {
  display: inline-block; padding: .55rem 1.1rem; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font: inherit; font-size: .88rem;
  font-weight: 600; cursor: pointer;
}
.btn:hover { opacity: .9; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.form-status { margin-top: .7rem; font-size: .86rem; min-height: 1.3em; }
.form-status.ok { color: #1a7f4b; }
.form-status.err { color: #c0392b; }
@media (prefers-color-scheme: dark) {
  .form-status.ok { color: #57c98a; }
  .form-status.err { color: #ef8b7f; }
}

/* ---------- footer ---------- */
footer { border-top: 1px solid var(--border); margin-top: 2.5rem; padding: 1.4rem 0; }
.footer-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.copyright { color: var(--fg-muted); font-size: .82rem; }
.socials { display: flex; align-items: center; gap: 1rem; }
footer a { color: var(--fg-muted); display: inline-flex; }
footer a:hover { color: var(--accent); }
@media (max-width: 560px) { .footer-inner { justify-content: center; } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 0; }
  .toc-toggle { display: inline-block; }
  .sidebar {
    position: static; max-height: none; border-right: none;
    border-bottom: 1px solid var(--border); padding: 1rem 0;
  }
  .sidebar[hidden] { display: none; }
  .content { padding-top: 1.4rem; }
}
