/* ============================================================
   wiki.css — textbook-style wiki for Biocircuits Explorer
   Three-column layout inspired by Quarto book templates.
   ============================================================ */

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

:root {
  --ink: #1a1d24;
  --ink-2: #2a2d34;
  --muted: #5a6170;
  --muted-2: #8a909c;
  --line: #e6e9ef;
  --line-soft: #eef1f6;
  --paper: #ffffff;
  --paper-2: #f7f8fa;
  --paper-3: #f1f3f7;
  --accent: #1f74f9;
  --accent-deep: #0b55d1;
  --accent-soft: #eaf1ff;
  --warn: #b96b1b;
  --warn-soft: #fff4e3;
  --code-bg: #f5f6f9;
  --code-border: #e6e9ef;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --t: 220ms;
  --sidebar-w: 280px;
  --margin-w: 230px;
  --content-max: 760px;
  --radius: 10px;
  --radius-lg: 16px;
}

html {
  scroll-behavior: smooth;
  color-scheme: light;
}

body {
  margin: 0;
  /* overflow-x: clip prevents horizontal overflow without turning the body
     into a scroll container — `overflow-x: hidden` would do the latter and
     break `position: sticky` on the wiki sidebars. */
  overflow-x: clip;
  background: var(--paper);
  color: var(--ink);
  font-family: "Inter", "Helvetica Neue", Helvetica, Arial, "PingFang SC",
    "PingFang TC", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.7;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
}

a {
  color: var(--accent-deep);
  text-decoration: none;
  transition: color var(--t) var(--ease);
}

a:hover {
  color: var(--accent);
}

img,
video {
  display: block;
  max-width: 100%;
  height: auto;
}

/* ---------- Top bar (sticky) ---------- */
.wiki-topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 56px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(150%) blur(12px);
  -webkit-backdrop-filter: saturate(150%) blur(12px);
}

.wiki-brand {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.wiki-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.wiki-breadcrumb a {
  color: var(--muted);
}

.wiki-breadcrumb a:hover {
  color: var(--ink);
}

.wiki-breadcrumb .sep {
  color: var(--muted-2);
}

.wiki-topnav {
  margin-left: auto;
  display: flex;
  gap: 20px;
  font-size: 13px;
  color: var(--muted);
}

.wiki-topnav a:hover {
  color: var(--ink);
}

.wiki-topnav .cta {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 600;
}

.wiki-topnav .cta:hover {
  background: var(--ink-2);
  color: #ffffff;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.lang-switch a {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 10px;
  color: var(--muted);
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}

.lang-switch a + a {
  border-left: 1px solid var(--line);
}

.lang-switch a:hover {
  color: var(--ink);
  background: var(--paper-2);
}

.lang-switch a.active {
  background: var(--ink);
  color: #ffffff;
}

/* ---------- Main layout (three columns) ---------- */
.wiki-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--margin-w);
  align-items: start;
  max-width: 1380px;
  margin: 0 auto;
  padding: 0 24px;
}

.wiki-shell > * {
  min-width: 0;
}

.wiki-sidebar {
  position: sticky;
  top: 56px;
  align-self: start;
  max-height: calc(100vh - 56px);
  overflow-y: auto;
  padding: 32px 16px 48px 0;
  border-right: 1px solid var(--line-soft);
  font-size: 14px;
}

.wiki-sidebar h4 {
  margin: 0 0 12px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.wiki-sidebar ol,
.wiki-sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.wiki-sidebar > ol > li {
  margin: 0;
}

.wiki-sidebar > ol > li > a {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--ink-2);
  font-weight: 500;
  line-height: 1.45;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}

.wiki-sidebar > ol > li > a:hover {
  background: var(--paper-3);
  color: var(--ink);
}

