:root {
  --bg: #fff;
  --fg: oklch(14.5% 0 0);
  --muted: oklch(55.6% 0 0);
  --line: oklch(92.2% 0 0);
  --hover: oklch(97% 0 0);
  --press: oklch(92.2% 0 0);
  --code: oklch(97% 0 0);
  --mark: #fff3a3;
  --r: 3px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, Menlo, Consolas, monospace;
  --measure: 42rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: oklch(14.5% 0 0); --fg: oklch(98.5% 0 0); --muted: oklch(70.8% 0 0);
    --line: oklch(26.9% 0 0); --hover: oklch(20.5% 0 0); --press: oklch(26.9% 0 0);
    --code: oklch(20.5% 0 0); --mark: #5c5000;
  }
}
:root[data-theme="dark"] {
  --bg: oklch(14.5% 0 0); --fg: oklch(98.5% 0 0); --muted: oklch(70.8% 0 0);
  --line: oklch(26.9% 0 0); --hover: oklch(20.5% 0 0); --press: oklch(26.9% 0 0);
  --code: oklch(20.5% 0 0); --mark: #5c5000;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
body[data-width="wide"] { --measure: 54rem; }

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--sans); }
#root { isolation: isolate; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: -1px; }
kbd { font: 11px var(--mono); color: var(--muted); }
code { font-family: var(--mono); }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 28px; padding: 0 10px; margin: 0;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--bg);
  cursor: default; white-space: nowrap; user-select: none;
}
.btn:hover { background: var(--hover); }
.btn:active, .btn[data-pressed], .btn[data-popup-open] { background: var(--press); }
.btn.ghost { border-color: transparent; }
.btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn.primary:hover { opacity: .88; }
.btn.sm { height: 24px; padding: 0 8px; font-size: 12px; }

/* bar */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg);
  transition: opacity .3s;
}
.bar-side { display: flex; align-items: center; gap: 2px; }
body.typing .bar, body.typing .foot { opacity: 0; }
body.typing .bar:hover, body.typing .bar:focus-within { opacity: 1; }

/* popups */
.positioner { z-index: 50; outline: 0; }
.popup {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: 0 2px 8px rgb(0 0 0 / .08); outline: 0;
  transition: opacity .1s;
}
.popup[data-starting-style], .popup[data-ending-style] { opacity: 0; }
.menu { padding: 4px; min-width: 180px; }
.item {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 5px 8px; border-radius: 2px; cursor: default; user-select: none; outline: 0;
}
.item[data-highlighted] { background: var(--hover); }
.item-ind { display: flex; }
.sep { height: 1px; margin: 4px; background: var(--line); }

/* drafts */
.drafts { width: 280px; max-height: 70vh; display: flex; flex-direction: column; }
.drafts-head { display: flex; gap: 4px; padding: 6px; border-bottom: 1px solid var(--line); }
.drafts-list { list-style: none; margin: 0; padding: 4px; overflow-y: auto; }
.drafts-list li { display: flex; border-radius: 2px; }
.drafts-list li:hover, .drafts-list li.current { background: var(--hover); }
.drafts-list button { border: 0; background: none; cursor: default; }
.drafts-list .open { flex: 1; min-width: 0; text-align: left; padding: 6px 8px; display: flex; justify-content: space-between; gap: 8px; }
.drafts-list .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drafts-list .m { color: var(--muted); font-size: 12px; white-space: nowrap; }
.drafts-list .del { color: var(--muted); padding: 0 8px; font-size: 15px; visibility: hidden; }
.drafts-list li:hover .del { visibility: visible; }
.drafts-list .del:hover { color: var(--fg); }

/* page */
.page { max-width: calc(var(--measure) + 32px); margin: 0 auto; padding: 48px 16px 40vh; }
.title {
  display: block; width: 100%; padding: 0; margin: 0 0 20px; border: 0; background: none;
  font: 600 28px/1.25 var(--sans);
}
.title:focus { outline: none; }
.title::placeholder { color: var(--muted); }

/* fields */
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.label { font-size: 12px; color: var(--muted); }
.input {
  width: 100%; height: 28px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--bg);
}
textarea.input { height: auto; padding: 6px 8px; resize: vertical; }
.input:focus { outline: 1px solid var(--fg); outline-offset: -1px; }
.select { display: flex; align-items: center; justify-content: space-between; cursor: default; text-align: left; }
.select-icon { display: flex; color: var(--muted); }
.row { display: flex; gap: 4px; }
.check { display: flex; align-items: center; gap: 8px; cursor: default; }
.checkbox {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border: 1px solid var(--muted); border-radius: 2px; background: var(--bg);
}
.checkbox[data-checked] { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.checkbox-ind { display: flex; }
.checkbox-ind[data-unchecked] { display: none; }

/* attributes */
.attrs-panel { overflow: hidden; }
.attrs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px;
  margin: 0 0 28px; padding: 12px; border: 1px solid var(--line); border-radius: var(--r);
}
.attrs .wide { grid-column: 1 / -1; }
.attrs .checks { display: flex; gap: 18px; align-items: flex-end; padding-bottom: 5px; }
.attrs .check { font-size: 12px; }

