:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1c1c1a;
  --muted: #63635e;
  --line: #dedcd6;
  --accent: #1c5f8b;
  --accent-soft: #e6f0f7;
  --code-bg: #f2f1ed;
  --mark: #ffe9a8;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 18px rgba(0,0,0,.05);
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --panel: #1b1e23;
  --ink: #e7e6e2;
  --muted: #9b9a94;
  --line: #2c3037;
  --accent: #6fb3dd;
  --accent-soft: #1e2a34;
  --code-bg: #101317;
  --mark: #5c4a12;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --panel: #1b1e23;
    --ink: #e7e6e2;
    --muted: #9b9a94;
    --line: #2c3037;
    --accent: #6fb3dd;
    --accent-soft: #1e2a34;
    --code-bg: #101317;
    --mark: #5c4a12;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[hidden] { display: none !important; }

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

/* ------------------------------------------------------------- sign in */

.signin {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  overflow-y: auto;
  z-index: 50;
}

.signin-card {
  width: 100%;
  max-width: 480px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.signin-card h1 { margin: 0 0 4px; font-size: 20px; }
.signin-sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

.signin-card label {
  display: block;
  margin: 14px 0 4px;
  font-size: 13px;
  font-weight: 600;
}

.signin-card input[type="text"],
.signin-card input[type="password"] {
  width: 100%;
  padding: 9px 10px;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.signin-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.agree {
  margin: 20px 0 8px;
  padding: 14px;
  background: var(--accent-soft);
  border-radius: 8px;
}

.agree-line {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 0 !important;
  font-weight: 600;
  font-size: 14px !important;
  cursor: pointer;
}

.agree-line input { margin-top: 3px; }

.small-print {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}

.signin-error {
  margin: 14px 0 0;
  padding: 9px 11px;
  font-size: 13px;
  color: #8a1f1f;
  background: #fdeaea;
  border: 1px solid #f0c2c2;
  border-radius: 6px;
}

:root[data-theme="dark"] .signin-error { color: #ffb4b4; background: #3a1d1d; border-color: #5c2b2b; }

#signin-button {
  margin-top: 18px;
  width: 100%;
  padding: 11px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

#signin-button:disabled { opacity: .45; cursor: not-allowed; }

/* --------------------------------------------------------------- shell */

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand { font-weight: 700; white-space: nowrap; }

.icon-button, .linklike {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 9px;
  cursor: pointer;
}

.linklike { border: 0; padding: 0; color: var(--accent); text-decoration: underline; }

#menu-toggle { display: none; }

.search-wrap { position: relative; flex: 1 1 auto; max-width: 460px; }

#search {
  width: 100%;
  padding: 7px 10px;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.results {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 20;
}

.result {
  display: block;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}

.result:last-child { border-bottom: 0; }
.result:hover { background: var(--accent-soft); text-decoration: none; }
.result.empty { color: var(--muted); }
.r-title { display: block; font-weight: 600; font-size: 14px; }
.r-path { display: block; font-size: 11px; color: var(--muted); font-family: ui-monospace, Menlo, Consolas, monospace; }
.r-snip { display: block; margin-top: 3px; font-size: 12px; color: var(--muted); }

mark { background: var(--mark); color: inherit; }

.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.whoami { font-size: 13px; color: var(--muted); white-space: nowrap; }
.dot { opacity: .6; }

.body { display: flex; flex: 1 1 auto; min-height: 0; }

.nav {
  flex: 0 0 288px;
  overflow-y: auto;
  padding: 16px 12px 40px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.nav-section { margin-bottom: 20px; }

.nav-section h2 {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav ul { list-style: none; margin: 0; padding: 0; }
.nav li { margin: 0; }

.nav a {
  display: block;
  padding: 4px 8px;
  font-size: 13.5px;
  color: var(--ink);
  border-radius: 5px;
  overflow-wrap: anywhere;
}

.nav a:hover { background: var(--accent-soft); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.tree { padding-left: 10px; }
.tree summary {
  cursor: pointer;
  padding: 3px 4px;
  font-size: 13px;
  color: var(--muted);
  border-radius: 5px;
}
.tree summary:hover { background: var(--accent-soft); }

.main { flex: 1 1 auto; overflow-y: auto; padding: 0 0 80px; }

.crumbs {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 28px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  z-index: 10;
}

.crumbs .sep { opacity: .5; }
.crumbs button { margin-left: auto; flex: 0 0 auto; font-family: inherit; }

/* -------------------------------------------------------------- content */

.content {
  max-width: 74ch;
  margin: 0 auto;
  padding: 28px 28px 0;
}

.content h1, .content h2, .content h3, .content h4, .content h5, .content h6 {
  line-height: 1.25;
  margin: 1.7em 0 .55em;
}

.content h1 { font-size: 27px; margin-top: .3em; }
.content h2 { font-size: 21px; padding-bottom: .25em; border-bottom: 1px solid var(--line); }
.content h3 { font-size: 17px; }
.content h4, .content h5, .content h6 { font-size: 15px; }

.content p { margin: 0 0 1em; }
.content ul, .content ol { margin: 0 0 1em; padding-left: 1.5em; }
.content li { margin: .25em 0; }

.content blockquote {
  margin: 0 0 1em;
  padding: .1em 1em;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
}

.content blockquote p:last-child { margin-bottom: 1em; }

.content code {
  padding: .12em .35em;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .88em;
  background: var(--code-bg);
  border-radius: 4px;
}

.content pre.code {
  margin: 0 0 1em;
  padding: 12px 14px;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.content pre.code code { padding: 0; background: none; font-size: 12.5px; line-height: 1.55; }

.content hr { margin: 2em 0; border: 0; border-top: 1px solid var(--line); }

.content img { max-width: 100%; height: auto; border-radius: 6px; }

.table-wrap { overflow-x: auto; margin: 0 0 1em; }

.content table { border-collapse: collapse; width: 100%; font-size: 13.5px; }

.content th, .content td {
  padding: 6px 10px;
  text-align: left;
  border: 1px solid var(--line);
  vertical-align: top;
}

.content th { background: var(--code-bg); font-weight: 600; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .brand { display: none; }
  .whoami { font-size: 12px; }
}

@media (max-width: 760px) {
  #menu-toggle { display: inline-block; }
  .nav {
    position: absolute;
    top: 49px;
    bottom: 0;
    left: 0;
    z-index: 30;
    width: 280px;
    display: none;
    box-shadow: var(--shadow);
  }
  .nav.open { display: block; }
  .content { padding: 20px 16px 0; }
  .crumbs { padding: 9px 16px; }
  .topbar { flex-wrap: wrap; }
}
