:root {
  --bg: #f5f9fc;
  --panel: #e7f1f8;
  --card: #ffffff;
  --text: #14202b;
  --dim: #5d6f7c;
  --accent: #1668b8;
  --accent-2: #0d597f;
  --border: #cfdfea;
  --code-bg: #eef5fa;
  --flag: #c2410c;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre.code { font-family: var(--mono); }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  flex: 0 0 236px;
  width: 236px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 26px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sidebar .brand a { font-family: var(--mono); color: var(--accent-2); font-weight: 600; font-size: 15px; }
.sidebar .toc { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.sidebar .toc a {
  color: var(--text);
  padding: 3px 8px;
  border-radius: 3px;
  border-left: 2px solid transparent;
}
.sidebar .toc a:hover { background: #dceaf4; text-decoration: none; }
.sidebar .toc a[aria-current="page"] {
  color: var(--accent-2);
  font-weight: 600;
  border-left-color: var(--accent-2);
  background: #dceaf4;
}
.sidebar .toc-group { display: flex; flex-direction: column; gap: 2px; margin: 6px 0; }
.sidebar .toc-label {
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.03em;
  padding: 4px 8px 2px;
}
.sidebar .toc-group a { padding-left: 18px; }
.sidebar .side-footer { margin-top: auto; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.sidebar .side-footer .muted { color: var(--dim); }

.doc {
  flex: 1;
  max-width: 760px;
  padding: 44px 56px 80px;
}

/* ---------- doc body ---------- */
.doc h1 { font-size: 23px; margin: 0 0 6px; color: var(--accent-2); font-weight: 650; }
.doc h2 {
  font-size: 16px;
  margin: 26px 0 12px;
  color: var(--accent-2);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
.tag { color: var(--dim); margin: 0 0 18px; }
.intro { max-width: 62ch; }
.lead { color: var(--dim); margin: 0 0 24px; }
.dim { color: var(--dim); }

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent-2);
  border: 1px solid var(--accent-2);
  border-radius: 3px;
  padding: 1px 8px;
  margin: 0 0 8px;
}
.actions { margin: 8px 0; }

ul.teaser { list-style: none; padding: 0; }
ul.teaser li { margin: 6px 0; }

pre.code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
}

/* details */
details { border-top: 1px solid var(--border); padding: 8px 0; margin-top: 8px; }
details summary { cursor: pointer; list-style: none; color: var(--accent); }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "+ "; font-family: var(--mono); }
details[open] summary::before { content: "\2212 "; }
.draft { color: var(--dim); }

/* photos */
figure.photo {
  margin: 14px 0;
  max-width: 300px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px;
}
figure.photo.wide { max-width: 360px; }
figure.photo .photo-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  padding: 2px 2px 6px;
}
figure.photo img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 2px;
  filter: saturate(0.92) contrast(1.02);
}

/* iv plot */
.ivplot {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  margin: 12px 0;
}
.surface3d { width: 100%; height: 440px; }
.ivplot svg { width: 100%; height: auto; display: block; }
.ivplot .axis { stroke: var(--border); stroke-width: 1; }
.ivplot .tick { fill: var(--dim); font-size: 10px; font-family: var(--mono); }
.ivplot path.fit { fill: none; stroke: var(--accent); stroke-width: 2; }
.ivplot circle.mkt { fill: var(--accent-2); }
.ivplot circle.mis { fill: var(--flag); stroke: var(--flag); }
.ivplot .legend { fill: var(--dim); font-size: 11px; font-family: var(--mono); }
.ivplot .caption { color: var(--dim); font-size: 12.5px; margin: 6px 0 0; }

/* placeholders (visible while drafting) */
.todo {
  color: var(--flag);
  border: 1px dashed var(--flag);
  border-radius: 3px;
  padding: 1px 8px;
  font-size: 13px;
  display: inline-block;
}

/* pager */
.pager {
  display: flex;
  justify-content: space-between;
  margin-top: 48px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  font-size: 13.5px;
}

/* dig: excavate the math (scattered, in-place reveals) */
.dig-field { position: relative; margin-top: 12px; }
.dig-card {
  position: fixed; z-index: 40; width: 272px; max-width: 82vw;
  background: var(--card); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 6px; padding: 10px 13px; box-shadow: 0 2px 10px rgba(13,89,127,.08);
  animation: digpop .22s ease both;
}
@keyframes digpop { from { opacity: 0; transform: translateY(5px) scale(.98); } to { opacity: 1; transform: none; } }
.dig-title { font-weight: 600; color: var(--accent-2); }
.dig-body { margin: 4px 0 6px; font-size: 14px; }
.math { margin: 6px 0 0; overflow-x: auto; overflow-y: hidden; font-size: 13.5px; }
.math .katex-display { margin: .4em 0; text-align: left; overflow-x: auto; overflow-y: hidden; }
.refs { font-size: 13px; color: var(--dim); padding-left: 18px; margin: 8px 0 0; }
.refs li { margin: 5px 0; }
.dig-unlock {
  position: fixed; z-index: 45; width: 44px; height: 44px; padding: 0; cursor: pointer;
  background: #fff; border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 2px 9px rgba(13,89,127,.14);
  display: flex; align-items: center; justify-content: center;
  animation: digpulse 2s ease-in-out infinite; transition: transform .12s;
}
.dig-unlock:hover { transform: scale(1.12); border-color: var(--accent); }
.dig-unlock:active { transform: scale(.96); }
.shovel { display: inline-flex; line-height: 0; }
.shovel svg { display: block; }
@keyframes digpulse {
  0%, 100% { box-shadow: 0 2px 9px rgba(13,89,127,.14); }
  50% { box-shadow: 0 0 0 5px rgba(22,104,184,.10), 0 2px 11px rgba(13,89,127,.2); }
}
@media (max-width: 1024px) {
  .dig-card { position: static; width: auto; max-width: none; margin: 10px 0; }
  .dig-unlock { position: static; margin: 12px 0; }
}

/* voice setup */
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.preset {
  font-family: var(--sans); font-size: 13px; cursor: pointer;
  background: #eef5fa; border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 12px; color: var(--accent-2);
}
.preset:hover { background: #dceaf4; }
.agents { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 8px 0; }
.agent { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--dim); }
.agent textarea {
  font-family: var(--mono); font-size: 12.5px; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: 4px;
  padding: 8px; min-height: 92px; resize: vertical; line-height: 1.5; width: 100%;
}
.start {
  font-family: var(--sans); font-size: 14px; margin-top: 6px;
  padding: 6px 16px; border-radius: 4px; border: 1px solid var(--border);
  background: #dceaf4; color: var(--accent-2); cursor: pointer;
}
.start[disabled] { opacity: .55; cursor: not-allowed; }
.small { font-size: 12.5px; margin-top: 6px; }
@media (max-width: 600px) { .agents { grid-template-columns: 1fr; } }

/* photo gallery */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.gallery img {
  width: 100%; height: 160px; object-fit: cover;
  border: 1px solid var(--border); border-radius: 4px;
  filter: saturate(0.95);
}

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar {
    flex: none; width: auto; height: auto; position: static;
    flex-direction: column; gap: 10px;
  }
  .doc { padding: 28px 20px 64px; }
}
