:root {
  --bg: #ffffff;
  --surface: #f7f6f3;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e6e4df;
  --accent: #b5442f;
  --accent-text: #ffffff;
  --danger: #b42318;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514; --surface: #201f1d; --text: #ecebe8; --muted: #a09d97;
    --line: #34322f; --accent: #e07a5f; --accent-text: #161514; --danger: #f97066;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); line-height: 1.5; }
a { color: var(--accent); }
img { max-width: 100%; height: auto; }
.quiet { color: var(--muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
.danger { color: var(--danger) !important; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* Buttons & inputs */
.button, button.button, input[type=submit].button {
  display: inline-block; font: 600 0.95rem/1 var(--sans); padding: 0.75rem 1.1rem;
  background: var(--accent); color: var(--accent-text); border: 1px solid var(--accent);
  border-radius: 8px; cursor: pointer; text-decoration: none; text-align: center;
}
.button:hover { filter: brightness(1.06); }
.button--small { padding: 0.45rem 0.8rem; font-size: 0.85rem; }
.button.button--secondary { background: transparent; color: var(--text); border-color: var(--line); }
.button--block { display: block; width: 100%; margin-bottom: 0.5rem; }
.linkish { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 0.875rem; cursor: pointer; text-decoration: underline; }
form.button_to { display: inline; }
input[type=email], input[type=text], input[type=password], input[type=search], input[type=datetime-local], textarea {
  font: 1rem var(--sans); color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 0.7rem 0.8rem; width: 100%;
}
input:focus, textarea:focus, trix-editor:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.flash { max-width: 680px; margin: 1rem auto; padding: 0.75rem 1rem; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.flash--alert { border-color: var(--danger); color: var(--danger); }

/* Public site */
.wrap { max-width: 680px; margin: 0 auto; padding: 0 16px; }
.site-header { border-bottom: 1px solid var(--line); }
.site-header__inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 60px; }
.site-title { font: 700 1.1rem var(--sans); color: var(--text); text-decoration: none; }
.site-nav { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; }
.site-nav a:not(.button) { color: var(--muted); text-decoration: none; }
.site-nav a:not(.button):hover { color: var(--text); }

.masthead { text-align: center; padding: 3.5rem 0 2.5rem; border-bottom: 1px solid var(--line); }
.masthead h1 { font: 700 2.4rem/1.15 var(--sans); margin: 0 0 0.5rem; letter-spacing: -0.02em; }
.masthead__tagline { color: var(--muted); font-size: 1.15rem; margin: 0 0 1.75rem; }

.subscribe-form { display: flex; gap: 0.5rem; max-width: 440px; margin: 0 auto; }
.subscribe-form input[type=email] { flex: 1; min-width: 0; }

.post-list__item { padding: 1.75rem 0; border-bottom: 1px solid var(--line); }
.post-list__item h2 { font: 700 1.4rem/1.25 var(--sans); margin: 0 0 0.35rem; letter-spacing: -0.01em; }
.post-list__item h2 a { color: var(--text); text-decoration: none; }
.post-list__item h2 a:hover { text-decoration: underline; }
.post-list__excerpt { color: var(--muted); margin: 0 0 0.5rem; }
.post-list time { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.empty { padding: 3rem 0; text-align: center; color: var(--muted); }

.draft-banner { margin: 1rem 0 0; padding: 0.6rem 1rem; background: var(--surface); border: 1px dashed var(--line); border-radius: 8px; font-size: 0.9rem; }
.post { padding: 2.5rem 0 1rem; }
.post__header h1 { font: 700 2.4rem/1.15 var(--sans); margin: 0 0 0.5rem; letter-spacing: -0.02em; }
.post__subtitle { font-size: 1.3rem; color: var(--muted); margin: 0 0 1rem; line-height: 1.35; }
.post__meta { font-size: 0.9rem; color: var(--muted); margin: 0 0 2rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.post__meta a { color: var(--muted); }

.post__body .trix-content { font-family: var(--serif); font-size: 1.2rem; line-height: 1.7; }
.post__body .trix-content h1 { font: 700 1.6rem/1.25 var(--sans); margin: 2rem 0 0.75rem; }
.post__body .trix-content h2, .post__body .trix-content h3 { font: 700 1.3rem/1.3 var(--sans); margin: 1.75rem 0 0.5rem; }
.post__body .trix-content blockquote { border-left: 3px solid var(--accent); margin: 1.5rem 0; padding-left: 1.25rem; color: var(--muted); font-style: italic; }
.post__body .trix-content pre { background: var(--surface); padding: 1rem; border-radius: 8px; overflow-x: auto; font-size: 0.9rem; line-height: 1.5; }
.post__body .trix-content figure, .post__body figure { margin: 2rem 0; text-align: center; }
.post__body .trix-content img { border-radius: 4px; }
.post__body figcaption, .post__body .attachment__caption { font: 0.85rem var(--sans); color: var(--muted); margin-top: 0.5rem; }
.post__body .trix-content hr, .post__body hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem auto; width: 40%; }

.post__reply { margin: 2.5rem 0 0; padding-top: 1.25rem; border-top: 1px solid var(--line); color: var(--muted); }

.subscribe-box { margin: 2rem 0 3rem; padding: 2rem 1.5rem; background: var(--surface); border-radius: 12px; text-align: center; }
.subscribe-box h2 { margin: 0 0 0.25rem; font-size: 1.3rem; }
.subscribe-box p { color: var(--muted); margin: 0 0 1.25rem; }

.notice-page { max-width: 440px; margin: 4rem auto; text-align: center; }
.notice-page h1 { font-size: 1.8rem; margin: 0 0 1rem; }
.notice-page .settings { text-align: left; }

.site-footer { display: flex; justify-content: space-between; padding: 3rem 16px; font-size: 0.85rem; color: var(--muted); }
.site-footer a { color: var(--muted); }

/* Admin */
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px 4rem; }
.admin-bar { border-bottom: 1px solid var(--line); background: var(--surface); }
.admin-bar__inner { display: flex; align-items: center; justify-content: space-between; min-height: 56px; gap: 1rem; padding-bottom: 0; flex-wrap: wrap; }
.admin-bar__title { font-weight: 700; color: var(--text); text-decoration: none; }
.admin-bar nav { display: flex; gap: 1.25rem; align-items: center; font-size: 0.9rem; flex-wrap: wrap; }
.admin-bar nav a { color: var(--muted); text-decoration: none; }
.admin-bar nav a.active, .admin-bar nav a:hover { color: var(--text); }
.admin h1 { font-size: 1.6rem; margin: 2rem 0 0.5rem; }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.admin-head h1 { margin-bottom: 0.25rem; }
.admin-section { font-size: 1rem; margin: 2rem 0 0.5rem; }
.count { color: var(--muted); font-weight: 400; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th { text-align: left; font-size: 0.8rem; color: var(--muted); font-weight: 500; padding: 0.5rem; border-bottom: 1px solid var(--line); }
.admin-table td { padding: 0.75rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin-table__main { width: 100%; }
.admin-table__main a { color: var(--text); font-weight: 600; text-decoration: none; }
.admin-table .actions form { margin-left: 0.75rem; }
.chip { display: inline-block; font-size: 0.75rem; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.chip--sent { color: #1f7a4d; border-color: #b7e0c8; background: #eef8f2; }
@media (prefers-color-scheme: dark) { .chip--sent { color: #7fd1a6; border-color: #2c5a43; background: #17291f; } }

.tabs { display: flex; gap: 1rem; margin: 1.25rem 0 1rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs a { padding: 0.5rem 0; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-color: var(--text); }
.search { margin-bottom: 0.5rem; max-width: 360px; }

.panel { border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.1rem; margin-bottom: 1rem; }
.panel h3 { margin: 0 0 0.6rem; font-size: 0.95rem; }
.panel p { margin: 0 0 0.6rem; }
.panel--quiet { border-style: dashed; display: flex; gap: 1rem; flex-wrap: wrap; }
.panel textarea, .panel input[type=file] { margin-bottom: 0.6rem; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 2rem; }

.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 2rem; margin-top: 1.5rem; }
.editor { margin-top: 1.5rem; }
.editor-layout .editor { margin-top: 0; }
.editor input.editor__title { font: 700 2rem/1.2 var(--sans); border: 0; padding: 0.25rem 0; background: transparent; }
.editor input.editor__subtitle { font-size: 1.2rem; color: var(--muted); border: 0; padding: 0.25rem 0 1rem; background: transparent; }
.editor input.editor__title:focus, .editor input.editor__subtitle:focus { outline: none; }
.editor trix-toolbar { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
.editor trix-editor { min-height: 60vh; border: 0; padding: 1rem 0; font-family: var(--serif); font-size: 1.15rem; line-height: 1.7; }
.editor__details { margin: 1.5rem 0; border-top: 1px solid var(--line); padding-top: 1rem; }
.editor__details summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.editor__details label, .settings label { display: block; margin: 1rem 0; font-size: 0.9rem; font-weight: 600; }
.editor__details label input, .settings label input, .settings trix-editor { margin-top: 0.35rem; font-weight: 400; }
.settings { max-width: 640px; }
.settings .field { margin: 1rem 0; }
.settings .field label { margin: 0; }
.settings trix-editor { min-height: 12rem; background: var(--bg); }
.slug-field { display: flex; align-items: center; gap: 0.25rem; }
.editor__actions { display: flex; align-items: center; gap: 1rem; position: sticky; bottom: 0; background: var(--bg); padding: 1rem 0; border-top: 1px solid var(--line); }
.editor-panel { position: sticky; top: 1rem; align-self: start; }

/* Trix editor: map its hard-coded light colors onto the theme tokens, so it follows dark mode. */
trix-toolbar .trix-button-group { border-color: var(--line); }
trix-toolbar .trix-button { color: var(--muted); border-bottom-color: var(--line); }
trix-toolbar .trix-button:not(:first-child) { border-left-color: var(--line); }
trix-toolbar .trix-button.trix-active { background: var(--surface); color: var(--text); }
trix-toolbar .trix-dialog { background: var(--surface); color: var(--text); border-top-color: var(--line); box-shadow: 0 0.3em 1em rgb(0 0 0 / 0.25); }
trix-toolbar .trix-input--dialog { background-color: var(--bg); color: var(--text); border-color: var(--line); }
trix-toolbar .trix-input--dialog.validate:invalid { box-shadow: 0 0 0 1px var(--danger); }
trix-editor .attachment__caption-editor, trix-editor .attachment__caption { color: var(--muted); }
trix-editor .trix-button { color: var(--muted); background: var(--surface); }
trix-editor .trix-button:not(:first-child) { border-left-color: var(--line); }
trix-editor .trix-button--remove { background-color: var(--bg); }
.trix-content pre, trix-editor pre { background: var(--surface); color: var(--text); }
.trix-content code { background: var(--surface); padding: 0.1em 0.3em; border-radius: 4px; font-size: 0.9em; }
.trix-content pre code { background: none; padding: 0; }
.trix-content a { color: var(--accent); }

@media (prefers-color-scheme: dark) {
  /* Toolbar and remove-button icons are black SVGs; flip them to light. */
  trix-toolbar .trix-button--icon::before,
  trix-editor .trix-button--remove::before { filter: invert(1); }
  trix-toolbar .trix-button--icon:disabled::before { opacity: 0.25; }
  trix-editor [data-trix-mutable].attachment img, trix-editor [data-trix-mutable] .attachment__caption-editor { box-shadow: 0 0 0 2px var(--accent); }
}

/* Field hints inside labels shouldn't inherit the label's bold. */
label .small { display: block; font-weight: 400; margin-top: 0.35rem; }
.mobile-only { display: none; }
input[type=search] { -webkit-appearance: none; appearance: none; }
.post__body, .post-list, .admin-table__main { overflow-wrap: anywhere; }

/* Long publication names truncate instead of pushing the nav off screen. */
.site-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-nav { flex-shrink: 0; }

@media (max-width: 800px) {
  /* minmax(0, …) lets the grid shrink below the editor toolbar's natural width. */
  .editor-layout { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
  .admin-grid { grid-template-columns: minmax(0, 1fr); }
  .editor-panel { position: static; scroll-margin-top: 1rem; }
  .masthead h1, .post__header h1 { font-size: 1.9rem; }
  .subscribe-form { flex-direction: column; }
  .mobile-only { display: inline; }
}

@media (max-width: 640px) {
  .site-nav { gap: 0.85rem; }
  .masthead { padding: 2.5rem 0 2rem; }
  .post { padding-top: 1.75rem; }
  .post__subtitle { font-size: 1.15rem; }
  .post__body .trix-content { font-size: 1.125rem; }
  .post__body .trix-content figure, .post__body figure { margin: 1.5rem 0; }
  .subscribe-box { padding: 1.5rem 1rem; }
  .notice-page { margin: 2.5rem auto; }

  .admin h1 { font-size: 1.4rem; margin-top: 1.25rem; }
  .admin-bar__inner { padding-top: 0.6rem; padding-bottom: 0.6rem; min-height: 0; }
  .admin-bar nav { gap: 1rem; }

  /* Tables become stacked rows: the main cell gets its own line, the rest flow beneath it. */
  .admin-table thead { display: none; }
  .admin-table tr { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.75rem; padding: 0.85rem 0; border-bottom: 1px solid var(--line); }
  .admin-table td { padding: 0; border: 0; }
  .admin-table td.admin-table__main { flex-basis: 100%; }
  .admin-table .actions { margin-left: auto; }
  .admin-table .actions form { margin-left: 0.5rem; }
  .admin-table .linkish { padding: 0.35rem 0.25rem; }

  .editor { margin-top: 1rem; }
  .editor input.editor__title { font-size: 1.6rem; }
  .editor input.editor__subtitle { font-size: 1.05rem; }
  .editor trix-editor { min-height: 50vh; font-size: 1.1rem; }
  .editor__actions { padding: 0.75rem 0; }
  .panel--quiet { justify-content: space-between; }
}

.editor trix-editor blockquote { border-left: 3px solid var(--accent); margin: 1rem 0; padding-left: 1rem; color: var(--muted); }
.editor trix-editor h1 { font: 700 1.5rem/1.3 var(--sans); }
