:root {
  --bg: #f6f4ef; --surface: #fffdf9; --ink: #1f1d1a; --ink2: #3d3a35; --muted: #6b665e; --rule: #e5e0d6;
  --accent: #8a6514; --accent-bg: #f3ead3; --mark: #f6e3a6; --link: #7a5810; --broken: #a0522d;
  --code: #f0ece3; --focus: #a87f24; --shadow: 0 1px 2px rgba(31,29,26,.06), 0 4px 16px rgba(31,29,26,.05);
  --r: 10px; --side: 220px; --read: 46rem;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Charter", "Georgia", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111015; --surface: #18171e; --ink: #ece8e0; --ink2: #d3cfc6; --muted: #9a95a6; --rule: #2a2833;
    --accent: #d4a84b; --accent-bg: #2a2416; --mark: #5a4710; --link: #e0b95e; --broken: #e08a5e;
    --code: #222029; --focus: #d4a84b; --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111015; --surface: #18171e; --ink: #ece8e0; --ink2: #d3cfc6; --muted: #9a95a6; --rule: #2a2833;
  --accent: #d4a84b; --accent-bg: #2a2416; --mark: #5a4710; --link: #e0b95e; --broken: #e08a5e;
  --code: #222029; --focus: #d4a84b; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1 { font-size: 1.65rem; line-height: 1.2; margin: .2rem 0 .6rem; letter-spacing: -.01em; }
code, pre { font-family: var(--mono); font-size: .88em; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; z-index: 9; background: var(--surface); padding: 6px 10px; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .mt { margin-top: .6rem; }

/* top bar */
.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 12px; align-items: center; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--rule); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--ink); text-decoration: none; width: calc(var(--side) - 28px); }
.topsearch { flex: 1; max-width: var(--read); }
.topsearch input, .bigsearch input, .input, .gctl input[type=search] { width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule); border-radius: 8px; padding: 8px 12px; }
.topnew { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--rule);
  background: var(--surface); color: var(--ink); text-decoration: none; font-size: 1.3rem; line-height: 1; }

/* layout */
.layout { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); }
.side { position: sticky; top: 57px; align-self: start; height: calc(100vh - 57px); overflow-y: auto; padding: 14px 10px 30px 14px;
  display: flex; flex-direction: column; gap: 1px; border-right: 1px solid var(--rule); }
.side a { color: var(--ink2); text-decoration: none; padding: 6px 10px; border-radius: 7px; font-size: .94rem; }
.side a:hover { background: var(--accent-bg); color: var(--ink); }
.side a.on { background: var(--accent-bg); color: var(--ink); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.side a.fold { color: var(--muted); }
.side hr { border: 0; border-top: 1px solid var(--rule); margin: 10px 4px; width: auto; }
.sidehead { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 2px 10px 4px; }
main { padding: 22px 28px 90px; min-width: 0; }
.tabs { display: none; }

/* home */
.capture { max-width: var(--read); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow); }
.capture textarea { width: 100%; border: 0; resize: vertical; font: inherit; color: var(--ink); background: transparent; padding: 4px 0; min-height: 3em; }
.capture textarea:focus { outline: none; }
.lbl { display: block; font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.strip { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; max-width: var(--read); }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--rule); background: var(--surface); color: var(--ink2); text-decoration: none; font-size: .9rem; }
.chip b { color: var(--accent); margin-left: 2px; } .chip.quiet { color: var(--muted); }
.panel { max-width: var(--read); margin-top: 28px; }
.ph { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.count { font-weight: 500; color: var(--muted); margin-left: 4px; }

/* buttons */
.btn { font: inherit; font-weight: 600; font-size: .92rem; color: var(--surface); background: var(--ink); border: 1px solid var(--ink);
  border-radius: 8px; padding: 7px 14px; cursor: pointer; text-decoration: none; display: inline-block; white-space: nowrap; }
.btn:hover { color: var(--surface); opacity: .9; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn.ghost:hover { background: var(--accent-bg); color: var(--ink); }
.btn.block { display: block; width: 100%; padding: 11px 14px; margin-top: 14px; }

/* lists */
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 9px 0; border-bottom: 1px solid var(--rule); display: flex; flex-direction: column; gap: 1px; }
.list li > a { font-weight: 550; text-decoration: none; color: var(--ink); }
.list li > a:hover { color: var(--accent); text-decoration: underline; }
.list.tight li { padding: 6px 0; }
.meta { color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.folders { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.folders a { display: inline-block; padding: 6px 12px; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); text-decoration: none; color: var(--ink2); }
.folders a::before { content: "\25B8  "; color: var(--muted); }

/* note */
.notegrid { display: grid; grid-template-columns: minmax(0, var(--read)) minmax(220px, 300px); gap: 40px; }
.note { max-width: var(--read); min-width: 0; }
.notehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.actions { display: flex; gap: 8px; flex-shrink: 0; padding-top: 4px; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 4px; } .crumbs a { color: var(--muted); }
.props { margin: 8px 0 14px; font-size: .88rem; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); }
.props summary { cursor: pointer; padding: 6px 12px; color: var(--muted); }
.props dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; padding: 4px 12px 10px; }
.props dt { color: var(--muted); } .props dd { margin: 0; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.tag { font-size: .8rem; padding: 2px 8px; border-radius: 999px; background: var(--accent-bg); color: var(--accent); text-decoration: none; }
.tagcloud { display: flex; flex-wrap: wrap; gap: 8px; }
.links { position: sticky; top: 76px; align-self: start; max-height: calc(100vh - 96px); overflow-y: auto; font-size: .92rem; }
.links section + section { margin-top: 24px; }

/* rendered markdown */
.md { font-size: 1.02rem; line-height: 1.65; overflow-wrap: break-word; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.25; margin: 1.6em 0 .5em; letter-spacing: -.005em; }
.md h1 { font-size: 1.45rem; } .md h2 { font-size: 1.22rem; padding-bottom: 4px; border-bottom: 1px solid var(--rule); } .md h3 { font-size: 1.06rem; } .md h4 { font-size: 1rem; color: var(--ink2); }
.md > :first-child { margin-top: .4em; }
.md p, .md ul, .md ol, .md pre, .md table, .md blockquote { margin: 0 0 .9em; }
.md ul, .md ol { padding-left: 1.4em; } .md li { margin: .2em 0; } .md li > ul, .md li > ol { margin: .2em 0; }
.md a.broken, a.broken { color: var(--broken); text-decoration-style: dashed; }
.md code { background: var(--code); padding: .1em .35em; border-radius: 4px; }
.md pre { background: var(--code); padding: 12px 14px; border-radius: 8px; overflow-x: auto; line-height: 1.45; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--accent); padding: .1em 0 .1em 1em; color: var(--ink2); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: .93rem; }
.md th, .md td { border: 1px solid var(--rule); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--code); }
.md hr { border: 0; border-top: 1px solid var(--rule); margin: 1.6em 0; }
.md .task-list-item { list-style: none; margin-left: -1.3em; } .md .task-list-item input { margin-right: .5em; }

