/* Layout, theme tokens, navigation, search, setup. No external fonts. */
:root {
  --bg: #ffffff; --bg-soft: #f6f7f9; --bg-code: #f3f4f7;
  --text: #1c2330; --muted: #5a6578; --border: #dde1e8;
  --accent: #2858c4; --accent-soft: rgba(40, 88, 196, .1);
  --danger: #b42318; --danger-bg: #fdeceb; --warn: #8a5a00; --warn-bg: #fff4d6;
  --focus: #2858c4; --shadow: 0 8px 30px rgba(20, 30, 50, .14);
  --topbar-h: 56px; --sidebar-w: 280px; --toc-w: 230px; --content-w: 820px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #12151b; --bg-soft: #181c24; --bg-code: #1b2029;
  --text: #e3e7ee; --muted: #9aa5b8; --border: #2a303b;
  --accent: #7ea6ff; --accent-soft: rgba(126, 166, 255, .14);
  --danger: #ff8a80; --danger-bg: #3a1b1a; --warn: #f2c066; --warn-bg: #36290f;
  --focus: #9dbcff; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --bg-soft: #181c24; --bg-code: #1b2029;
    --text: #e3e7ee; --muted: #9aa5b8; --border: #2a303b;
    --accent: #7ea6ff; --accent-soft: rgba(126, 166, 255, .14);
    --danger: #ff8a80; --danger-bg: #3a1b1a; --warn: #f2c066; --warn-bg: #36290f;
    --focus: #9dbcff; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + 16px); }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
code, kbd { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--bg); color: var(--text); padding: 8px 12px; border: 2px solid var(--focus); z-index: 100; }
.skip-link:focus { left: 8px; }
.muted { color: var(--muted); } .small { font-size: .85rem; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 40; height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--bg); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 1px solid transparent; background: transparent; color: var(--text); border-radius: 8px; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--bg-soft); border-color: var(--border); }
.icon-btn svg { width: 20px; height: 20px; }
.menu-btn { display: none; }

/* Search */
.search { position: relative; flex: 1; max-width: 460px; margin-left: auto; }
.search input { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-soft); color: var(--text); font: inherit; font-size: .92rem; }
.search input:disabled { opacity: .6; }
.search-results { position: absolute; top: 44px; left: 0; right: 0; max-height: min(70vh, 480px); overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 60; }
.search-results .sr-item { display: block; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.search-results .sr-item[aria-selected="true"], .search-results .sr-item:hover { background: var(--accent-soft); }
.sr-title { font-weight: 600; display: block; }
.sr-path { font-size: .78rem; color: var(--muted); display: block; font-family: var(--mono); }
.sr-excerpt { font-size: .86rem; color: var(--muted); display: block; margin-top: 2px; }
.sr-status { padding: 10px; color: var(--muted); font-size: .9rem; }
.search-results mark { background: var(--warn-bg); color: inherit; border-radius: 2px; }

/* Shell */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w); align-items: start; max-width: 1500px; margin: 0 auto; }
body.no-nav .shell { grid-template-columns: minmax(0, 1fr); }
.sidebar { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 16px 12px 32px 16px; border-right: 1px solid var(--border); font-size: .94rem; overscroll-behavior: contain; }
.content { min-width: 0; padding: 28px 40px 60px; max-width: calc(var(--content-w) + 80px); width: 100%; margin: 0 auto; }
.content:focus { outline: none; }
.toc { position: sticky; top: var(--topbar-h); max-height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 28px 16px 24px 8px; font-size: .86rem; }
.toc-title { margin: 0 0 8px; font-weight: 650; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc a { display: block; padding: 3px 0 3px 12px; margin-left: -1px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.toc .lvl-3 a { padding-left: 24px; } .toc .lvl-4 a { padding-left: 36px; }

/* Navigation tree */
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list .nav-list { margin-left: 12px; padding-left: 6px; border-left: 1px solid var(--border); }
.nav-list li { margin: 1px 0; }
.nav-dir summary { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px; cursor: pointer; list-style: none; user-select: none; }
.nav-dir summary::-webkit-details-marker { display: none; }
.nav-dir summary:hover, .nav-link:hover { background: var(--bg-soft); }
.nav-label { color: var(--text); font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
a.nav-label:hover { text-decoration: underline; }
.nav-link { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.nav-link.current, .nav-label.current { color: var(--accent); }
.nav-link.current { background: var(--accent-soft); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.ico { width: 15px; height: 15px; flex: none; color: var(--muted); }
.chev { transition: transform .15s; }
details[open] > summary .chev { transform: rotate(90deg); }

/* Breadcrumbs, footer */
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 14px; padding: 0; font-size: .85rem; color: var(--muted); }
.crumbs li + li::before { content: "/"; margin-right: 4px; opacity: .6; }
.crumbs a { color: var(--muted); }
.footer { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; padding: 18px 16px 28px; border-top: 1px solid var(--border); color: var(--muted); font-size: .82rem; }
.footer a { color: var(--muted); }
.sync-indicator { color: var(--accent); }

/* Buttons, notices, directory overview */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-soft); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #0b1020; }
.btn-ghost { background: transparent; }
.btn[disabled] { opacity: .6; cursor: progress; }
.notice { padding: 48px 0; max-width: 560px; }
.notice-code { font: 700 3rem/1 var(--mono); color: var(--muted); margin: 0 0 12px; }
.notice h1 { margin: 0 0 8px; } .notice-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.dir-overview { list-style: none; padding: 0; display: grid; gap: 6px; }
.dir-overview li a { display: block; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; text-decoration: none; }
.dir-overview li a:hover { background: var(--bg-soft); }

/* Setup */
.setup-page { display: grid; place-items: center; min-height: 100vh; padding: 20px 16px; background: var(--bg-soft); }
.setup-card { width: 100%; max-width: 560px; background: var(--bg); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.setup-card h1 { margin: 8px 0; font-size: 1.6rem; }
.setup-card label { display: block; margin: 16px 0 6px; font-weight: 600; }
.setup-card input[type="url"], .setup-card input[type="text"] { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }
.form-error, .form-warn, .warning-box { padding: 10px 12px; border-radius: 8px; margin: 14px 0; font-size: .92rem; }
.form-error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.form-warn, .warning-box { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.setup-card .btn { width: 100%; margin-top: 8px; }

/* Mobile / tablet */
@media (max-width: 1180px) {
  .shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-grid; }
  .content { padding: 20px 16px 48px; }
  .sidebar { position: fixed; z-index: 50; top: var(--topbar-h); left: 0; bottom: 0; height: auto; width: min(86vw, 320px); background: var(--bg); transform: translateX(-102%); visibility: hidden; transition: transform .2s ease, visibility 0s .2s; padding-top: 12px; box-shadow: var(--shadow); }
  body.drawer-open .sidebar { transform: none; visibility: visible; transition: transform .2s ease; }
  .scrim { position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: 0; z-index: 45; background: rgba(0, 0, 0, .45); }
  body.drawer-open { overflow: hidden; }
  .nav-link, .nav-dir summary { min-height: 44px; }
  .search { max-width: none; }
  .brand span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; scroll-behavior: auto !important; }
}
