:root {
  color-scheme: dark;
  --bg: #0d0e10;
  --panel: #141518;
  --panel-2: #181a1e;
  --line: #2a2d33;
  --line-soft: #22252a;
  --text: #f3f4f6;
  --muted: #8d929b;
  --blue: #5e8cff;
  --paper-w: 794px;
  --paper-h: 1123px;
  --zoom: .75;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }

.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: 66px;
  flex: 0 0 66px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #111216;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: #f4f4f5; color: #121316;
  font-weight: 900; font-size: 17px;
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 14px; }
.brand span { margin-top: 1px; color: var(--muted); font-size: 11px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.filename-wrap {
  height: 38px; padding: 0 10px;
  display: flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); border-radius: 9px;
  background: #17191d;
}
.filename-wrap span { font-size: 11px; color: var(--muted); }
.filename-wrap input {
  width: 105px; border: 0; outline: none;
  color: var(--text); background: transparent; font-weight: 600;
}
.filename-wrap b { font-size: 12px; color: #747a84; }
.button {
  height: 38px; border-radius: 9px; padding: 0 14px;
  border: 1px solid var(--line); cursor: pointer; font-weight: 700;
}
.button.secondary { background: #181a1f; }
.button.primary { background: #f4f4f5; color: #101114; border-color: #f4f4f5; }
.button:disabled { opacity: .55; cursor: wait; }

.main-grid {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(470px, 1.3fr) 320px;
}
.pane { min-width: 0; min-height: 0; background: var(--panel); }
.editor-pane, .preview-pane { border-right: 1px solid var(--line); }
.editor-pane { display: flex; flex-direction: column; }
.preview-pane { display: flex; flex-direction: column; background: #1c1e22; }
.settings-pane { display: flex; flex-direction: column; }
.pane-title {
  height: 52px; flex: 0 0 52px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel-2);
}
.pane-title strong, .pane-title span { display: block; }
.pane-title strong { font-size: 12px; letter-spacing: .01em; }
.pane-title span { margin-top: 2px; color: var(--muted); font-size: 10px; }
.mini-actions, .zoom-control { display: flex; gap: 5px; align-items: center; }
.mini-actions button, .zoom-control button, .toolbar button {
  border: 1px solid transparent; background: transparent; color: #a9aeb7;
  cursor: pointer; border-radius: 6px;
}
.mini-actions button { padding: 5px 7px; font-size: 11px; }
.mini-actions button:hover, .zoom-control button:hover, .toolbar button:hover { background: #24272d; color: #fff; }

.toolbar {
  min-height: 42px; padding: 6px 9px;
  display: flex; align-items: center; flex-wrap: wrap; gap: 3px;
  border-bottom: 1px solid var(--line-soft); background: #111317;
}
.toolbar button { min-width: 28px; height: 28px; padding: 0 7px; font-size: 11px; }
.toolbar-sep { width: 1px; height: 17px; margin: 0 3px; background: var(--line); }
#markdownInput {
  flex: 1; width: 100%; min-height: 0; resize: none;
  border: 0; outline: 0; padding: 19px 20px 60px;
  background: #0f1013; color: #dfe2e7;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px; line-height: 1.68; tab-size: 2;
}

.zoom-control { padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: #121419; }
.zoom-control button { width: 25px; height: 24px; font-size: 16px; }
.zoom-control span { min-width: 40px; text-align: center; margin: 0; color: #b6bbc3; font-size: 10px; }
.preview-viewport {
  flex: 1; min-height: 0; overflow: auto; padding: 30px;
  background-color: #24262b;
  background-image: radial-gradient(#373a40 .7px, transparent .7px);
  background-size: 16px 16px;
}
.pages-container {
  width: calc(var(--paper-w) * var(--zoom));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: calc(22px * var(--zoom));
}
.page-shell {
  width: calc(var(--paper-w) * var(--zoom));
  height: calc(var(--paper-h) * var(--zoom));
  flex: 0 0 auto;
}
.paper {
  position: relative;
  overflow: hidden;
  width: var(--paper-w);
  height: var(--paper-h);
  transform: scale(var(--zoom));
  transform-origin: top left;
  background: #fff;
  color: #23252a;
  box-shadow: 0 18px 60px rgba(0,0,0,.35);
  font-family: Inter, Arial, sans-serif;
  font-size: 14.67px;
  line-height: 1.55;
}
.doc-header, .doc-footer {
  position: absolute;
  color: #777c86;
  font-size: 9px;
  letter-spacing: .02em;
  z-index: 4;
}
.doc-header { padding-bottom: 8px; border-bottom: 1px solid #eceef1; }
.doc-footer { padding-top: 8px; border-top: 1px solid #eceef1; }
.watermark {
  pointer-events: none; position: absolute; inset: 0;
  display: grid; place-items: center; z-index: 2;
  color: #111; opacity: .08; font-size: 74px; font-weight: 900;
  letter-spacing: .08em; transform: rotate(-29deg); white-space: nowrap;
}
.doc-content {
  position: absolute;
  z-index: 3;
  overflow: hidden;
}
.doc-content h1, .doc-content h2, .doc-content h3, .doc-content h4, .doc-content h5, .doc-content h6 {
  font-family: Inter, Arial, sans-serif; color: #111318; line-height: 1.18;
  margin: 1.25em 0 .55em; break-after: avoid; page-break-after: avoid;
}
.doc-content h1 { margin-top: 0; font-size: 2.2em; letter-spacing: -.035em; }
.doc-content h2 { font-size: 1.65em; letter-spacing: -.025em; }
.doc-content h3 { font-size: 1.28em; }
.doc-content p { margin: 0 0 .9em; }
.doc-content ul, .doc-content ol { margin: .35em 0 1em; padding-left: 1.5em; }
.doc-content li { margin: .24em 0; }
.doc-content a { color: #2563eb; text-decoration-thickness: .07em; text-underline-offset: .13em; }
.doc-content blockquote { margin: 1.2em 0; padding: .15em 0 .15em 1em; border-left: 3px solid #dfe5ee; color: #5c626d; }
.doc-content code { padding: .12em .34em; border-radius: 4px; background: #f1f3f5; font-family: "SFMono-Regular", Consolas, monospace; font-size: .88em; }
.doc-content pre { overflow: auto; margin: 1.15em 0; padding: 1em; border: 1px solid #e5e7eb; border-radius: 9px; background: #f6f7f8; break-inside: avoid; page-break-inside: avoid; }
.doc-content pre code { padding: 0; background: transparent; }
.doc-content table { width: 100%; border-collapse: collapse; margin: 1.2em 0; font-size: .92em; }
.doc-content th, .doc-content td { padding: .55em .7em; border: 1px solid #dfe2e6; text-align: left; vertical-align: top; }
.doc-content th { background: #f5f6f7; font-weight: 700; }
.doc-content hr { border: 0; border-top: 1px solid #dfe2e6; margin: 1.7em 0; }
.doc-content img { max-width: 100%; height: auto; }
.doc-content input[type="checkbox"] { accent-color: #20242c; }

.settings-title { padding-left: 16px; }
.settings-scroll { flex: 1; min-height: 0; overflow: auto; }
details { border-bottom: 1px solid var(--line-soft); }
summary {
  list-style: none; cursor: pointer; padding: 14px 16px;
  font-size: 11px; font-weight: 800; letter-spacing: .035em;
  text-transform: uppercase; color: #bfc3ca;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; float: right; color: #707680; font-size: 16px; font-weight: 400; line-height: 10px; }
details[open] summary::after { content: "−"; }
.settings-group { padding: 0 16px 16px; display: grid; gap: 12px; }
.settings-group > label, .two-col label { display: grid; gap: 6px; }
.settings-group label > span, .margin-title { color: #8d929b; font-size: 10px; }
.settings-group select, .settings-group input[type="text"], .settings-group input[type="number"] {
  width: 100%; height: 34px; padding: 0 9px;
  outline: none; border: 1px solid var(--line); border-radius: 7px;
  background: #101216; color: #e3e5e8;
}
.settings-group input:focus, .settings-group select:focus { border-color: #4d5666; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.range-row { display: grid; gap: 7px; }
.range-row label { display: flex; justify-content: space-between; }
.range-row output { color: #d3d6db; font-size: 10px; }
input[type="range"] { width: 100%; accent-color: #d9dce2; }
.color-grid { gap: 7px; }
.color-field {
  display: grid !important; grid-template-columns: 56px 30px 1fr; gap: 7px !important; align-items: center;
}
.color-field input[type="color"] {
  width: 30px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: transparent;
}
.color-field input:not([type="color"]) {
  width: 100%; height: 28px; border: 1px solid var(--line); border-radius: 6px;
  padding: 0 7px; background: #101216; color: #c7cbd2; font-family: monospace; font-size: 10px;
}
.margin-title { display: flex; align-items: center; justify-content: space-between; }
.link-toggle {
  border: 0; background: transparent; color: #737983; font-size: 9px; cursor: pointer;
}
.link-toggle.active { color: #c9cdd4; }
.margin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.margin-grid label {
  height: 34px; padding: 0 8px; display: flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); border-radius: 7px; background: #101216;
}
.margin-grid label span { min-width: 20px; }
.margin-grid input { min-width: 0; height: 28px !important; padding: 0 !important; border: 0 !important; background: transparent !important; text-align: right; }
.margin-grid b { color: #646a74; font-size: 9px; }
.toggles label { display: flex; align-items: center; gap: 8px; color: #c2c6cd; font-size: 11px; }
.toggles input { accent-color: #e7e9ed; }

@media (max-width: 1180px) {
  .main-grid { grid-template-columns: minmax(340px, 1fr) minmax(440px, 1.2fr); }
  .settings-pane { position: fixed; z-index: 20; top: 66px; right: 0; bottom: 0; width: 320px; box-shadow: -20px 0 50px rgba(0,0,0,.3); }
}
@media (max-width: 820px) {
  body { overflow: auto; }
  .topbar { height: auto; min-height: 66px; align-items: flex-start; gap: 12px; padding: 12px; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .main-grid { display: block; }
  .editor-pane, .preview-pane { height: 70vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .settings-pane { position: static; width: auto; height: auto; box-shadow: none; }
}
