:root {
  --fg: #1f2328;
  --muted: #6b7280;
  --bg: #fdfdfb;
  --card: #ffffff;
  --border: #e5e7eb;
  --accent: #8b3a2b;
  --mark: #fde68a;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 1.25rem; }
.muted { color: var(--muted); }
.error { color: var(--danger); display: block; font-size: .9rem; }
.flash { background: #ecfdf5; border: 1px solid #a7f3d0; padding: .5rem .75rem; border-radius: 6px; }
.draft { color: #a16207; }
mark { background: var(--mark); padding: 0 .1em; }

/* header / footer */
.site-header { border-bottom: 1px solid var(--border); background: var(--card); }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; min-height: 3.5rem; flex-wrap: wrap; gap: .5rem; }
.brand { font: 700 1.4rem/1 Georgia, serif; color: var(--fg); text-decoration: none; }
.site-header nav { display: flex; gap: 1rem; align-items: center; }
.site-footer { padding: 2rem 1.25rem; font-size: .85rem; }
.site-footer a { color: var(--muted); }

main { padding-top: 1.5rem; padding-bottom: 2rem; }

/* forms */
input, textarea, select, button {
  font: inherit;
  color: inherit;
}
input:not([type=checkbox]), textarea, select {
  width: 100%;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
button, .button {
  display: inline-block;
  padding: .45rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
}
button.link {
  background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline;
}
button.link.danger { color: var(--danger); }
form.inline { display: inline; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; }
.stack label.check { flex-direction: row; align-items: center; font-weight: normal; }
.narrow { max-width: 380px; margin: 2rem auto; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

/* listing */
.layout { display: grid; grid-template-columns: 1fr 240px; gap: 2.5rem; }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } }

.search { display: flex; gap: .5rem; margin-bottom: 1.25rem; }
.search select { width: auto; max-width: 40%; }

#results { transition: opacity .15s; }
#results.htmx-request { opacity: .5; }

.card { padding: 1rem 0 1.25rem; border-bottom: 1px solid var(--border); }
.card h2 { margin: 0; font: 600 1.35rem/1.3 Georgia, serif; }
.card h2 a { color: var(--fg); text-decoration: none; }
.card h2 a:hover { color: var(--accent); }
.card p { margin: .35rem 0; }
.meta { color: var(--muted); font-size: .85rem; margin: .25rem 0; }

.tags { list-style: none; padding: 0; margin: .4rem 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.tags a {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px;
  background: #f3efe9; color: var(--accent); text-decoration: none; font-size: .85rem;
}
.tags a.active, .tags a:hover { background: var(--accent); color: #fff; }
.sidebar h3 { margin-top: 0; }

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 1.5rem; }

/* article */
.full { max-width: 720px; margin: 0 auto; }
.full h1 { font: 700 2.2rem/1.2 Georgia, serif; margin: 0 0 .25rem; }
.lead { font-size: 1.15rem; color: var(--muted); font-style: italic; }

.prose { font: 1.1rem/1.75 Georgia, "Times New Roman", serif; overflow-wrap: break-word; }
.prose h2, .prose h3, .prose h4 { line-height: 1.3; margin-top: 1.8em; }
.prose blockquote { margin: 1em 0; padding: .2em 1em; border-left: 3px solid var(--accent); color: #444; }
.prose code { background: #f3f4f6; padding: .1em .3em; border-radius: 4px; font-size: .9em; }
.prose pre { background: #f3f4f6; padding: 1rem; overflow-x: auto; border-radius: 6px; }
.prose pre code { background: none; padding: 0; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.prose .table-scroll { max-width: 100%; overflow-x: auto; margin: 1.5em 0; }
.prose table { width: 100%; border-collapse: collapse; font-size: .95em; line-height: 1.5; }
.prose caption { padding: .6em .75em; text-align: left; font-weight: 700; }
.prose th, .prose td { border: 1px solid var(--border); padding: .55em .75em; text-align: left; vertical-align: top; }
.prose thead th { background: #f3efe9; }
.prose tbody tr:nth-child(even) { background: #f8f7f3; }
.prose .wikitable { border: 1px solid var(--border); }

/* admin */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--border); }
.admin-table .actions { white-space: nowrap; display: flex; gap: .75rem; }

.editor .toolbar { display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: .4rem; }
.editor .toolbar button {
  background: #fff; color: var(--fg); border: 1px solid var(--border); padding: .2rem .6rem; min-width: 2.2rem;
  height: 2.2rem; display: inline-flex; align-items: center; justify-content: center;
}
.editor .toolbar button:hover { border-color: var(--accent); }
.editor .toolbar .table-picker { position: relative; display: inline-flex; margin-top: 0; }
.editor .table-picker-menu {
  position: absolute; z-index: 5; top: calc(100% + .35rem); right: 0;
  display: flex; align-items: end; gap: .6rem; min-width: 18rem; padding: .75rem;
  border: 1px solid var(--border); border-radius: 4px; background: var(--card);
  box-shadow: 0 8px 20px rgb(31 35 40 / 12%);
}
.editor .table-picker-menu[hidden] { display: none; }
.editor .table-picker-menu label { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; }
.editor .table-picker-menu input { width: 5rem; }
.editor .table-picker-menu button { margin-left: auto; }
.editor .panes { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .editor .panes { grid-template-columns: 1fr; } }
.editor textarea { font: .95rem/1.6 ui-monospace, Consolas, monospace; resize: vertical; min-height: 420px; }
.editor .preview {
  border: 1px dashed var(--border); border-radius: 6px; padding: 0 1rem; background: var(--card);
  max-height: 640px; overflow-y: auto; font-size: 1rem;
}
.editor details { margin-top: .5rem; }
.editor pre { font-size: .85rem; }
