:root {
  --bg: oklch(0.986 0.003 80);
  --ink: oklch(0.21 0.01 260);
  --ink-2: oklch(0.36 0.01 260);
  --muted: oklch(0.5 0.01 260);
  --line: oklch(0.9 0.005 260);
  --soft: oklch(0.95 0.004 260);
  --accent: oklch(0.6 0.17 38);
  --tip-bg: oklch(0.2 0.01 260);
  --tip-ink: oklch(0.97 0.003 80);
  --sel: oklch(0.88 0.08 70);
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --r: 10px;
  --z-bar: 10; --z-pop: 20; --z-dlg: 30;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: oklch(0.19 0.006 260);
    --ink: oklch(0.93 0.005 80);
    --ink-2: oklch(0.8 0.005 80);
    --muted: oklch(0.66 0.008 260);
    --line: oklch(0.32 0.008 260);
    --soft: oklch(0.24 0.008 260);
    --tip-bg: oklch(0.95 0.004 80);
    --tip-ink: oklch(0.2 0.01 260);
    --sel: oklch(0.42 0.08 60);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: oklch(0.19 0.006 260); --ink: oklch(0.93 0.005 80); --ink-2: oklch(0.8 0.005 80);
  --muted: oklch(0.66 0.008 260); --line: oklch(0.32 0.008 260); --soft: oklch(0.24 0.008 260);
  --tip-bg: oklch(0.95 0.004 80); --tip-ink: oklch(0.2 0.01 260); --sel: oklch(0.42 0.08 60); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.5 Onest, system-ui, sans-serif; }
::selection { background: var(--sel); }
button { font: inherit; color: inherit; }

/* top bar */
.bar { position: sticky; top: 0; z-index: var(--z-bar); display: flex; align-items: center; justify-content: space-between;
  gap: 12px; height: 60px; padding: 0 max(16px, calc((100vw - 760px) / 2)); background: var(--bg); }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand img { display: block; }
body[data-mode="view"] .brand span, body[data-mode="own"] .brand span { color: var(--muted); font-weight: 500; }
.actions { display: flex; align-items: center; gap: 10px; }
.status { font-size: 13px; color: var(--muted); }
.status.err { color: oklch(0.55 0.19 25); }
.btn { min-height: 36px; padding: 0 16px; border: 1px solid var(--line); border-radius: 999px; background: transparent;
  font-size: 14px; font-weight: 500; cursor: pointer; transition: background-color .15s, transform .12s var(--ease); }