.wiki-sidebar > ol > li > a .num {
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.wiki-sidebar ol ol {
  margin: 2px 0 8px 12px;
  border-left: 1px solid var(--line-soft);
}

.wiki-sidebar ol ol li a {
  display: block;
  padding: 4px 12px;
  margin-left: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  border-radius: 6px;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}

.wiki-sidebar ol ol li a:hover {
  background: var(--paper-3);
  color: var(--ink);
}

/* ---------- Main content column ---------- */
.wiki-content {
  padding: 48px 56px 96px;
  max-width: 920px;
  min-width: 0;
}

.wiki-title-block {
  margin: 0 0 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--line);
}

.wiki-title-block .eyebrow {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.wiki-title-block h1 {
  margin: 0;
  font-size: clamp(34px, 4.2vw, 48px);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.wiki-title-block .subtitle {
  margin: 16px 0 0;
  max-width: 680px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.65;
}

.wiki-content section {
  scroll-margin-top: 80px;
}

.wiki-content h2 {
  margin: 64px 0 16px;
  padding-top: 4px;
  font-size: clamp(24px, 2.4vw, 30px);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.wiki-content h3 {
  margin: 36px 0 12px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.wiki-content h4 {
  margin: 24px 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.005em;
}

.wiki-content h2 .sec-num,
.wiki-content h3 .sec-num {
  color: var(--muted-2);
  font-weight: 500;
  margin-right: 10px;
  font-variant-numeric: tabular-nums;
}

.wiki-content p {
  margin: 0 0 16px;
  color: var(--ink-2);
  font-size: 16px;
  line-height: 1.75;
}

.wiki-content ul,
.wiki-content ol {
  margin: 0 0 18px;
  padding-left: 24px;
  color: var(--ink-2);
  font-size: 16px;
  line-height: 1.7;
}

.wiki-content li {
  margin-bottom: 6px;
}

.wiki-content ul li::marker {
  color: var(--muted-2);
}

.wiki-content strong {
  color: var(--ink);
}

.wiki-content code {
  font-family: "SF Mono", "JetBrains Mono", "Menlo", ui-monospace, monospace;
  font-size: 0.92em;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  color: var(--ink);
}

.wiki-content pre {
  margin: 18px 0 24px;
  padding: 18px 20px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.55;
}

.wiki-content pre code {
  background: transparent;
  border: 0;
  padding: 0;
  font-size: inherit;
}

/* ---------- Tables / reference grids ---------- */
.wiki-table-wrap {
  margin: 18px 0 26px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.wiki-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.55;
}

.wiki-table th,
.wiki-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
  text-align: left;
}

.wiki-table th {
  background: var(--paper-2);
  color: var(--ink);
  font-weight: 600;
}

.wiki-table tr:last-child td {
  border-bottom: 0;
}

.wiki-table td {
  color: var(--ink-2);
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 22px 0 26px;
}

.reference-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: var(--paper);
}

.reference-card h4 {
  margin-top: 0;
}

.reference-card p:last-child,
.reference-card ul:last-child {
  margin-bottom: 0;
}

/* ---------- Callouts ---------- */
.callout {
  margin: 24px 0;
  padding: 18px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--paper-2);
}

.callout .callout-head {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.callout p:last-child {
  margin-bottom: 0;
}

.callout-tip {
  background: var(--accent-soft);
  border-color: #d1e0ff;
}

.callout-tip .callout-head {
  color: var(--accent-deep);
}

.callout-note {
  background: var(--paper-2);
  border-color: var(--line);
}

.callout-warning {
  background: var(--warn-soft);
  border-color: #f3d9a9;
}

.callout-warning .callout-head {
  color: var(--warn);
}

/* ---------- Figures ---------- */
.wiki-figure {
  margin: 28px 0;
  text-align: center;
}

.wiki-figure img,
.wiki-figure video {
  margin: 0 auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--paper-2);
  max-height: 460px;
  object-fit: contain;
}

.wiki-figure figcaption {
  margin: 12px auto 0;
  max-width: 640px;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.55;
}

.wiki-figure figcaption .fig-label {
  color: var(--ink);
  font-weight: 600;
  margin-right: 6px;
}

/* ---------- Equations ---------- */
mjx-container[display="true"] {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  margin: 18px 0 22px !important;
  padding-bottom: 2px;
}

mjx-container[display="true"] svg {
  max-width: 100% !important;
  height: auto;
}

/* ---------- Definition list / glossary ---------- */
.wiki-content dl {
  margin: 18px 0 24px;
  display: grid;
  grid-template-columns: minmax(140px, max-content) 1fr;
  column-gap: 24px;
  row-gap: 12px;
}

.wiki-content dt {
  font-weight: 600;
  color: var(--ink);
}

.wiki-content dd {
  margin: 0;
  color: var(--ink-2);
}

/* ---------- Step list (numbered recipe) ---------- */
.step-list {
  list-style: none;
  padding: 0;
  margin: 24px 0;
  counter-reset: step;
}

.step-list li {
  position: relative;
  margin: 0 0 18px;
  padding: 18px 20px 18px 64px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  counter-increment: step;
}

.step-list li::before {
  content: counter(step);
  position: absolute;
  top: 18px;
  left: 18px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--ink);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "SF Mono", "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 600;
}

