/* Margin — quiet page, loud only where a decision is pending. */
:root {
  --bg: #fbfaf7; --ink: #1d1c1a; --muted: #8a867e; --line: #e7e3da;
  --panel: #f4f2ec; --alt: #b9a47a; --hl: #f1e7cf; --cut: #e9e2f3; --flag: #fbe3a7;
  --accent: #2f5d50;
  --serif: "Iowan Old Style", Charter, "Palatino Linotype", Georgia, serif;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, Menlo, Consolas, monospace;
  --typewriter: "American Typewriter", "Courier Prime", "Courier New", Courier, monospace;
  --ed-font: var(--serif); --ed-ink: var(--ink);
}
/* Look (Settings): editor font and ink colour, set as data-font / data-ink on <html> */
[data-font="sans"] { --ed-font: var(--ui); }
[data-font="mono"] { --ed-font: var(--mono); }
[data-font="typewriter"] { --ed-font: var(--typewriter); }
[data-ink="sepia"] { --ed-ink: #5b4636; }
[data-ink="blue"] { --ed-ink: #1f3a68; }
[data-ink="green"] { --ed-ink: #24543f; }
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18; --ink: #e9e5dc; --muted: #8f8a80; --line: #34312c;
    --panel: #22201d; --alt: #9c8a62; --hl: #3a3224; --cut: #342d3d; --flag: #5a4716;
    --accent: #8cc4b2;
  }
  [data-ink="sepia"] { --ed-ink: #d9c3a5; }
  [data-ink="blue"] { --ed-ink: #a9c1e8; }
  [data-ink="green"] { --ed-ink: #9fd3b5; }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 13px/1.4 var(--ui); display: flex; flex-direction: column; }
button { font: inherit; color: inherit; background: none; border: 1px solid transparent; border-radius: 6px; padding: 4px 9px; cursor: pointer; }
button:hover { background: var(--panel); border-color: var(--line); }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 10px; }
kbd { font: 11px var(--ui); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

/* ---------- top bar ---------- */
#bar { display: flex; align-items: center; gap: 4px; padding: 6px 12px; color: var(--muted); border-bottom: 1px solid transparent; }
#file { color: var(--ink); opacity: .7; }
#status { margin-left: 8px; font-size: 12px; }
#count { margin-right: 8px; font-variant-numeric: tabular-nums; }
#bar button[aria-pressed="true"] { color: var(--ink); background: var(--panel); border-color: var(--line); }

/* ---------- layout ---------- */
main { flex: 1; display: flex; min-height: 0; }
#page { flex: 1; overflow-y: auto; }
#side { width: 320px; flex: none; border-left: 1px solid var(--line); background: var(--panel); padding: 14px; overflow-y: auto; }
#side h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; }
#side h3:first-child { margin-top: 0; }
.row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.row button, #side > section > button { border-color: var(--line); background: var(--bg); }

/* ---------- the page ---------- */
#ed { max-width: 700px; margin: 0 auto; padding: 64px 40px 45vh; outline: none;
      font: calc(19px * var(--zoom, 1))/1.7 var(--ed-font); color: var(--ed-ink); caret-color: var(--accent); }
[data-font="mono"] #ed, [data-font="typewriter"] #ed { font-size: calc(17px * var(--zoom, 1)); } /* fixed-width faces run wide */
#ed > div { min-height: 1.7em; }
/* Markdown styling while editing: marks fade, content looks like what it means */
#ed > div.h { font-weight: 700; line-height: 1.3; margin: .3em 0 .2em; }
#ed > div.h1 { font-size: 1.6em; }
#ed > div.h2 { font-size: 1.35em; }
#ed > div.h3 { font-size: 1.15em; }
#ed > div.li { padding-left: 1.1em; text-indent: -1.1em; }
#ed > div.quote { border-left: 3px solid var(--line); padding-left: .8em; color: color-mix(in srgb, var(--ink) 75%, var(--bg)); }
#ed > div.hr, #ed > div.tsep, #ed > div.fence { color: var(--muted); opacity: .5; font-size: .8em; }
#ed > div.code { font: .85em/1.6 ui-monospace, Menlo, monospace; background: var(--panel); padding: 0 .6em; }
#ed > div.tr { font-size: .92em; }
.md-mark { color: var(--muted); opacity: .45; font-weight: 400; font-style: normal; }
.md-b { font-weight: 700; }
.md-i { font-style: italic; }
.md-code { font: .86em ui-monospace, Menlo, monospace; background: var(--panel); border-radius: 4px; padding: 0 3px; }
.md-link { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

/* the What's New window: no editor controls, just the notes */
body.notes-window #bar > :not(#file) { display: none; }

/* reading view (⇧⌘P) */
body.reading #ed, body:not(.reading) #preview { display: none; }
#preview { max-width: 760px; margin: 0 auto; padding: 56px 40px 30vh; font: calc(17px * var(--zoom, 1))/1.65 var(--ui); }
#preview h1, #preview h2, #preview h3 { line-height: 1.25; margin: 1.4em 0 .5em; }
#preview h1 { font-size: 2em; } #preview h2 { font-size: 1.5em; } #preview h3 { font-size: 1.2em; }
#preview :is(h1, h2, h3):first-child { margin-top: 0; }
#preview code { font: .88em ui-monospace, Menlo, monospace; background: var(--panel); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
#preview pre { background: var(--panel); border-radius: 8px; padding: 12px 14px; overflow-x: auto; }
#preview pre code { border: 0; padding: 0; background: none; }
#preview blockquote { margin: 1em 0; padding-left: 1em; border-left: 3px solid var(--line); color: var(--muted); }
#preview hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
#preview a { color: var(--accent); }
#preview table { border-collapse: separate; border-spacing: 0; width: 100%; margin: 1.2em 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
#preview th, #preview td { text-align: left; vertical-align: top; padding: 10px 14px; border-top: 1px solid var(--line); }
#preview th + th, #preview td + td { border-left: 1px solid var(--line); }
#preview thead th { border-top: 0; background: var(--panel); }
#preview td:first-child { font-weight: 600; white-space: nowrap; }

/* alternates: wavy underline, dots = how many versions, filled dot = the one shown */
.alt { text-decoration: underline wavy var(--alt) 1px; text-underline-offset: 5px; cursor: pointer; border-radius: 3px; }
.alt::after { content: attr(data-dots); font: 7px var(--ui); letter-spacing: 1px; vertical-align: super; color: var(--muted); margin-left: 2px; }
.alt.variant::after { color: var(--accent); }
.alt.single { text-decoration: none; }
.alt.single::after { content: none; }
.alt:hover, .alt.focus { background: var(--hl); }

/* stash marker: where a passage went to the overflow (⌘J). Text-free, so it never counts as words */
.stash { display: inline-block; vertical-align: .1em; margin: 0 2px; padding: 0 5px; border-radius: 6px;
         font: 600 .62em/1.5 var(--ui); color: var(--muted); background: var(--panel); border: 1px solid var(--line);
         cursor: pointer; user-select: none; }
.stash::before { content: "⤶ stashed"; }
.stash:hover { color: var(--accent); border-color: var(--accent); }
.hint .stash { cursor: default; }
/* Overflow panel: the stashed passages, each with Put back */
#stashes { list-style: none; padding: 0; margin: 0 0 10px; }
#stashes li { display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px; margin-bottom: 4px; border-radius: 6px;
              background: var(--bg); border: 1px solid var(--line); cursor: pointer; }
#stashes q { flex: 1; font: 13px/1.4 var(--serif); quotes: none; color: var(--ink); }
#stashes button { flex: none; font-size: 12px; border-color: var(--line); }
#stashes button:hover { color: var(--accent); border-color: var(--accent); }

/* ghosted text: still there, easy to ignore */
.ghost { opacity: .16; transition: opacity .15s; }
.ghost:hover { opacity: .45; }
.ghost.trim { opacity: .22; background: var(--cut); border-radius: 2px; }
.flag { background: var(--flag); border-radius: 2px; cursor: help; }
.flash { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- alternates panel ---------- */
.opt { display: flex; align-items: flex-start; gap: 4px; padding: 3px; border-radius: 6px; }
.opt.on { background: var(--bg); box-shadow: inset 0 0 0 1px var(--line); }
.opt .mark { width: 24px; padding: 4px 0; color: var(--muted); }
.opt.on .mark { color: var(--accent); }
.opt textarea, #addOpt, #overflow, dialog input {
  flex: 1; width: 100%; font: 14px/1.45 var(--serif); color: var(--ink); background: transparent;
  border: 1px solid transparent; border-radius: 5px; padding: 4px 6px; resize: none; outline: none; }
.opt textarea:focus, #addOpt:focus, dialog input:focus { border-color: var(--line); background: var(--bg); }
.opt .del { color: var(--muted); padding: 4px 6px; visibility: hidden; }
.opt:hover .del { visibility: visible; }
#addOpt { margin: 6px 0 10px; border-color: var(--line); background: var(--bg); }
.legend { color: var(--muted); font-size: 11px; margin-top: 10px; }

#overflow { min-height: 60vh; border-color: var(--line); background: var(--bg); resize: vertical; }

/* history panel + version view (shown in the reading area) */
#versions { list-style: none; padding: 0; margin: 0; }
#versions li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; margin-bottom: 4px; background: var(--bg); }
#versions li span { color: var(--muted); font-size: 12px; }
#versions li.empty { cursor: default; color: var(--muted); background: none; }
#preview.versions { font: calc(17px * var(--zoom, 1))/1.6 var(--ed-font); }
#preview.versions > div { min-height: 1.6em; padding: 0 6px; border-radius: 4px; }
.version-bar { position: sticky; top: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 0 12px;
               background: var(--bg); font: 13px var(--ui); color: var(--muted); z-index: 1; }
.version-bar span { flex: 1 1 260px; }
.v-same { opacity: .55; }
.v-old { background: var(--hl); }
.v-new { text-decoration: line-through; text-decoration-color: var(--muted); opacity: .4; }
.bring { float: right; font: 12px var(--ui); border-color: var(--line); background: var(--bg); padding: 1px 8px; margin-left: 8px; }

/* Lab ▸ Publish */
.pub { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.pub button { flex: none; border-color: var(--line); background: var(--bg); }
.pub span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#publish .notes { margin: 8px 0 0; padding-left: 1.1em; color: var(--muted); font-size: 12px; }

#findings { list-style: none; padding: 0; margin: 8px 0; }
#findings li { padding: 6px 8px; border-radius: 6px; cursor: pointer; margin-bottom: 4px; background: var(--bg); }
#findings li q { font-family: var(--serif); display: block; }
#findings li span { color: var(--muted); font-size: 12px; }

/* drag a file over the window */
body.dropping #page { outline: 2px dashed var(--accent); outline-offset: -14px; border-radius: 18px; }

/* ---------- menu, toast, dialog ---------- */
#menu { position: fixed; z-index: 10; min-width: 230px; padding: 5px; background: var(--bg); border: 1px solid var(--line);
        border-radius: 9px; box-shadow: 0 8px 28px rgba(0,0,0,.16); }
#menu button { display: flex; width: 100%; text-align: left; border: 0; padding: 5px 9px; }
#menu button:hover { background: var(--hl); }
#menu kbd { margin-left: auto; border: 0; color: var(--muted); }
#menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
         padding: 8px 14px; border-radius: 8px; max-width: 80vw; z-index: 20; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); width: 460px; max-width: calc(100vw - 32px); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.25); }
dialog h2 { margin: 0 0 14px; font-size: 16px; }
dialog p, dialog li { line-height: 1.5; }
dialog ul { padding-left: 1.2em; margin: 8px 0 12px; }
dialog label { display: block; margin-bottom: 6px; color: var(--muted); }
dialog input { display: block; margin-top: 4px; border-color: var(--line); font: 13px var(--ui); }
dialog h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; }
.look { display: flex; gap: 8px; }
.look label { flex: 1; }
dialog input[type=range] { padding: 0; accent-color: var(--accent); }
dialog select { display: block; width: 100%; margin-top: 4px; font: 13px var(--ui); color: var(--ink); background: var(--bg);
                border: 1px solid var(--line); border-radius: 5px; padding: 4px; }
dialog menu { display: flex; gap: 6px; padding: 0; margin: 16px 0 0; }
.primary { background: var(--accent); color: var(--bg); }
.primary:hover { background: var(--accent); opacity: .9; }
