:root {
  --bg: #fcfbf8; --panel: #fff; --text: #1d1c1a; --muted: #6f6a62; --border: #e5e0d6;
  --accent: #b5532a; --accent-soft: #f8ebe3; --ok: #2f7d4f; --warn: #a15c00; --err: #b3261e;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #171614; --panel: #1f1e1b; --text: #ebe7df; --muted: #a39d92; --border: #35332e; --accent: #e08452; --accent-soft: #2f2219; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.65 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 720px; margin: 0 auto; padding: 24px 20px 64px; }
.editor-main { max-width: 1180px; margin: 0 auto; padding: 16px 20px 64px; }
.site-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; max-width: 1180px; margin: 0 auto; padding: 18px 20px; }
.site-header .brand { font-weight: 700; color: var(--text); font-size: 18px; }
.site-header nav { display: flex; gap: 4px; }
.site-header nav a { color: var(--muted); padding: 4px 10px; border-radius: 6px; font-size: 15px; }
.site-header nav a.active, .site-header nav a:hover { color: var(--text); background: var(--accent-soft); text-decoration: none; }
.site-footer { max-width: 1180px; margin: 0 auto; padding: 24px 20px 40px; color: var(--muted); font-size: 14px; display: flex; gap: 12px; align-items: center; }
.muted { color: var(--muted); } .ok { color: var(--ok); } .warn { color: var(--warn); } .error { color: var(--err); }
.inline { display: inline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 7px 14px; font-size: 14px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:disabled { opacity: .6; cursor: wait; }
button.ghost { background: transparent; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: inherit; }
button.link.danger, .danger { color: var(--err); }
button.icon { padding: 4px 9px; font-size: 14px; line-height: 1; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
textarea { resize: vertical; }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0; }
label small { display: block; font-size: 12px; }
label input, label select, label textarea { margin-top: 4px; color: var(--text); }
.row { display: flex; gap: 12px; align-items: end; }
.row > * { flex: 1; }
.row button { flex: 0 0 auto; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 24px 28px; }
.card.narrow { max-width: 380px; margin: 60px auto; }
.card h1 { margin-top: 0; font-size: 24px; }
.hidden { display: none !important; }

/* public */
.hero h1 { font-family: var(--serif); font-size: 40px; margin: 24px 0 4px; line-height: 1.15; }
.tagline { color: var(--muted); margin: 0 0 20px; font-size: 18px; }
.tags { margin: 0 0 24px; }
.tag { display: inline-block; font-size: 13px; color: var(--muted); background: var(--accent-soft); padding: 2px 9px; border-radius: 999px; margin: 2px 2px 2px 0; }
.tag.active, .tag:hover { color: var(--accent); text-decoration: none; }
.post-list { list-style: none; padding: 0; margin: 0; }
.post-list li { padding: 20px 0; border-top: 1px solid var(--border); }
.post-list time { color: var(--muted); font-size: 13px; }
.post-list h2 { margin: 4px 0 6px; font-family: var(--serif); font-size: 26px; line-height: 1.25; }
.post-list h2 a { color: var(--text); }
.post-list p { margin: 0; color: var(--muted); }
.empty { color: var(--muted); padding: 40px 0; }
.post header h1 { font-family: var(--serif); font-size: 40px; line-height: 1.15; margin: 20px 0 8px; }
.post .meta { color: var(--muted); font-size: 14px; margin: 0 0 32px; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); text-transform: capitalize; }
.badge.published { background: #e4f3ea; color: var(--ok); }
.prose { font-family: var(--serif); font-size: 19px; line-height: 1.7; }
.prose h1, .prose h2, .prose h3 { font-family: var(--font); line-height: 1.25; margin: 1.6em 0 .5em; }
.prose h2 { font-size: 26px; } .prose h3 { font-size: 20px; }
.prose p { margin: 0 0 1.2em; }
.prose img { max-width: 100%; height: auto; border-radius: 8px; }
.prose pre { font: 14px/1.5 var(--mono); background: #1e1d1b; color: #ece8e1; padding: 14px 16px; border-radius: 10px; overflow-x: auto; }
.prose code { font: .9em var(--mono); background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { margin: 1.2em 0; padding: 2px 0 2px 18px; border-left: 3px solid var(--accent); color: var(--muted); }
.prose table { border-collapse: collapse; font-family: var(--font); font-size: 15px; }
.prose th, .prose td { border-bottom: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }

/* admin */
.admin-head { display: flex; align-items: baseline; justify-content: space-between; }
.admin-head h1 { font-size: 28px; }
.posts-table { width: 100%; border-collapse: collapse; margin-top: 20px; font-size: 15px; }
.posts-table th, .posts-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.posts-table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.posts-table .actions { white-space: nowrap; } .posts-table .actions form { margin-left: 10px; }

/* editor */
.editor-top { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 24px; align-items: start; }
.editor-side { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 12px; }
.editor-side .status-line { font-size: 13px; }
.editor-side a { font-size: 14px; }
.title-input { font-family: var(--serif); font-size: 30px; font-weight: 600; padding: 8px 10px; border-color: transparent; background: transparent; }
.title-input:focus { border-color: var(--border); background: var(--panel); outline: none; }
.editor-fields .row label { margin: 6px 0; }
.summary-row { margin: 6px 0; }
.with-btn { display: flex; gap: 6px; margin-top: 4px; }
.with-btn input { margin: 0; }
.ai-btn { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); font-weight: 600; }
.ai-btn.small { padding: 4px 10px; flex: 0 0 auto; }
.post-ai { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.model-row { margin: 4px 0 0; font-size: 12px; }
.editor-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; margin-top: 16px; }
#editor.split .editor-body { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.preview { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 8px 28px 28px; font-size: 17px; max-height: 80vh; overflow: auto; position: sticky; top: 12px; }
.blocks { display: flex; flex-direction: column; gap: 14px; }
.block { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 8px 12px 12px; }
.block:focus-within { border-color: var(--accent); }
.block-bar { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.block-bar .spacer { flex: 1; }
.block-bar .drag { font-size: 14px; padding: 0 4px; }
.ai-flag { font-size: 12px; color: var(--accent); background: var(--accent-soft); padding: 1px 8px; border-radius: 999px; }
.block-text { font: 15.5px/1.6 var(--mono); border: 0; padding: 6px 4px; background: transparent; min-height: 96px; resize: none; overflow: hidden; }
.block-text:focus { outline: none; }
.ai-menu { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 4px; border-top: 1px dashed var(--border); }
.ai-menu button { font-size: 13px; padding: 5px 11px; }
.ai-panel { margin-top: 10px; border: 1px solid var(--accent-soft); background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; }
.ai-panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.ai-instruction { background: var(--panel); margin-bottom: 8px; }
.ai-controls { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.ai-output { font: 14.5px/1.55 var(--mono); white-space: pre-wrap; background: var(--panel); border-radius: 8px; padding: 12px 14px; margin: 10px 0 0; max-height: 420px; overflow: auto; }
.ai-apply { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ai-apply button { font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 24px; }
@media (max-width: 860px) {
  .editor-top { grid-template-columns: 1fr; }
  .editor-side { position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  #editor.split .editor-body { grid-template-columns: 1fr; }
  .preview { position: static; max-height: none; }
  .row { flex-direction: column; align-items: stretch; }
  .hero h1, .post header h1 { font-size: 32px; }
  .prose { font-size: 18px; }
}

/* quick title improvement */
.title-row { display: flex; gap: 8px; align-items: center; }
.title-row .title-input { flex: 1 1 auto; min-width: 0; margin: 0; }
.title-row .ai-btn { min-height: 44px; padding: 0 14px; font-size: 14px; }
.title-row .ai-btn[aria-busy="true"] { opacity: .6; cursor: progress; }
.title-suggest { margin: 8px 0 4px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }
.ts-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; margin-bottom: 8px; }
.ts-actions { display: flex; gap: 16px; }
.ts-actions .link { min-height: 32px; font-size: 13px; }
.ts-chips { display: flex; flex-direction: column; gap: 6px; }
.ts-chips:empty::before { content: ""; display: block; height: 44px; border-radius: 8px; background: var(--accent-soft); opacity: .5; }
.ts-chip { display: block; width: 100%; min-height: 44px; text-align: left; padding: 10px 12px; font-family: var(--serif); font-size: 17px; line-height: 1.3; color: var(--text); background: transparent; border: 1px solid var(--border); border-radius: 8px; }
.ts-chip:hover, .ts-chip:focus-visible { border-color: var(--accent); }
.ts-chip.chosen { border-color: var(--accent); background: var(--accent-soft); }
@media (max-width: 640px) { .title-input { font-size: 24px; } .title-row .ai-btn { padding: 0 10px; } }
