/* Layout: sticky top bar, a slim contents column on the left, the article in the middle, an infobox on the right. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1d2127;
  --muted: #5d6671;
  --rule: #dce0e6;
  --link: #2352a6;
  --visited: #65409a;
  --ent: #13695f;
  --accent: #2352a6;
  --accent-ink: #ffffff;
  --soft: #eceff3;
  --serif: Charter, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171b; --panel: #1b1f24; --ink: #e6e8eb; --muted: #98a0ab; --rule: #2c323a;
    --link: #8db3ef; --visited: #b79be6; --ent: #6fd1c5; --accent: #7aa5ee; --accent-ink: #10151b; --soft: #242a31;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171b; --panel: #1b1f24; --ink: #e6e8eb; --muted: #98a0ab; --rule: #2c323a;
  --link: #8db3ef; --visited: #b79be6; --ent: #6fd1c5; --accent: #7aa5ee; --accent-ink: #10151b; --soft: #242a31;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { scroll-padding-top: 64px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.6 var(--serif); }
a { color: var(--link); }
a:visited { color: var(--visited); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; height: 52px;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--panel); border-bottom: 1px solid var(--rule); font-family: var(--sans); }
.brand { font: 600 1.15rem/1 var(--serif); color: var(--ink); text-decoration: none; white-space: nowrap; }
a.brand:visited { color: var(--ink); }
.search { flex: 1; max-width: 26rem; margin-left: auto; }
.search input, .bigsearch input, .filter, .mbar input, .mbar select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--rule); border-radius: 6px; background: var(--bg); color: var(--ink); font: 15px var(--sans); }
.menu { display: none; border: 0; background: none; color: var(--ink); font-size: 1.4rem; padding: 4px 8px; cursor: pointer; }

.shell { display: grid; grid-template-columns: 200px minmax(0, 1fr); max-width: 1280px; margin: 0 auto;
  padding-left: max(0px, env(safe-area-inset-left)); padding-right: max(0px, env(safe-area-inset-right)); }
.side { position: sticky; top: 52px; align-self: start; display: flex; flex-direction: column; padding: 18px 12px; font: 15px var(--sans); }
.side a { padding: 7px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.side a:visited { color: var(--ink); }
.side a:hover { background: var(--soft); }
.side a.on { background: var(--soft); font-weight: 600; color: var(--accent); }

main { display: flex; align-items: flex-start; gap: 24px; padding: 24px 16px 56px; min-width: 0; }
.page { flex: 1; min-width: 0; max-width: 52rem; background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 22px clamp(16px, 3vw, 34px) 30px; }
.wide .page { max-width: none; }
.infobox { width: 270px; flex: none; position: sticky; top: 68px; background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 14px 16px; font: 14px/1.5 var(--sans); }
.infobox h3 { margin: 0 0 8px; font: 600 1.1rem var(--serif); }
.infobox h4 { margin: 14px 0 4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.infobox table { width: 100%; border-collapse: collapse; }
.infobox th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 8px 4px 0; vertical-align: top; width: 38%; }
.infobox td { padding: 4px 0; }
.infobox ul { margin: 0; padding-left: 1.1rem; }

h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.25; text-wrap: balance; }
h1 { font-size: 2rem; margin: .1em 0 .15em; font-weight: 600; }
h2 { font-size: 1.35rem; margin: 1.8em 0 .5em; padding-bottom: .2em; border-bottom: 1px solid var(--rule); font-weight: 600; }
h3 { font-size: 1.1rem; margin: 1.2em 0 .4em; }
h4 { font-size: 1rem; margin: .8em 0 .2em; }
.sub, .crumbs { font: 14px var(--sans); color: var(--muted); margin: 0 0 14px; }
.crumbs a { color: var(--muted); }
.lede { font-size: 1.12rem; }
small { color: var(--muted); font-family: var(--sans); font-size: .8em; }

.ent { color: var(--ent); text-decoration: underline dotted; text-underline-offset: 3px; }
a.ent:visited { color: var(--ent); }
.mention { background: var(--soft); border-radius: 4px; padding: 0 4px; font-family: var(--sans); font-size: .9em; }
.gif { font-family: var(--sans); font-size: .9em; }
.gifembed { display: block; border: 0; width: min(100%, 440px); height: 330px; border-radius: 8px; background: var(--soft); margin: 6px 0; }
.more-body { margin-top: 4px; }
.gifembed + a.gif { display: block; font-size: .8em; color: var(--muted); }
.emoji { height: 1.3em; width: auto; vertical-align: -0.25em; }
.spoiler { background: var(--ink); color: transparent; border-radius: 3px; cursor: pointer; }
.spoiler.shown { background: var(--soft); color: inherit; }
blockquote { margin: .6em 0; padding: .1em 1em; border-left: 3px solid var(--rule); color: var(--muted); }
pre { overflow-x: auto; background: var(--soft); padding: 10px 12px; border-radius: 6px; font-size: .85rem; }
code { background: var(--soft); padding: 1px 5px; border-radius: 4px; font-size: .88em; }
pre code { background: none; padding: 0; }
.small { font-size: .85em; color: var(--muted); }

.flow { margin-top: 12px; }
.msg { padding: 6px 0; position: relative; overflow-wrap: anywhere; }
.msg p { margin: .2em 0; }
.msg .head { font: 13px var(--sans); color: var(--muted); margin-top: 10px; }
.msg .head strong { color: var(--ink); margin-right: 6px; }
.msg .pin { position: absolute; right: 0; top: 6px; font-size: .8rem; }
.msg .open { font: 13px var(--sans); }
.msg:target { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 6px; }
.docs .card { border: 1px solid var(--rule); border-radius: 8px; padding: 10px 14px; margin: 10px 0; background: var(--bg); }
.docs .card .head { margin-top: 0; }
.doc { font-size: 1.15rem; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.atts img, .atts video { display: block; max-width: min(100%, 460px); max-height: 380px; border-radius: 6px; border: 1px solid var(--rule); background: var(--soft); }
.atts audio { width: min(100%, 360px); }
.file, .missing { font: 14px var(--sans); }
.missing { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip { font: 14px var(--sans); text-decoration: none; padding: 4px 12px; border: 1px solid var(--rule); border-radius: 999px; color: var(--ent); background: var(--bg); }
a.chip:visited { color: var(--ent); }
.chip:hover { border-color: var(--ent); }
.pager { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 16px 0; font: 14px var(--sans); }
.pager a, .pager .cur { padding: 4px 10px; border: 1px solid var(--rule); border-radius: 6px; text-decoration: none; }
.pager .cur { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.kids, .mentions, .results { padding-left: 1.2rem; }
.mentions li, .kids li { margin: .35em 0; }
.cols { columns: 15rem auto; column-gap: 28px; list-style: none; padding: 0; margin: 0; }
.cols li { break-inside: avoid; padding: 2px 0; }
.group h2 small { font-weight: 400; }
.filter { max-width: 22rem; margin: 6px 0 4px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 20px 0; }
.stats div { border: 1px solid var(--rule); border-radius: 8px; padding: 12px 14px; background: var(--bg); }
.stats strong { display: block; font: 600 1.6rem var(--serif); }
.stats span { font: 13px var(--sans); color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }
.btn, button { font: 600 14px var(--sans); padding: 8px 16px; border: 1px solid var(--rule); border-radius: 6px; background: var(--panel); color: var(--ink); text-decoration: none; cursor: pointer; }
a.btn:visited { color: var(--ink); }
.btn:hover, button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
.results { list-style: none; padding: 0; }
.results li { padding: 10px 0; border-bottom: 1px solid var(--rule); }
.results .where { font: 13px var(--sans); color: var(--muted); }
.results mark { background: color-mix(in srgb, var(--accent) 25%, transparent); color: inherit; border-radius: 2px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }

#graph { position: relative; height: calc(100vh - 250px); min-height: 380px; border: 1px solid var(--rule); border-radius: 8px; background: var(--bg); overflow: hidden; }
#gcanvas { width: 100%; height: 100%; display: block; cursor: grab; }
#gtip { position: absolute; pointer-events: none; padding: 4px 8px; border-radius: 6px; background: var(--ink); color: var(--bg); font: 13px var(--sans); display: none; }

.mbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; font: 14px var(--sans); }
.mbar select, .mbar input { width: auto; min-width: 9rem; }
.seg { display: flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--panel); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 12px; }
.tile { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--soft); border: 2px solid transparent; cursor: pointer; }
.tile.sel { border-color: var(--accent); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .ph { display: grid; place-items: center; height: 100%; font: 13px var(--sans); color: var(--muted); padding: 8px; text-align: center; }
.tile input { position: absolute; top: 6px; left: 6px; width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
.tile .badge { position: absolute; right: 6px; bottom: 6px; font: 600 11px var(--sans); padding: 2px 6px; border-radius: 4px; background: rgba(0, 0, 0, .65); color: #fff; }
.tile .nm { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; font: 11px var(--sans); color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .7)); opacity: 0; transition: opacity .15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile:hover .nm { opacity: 1; }
.more { text-align: center; padding: 20px; color: var(--muted); font: 14px var(--sans); }

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .86); display: grid; place-items: center; padding: 24px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 82vh; border-radius: 6px; }
.lightbox .bar { position: absolute; bottom: 16px; left: 0; right: 0; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; font: 14px var(--sans); color: #fff; }
.lightbox .bar a { color: #fff; padding: 6px 14px; border: 1px solid #fff6; border-radius: 6px; text-decoration: none; }
.foot { text-align: center; padding: 20px 16px 36px; color: var(--muted); font: 13px var(--sans); }

@media (max-width: 960px) {
  .infobox { display: none; }
  main { display: block; }
  .infobox.show { display: block; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .menu { display: block; }
  .side { display: none; position: fixed; top: 52px; left: 0; bottom: 0; width: 240px; background: var(--panel); border-right: 1px solid var(--rule); z-index: 30; overflow: auto; }
  .side.open { display: flex; }
  main { padding: 12px 8px 40px; }
  .brand { font-size: 1rem; }
}
@media (max-width: 960px) {
  .infobox { display: block; position: static; width: auto; margin-top: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Long notes written in Markdown (vault/Pages) */
.note h1 { margin-bottom: .3em; }
.note h2 { margin-top: 2em; }
.note h3 { font-size: 1.12rem; margin: 1.6em 0 .3em; }
.note table { border-collapse: collapse; display: block; overflow-x: auto; margin: 12px 0; font: 14px/1.5 var(--sans); }
.note th, .note td { border: 1px solid var(--rule); padding: 6px 10px; vertical-align: top; text-align: left; }
.note th { background: var(--soft); }
.note .toc { background: var(--bg); border: 1px solid var(--rule); border-radius: 8px; padding: 8px 18px; margin: 16px 0; font: 14px/1.5 var(--sans); }
.note .toc ul { margin: 0; padding-left: 1.1rem; }
.note blockquote { margin: .8em 0; }
.summary h4 { margin: 1em 0 .3em; font-size: 1.05rem; }
.summary ul { padding-left: 1.2rem; }
