:root {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --text: #22262b;
  --muted: #6a7078;
  --line: #e1ddd3;
  --accent: #8a4b12;
  --accent-soft: #f4e9dc;
  --link: #1d5fa8;
  --note: #2f6fb5;
  --warn: #b5651d;
  --quote: #6b6f76;
  --private: #b0413e;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181b;
    --panel: #1d2024;
    --text: #e4e2dc;
    --muted: #9aa0a8;
    --line: #34383d;
    --accent: #e0a766;
    --accent-soft: #2a241d;
    --link: #7db4ec;
    --note: #6aa5e4;
    --warn: #e0a066;
    --quote: #a0a4ab;
    --private: #e0827f;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--accent); text-decoration: none; letter-spacing: .01em; white-space: nowrap; }
.topnav { display: flex; gap: 4px 16px; flex-wrap: wrap; flex: 1; }
.topnav a { color: var(--text); text-decoration: none; padding: 2px 0; border-bottom: 2px solid transparent; }
.topnav a:hover { border-bottom-color: var(--accent); }
.menu-btn { display: none; margin-left: auto; background: none; border: 1px solid var(--line); color: var(--text); border-radius: var(--radius); font-size: 20px; line-height: 1; padding: 6px 10px; }

.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); max-width: 1500px; margin: 0 auto; }
.side {
  position: sticky; top: 49px; align-self: start;
  height: calc(100vh - 49px); overflow: auto;
  padding: 14px 12px 40px 16px; border-right: 1px solid var(--line); font-size: 14px;
}
.side-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 14px; border-left: 1px solid var(--line); margin-left: 4px; }
.tree li { margin: 1px 0; }
.tree summary { cursor: pointer; padding: 1px 0; }
.tree a { color: var(--text); text-decoration: none; }
.tree a:hover { color: var(--link); text-decoration: underline; }
.tree a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.tree .lvl { color: var(--muted); font-size: 11px; }
.tree .cnt { color: var(--muted); font-size: 11px; background: var(--accent-soft); border-radius: 10px; padding: 0 6px; }
.tree .cave .reg { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.content { padding: 24px clamp(16px, 4vw, 48px) 64px; min-width: 0; }
.note { max-width: 920px; }
.note h1 { font-size: 1.9rem; line-height: 1.25; margin: .2em 0 .6em; }
.note h2 { font-size: 1.4rem; margin: 1.6em 0 .5em; padding-bottom: .2em; border-bottom: 1px solid var(--line); }
.note h3 { font-size: 1.15rem; margin: 1.4em 0 .4em; }
.note h4 { font-size: 1rem; margin: 1.2em 0 .3em; }
.note p { margin: .7em 0; }
.note img { max-width: 100%; height: auto; }
.note hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }
.note code { background: var(--accent-soft); padding: 0 .3em; border-radius: 4px; font-size: .92em; }
.note pre { background: var(--accent-soft); padding: 12px 14px; border-radius: var(--radius); overflow: auto; }
.note pre code { background: none; padding: 0; }
.note blockquote { margin: 1em 0; padding: .1em 1em; border-left: 3px solid var(--line); color: var(--quote); }
.note mark { background: #ffe58a; color: #000; padding: 0 .15em; border-radius: 3px; }
.note abbr[title] { text-decoration: underline dotted; cursor: help; }
.note ul, .note ol { padding-left: 1.5em; }

.wikilink-missing { border-bottom: 1px dotted var(--muted); cursor: help; }
.file-meta { color: var(--muted); font-size: .85em; white-space: nowrap; }

.table-wrap { overflow-x: auto; margin: 1em 0; }
.note table { border-collapse: collapse; font-size: .94rem; min-width: 50%; }
.note th, .note td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; vertical-align: top; }
.note th { background: var(--accent-soft); font-weight: 600; }
.note tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--accent-soft) 35%, transparent); }

.callout { margin: 1em 0; border: 1px solid var(--line); border-left: 4px solid var(--note); border-radius: var(--radius); background: var(--panel); }
.callout-title { padding: 8px 14px; font-weight: 600; color: var(--note); cursor: default; }
details.callout > summary { cursor: pointer; list-style-position: inside; }
.callout-body { padding: 0 14px 6px; }
.callout-body > :first-child { margin-top: .4em; }
.callout-warning { border-left-color: var(--warn); }
.callout-warning .callout-title { color: var(--warn); }
.callout-quote { border-left-color: var(--quote); background: transparent; font-style: italic; }
.callout-quote .callout-body { padding-top: 8px; }

