/* LifeWiki – plain, readable, like a quiet Wikipedia. */
:root {
  --bg: #fbfaf7;
  --bg-soft: #f3f1ec;
  --bg-hover: #ebe8e1;
  --text: #22211f;
  --muted: #6d6a64;
  --faint: #9a968e;
  --line: #e4e0d8;
  --accent: #1f5fbf;
  --accent-soft: rgba(31, 95, 191, 0.28);
  --visited: #5b46a8;
  --broken: #b3261e;
  --code-bg: #f1eee8;
  --mark: #fbe7a1;
  --serif: "Source Serif 4 Variable", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
/* Dark: follows the device, unless the reader picked a theme with the button. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161615;
    --bg-soft: #1d1d1b;
    --bg-hover: #282826;
    --text: #e6e3dc;
    --muted: #a19d95;
    --faint: #75726c;
    --line: #2f2e2b;
    --accent: #8db4f5;
    --accent-soft: rgba(141, 180, 245, 0.35);
    --visited: #b9a5ef;
    --broken: #f0908a;
    --code-bg: #222220;
    --mark: #5a4c1c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161615;
  --bg-soft: #1d1d1b;
  --bg-hover: #282826;
  --text: #e6e3dc;
  --muted: #a19d95;
  --faint: #75726c;
  --line: #2f2e2b;
  --accent: #8db4f5;
  --accent-soft: rgba(141, 180, 245, 0.35);
  --visited: #b9a5ef;
  --broken: #f0908a;
  --code-bg: #222220;
  --mark: #5a4c1c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 1.5rem; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.7 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
  height: 3.5rem;
  padding: 0 1.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand, .brand:visited {
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
.brand { display: inline-flex; align-items: center; gap: 0.55rem; }
.fox { height: 1.5rem; width: auto; color: var(--muted); }
.tools { display: flex; gap: 0.25rem; }
.theme, .menu {
  display: inline-flex; align-items: center; gap: 0.4rem;
  height: 2.25rem; padding: 0 0.6rem;
  font: 500 0.9rem var(--sans);
  color: var(--muted); background: none;
  border: 0; border-radius: 6px;
  cursor: pointer;
}
.theme:hover, .menu:hover { color: var(--text); background: var(--bg-hover); }
.theme svg, .menu svg { width: 1.1rem; height: 1.1rem; }
.theme .sun { display: none; }
:root[data-theme="dark"] .theme .sun { display: block; }
:root[data-theme="dark"] .theme .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme .sun { display: block; }
  :root:not([data-theme="light"]) .theme .moon { display: none; }
}
.menu { display: none; }

/* ---------- layout ---------- */
.layout { display: flex; align-items: flex-start; }
.sidebar {
  position: sticky; top: 3.5rem;
  flex: 0 0 17rem;
  display: flex; flex-direction: column;
  height: calc(100vh - 3.5rem);
  height: calc(100dvh - 3.5rem);
  padding: 1.25rem 1rem 0;
  font-size: 0.9rem; line-height: 1.45;
  border-right: 1px solid var(--line);
}
.page { flex: 1; min-width: 0; }
.page-inner { max-width: 44rem; margin: 0 auto; padding: 2.5rem 2rem 5rem; }

/* ---------- page list ---------- */
#find {
  width: 100%;
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  font: inherit;
  color: var(--text); background: var(--bg-soft);
  border: 1px solid transparent; border-radius: 6px;
}
#find::placeholder { color: var(--faint); }
#find:focus { outline: none; background: var(--bg); border-color: var(--accent); }
.sidebar ul, .index-tree ul { list-style: none; margin: 0; padding: 0 0 0 0.75rem; }
.sidebar-list > ul, .index-tree > ul { padding-left: 0; }
.sidebar-list { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -1rem; padding: 0 1rem 1rem; }
.sidebar-foot { margin: 0 -1rem; padding: 0.6rem 1rem 0.75rem; border-top: 1px solid var(--line); }
.sidebar .graph-link, .sidebar .graph-link:visited { display: flex; align-items: center; gap: 0.55rem; color: var(--muted); }
.sidebar .graph-link:hover { color: var(--text); }
.graph-link svg { width: 1rem; height: 1rem; flex: none; }
.sidebar li { margin: 1px 0; }
.sidebar a, .sidebar a:visited, summary {
  display: block;
  padding: 0.28rem 0.6rem;
  border-radius: 5px;
  color: var(--text);
  text-decoration: none;
}
.sidebar a:hover, summary:hover { background: var(--bg-hover); }
.sidebar a[aria-current="page"] { background: var(--bg-hover); color: var(--text); font-weight: 600; }
.sidebar li.leaf > a { padding-left: 1.65rem; }
summary {
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: "";
  display: inline-block;
  width: 0.4rem; height: 0.4rem;
  margin: 0 0.55rem 0.12rem 0.05rem;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  opacity: 0.7;
}
details[open] > summary::before { transform: rotate(45deg); margin-bottom: 0.2rem; }
.none { color: var(--faint); padding: 0 0.6rem; }
.index-tree li { margin: 0.2rem 0; }
.index-tree summary { display: inline-block; padding: 0; color: var(--text); font-weight: 600; }
.index-tree summary:hover { background: none; }