.btn:hover { background: var(--soft); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible, .linkish:focus-visible, .tip button:focus-visible, .side button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { background: var(--ink-2); }
.btn[disabled] { opacity: .5; cursor: progress; }

/* article */
.page { max-width: 732px; margin: 0 auto; padding: 28px 21px 80px; }
.article { position: relative; }
#title { margin: 0 0 12px; font: 700 34px/1.18 Onest, system-ui, sans-serif; letter-spacing: -0.02em; text-wrap: balance; overflow-wrap: anywhere; }
address { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 10px; margin: 0 0 26px; font: 400 15px/1.4 Onest, system-ui, sans-serif; font-style: normal; color: var(--muted); }
#author a { color: var(--ink-2); text-decoration: none; }
#author a:hover { text-decoration: underline; }
#author:empty + time:not(:empty)::before { content: none; }
#author:not(:empty) + time:not(:empty)::before { content: "·"; margin-right: 10px; }

.content { font: 400 18px/1.62 Lora, Georgia, serif; overflow-wrap: break-word; }
.content > * { margin: 0 0 21px; }
.content p { text-wrap: pretty; }
.content a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.content h3 { font: 700 26px/1.25 Onest, system-ui, sans-serif; letter-spacing: -0.015em; margin: 36px 0 12px; text-wrap: balance; }
.content h4 { font: 700 20px/1.3 Onest, system-ui, sans-serif; margin: 28px 0 10px; }
.content blockquote { margin-left: 0; padding: 0 0 0 20px; border-left: 3px solid var(--ink); font-style: italic; }
.content aside { margin: 32px 0; text-align: center; font-style: italic; font-size: 22px; line-height: 1.5; color: var(--ink-2); }
.content ul, .content ol { padding-left: 26px; }
.content li { margin: 0 0 6px; }
.content pre { padding: 14px 16px; background: var(--soft); border-radius: 8px; overflow-x: auto; font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
.content code { font: .88em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--soft); padding: 1px 5px; border-radius: 4px; }
.content pre code { background: none; padding: 0; }
.content hr { border: 0; height: 24px; margin: 30px 0; text-align: center; }
.content hr::before { content: "* * *"; letter-spacing: 12px; color: var(--muted); font-size: 18px; }
.content figure { margin: 0 0 24px; position: relative; }
.content figure img, .content figure video { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 4px; }
.content figure iframe { display: block; width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; border-radius: 4px; background: var(--soft); }
.content figcaption { margin-top: 10px; text-align: center; font: 400 14px/1.45 Onest, system-ui, sans-serif; color: var(--muted); }
.content figcaption:empty { display: none; }

/* edit state */
body.editing [contenteditable] { outline: none; }
body.editing [data-placeholder]:empty::before { content: attr(data-placeholder); color: var(--muted); opacity: .75; pointer-events: none; }
#content { position: relative; }
body.editing #content.is-empty::before { content: "Your story…"; position: absolute; left: 0; top: 0; color: var(--muted); opacity: .75; pointer-events: none; }
body.editing #author:empty { min-width: 6em; display: inline-block; }
body.editing #date { display: none; }
body.editing .content figcaption:empty { display: block; }
body.editing .content figcaption:empty::before { content: "Caption (optional)"; color: var(--muted); opacity: .7; }
body.editing figure.sel { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
figure.loading { min-height: 120px; background: var(--soft); border-radius: 4px; display: grid; place-items: center; color: var(--muted); font: 14px Onest, sans-serif; }
figure.loading img, figure.loading video { opacity: .45; }
.embed-input { display: block; width: 100%; border: 0; border-bottom: 1px dashed var(--line); padding: 4px 0; background: transparent; color: var(--ink);
  font: italic 400 18px/1.6 Lora, Georgia, serif; outline: none; }

/* selection tooltip */
.tip { position: absolute; z-index: var(--z-pop); background: var(--tip-bg); color: var(--tip-ink); border-radius: 8px; padding: 4px;
  box-shadow: 0 6px 24px oklch(0 0 0 / .18); transform-origin: 50% 100%; animation: pop .16s var(--ease); }
.tip::after { content: ""; position: absolute; left: 50%; bottom: -5px; width: 10px; height: 10px; background: var(--tip-bg); transform: translateX(-50%) rotate(45deg); border-radius: 2px; }
@keyframes pop { from { opacity: 0; transform: scale(.95) translateY(3px); } }
.tip-btns { display: flex; align-items: center; }
.tip button { width: 38px; height: 36px; display: grid; place-items: center; border: 0; background: none; border-radius: 6px; cursor: pointer; font-size: 17px; font-family: Lora, serif; }
.tip button:hover { background: oklch(from var(--tip-ink) l c h / .12); }
.tip button.on { color: var(--accent); }
.tip .tH { font: 700 19px Onest, sans-serif; }
.tip .th { font: 700 14px Onest, sans-serif; }
.tip .sep { width: 1px; height: 20px; margin: 0 4px; background: oklch(from var(--tip-ink) l c h / .25); }
.tip-link { width: 260px; height: 36px; border: 0; background: none; color: var(--tip-ink); padding: 0 10px; font: 15px Onest, sans-serif; outline: none; }
.tip-link::placeholder { color: oklch(from var(--tip-ink) l c h / .6); }

/* side "+" inserter */
.side { position: absolute; z-index: var(--z-pop); display: flex; align-items: center; gap: 6px; }
.side button { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); color: var(--muted);
  display: grid; place-items: center; cursor: pointer; transition: transform .2s var(--ease), color .15s, border-color .15s; }
.side button:hover { color: var(--ink); border-color: var(--ink-2); }
.side-plus[aria-expanded="true"] { transform: rotate(45deg); }
.side-menu { display: flex; gap: 6px; opacity: 0; pointer-events: none; transform: translateX(-6px); transition: opacity .18s var(--ease), transform .18s var(--ease); }
.side.open .side-menu { opacity: 1; pointer-events: auto; transform: none; }

/* footer + dialog */
.foot { margin-top: 56px; display: flex; gap: 18px; font-size: 13px; color: var(--muted); }
.foot a, .linkish { color: var(--muted); text-decoration: none; background: none; border: 0; padding: 0; cursor: pointer; font-size: 13px; }
.foot a:hover, .linkish:hover { color: var(--ink); text-decoration: underline; }
body.editing .foot { display: none; }
.dlg { border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(440px, calc(100vw - 32px)); background: var(--bg); color: var(--ink); }
.dlg::backdrop { background: oklch(0 0 0 / .35); }
.dlg h2 { margin: 0 0 6px; font-size: 19px; }
.dlg p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.dlg label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.dlg textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: var(--bg); color: var(--ink); font: 15px/1.45 Onest, sans-serif; resize: vertical; }
.dlg textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.dlg-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

@media (max-width: 600px) {
  .page { padding: 16px 16px 64px; }
  #title { font-size: 28px; }
  .content { font-size: 17px; }
  .brand span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
body:not(.editing) #author:empty { display: none; }