.aks-private { border: 1px dashed var(--private); border-radius: var(--radius); padding: 2px 10px; margin: 1em 0; }
.aks-private .callout-warning { border-left-color: var(--private); }
.aks-private .callout-warning .callout-title { color: var(--private); }
.aks-right { float: right; max-width: 45%; margin: 0 0 .6em 1.2em; font-size: .9rem; color: var(--muted); }
.aks-right p { margin: 0; }
.aks-card { margin: 1em 0; }
.aks-spoiler { margin: 1em 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.aks-spoiler > summary { cursor: pointer; padding: 8px 14px; font-weight: 600; }
.spoiler-body { padding: 0 14px 6px; }
.aks-zenphoto { display: inline-block; color: var(--muted); font-size: .88rem; border: 1px dashed var(--line); border-radius: 6px; padding: 0 8px; }

.aks-gallery { margin: 1em 0; clear: both; }
.g-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.g-item { display: block; width: var(--gw, 100px); height: var(--gh, 100px); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); background: var(--accent-soft); }
.g-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.aks-gallery figcaption { color: var(--muted); font-size: .88rem; margin-top: 4px; }

.aks-video { margin: 1em 0; }
.aks-video a, .aks-video button {
  display: inline-block; padding: 10px 16px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--text); text-decoration: none; font: inherit; cursor: pointer;
}
.aks-video iframe { width: 100%; max-width: 720px; aspect-ratio: 16 / 9; border: 0; border-radius: var(--radius); }

.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.88); display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.lightbox img { max-width: 96vw; max-height: 94vh; object-fit: contain; }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); max-height: 60vh; }
  .side.open { display: block; }
  .menu-btn { display: block; }
  .topnav { display: none; }
  .aks-right { float: none; max-width: none; margin: 0 0 .6em; }
}
@media print {
  .top, .side, .menu-btn { display: none; }
  .layout { display: block; }
  .content { padding: 0; }
  a { color: inherit; }
}

.account { display: flex; align-items: center; gap: 12px; margin-left: auto; font-size: 14px; }
.account .who { color: var(--muted); max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account form { margin: 0; }
.account button, .login button {
  font: inherit; cursor: pointer; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 12px;
}
.account button:hover, .login button:hover { border-color: var(--accent); }
.login-link { color: var(--text); text-decoration: none; border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 12px; }
.login-link:hover { border-color: var(--accent); }
.login { display: grid; gap: 14px; max-width: 340px; margin: 1.2em 0; }
.login label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.login input { font: inherit; font-size: 16px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.login input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login button { padding: 8px 14px; background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.form-error { color: var(--private); border: 1px solid var(--private); border-radius: var(--radius); padding: 8px 12px; max-width: 340px; }
.muted { color: var(--muted); font-size: .9rem; }
@media (max-width: 860px) {
  .account { margin-left: auto; margin-right: 8px; }
  .account .who { display: none; }
  .menu-btn { margin-left: 0; }
}

.search { margin: 0; flex: 0 1 220px; }
.search input { width: 100%; font: inherit; font-size: 14px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 4px 14px; }
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.account { margin-left: 0; }
.search-page { margin: 1em 0; }
.sp-main { display: flex; gap: 8px; }
.sp-main input { flex: 1; font: inherit; font-size: 16px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; min-width: 0; }
.sp-main button { font: inherit; font-weight: 600; cursor: pointer; background: var(--accent); color: var(--bg); border: 1px solid var(--accent); border-radius: var(--radius); padding: 8px 18px; }
.sp-filters { margin-top: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 6px 14px 10px; }
.sp-filters summary { cursor: pointer; padding: 4px 0; font-weight: 600; }
.sp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px 16px; margin-top: 8px; }
.sp-grid label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.sp-grid select, .sp-grid input { font: inherit; font-size: 15px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; min-width: 0; width: 100%; }
.range { display: flex; gap: 6px; }
.sp-count { color: var(--muted); }
.hits { list-style: none; padding: 0; margin: 0; }
.hit { padding: 12px 0; border-bottom: 1px solid var(--line); }
.hit-title { font-size: 1.1rem; font-weight: 600; }
.hit-kind, .hit-reg { font-size: .78rem; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; margin-left: 4px; white-space: nowrap; }
.hit-path, .hit-meta { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.hit-snippet { margin: 6px 0 0; font-size: .95rem; }
.hit-snippet mark, .hit-title mark { background: color-mix(in srgb, var(--accent) 35%, transparent); color: inherit; padding: 0 .1em; border-radius: 3px; }
.pager { display: flex; flex-wrap: wrap; gap: 6px; margin: 1.2em 0; }
.pager a, .pager span { min-width: 2.2em; text-align: center; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; }
.pager [aria-current] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
@media (max-width: 860px) {
  .search { flex: 1 1 auto; margin-left: 12px; }
  .brand { display: none; }
  .account { margin-left: 8px; }
}

.sidenav { display: none; }
@media (max-width: 860px) {
  .sidenav { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 14px; font-size: 15px; }
}