/* ---------- article ---------- */
.crumbs {
  margin: 0 0 0.5rem;
  color: var(--faint);
  font-size: 0.78rem; font-weight: 500;
  letter-spacing: 0.06em; text-transform: uppercase;
}
.crumbs span { margin: 0 0.3rem; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 2.5rem; margin: 0 0 1.5rem; letter-spacing: -0.02em; }
h2 { font-size: 1.65rem; margin: 2.75rem 0 0.9rem; padding-bottom: 0.35rem; border-bottom: 1px solid var(--line); }
h3 { font-size: 1.3rem; margin: 2rem 0 0.6rem; }
h4 { font-size: 1.1rem; margin: 1.6rem 0 0.5rem; }
h5, h6 { font-size: 1rem; margin: 1.4rem 0 0.5rem; }
.content > h1:first-child { margin-top: 0; }
p, ul, ol, blockquote, table, pre, .math { margin: 0 0 1.15rem; }
ul, ol { padding-left: 1.5rem; }
li { margin: 0.25rem 0; }
li::marker { color: var(--faint); }
li > ul, li > ol { margin: 0.25rem 0 0; }
strong { font-weight: 650; }

a { color: var(--accent); }
a:visited { color: var(--visited); }
.content a {
  text-decoration: underline;
  text-decoration-color: var(--accent-soft);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.content a:hover { text-decoration-color: currentColor; }
.broken, .content a.broken { color: var(--broken); text-decoration-style: dotted; cursor: help; }
a.external::after { content: "↗"; font-size: 0.7em; margin-left: 2px; vertical-align: 0.15em; }

blockquote {
  margin-left: 0;
  padding: 0.1rem 0 0.1rem 1.1rem;
  border-left: 3px solid var(--line);
  color: var(--muted);
}
blockquote > :last-child { margin-bottom: 0; }
mark { background: var(--mark); color: inherit; padding: 0.05em 0.2em; border-radius: 3px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }
img { max-width: 100%; height: auto; border-radius: 4px; }

code, pre { font-family: var(--mono); font-size: 0.86em; }
code { background: var(--code-bg); padding: 0.15em 0.4em; border-radius: 4px; }
pre {
  background: var(--code-bg);
  padding: 1rem 1.15rem;
  overflow-x: auto;
  border-radius: 8px;
  line-height: 1.55;
}
pre code { background: none; padding: 0; font-size: 1em; }

table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 0.94rem; }
th, td { padding: 0.55rem 0.9rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { font-weight: 600; border-bottom: 1.5px solid var(--text); }
tr:last-child td { border-bottom: 0; }

.math { overflow-x: auto; overflow-y: hidden; }
.katex { font-size: 1.08em; }
.task-list-item { list-style: none; }
.task-list-item input { margin: 0 0.5rem 0 -1.4rem; accent-color: var(--accent); }
.footnotes { font-size: 0.88rem; color: var(--muted); }
.footnotes-sep { margin: 3rem 0 1rem; }

.backlinks { margin-top: 3.5rem; padding-top: 1.25rem; border-top: 1px solid var(--line); font-size: 0.92rem; }
.backlinks h2 {
  margin: 0 0 0.6rem; padding: 0; border: 0;
  font: 600 0.78rem var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint);
}
.backlinks ul { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; padding: 0; margin: 0; list-style: none; }
.page-foot { margin-top: 2rem; font-size: 0.85rem; color: var(--faint); }
.page-foot a, .page-foot a:visited { color: var(--muted); text-decoration: none; }
.page-foot a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- phones ---------- */
@media (max-width: 800px) {
  body { font-size: 16.5px; }
  .top { padding: 0 1rem; }
  .menu { display: inline-flex; }
  .layout { display: block; }
  .sidebar {
    display: none; position: static; height: auto;
    padding: 1rem;
    border-right: 0; border-bottom: 1px solid var(--line);
    background: var(--bg-soft);
  }
  .sidebar #find { background: var(--bg); }
  .sidebar.open { display: flex; }
  .sidebar-list { overflow: visible; }
  .page-inner { padding: 1.75rem 1rem 3.5rem; }
  h1 { font-size: 2rem; }
  h2 { font-size: 1.4rem; margin-top: 2.25rem; }
}
