:root {
  --bg: #1e1e22;
  --side: #17171a;
  --panel: #252529;
  --line: #2f2f35;
  --text: #dcddde;
  --muted: #9a9aa3;
  --faint: #5f5f69;
  --accent: #8b7bff;
  --accent-soft: #8b7bff26;
  --code: #e5a56f;
  --hover: #ffffff0d;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #ffffff;
  --side: #f6f6f7;
  --panel: #ffffff;
  --line: #e3e3e6;
  --text: #222226;
  --muted: #6b6b75;
  --faint: #a8a8b1;
  --accent: #6c5ce7;
  --accent-soft: #6c5ce71f;
  --code: #b5551b;
  --hover: #0000000a;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.pad { padding: 10px 14px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

#app { display: flex; height: 100vh; }

/* sidebar */
#sidebar { width: 260px; flex-shrink: 0; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
body.no-sidebar #sidebar { display: none; }
.side-head { display: flex; align-items: center; gap: 2px; padding: 10px 8px 6px 14px; }
.brand { font-weight: 650; letter-spacing: -.01em; }
.icon { width: 30px; height: 30px; display: grid; place-items: center; border: 0; background: none; border-radius: 6px; color: var(--muted); }
.icon:hover, .icon.on { background: var(--hover); color: var(--text); }
.search-wrap { padding: 4px 10px 8px; }
#search { width: 100%; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 13px; outline: none; }
#search:focus { border-color: var(--accent); }
#tree, #results { flex: 1; overflow: auto; padding: 2px 6px 10px; font-size: 14px; }
#results { display: none; }
body.searching #tree { display: none; }
body.searching #results { display: block; }
.node { display: flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 5px; cursor: pointer; color: var(--muted); white-space: nowrap; user-select: none; }
.node .name { overflow: hidden; text-overflow: ellipsis; }
.node:hover { background: var(--hover); color: var(--text); }
.node.active { background: var(--accent-soft); color: var(--text); }
.node.drop { outline: 1px dashed var(--accent); }
.chev { display: inline-block; width: 12px; transition: transform .12s; color: var(--faint); }
.chev.open { transform: rotate(90deg); }
.result { padding: 6px 8px; border-radius: 5px; cursor: pointer; }
.result:hover { background: var(--hover); }
.r-title { font-weight: 600; font-size: 13px; }
.r-hit { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
mark { background: #ffd60a55; color: inherit; border-radius: 2px; }
.side-foot { display: flex; gap: 2px; padding: 6px 8px; border-top: 1px solid var(--line); }

/* main */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); min-height: 44px; }
#crumb { color: var(--faint); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; white-space: nowrap; }
.pill:hover { border-color: var(--accent); }
.pill.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill[hidden] { display: none; }
#scroller { flex: 1; overflow: auto; position: relative; }
#page { max-width: 820px; margin: 0 auto; padding: 36px 48px 40vh; }
body.empty #page { display: none; }
#empty { display: none; text-align: center; padding-top: 22vh; color: var(--muted); }
body.empty #empty { display: block; }
#title { width: 100%; border: 0; outline: none; background: none; color: var(--text); font-family: inherit; font-size: 2em; font-weight: 700; line-height: 1.25; padding: 0; margin-bottom: 18px; }

/* editor */
#editor .cm-editor { background: none; color: var(--text); font-size: 16px; }
#editor .cm-editor.cm-focused { outline: none; }
#editor .cm-scroller { font-family: inherit; line-height: 1.7; }
#editor .cm-content { padding: 0; caret-color: var(--accent); font-family: inherit; line-height: 1.7; }
#editor .cm-line { padding: 0; }
#editor .cm-activeLine { background: none; }
#editor .cm-cursor { border-left: 2px solid var(--accent); }
#editor .cm-selectionBackground, #editor .cm-focused .cm-selectionBackground, #editor ::selection { background: #8b7bff44 !important; }
#editor .cm-placeholder { color: var(--faint); }
#editor .cm-wikilink { color: var(--accent); cursor: pointer; }
#editor .cm-wikilink:hover { text-decoration: underline; }
#editor .cm-selectionMatch { background: #ffd60a22; }
#editor .cm-tooltip { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
#editor .cm-tooltip-autocomplete ul li[aria-selected] { background: var(--accent); color: #fff; }
#editor .cm-panels { background: var(--side); color: var(--text); border-color: var(--line); }
#editor .cm-panels input, #editor .cm-panels button { color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
body.reading #editor { display: none; }

/* reading view */
#reading { display: none; font-size: 16px; line-height: 1.7; }
body.reading #reading { display: block; }
#reading h1, #reading h2, #reading h3 { line-height: 1.3; margin: 1.2em 0 .5em; }
#reading code { font-family: var(--mono); color: var(--code); font-size: .9em; }
#reading pre { background: var(--side); padding: 12px 14px; border-radius: 8px; overflow: auto; }
#reading blockquote { border-left: 3px solid var(--accent); margin: 0; padding-left: 14px; color: var(--muted); }
#reading a { color: var(--accent); }
#reading a.wikilink { cursor: pointer; text-decoration: none; }
#reading a.wikilink:hover { text-decoration: underline; }
#reading a.unresolved { opacity: .65; }
#reading img { max-width: 100%; }

/* drawing fields */
.ink-embed { white-space: normal; margin: 10px 0; border-radius: 10px; border: 1px solid var(--line); overflow: hidden; background: var(--panel); transition: border-color .15s, box-shadow .15s; }
.ink-embed.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ink-paper { position: relative; cursor: pointer; line-height: 0; min-height: 60px; }
.ink-paper canvas { width: 100%; height: 100%; display: block; }
.ink-overlay { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transition: opacity .15s; background: #00000010; line-height: 1.4; }
.ink-overlay span { background: #000a; color: #fff; padding: 6px 12px; border-radius: 16px; font-size: 13px; }
.ink-paper:hover .ink-overlay { opacity: 1; }
.ink-embed.active .ink-overlay { display: none; }
.ink-bar { display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); line-height: 1.4; }
.ink-embed.active .ink-state { color: var(--accent); }
.ink-embed.active .ink-state::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 6px; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.ink-btn { border: 0; background: none; padding: 3px 8px; border-radius: 5px; color: var(--muted); font-size: 12px; }
.ink-btn:hover { background: var(--hover); color: var(--text); }
.ink-btn[hidden] { display: none; }
.ink-done { background: var(--accent); color: #fff; }
.ink-done:hover { background: var(--accent); color: #fff; filter: brightness(1.1); }
.ink-remove { opacity: 0; }
.ink-embed:hover .ink-remove { opacity: 1; }

/* status bar */
#status { display: flex; align-items: center; gap: 14px; padding: 3px 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
#tablet-chip { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--muted); padding: 2px 6px; border-radius: 5px; font-size: 12px; }
#tablet-chip:hover { background: var(--hover); color: var(--text); }
#tablet-chip i { width: 7px; height: 7px; border-radius: 50%; background: #d29922; }
#tablet-chip.ok i { background: #3fb950; }
#tablet-chip.off i { background: #f85149; }

/* menus, modals, toast */
#ctx { position: fixed; z-index: 50; min-width: 160px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: 0 10px 30px #0006; }
#ctx[hidden] { display: none; }
#ctx button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 10px; border-radius: 5px; font-size: 13px; }
#ctx button:hover { background: var(--hover); }
#ctx .danger { color: #f85149; }
.modal { position: fixed; inset: 0; z-index: 40; background: #0008; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.modal[hidden] { display: none; }
.dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 20px 60px #0008; width: 100%; max-width: 560px; }
.switcher input { width: 100%; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); font: inherit; font-size: 16px; outline: none; }
.switcher .list { max-height: 50vh; overflow: auto; padding: 6px; }
.switcher .item { padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.switcher .item.sel { background: var(--accent-soft); }
.connect { padding: 20px 24px; }
.connect h2 { margin: 0 0 8px; font-size: 20px; }
.connect .urls { display: flex; flex-wrap: wrap; gap: 16px; margin: 14px 0; }
.connect .url { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.connect .url img { width: 168px; height: 168px; background: #fff; border-radius: 8px; padding: 6px; }
.connect code { font-family: var(--mono); font-size: 13px; user-select: all; }
.connect .docker[hidden] { display: none; }
#toast { position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(10px); background: var(--panel); border: 1px solid var(--line); padding: 8px 16px; border-radius: 8px; box-shadow: 0 10px 30px #0006; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; font-size: 14px; z-index: 60; }
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 720px) {
  #sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; box-shadow: 10px 0 30px #0006; }
  #page { padding: 24px 16px 40vh; }
  #btn-draw { font-size: 0; gap: 0; padding: 5px 8px; }
}
