:root {
  --bg: #0b0f14;
  --panel: #121820;
  --panel2: #0f141b;
  --line: #223041;
  --text: #e6edf3;
  --muted: #8fa3b8;
  --accent: #4aa3ff;
  --accent2: #2b6fd6;
  --err: #ff6b6b;
  --ok: #5fd08a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.dot { color: var(--accent); }

/* login */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #16202c, var(--bg));
  padding: 24px;
}
.card {
  width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px 22px; text-align: center; display: flex; flex-direction: column; gap: 12px;
}
.card h1 { margin: 0; font-size: 30px; letter-spacing: -0.5px; }
.card p { margin: -6px 0 8px; }

/* header */
header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 14px 12px calc(14px + env(safe-area-inset-top)); background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 20px; letter-spacing: 0; white-space: nowrap; }
.agent-switch {
  display: grid; grid-template-columns: 1fr 1fr; min-width: 128px;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel2);
}
.agent-choice {
  min-width: 0; height: 34px; padding: 0 10px; border-radius: 0;
  background: transparent; color: var(--muted); font-size: 13px; font-weight: 700;
}
.agent-choice + .agent-choice { border-left: 1px solid var(--line); }
.agent-choice.active { background: #14202e; color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }

/* tabs */
.tabs { display: flex; gap: 6px; padding: 10px 12px; position: sticky; top: 52px; background: var(--bg); z-index: 4; }
.tab {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--muted); font-weight: 600;
}
.tab.active { color: var(--text); border-color: var(--accent2); background: #14202e; }

main { padding: 12px 12px 40px; max-width: 720px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.composer { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
textarea {
  width: 100%; resize: vertical; background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: inherit;
}
textarea:focus { outline: none; border-color: var(--accent2); }
.row { display: flex; gap: 8px; margin-top: 10px; }

button { cursor: pointer; border: none; border-radius: 10px; font: inherit; }
input { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: inherit; }
input:focus { outline: none; border-color: var(--accent2); }

.primary { background: var(--accent); color: #05121f; font-weight: 700; padding: 12px 16px; flex: 1; }
.primary:active { background: var(--accent2); }
.primary.wide { width: 100%; }
.primary[disabled], .card button[disabled] { opacity: .55; cursor: default; }
.card button { background: var(--accent); color: #05121f; font-weight: 700; padding: 12px; }
.ghost { background: transparent; color: var(--muted); font-size: 18px; padding: 6px 10px; }
.mic { width: 48px; background: var(--panel2); border: 1px solid var(--line); color: var(--text); font-size: 18px; }
.mic.rec { background: #3a1a1a; border-color: var(--err); color: var(--err); }

.out { margin-top: 14px; padding: 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); min-height: 8px; }
.out:empty { display: none; }
.out.loading { color: var(--muted); }
.out .banner-ok { color: var(--ok); font-weight: 600; margin-bottom: 10px; }
.err { color: var(--err); font-size: 14px; min-height: 16px; }

/* rendered markdown */
.md { line-height: 1.6; font-size: 15px; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { color: var(--text); font-weight: 700; line-height: 1.25; margin: 1.25em 0 .5em; }
.md h1 { font-size: 1.3rem; }
.md h2 { font-size: 1.15rem; }
.md h3 { font-size: 1rem; color: var(--accent); padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.md h4 { font-size: .82rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.md p { margin: .55em 0; }
.md strong { color: #fff; font-weight: 700; }
.md a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(74,163,255,.4); }
.md a:hover { border-bottom-color: var(--accent); }
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; background: #0b1420; color: #9fd0ff; border: 1px solid var(--line); border-radius: 6px; padding: .06em .38em; }
.md pre { background: #0b1420; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: .6em 0; }
.md pre code { background: none; border: none; padding: 0; color: #cfe6ff; }
.md ul, .md ol { margin: .5em 0; padding-left: 0; list-style: none; }
.md ol { counter-reset: li; }
.md li { position: relative; padding-left: 1.5em; margin: .3em 0; }
.md ul > li::before { content: ""; position: absolute; left: .4em; top: .66em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent2); }
.md ol > li { counter-increment: li; }
.md ol > li::before { content: counter(li) "."; position: absolute; left: 0; top: 0; color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.md li.task { padding-left: 2em; }
.md li.task::before { display: none; }
.md .chk { position: absolute; left: 0; top: .12em; width: 1.2em; height: 1.2em; border: 1.5px solid var(--line); border-radius: 5px; background: var(--panel2); display: inline-flex; align-items: center; justify-content: center; font-size: .78em; color: #05121f; line-height: 1; }
.md .chk.on { background: var(--ok); border-color: var(--ok); }
.md blockquote { margin: .6em 0; padding: .35em .9em; color: var(--muted); border-left: 3px solid var(--accent2); background: rgba(43,111,214,.07); border-radius: 0 8px 8px 0; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 1em 0; }
.md .wl, .md .ref { border-radius: 6px; padding: .02em .4em; font-size: .92em; white-space: nowrap; }
.md .wl { color: var(--accent); background: rgba(74,163,255,.1); border: 1px solid rgba(74,163,255,.22); }
.md .ref { color: var(--muted); background: rgba(143,163,184,.08); border: 1px solid rgba(143,163,184,.2); }
/* clickable wikilinks / vault refs are anchors — drop the generic underline, add pointer */
.md a.wl, .md a.ref { border-bottom: none; cursor: pointer; }
.md a.wl:hover { background: rgba(74,163,255,.2); }
.md a.ref:hover { background: rgba(143,163,184,.16); }

/* header buttons */
#menuBtn { font-size: 22px; }

/* drawer + backdrop */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 76%; max-width: 300px; z-index: 21;
  background: var(--panel); border-right: 1px solid var(--line);
  transform: translateX(-100%); transition: transform .22s ease;
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); padding-top: calc(14px + env(safe-area-inset-top));
  display: flex; flex-direction: column; gap: 4px;
}
.drawer.open { transform: translateX(0); }
.drawer-head { font-size: 20px; font-weight: 700; padding: 8px 10px 14px; }
.navitem {
  text-align: left; background: transparent; color: var(--muted);
  padding: 13px 12px; border-radius: 10px; font-size: 16px; font-weight: 600;
  display: flex; align-items: center; gap: 12px;
}
.navitem .ni-ic { width: 20px; text-align: center; color: var(--muted); }
.navitem.active { background: #14202e; color: var(--text); }
.navitem.active .ni-ic { color: var(--accent); }

/* notes browser */
#noteSearch { width: 100%; margin-bottom: 6px; }
.notecount { font-size: 12px; margin: 2px 2px 10px; }
.notelist { display: flex; flex-direction: column; gap: 3px; }
.note-group {
  position: sticky; top: 52px; z-index: 1;
  font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); background: var(--bg); padding: 12px 6px 4px;
}
.note-item {
  text-align: left; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; display: flex; flex-direction: column; gap: 2px; width: 100%;
}
.note-item:active { background: #14202e; }
.ni-name { color: var(--text); font-weight: 600; }
.ni-path { color: var(--muted); font-size: 12px; }

/* note reader */
.reader-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.reader-bar .ghost { font-size: 18px; border: 1px solid var(--line); border-radius: 10px; padding: 5px 13px; background: var(--panel2); }
.reader-path { color: var(--muted); font-size: 13px; word-break: break-all; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 30; background: #1b2937; color: var(--text); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90%; box-shadow: 0 6px 24px rgba(0,0,0,.4);
}

@media (max-width: 380px) {
  header { padding-left: 8px; padding-right: 8px; gap: 6px; }
  .brand { font-size: 18px; }
  .agent-switch { min-width: 112px; }
  .agent-choice { padding: 0 7px; font-size: 12px; }
  .ghost { padding-left: 8px; padding-right: 8px; }
}
