:root {
  --bg: #f7f6f3;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #6b6f76;
  --border: #e3e1dc;
  --accent: #3b6ef5;
  --accent-text: #ffffff;
  --code-bg: #f1efea;
  --hover: #efede8;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181b; --panel: #1e2024; --text: #e6e6e6; --muted: #9a9ea6;
    --border: #2e3137; --accent: #6b93ff; --accent-text: #0d0f14;
    --code-bg: #26292e; --hover: #2a2d33;
  }
}
:root[data-theme="dark"] {
  --bg: #17181b; --panel: #1e2024; --text: #e6e6e6; --muted: #9a9ea6;
  --border: #2e3137; --accent: #6b93ff; --accent-text: #0d0f14;
  --code-bg: #26292e; --hover: #2a2d33;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--sans);
  display: flex; flex-direction: column;
}

header {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.filename {
  display: flex; align-items: center; gap: 2px; flex: 1 1 220px; min-width: 0;
}
.filename input {
  flex: 1; min-width: 0; font: 600 16px var(--sans); color: var(--text);
  background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 6px 8px;
}
.filename input:hover { border-color: var(--border); }
.filename input:focus { outline: none; border-color: var(--accent); }
.filename span { color: var(--muted); font-size: 16px; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }
button {
  font: 500 13px var(--sans); color: var(--text); background: transparent;
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; cursor: pointer;
}
button:hover { background: var(--hover); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); }

.toolbar {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 6px 16px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.toolbar button { border-color: transparent; min-width: 32px; padding: 5px 8px; }
.toolbar .sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.toolbar .spacer { flex: 1; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button[aria-pressed="true"] { background: var(--hover); font-weight: 600; }
label.toggle { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-right: 8px; cursor: pointer; }

main { flex: 1; display: flex; min-height: 0; }
.pane { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pane + .pane { border-left: 1px solid var(--border); }
main[data-view="edit"] #previewPane, main[data-view="preview"] #editPane { display: none; }

textarea {
  flex: 1; width: 100%; resize: none; border: 0; outline: none;
  padding: 24px 28px; background: var(--panel); color: var(--text);
  font: 15px/1.65 var(--mono); tab-size: 4;
}
#preview { flex: 1; overflow: auto; padding: 24px 32px; background: var(--bg); }
.doc { max-width: 720px; margin: 0 auto; font-size: 16px; line-height: 1.7; }
.doc h1, .doc h2, .doc h3, .doc h4 { line-height: 1.25; margin: 1.4em 0 .5em; }
.doc h1 { font-size: 2em; border-bottom: 1px solid var(--border); padding-bottom: .25em; }
.doc h2 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: .2em; }
.doc > :first-child { margin-top: 0; }
.doc a { color: var(--accent); }
.doc code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: .15em .35em; border-radius: 4px; }
.doc pre { background: var(--code-bg); padding: 14px 16px; border-radius: 8px; overflow: auto; }
.doc pre code { background: none; padding: 0; }
.doc blockquote { margin: 1em 0; padding: .2em 1em; border-left: 4px solid var(--border); color: var(--muted); }
.doc img { max-width: 100%; }
.doc hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.doc table { border-collapse: collapse; display: block; overflow: auto; }
.doc th, .doc td { border: 1px solid var(--border); padding: 6px 12px; }
.doc li.task { list-style: none; margin-left: -1.3em; }
.empty { color: var(--muted); font-style: italic; }

footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 6px 16px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--border); background: var(--panel);
}
#toast {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px;
  font-size: 13px; opacity: 0; transition: .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 760px) {
  main[data-view="split"] #previewPane { display: none; }
  textarea, #preview { padding: 16px; }
}

/* help dialog */
dialog#help {
  width: min(620px, calc(100% - 32px)); max-height: calc(100% - 48px);
  padding: 0; border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog#help::backdrop { background: rgba(0,0,0,.35); }
.help-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel);
}
.help-head h2 { margin: 0; font-size: 18px; }
.help-head button { border: 0; font-size: 16px; }
.help-body { padding: 8px 20px 20px; font-size: 14px; line-height: 1.6; }
.help-body ul { padding-left: 1.2em; }
.help-body li { margin: .45em 0; }
.help-body h3 { font-size: 14px; margin: 1.2em 0 .5em; }
.keys { border-collapse: collapse; }
.keys td { padding: 4px 14px 4px 0; }
kbd {
  font: 12px var(--mono); background: var(--code-bg); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px;
}
.note { color: var(--muted); margin-bottom: 0; }

/* Mac / Windows sections in help */
.os-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 1.4em; border-top: 1px solid var(--border); padding-top: 1em; }
.os-head h3 { margin: 0; }
.help-body h4 { font-size: 13px; margin: 1.1em 0 .2em; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.os { display: none; }
dialog[data-os="mac"] .os[data-for="mac"], dialog[data-os="win"] .os[data-for="win"] { display: block; }

/* top app bar */
.appbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-width: 0; }
.brand img { flex: none; border-radius: 7px; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; }
.brand-tagline { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 10px; border-left: 1px solid var(--border); }
@media (max-width: 600px) { .brand-tagline { display: none; } }
.appbar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 36px; height: 36px; padding: 0; display: grid; place-items: center;
  border-color: transparent; border-radius: 8px; color: var(--muted);
}
.icon-btn:hover { color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* show the moon in light mode and the sun in dark mode */
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: block; }
  :root:not([data-theme="light"]) .i-moon { display: none; }
}

/* privacy notice */
.privacy-link {
  display: inline-flex; align-items: center; gap: 5px; padding: 0; border: 0;
  font-size: 12px; color: var(--muted); background: none;
}
.privacy-link:hover { background: none; color: var(--text); text-decoration: underline; }
.privacy-link svg, .privacy h3 svg {
  width: 13px; height: 13px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.privacy { margin-top: 1.4em; border-top: 1px solid var(--border); padding-top: 1em; }
.privacy h3 { display: flex; align-items: center; gap: 6px; margin-top: 0; }
.privacy h3 svg { width: 16px; height: 16px; }
.privacy .note { font-size: 13px; }
@media (max-width: 600px) { footer { justify-content: center; text-align: center; } }

/* version number in footer */
.footer-end { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.version { padding-left: 10px; border-left: 1px solid var(--border); font-variant-numeric: tabular-nums; }