/* dialog */
.backdrop { position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / .2); }
.dialog {
  position: fixed; top: 50%; left: 50%; z-index: 31; transform: translate(-50%, -50%);
  width: min(380px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; padding: 16px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: 0 4px 16px rgb(0 0 0 / .12);
}
.dialog-title { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.fields { display: flex; flex-direction: column; gap: 10px; }
.actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 16px; }
.help { width: min(420px, calc(100vw - 32px)); }
.help table { width: 100%; border-collapse: collapse; }
.help td { padding: 4px 0; border-bottom: 1px solid var(--line); }
.help td:last-child { text-align: right; }
.help code { background: var(--code); padding: 0 3px; border-radius: 2px; }

/* toast */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 60; width: max-content; }
.toast {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  background: var(--fg); color: var(--bg); border-radius: var(--r);
  transition: opacity .15s;
}
.toast[data-starting-style], .toast[data-ending-style] { opacity: 0; }
.toast-content { display: flex; align-items: center; gap: 10px; padding: 6px 12px; white-space: nowrap; }
.toast .btn { background: transparent; color: inherit; border-color: currentColor; }

/* editor */
#editor { position: relative; }
.ProseMirror {
  outline: none; white-space: pre-wrap; word-wrap: break-word;
  font: 17px/1.65 var(--sans); font-variant-ligatures: none;
}
.ProseMirror pre { white-space: pre-wrap; }
.ProseMirror-hideselection *::selection { background: transparent; }
.ProseMirror-selectednode { outline: 2px solid var(--fg); }
.drop-cursor { background: var(--fg) !important; }

.prose > * + * { margin-top: .8em; }
.prose p { margin-bottom: 0; }
.prose li p, .prose blockquote p { margin-top: 0; }
.prose > :first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { line-height: 1.3; margin: 1.5em 0 .2em; }
.prose h1 { font-size: 1.6em; } .prose h2 { font-size: 1.3em; } .prose h3 { font-size: 1.1em; } .prose h4 { font-size: 1em; }
.prose blockquote { margin: 0; padding-left: 1em; border-left: 2px solid var(--line); color: var(--muted); }
.prose ul, .prose ol { padding-left: 1.4em; margin-bottom: 0; }
.prose li + li { margin-top: .2em; }
.prose a { color: inherit; text-underline-offset: 2px; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.prose img { max-width: 100%; height: auto; }
.prose mark { background: var(--mark); color: inherit; }
.prose sup, .prose sub { font-size: .7em; line-height: 0; }
.prose code { font-size: .85em; background: var(--code); padding: .1em .3em; border-radius: 2px; }
.prose pre { font: 13px/1.55 var(--mono); background: var(--code); padding: 10px 12px; border-radius: var(--r); margin: 1em 0; }
.prose pre code { background: none; padding: 0; font-size: inherit; }

.prose pre.raw { position: relative; border: 1px solid var(--line); background: var(--bg); padding-top: 22px; }
.prose pre.raw::before {
  content: attr(data-label); position: absolute; top: 4px; left: 12px;
  font: 10px var(--sans); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); pointer-events: none;
}
.prose pre.raw-template, .prose pre.raw-footnote { padding: 6px 12px 6px 90px; }
.prose pre.raw-template::before, .prose pre.raw-footnote::before { top: 50%; transform: translateY(-50%); }
.prose .raw-inline { font: .85em var(--mono); border: 1px solid var(--line); border-radius: 2px; padding: 0 .2em; }
.prose .is-empty::before { content: attr(data-placeholder); position: absolute; color: var(--muted); pointer-events: none; }

/* selection bubble */
.bubble {
  position: absolute; top: 0; left: 0; z-index: 4; display: flex; padding: 2px;
  background: var(--fg); border-radius: var(--r); visibility: hidden;
}
.bubble.show { visibility: visible; }
.bubble button { border: 0; background: none; color: var(--bg); min-width: 26px; padding: 2px 6px; border-radius: 2px; font-size: 13px; }
.bubble button:hover, .bubble button.on { background: rgb(127 127 127 / .35); }
.bubble mark { background: none; color: inherit; text-decoration: underline; }
.bubble code { font-size: 11px; }

/* source / preview */
.source {
  display: block; width: 100%; min-height: 60vh; padding: 0; border: 0; background: none; resize: none; overflow: hidden;
  font: 14px/1.7 var(--mono); tab-size: 2;
}
.source:focus { outline: none; }
.preview { display: block; width: 100%; height: 80vh; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }

.foot { position: fixed; right: 12px; bottom: 8px; color: var(--muted); font-size: 12px; pointer-events: none; transition: opacity .3s; }

@media (max-width: 640px) {
  .bar { padding: 6px 8px; }
  .bar .btn { padding: 0 6px; }
  .attrs { grid-template-columns: 1fr; }
  .page { padding-top: 24px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.select-pop { min-width: var(--anchor-width); }

/* password gate */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.gate-input { width: min(260px, 100%); height: 34px; }
.gate-input[aria-invalid], .gate-input[aria-invalid]:focus { border-color: oklch(57.7% 0.245 27.3); outline-color: oklch(57.7% 0.245 27.3); }