/* search */
.bigsearch { display: flex; gap: 8px; max-width: var(--read); margin-bottom: 10px; }
.results { list-style: none; padding: 0; max-width: var(--read); }
.results li { padding: 12px 0; border-bottom: 1px solid var(--rule); }
.rt { font-weight: 600; font-size: 1.05rem; text-decoration: none; color: var(--ink); } .rt:hover { color: var(--accent); }
.results .meta { display: block; }
.snip { margin: 4px 0 0; color: var(--ink2); font-size: .93rem; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }

/* editor */
.editor { max-width: 60rem; }
.edhead { display: flex; gap: 12px; align-items: flex-end; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; }
.edhead .input { min-width: 260px; flex: 1; font-family: var(--mono); font-size: .92rem; }
.edtitle { font-size: 1rem; font-family: var(--mono); font-weight: 500; color: var(--muted); margin: 0; overflow-wrap: anywhere; }
.edwrap { position: relative; }
.editor textarea { width: 100%; min-height: calc(100vh - 230px); font: 15px/1.6 var(--mono); color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--r); padding: 14px 16px; resize: vertical; tab-size: 2; }
.suggest { position: absolute; z-index: 6; list-style: none; margin: 0; padding: 4px; min-width: 260px; max-width: 420px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: 8px; box-shadow: var(--shadow); }
.suggest li { padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: .9rem; }
.suggest li[aria-selected=true], .suggest li:hover { background: var(--accent-bg); }
.suggest .meta { display: block; }
.lock { font-size: .88rem; color: var(--muted); border: 1px dashed var(--rule); border-radius: 8px; padding: 8px 12px; }
.err { color: var(--broken); background: color-mix(in srgb, var(--broken) 10%, transparent); padding: 8px 12px; border-radius: 8px; }

/* graph */
.graphbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.gctl { display: flex; gap: 10px; align-items: center; }
.gctl input[type=search] { width: 200px; padding: 6px 10px; }
.graphwrap { position: relative; margin-top: 10px; height: calc(100vh - 170px); min-height: 420px; border: 1px solid var(--rule); border-radius: var(--r); background: var(--surface); overflow: hidden; }
#graph { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.ghint { position: absolute; left: 12px; bottom: 6px; margin: 0; pointer-events: none; }
.glegend { position: absolute; right: 10px; top: 10px; list-style: none; margin: 0; padding: 8px 10px; background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid var(--rule); border-radius: 8px; font-size: .8rem; }
.glegend li { display: flex; align-items: center; gap: 6px; } .glegend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* auth */
.authpage { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.authcard { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; padding: 28px 24px; box-shadow: var(--shadow); text-align: center; }
.authcard h1 { margin: 8px 0 4px; } .authcard .lbl { text-align: left; margin-top: 14px; } .authcard .err { margin-top: 12px; }

/* phone */
@media (max-width: 1100px) {
  .notegrid { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .links { position: static; max-height: none; border-top: 1px solid var(--rule); padding-top: 18px; }
}
@media (max-width: 760px) {
  .layout { display: block; } .side { display: none; }
  .brand { width: auto; } .brand span { display: none; }
  main { padding: 14px 16px calc(84px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.4rem; }
  .tabs { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--rule); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabs a { display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: .7rem; color: var(--muted); text-decoration: none; padding: 2px 0; }
  .tabs a.on { color: var(--ink); font-weight: 600; }
  .tabs .ti { font-size: 1.15rem; line-height: 1.2; }
  .tabs a.cap .ti { width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: var(--surface); display: grid; place-items: center; font-size: 1.2rem; }
  .notehead { flex-wrap: wrap; gap: 6px 10px; align-items: center; } .actions { padding-top: 0; } .notehead .btn { padding: 5px 11px; font-size: .85rem; }
  .md { font-size: 1rem; }
  .editor textarea { min-height: calc(100vh - 260px); font-size: 14px; }
  .graphwrap { height: calc(100vh - 210px); }
  .gctl input[type=search] { width: 140px; }
  .editing .tabs { display: none; }
}
