@font-face {
  font-family: 'Zrnic';
  src: url('/fonts/zrnic.woff2') format('woff2'), url('/fonts/zrnic.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
/* Stand-in sized to Zrnic's proportions so text doesn't jump when the real font swaps in. */
@font-face {
  font-family: 'Zrnic Fallback';
  src: local('Arial'), local('Helvetica Neue'), local('Helvetica'), local('Liberation Sans');
  size-adjust: 87.6%;
  ascent-override: 107.2%;
  descent-override: 27.3%;
  line-gap-override: 0%;
}

/* Registered so the theme switch can animate them; every color derived from
   --bg/--fg (lines, borders, muted text) then fades in lockstep. */
@property --bg { syntax: '<color>'; inherits: true; initial-value: #f5f5f5; }
@property --fg { syntax: '<color>'; inherits: true; initial-value: #464646; }

/* Same greys the homepage animates between (245/70 light, 15/207 dark). */
:root {
  --bg: #f5f5f5;
  --fg: #464646;
  --muted: color-mix(in srgb, var(--fg) 70%, var(--bg));
  --line: color-mix(in srgb, var(--fg) 26%, var(--bg));
  --soft: color-mix(in srgb, var(--fg) 7%, var(--bg));
  --danger: #b3423a;
}
:root[data-theme="dark"] {
  --bg: #0f0f0f;
  --fg: #cfcfcf;
  --danger: #e0786f;
}
/* Only animate when the visitor flips the switch (blog.js adds .theme-anim briefly),
   never on page load or navigation. Solid (inverted) elements fade smoothly through a mid-grey; they
   never sit on a link, because visited links paint un-animated. */
:root.theme-anim { transition: --bg 0.35s linear, --fg 0.35s linear; }

/* dimmed elements (header links, footer, counts) stay readable on dark */
:root[data-theme="dark"] .home,
:root[data-theme="dark"] .adminbar a,
:root[data-theme="dark"] .linklike { opacity: 0.92; }
:root[data-theme="dark"] .tag .count { opacity: 0.8; }

* { box-sizing: border-box; }

html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.65;
}

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
img { max-width: 100%; height: auto; }

.wrap {
  width: 100%; max-width: 42rem; margin: 0 auto; padding: 1.25rem 1.25rem 1.25rem;
  flex: 1; display: flex; flex-direction: column;
}
.wrap > main { flex: 1; }
.wrap.wide { max-width: 56rem; }

/* ----- theme toggle (identical to the homepage) ----- */
.theme-toggle { position: fixed; top: 1.5rem; right: 1.5rem; width: 44px; height: 24px; z-index: 10; cursor: pointer; }
.theme-toggle input { display: none; }
.theme-toggle .slider {
  position: absolute; inset: 0;
  background: color-mix(in srgb, currentColor 20%, transparent);
  border-radius: 12px; transition: background 0.3s;
}
.theme-toggle .slider::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  background: var(--bg); border-radius: 50%; transition: transform 0.3s;
}
.theme-toggle input:checked + .slider::after { transform: translateX(20px); }

/* ----- masthead ----- */
.masthead {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem;
  padding: 0.5rem 3.5rem 1.5rem 0;
}
.masthead .home, .adminbar a, .linklike, .tag, .btn, .pager, .meta, .badge, .foot, .section-title, .blog-title {
  font-family: 'Zrnic', 'Zrnic Fallback', system-ui, sans-serif;
}
.home { text-decoration: none; opacity: 0.7; justify-self: start; }
.home:hover { opacity: 1; }
.blog-title { margin: 0; font-size: 1.75rem; font-weight: normal; text-align: center; }
.blog-title a { text-decoration: none; }
.adminbar { grid-column: 1 / -1; display: flex; gap: 1.25rem; justify-content: flex-end; font-size: 0.9rem; min-height: 1.4rem; }
.adminbar a { text-decoration: none; opacity: 0.75; }
.adminbar a:hover { opacity: 1; text-decoration: underline; }
.adminbar form { margin: 0; }

.linklike {
  background: none; border: 0; padding: 0; color: inherit; font-size: inherit; cursor: pointer;
  opacity: 0.75; text-decoration: none;
}
.linklike:hover { opacity: 1; text-decoration: underline; }
.linklike.danger { color: var(--danger); opacity: 1; }

.foot { margin-top: 4rem; text-align: center; color: var(--muted); }

/* ----- lists ----- */
.section-title { font-weight: normal; font-size: 1.6rem; margin: 0.5rem 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.card { padding: 1.4rem 0; border-top: 1px solid var(--line); }
.card:last-of-type { border-bottom: 1px solid var(--line); }
.card h2 { margin: 0 0 0.2rem; font-family: 'Zrnic', 'Zrnic Fallback', system-ui, sans-serif; font-weight: normal; font-size: 1.5rem; line-height: 1.25; }
.card h2 a { text-decoration: none; }
.card h2 a:hover { text-decoration: underline; }
.meta { margin: 0 0 0.6rem; font-size: 0.9rem; color: var(--muted); }
.excerpt { margin: 0 0 0.7rem; }
.tags { margin: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }

.tagbar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1.5rem; }
.tag {
  display: inline-block; border: 1px solid var(--line); border-radius: 999px;
  font-size: 0.9rem; line-height: 1.5;
}
.tag a { display: block; padding: 0.15rem 0.7rem; text-decoration: none; color: inherit; }
.tag .count { opacity: 0.55; }
/* solid when hovered/selected; the colors swap on the <span>, never on the link */
.tag:hover, .tag.active { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.tag.small { font-size: 0.8rem; }
.tag.small a { padding: 0.05rem 0.6rem; }

.pager { display: flex; justify-content: space-between; gap: 1rem; margin: 2rem 0 1rem; font-size: 0.95rem; }
.pager a { text-decoration: none; max-width: 48%; }
.pager a:hover { text-decoration: underline; }

/* ----- single post ----- */
.post-title { font-family: 'Zrnic', 'Zrnic Fallback', system-ui, sans-serif; font-weight: normal; font-size: 2.2rem; line-height: 1.2; margin: 0.5rem 0 0.4rem; }
.prose { margin-top: 1.5rem; font-size: 1.05rem; overflow-wrap: anywhere; }
.prose h2, .prose h3, .prose h4, .prose h5 { font-family: 'Zrnic', 'Zrnic Fallback', system-ui, sans-serif; font-weight: normal; line-height: 1.25; margin: 2rem 0 0.6rem; }
.prose h2 { font-size: 1.6rem; } .prose h3 { font-size: 1.3rem; } .prose h4, .prose h5 { font-size: 1.1rem; }
.prose p { margin: 0 0 1.1rem; }
.prose blockquote { margin: 1.2rem 0; padding: 0.1rem 1.1rem; border-left: 3px solid var(--line); color: var(--muted); }
.prose pre { background: var(--soft); border: 1px solid var(--line); border-radius: 6px; padding: 0.9rem 1rem; overflow-x: auto; }
.prose code { background: var(--soft); padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.92em; }
.prose pre code { background: none; padding: 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }
.prose figure { margin: 1.5rem 0; }
.prose figure img, .prose p img { display: block; border-radius: 6px; }
.prose figcaption { margin-top: 0.4rem; font-size: 0.85rem; color: var(--muted); text-align: center; }
.prose ul, .prose ol { padding-left: 1.4rem; margin: 0 0 1.1rem; }

/* ----- forms / buttons ----- */
.stack { display: grid; gap: 1rem; max-width: 24rem; }
label { display: grid; gap: 0.3rem; font-size: 0.95rem; }
input[type="text"], input[type="password"], textarea {
  width: 100%; padding: 0.6rem 0.75rem; font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px;
}
input:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.btn {
  display: inline-block; padding: 0.55rem 1.2rem; font-size: 1rem; cursor: pointer; text-decoration: none;
  background: #464646; color: #f5f5f5; border: 1px solid #464646; border-radius: 6px;
}
.btn:hover { opacity: 0.85; }
.btn.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.btn > a { color: inherit; text-decoration: none; }
.row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-top: 0.5rem; }
.row.between { justify-content: space-between; }

.notice { padding: 0.6rem 0.9rem; border: 1px solid var(--line); border-radius: 6px; background: var(--soft); }
.notice.error { border-color: var(--danger); color: var(--danger); }

/* ----- editor ----- */
.editor { display: grid; gap: 1rem; }
.title-input { font-size: 1.4rem; font-family: 'Zrnic', 'Zrnic Fallback', system-ui, sans-serif; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.toolbar button {
  font: inherit; font-size: 0.9rem; padding: 0.25rem 0.65rem; cursor: pointer; color: var(--fg);
  background: transparent; border: 1px solid var(--line); border-radius: 6px;
}
.toolbar button:hover, .toolbar .tab.active { background: var(--fg); color: var(--bg); }
.toolbar .spacer { flex: 1; }
#body { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.95rem; line-height: 1.55; resize: vertical; }
#body.dragging { outline: 2px dashed var(--fg); outline-offset: 2px; }
.preview { min-height: 18rem; padding: 0.6rem 0.9rem; margin: 0; border: 1px solid var(--line); border-radius: 6px; }
.preview[hidden] { display: none; }

/* ----- admin table ----- */
.table-wrap { overflow-x: auto; }
table.posts { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.posts th, table.posts td { text-align: left; padding: 0.6rem 0.6rem 0.6rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.posts th { font-family: 'Zrnic', 'Zrnic Fallback', system-ui, sans-serif; font-weight: normal; color: var(--muted); }
.actions { white-space: nowrap; display: flex; gap: 0.9rem; }
.actions form { margin: 0; }
.badge { font-size: 0.8rem; padding: 0.05rem 0.55rem; border: 1px solid var(--line); border-radius: 999px; }
.badge.published { background: var(--fg); color: var(--bg); border-color: var(--fg); }

@media (max-width: 560px) {
  .masthead { grid-template-columns: 1fr; text-align: left; padding-right: 3.5rem; gap: 0.4rem; }
  .blog-title { text-align: left; }
  .post-title { font-size: 1.8rem; }
}
