:root {
  --bg: #fff; --fg: #1d1d1f; --muted: #6e6e73; --line: #e3e3e6; --side: #f6f6f7;
  --accent: #2463eb; --code: #f3f3f5; --edit: #fafaf7; --sel: #dbe6ff;
  --body: 17px/1.6 Charter, "Iowan Old Style", Georgia, serif;
  --ui: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1d; --fg: #e6e6e8; --muted: #9a9aa0; --line: #333337; --side: #222225;
    --accent: #6c9cff; --code: #2a2a2e; --edit: #232326; --sel: #2c3a5c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body { font: var(--ui); display: flex; flex-direction: column; }
button { font: inherit; padding: .35em .8em; border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 6px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
input { font: inherit; padding: .4em .6em; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }

#bar { display: flex; align-items: center; gap: .6em; padding: .4em .8em; border-bottom: 1px solid var(--line); white-space: nowrap; }
#bar .grow { flex: 1; }
#toggle { border: 0; font-size: 1.1em; padding: .2em .5em; }
#where { color: var(--muted); overflow: hidden; text-overflow: ellipsis; max-width: 22ch; }
#fname { font-weight: 600; cursor: text; overflow: hidden; text-overflow: ellipsis; }
#status { color: var(--muted); font-size: .9em; }
#status.dirty { color: #c27c0e; }
#status.error { color: #d33; cursor: pointer; text-decoration: underline; }
#gdocs { color: var(--accent); text-decoration: none; font-size: .9em; }

#main { flex: 1; display: flex; min-height: 0; }
#side { width: 260px; flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
body.noside #side { display: none; }
#filter { margin: .6em; }
#sources { overflow: auto; flex: 1; padding: 0 .3em 1em; }
.src { margin-bottom: .8em; }
.srchead { display: flex; align-items: center; gap: .3em; padding: .3em .4em; }
.srctitle { flex: 1; font-weight: 600; font-size: .8em; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src.on .srctitle { color: var(--fg); }
.mini { font-size: .8em; padding: .1em .5em; }
.srcnote { color: var(--muted); font-size: .9em; padding: 0 .5em .3em; }
.srcnote a { color: var(--accent); }
#sources details > summary { cursor: pointer; padding: .2em .4em; color: var(--muted); list-style: none; }
#sources details > summary::before { content: "▸ "; }
#sources details[open] > summary::before { content: "▾ "; }
#sources details > div { padding-left: .9em; }
#sources .f { display: block; padding: .25em .5em; border-radius: 5px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); }
#sources .f:hover { background: var(--line); }
#sources .f.cur { background: var(--sel); }
#sources .f .ext { color: var(--muted); font-size: .85em; }
#sources .empty { color: var(--muted); padding: .5em; }

#scroll { flex: 1; overflow: auto; }
#welcome { max-width: 46rem; margin: 3rem auto; padding: 0 1rem; }
#welcome h1 { font-size: 2em; margin: 0 0 .2em; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { filter: brightness(1.1); }
button.big { font-size: 1.1em; padding: .6em 1.2em; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 1.4rem; background: var(--bg); color: var(--fg); width: min(30rem, calc(100vw - 2rem)); }
dialog::backdrop { background: #0005; }
dialog h2 { margin: 0 0 1rem; font-size: 1.2em; }
dialog .field { display: flex; flex-direction: column; gap: .3em; font-weight: 600; }
dialog .field input { font-weight: 400; }
dialog fieldset { border: 0; padding: 0; margin: 1rem 0 0; }
dialog legend { font-weight: 600; margin-bottom: .4em; padding: 0; }
dialog fieldset label { display: flex; gap: .5em; align-items: baseline; padding: .35em .5em; border-radius: 6px; cursor: pointer; }
dialog fieldset label:hover { background: var(--side); }
dialog fieldset label.off { opacity: .45; cursor: default; }
dialog small { display: block; color: var(--muted); font-weight: 400; }
dialog .buttons { display: flex; justify-content: flex-end; gap: .6em; margin-top: 1.2rem; }
#newFormat label { display: inline-flex; }
.note { color: var(--muted); margin: 0; }
.err { color: #d33; white-space: pre-wrap; }
.help table td { padding: .15em 1em .15em 0; }
.help td:first-child { color: var(--muted); }

/* ---------- document ---------- */
#doc { max-width: 46rem; margin: 0 auto; padding: 2rem 1.5rem 40vh; font: var(--body); min-height: 100%; cursor: text; }
.blk { position: relative; border-radius: 4px; min-height: 1.6em; }
.blk.pending { white-space: pre-wrap; color: var(--muted); }
.blk > :first-child { margin-top: 0; }
.blk > :last-child { margin-bottom: 0; }
.blk + .blk { margin-top: .9em; }
.blk.k-list + .blk.k-list, .blk.k-list + .blk.k-listcont, .blk.k-listcont + .blk.k-list { margin-top: .2em; }
.blk h1, .blk h2, .blk h3, .blk h4, .blk h5, .blk h6 { margin: 0; line-height: 1.25; font-family: var(--ui); }
.k-heading.h1 + .blk, .k-heading.h2 + .blk { margin-top: .6em; }
.blk.h1 { margin-top: 1.4em; } .blk.h2 { margin-top: 1.2em; }
.blk:first-child { margin-top: 0; }
h1, .h1.editing textarea { font-size: 2em; font-weight: 700; }
h2, .h2.editing textarea { font-size: 1.5em; font-weight: 700; }
h3, .h3.editing textarea { font-size: 1.25em; font-weight: 600; }
h4, .h4.editing textarea { font-size: 1.1em; font-weight: 600; }
h5, h6, .h5.editing textarea, .h6.editing textarea { font-size: 1em; font-weight: 600; }
.blk p { margin: 0; }
.blk ul, .blk ol { margin: 0; padding-left: 1.6em; }
.blk.task ul { list-style: none; padding-left: 1.6em; }
.blk.task li { position: relative; }
.blk.task input[type=checkbox] { position: absolute; left: -1.5em; top: .35em; margin: 0; cursor: pointer; }
.blk.task li:has(input:checked) { color: var(--muted); text-decoration: line-through; }
.blk blockquote { margin: 0; padding-left: 1em; border-left: 3px solid var(--line); color: var(--muted); }
.blk pre { margin: 0; background: var(--code); padding: .7em 1em; border-radius: 6px; overflow: auto; font: 14px/1.5 var(--mono); }
.blk code { font-family: var(--mono); font-size: .88em; }
.blk :not(pre) > code { background: var(--code); padding: .1em .3em; border-radius: 4px; }
.blk a { color: var(--accent); }
.blk img { max-width: 100%; }
.blk hr { border: 0; border-top: 1px solid var(--line); margin: .6em 0; }
.blk table { border-collapse: collapse; font-size: .92em; }
.blk th, .blk td { border: 1px solid var(--line); padding: .3em .7em; }
.blk th { background: var(--side); }
.blk .raw, .blk pre.front { color: var(--muted); font: 13px/1.5 var(--mono); white-space: pre-wrap; background: none; padding: 0; }

.blk.editing { background: var(--edit); box-shadow: 0 0 0 6px var(--edit); }
.blk.editing textarea {
  display: block; width: 100%; margin: 0; padding: 0; border: 0; outline: 0; resize: none; overflow: hidden;
  background: transparent; color: var(--fg); font: inherit; line-height: inherit; tab-size: 4;
  field-sizing: content; min-height: 1.6em;
}
.blk.editing.k-heading textarea { font-family: var(--ui); line-height: 1.25; }
.blk.editing.k-fence textarea, .blk.editing.k-code textarea, .blk.editing.k-table textarea,
.blk.editing.k-html textarea, .blk.editing.k-front textarea { font: 14px/1.5 var(--mono); }

@media (max-width: 700px) {
  #side { position: fixed; z-index: 5; top: 2.6em; bottom: 0; box-shadow: 0 0 20px #0003; }
  body:not(.sideopen) #side { display: none; }
  #where, #btnDel { display: none; }
  #doc { padding: 1rem 1rem 40vh; }
}