.step-list h4 {
  margin: 0 0 6px;
  font-size: 15.5px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.005em;
}

.step-list p {
  margin: 0 0 6px;
  font-size: 15px;
}

.step-list p:last-child {
  margin-bottom: 0;
}

/* ---------- Wire diagram (inline flow) ---------- */
.flow-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 14px 0 22px;
  padding: 14px 16px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: "SF Mono", "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  color: var(--ink-2);
}

.flow-line .node {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
}

.flow-line .arrow {
  color: var(--muted-2);
}

/* ---------- Right margin TOC ---------- */
.wiki-margin {
  position: sticky;
  top: 56px;
  align-self: start;
  max-height: calc(100vh - 56px);
  overflow-y: auto;
  padding: 56px 0 48px 28px;
  font-size: 13px;
  color: var(--muted);
}

.wiki-margin h4 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.wiki-margin ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--line-soft);
}

.wiki-margin li a {
  display: block;
  padding: 4px 12px;
  color: var(--muted);
  line-height: 1.45;
  border-left: 2px solid transparent;
  margin-left: -1px;
  transition: color var(--t) var(--ease), border-color var(--t) var(--ease);
}

.wiki-margin li a:hover {
  color: var(--ink);
  border-left-color: var(--accent);
}

.wiki-margin li a.active {
  color: var(--ink);
  border-left-color: var(--accent);
  font-weight: 500;
}

.wiki-margin li.lvl-3 a {
  padding-left: 24px;
  font-size: 12.5px;
}

/* ---------- Footer / page nav ---------- */
.wiki-pagenav {
  margin: 64px 0 0;
  padding: 32px 0 16px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 14px;
}

.wiki-pagenav a {
  color: var(--muted);
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
}

.wiki-pagenav a span.label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.wiki-pagenav a span.title {
  color: var(--ink);
  font-weight: 600;
}

.wiki-pagenav a:hover span.title {
  color: var(--accent);
}

.wiki-footer-strip {
  margin-top: 24px;
  padding: 24px 0 0;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .wiki-shell {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  .wiki-margin {
    display: none;
  }

  .wiki-content {
    padding: 40px 40px 80px;
  }
}

@media (max-width: 880px) {
  .wiki-shell {
    grid-template-columns: 1fr;
    padding: 0 16px;
  }

  .wiki-sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    padding: 18px 0 12px;
  }

  .wiki-content {
    padding: 28px 0 64px;
    max-width: 100%;
  }

  .wiki-topbar {
    padding: 0 16px;
    gap: 10px;
  }

  .wiki-topnav {
    display: none;
  }

  .wiki-breadcrumb {
    display: none;
  }

  .step-list li {
    padding: 16px 16px 16px 56px;
  }

  .wiki-content dl {
    display: block;
  }

  .wiki-content dt {
    margin-top: 14px;
  }

  .reference-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
