:root {
  --bg: #fff;
  --fg: #1a1a1a;
  --muted: #79828b;
  --line: #e6e8eb;
  --accent: #6c5ce7;
  --accent-fg: #fff;
  --quote: #f4f3fb;
  --code: #f3f4f6;
  --bad: #d63031;
  --serif: Georgia, 'PT Serif', 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --fg: #e8e9ec;
    --muted: #8b929b;
    --line: #2a2c33;
    --accent: #8f83ff;
    --quote: #1e1f26;
    --code: #22242b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 18px/1.6 var(--serif);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.page {
  width: 100%;
  max-width: 732px;
  margin: 0 auto;
  padding: 48px 21px 24px;
  flex: 1;
}
a { color: inherit; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

/* ---------- статья ---------- */
.post h1, .title-input {
  font: 700 32px/1.25 var(--serif);
  margin: 0 0 8px;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
}
.post address, .author-input {
  font: 15px/1.4 var(--sans);
  font-style: normal;
  color: var(--muted);
  margin: 0 0 28px;
}
.post address a { text-decoration: none; }
.post address a:hover { text-decoration: underline; }

.content { overflow-wrap: anywhere; }
.content p, .content blockquote, .content aside, .content li, .content figcaption { white-space: pre-wrap; }
.content p { margin: 0 0 1.1em; }
.content h3 { font: 700 26px/1.3 var(--sans); margin: 1.6em 0 .5em; }
.content h4 { font: 700 20px/1.35 var(--sans); margin: 1.4em 0 .4em; }
.content blockquote {
  margin: 1.4em 0;
  padding: 2px 0 2px 18px;
  border-left: 3px solid var(--accent);
  font-style: italic;
}
.content aside {
  margin: 1.6em 0;
  text-align: center;
  font-style: italic;
  font-size: 1.15em;
}
.content ul, .content ol { margin: 0 0 1.1em; padding-left: 1.4em; }
.content li { margin: .25em 0; }
.content pre {
  font: 15px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--code);
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre;
  margin: 0 0 1.2em;
}
.content code {
  font: .85em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--code);
  padding: .1em .35em;
  border-radius: 4px;
}
.content pre code { background: none; padding: 0; }
.content a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.content hr {
  border: 0;
  margin: 2em auto;
  height: 1px;
  width: 30%;
  background: var(--line);
}
.content figure { margin: 1.6em 0; position: relative; }
.content img, .content video { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 4px; }
.content > img { margin: 1.6em auto; }
.content .embed { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 4px; overflow: hidden; }
.content .embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.content figcaption {
  font: 14px/1.4 var(--sans);
  color: var(--muted);
  text-align: center;
  margin-top: 8px;
}

/* ---------- редактор ---------- */
.title-input, .author-input {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: none;
  color: var(--fg);
  outline: none;
  resize: none;
  overflow: hidden;
}
.author-input { color: var(--muted); margin-bottom: 16px; }
.title-input::placeholder, .author-input::placeholder { color: var(--muted); opacity: .6; }

.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  margin: 0 0 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
}
.tb-btn {
  min-width: 38px;
  height: 38px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--fg);
  font: 17px/38px var(--sans);
  text-align: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.toolbar::-webkit-scrollbar { display: none; }
.tb-btn { flex: none; }
.tb-btn:hover { background: var(--code); }
.tb-btn.b { font-weight: 800; }
.tb-btn.i { font-style: italic; font-family: var(--serif); }
.tb-btn.hd { font-weight: 800; }
.tb-btn.small { font-size: 14px; }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

.editable { outline: none; min-height: 40vh; padding-bottom: 40px; }
.editable.empty > p:first-child::before {
  content: 'Ваша история…';
  color: var(--muted);
  opacity: .6;
  pointer-events: none;
  position: absolute;
}
.editable figure { outline: none; }
.editable figure:hover, .editable figure:focus-within { box-shadow: 0 0 0 2px var(--line); border-radius: 6px; }
.editable figcaption { outline: none; min-height: 1.4em; }
.editable figcaption:empty::before { content: attr(data-ph); opacity: .6; }
.editable img.uploading { opacity: .45; filter: grayscale(1); }
.fig-del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  font: 20px/32px var(--sans);
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.editable figure:hover .fig-del, .editable figure:focus-within .fig-del { opacity: 1; }
@media (hover: none) { .fig-del { opacity: 1; } }
.editable hr { cursor: default; }

/* ---------- кнопки и низ ---------- */
.bar, .owner {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
  font-family: var(--sans);
  margin-top: 24px;
}
.owner { position: static; }
.status { margin-right: auto; color: var(--muted); font: 14px/1.3 var(--sans); }
.status.bad { color: var(--bad); }
.btn {
  display: inline-block;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-fg);
  font: 600 15px/1 var(--sans);
  padding: 11px 20px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .6; cursor: progress; }
.btn.ghost { background: none; color: var(--accent); }
.note { color: var(--muted); font-family: var(--sans); }
.foot {
  text-align: center;
  font: 13px/1.4 var(--sans);
  color: var(--muted);
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.foot a { color: inherit; text-decoration: none; }
.foot a:hover { text-decoration: underline; }

@media (max-width: 600px) {
  body { font-size: 17px; }
  .page { padding-top: 24px; padding-left: 16px; padding-right: 16px; }
  .post h1, .title-input { font-size: 27px; }
  .content h3 { font-size: 22px; }
  .content h4 { font-size: 18px; }
  .tb-btn { min-width: 36px; height: 36px; line-height: 36px; }
}
