*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ---------- fonts (self-hosted, SIL OFL — see static/fonts/OFL.txt) ---------- */

@font-face {
  font-family: "Libertinus Serif";
  src: url("fonts/LibertinusSerif-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Libertinus Serif";
  src: url("fonts/LibertinusSerif-Italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Libertinus Serif";
  src: url("fonts/LibertinusSerif-Semibold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Libertinus Serif";
  src: url("fonts/LibertinusSerif-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- theme tokens ---------- */

:root {
  --bg: #141210;
  --text: #e7e5e4;
  --muted: #a8a29e;
  --accent: #d97706;
  --accent-weak: rgba(217, 119, 6, 0.12);
  --border: #2b2723;
  --code-bg: #1d1a17;
  --ok: #4ade80;
  --bad: #f87171;
  --max-width: 44rem;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

:root[data-theme="light"] {
  --bg: #fafaf9;
  --text: #1c1917;
  --muted: #78716c;
  --accent: #b45309;
  --accent-weak: rgba(180, 83, 9, 0.07);
  --border: #e7e5e4;
  --code-bg: #f5f5f4;
  --ok: #15803d;
  --bad: #b91c1c;
}

/* ---------- base ---------- */

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: "Libertinus Serif", "Georgia", serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s, color 0.15s;
}

a:hover {
  border-bottom-color: var(--accent);
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection {
  background: var(--accent);
  color: var(--bg);
}

/* ---------- header / logo ---------- */

header {
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 3rem 1.5rem 0;
}

.logo {
  display: block;
  color: var(--text);
  border-bottom: none;
  line-height: 1;
}

.logo:hover {
  color: var(--accent);
  border-bottom-color: transparent;
}

.logo pre {
  font-family: var(--mono);
  font-size: clamp(0.34rem, 1.15vw, 0.55rem);
  line-height: 1;
  width: fit-content;
  margin: 0 auto;
  padding: 0;
  background: none;
  white-space: pre;
}

/* ---------- search ---------- */

.search-wrap {
  margin-top: 1.25rem;
}

#search {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, background-color 0.2s ease;
}

#search:focus {
  border-color: var(--muted);
  outline: none;
}

#search::placeholder {
  color: var(--muted);
}

#search-results {
  display: flex;
  flex-direction: column;
  margin-top: 0.25rem;
}

#search-results:empty {
  display: none;
}

.search-empty {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0.6rem 0.75rem;
  letter-spacing: 0.02em;
}

.search-result {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.search-result:last-child {
  border-bottom: none;
}

.search-result:hover {
  background: var(--accent-weak);
  border-bottom-color: var(--border);
}

.search-result .date {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  min-width: 6rem;
  flex-shrink: 0;
}

.search-result .title {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.35;
}

/* ---------- post list ---------- */

main {
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 0.5rem 1.5rem 4rem;
  flex: 1;
}

.post-list {
  display: flex;
  flex-direction: column;
}

.post-row {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  transition: background 0.15s;
}

.post-row:last-child {
  border-bottom: none;
}

.post-row:hover {
  background: var(--accent-weak);
  border-bottom-color: var(--border);
}

.post-row .date {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  min-width: 6rem;
  flex-shrink: 0;
}

.post-row .title {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.35;
}

/* ---------- article ---------- */

article header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

article header .date {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  margin-bottom: 0.5rem;
}

article header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.25;
}

article h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 2.5rem;
  margin-bottom: 0.5rem;
}

article h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

article p {
  margin-bottom: 1.1rem;
}

article blockquote {
  border-left: 2px solid var(--accent);
  padding-left: 1rem;
  margin: 1.5rem 0;
  color: var(--muted);
  font-style: italic;
}

article code {
  font-family: var(--mono);
  font-size: 0.875rem;
  background: var(--code-bg);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}

article pre {
  background: var(--code-bg);
  padding: 1rem;
  border-radius: 4px;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-size: 0.85rem;
  line-height: 1.5;
}

article pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}

article ul,
article ol {
  margin: 1rem 0 1.1rem 1.5rem;
}

article li {
  margin-bottom: 0.4rem;
}

article img {
  max-width: 100%;
  border-radius: 3px;
  margin: 1.5rem 0;
}

article hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

sup {
  line-height: 0;
}

/* footnotes (goldmark .footnotes section) */

.footnotes {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2.5rem;
}

.footnotes hr {
  border: none;
  border-top: 1px solid var(--border);
  width: 8rem;
  margin: 0 0 1rem;
}

.footnotes ol {
  margin: 0 0 1rem 1.25rem;
}

.footnotes li {
  margin-bottom: 0.4rem;
}

.footnotes a {
  color: var(--accent);
}

/* ---------- tables ---------- */

article table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0 2rem;
  font-size: 0.82rem;
  line-height: 1.45;
}

article table th {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  color: var(--muted);
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

article table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

article table tr.book-row td {
  border-bottom: none;
}

article table tr:last-child td {
  border-bottom: none;
}

article table td.review {
  font-style: italic;
  color: var(--muted);
  padding-top: 0;
  padding-bottom: 0.6rem;
}

/* rating bars */

.bar {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.bar .fill {
  color: var(--accent);
}

.bar .empty {
  color: var(--border);
}

/* reading year nav */

.year-nav {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: -1.5rem 0 2rem;
}

.year-nav a {
  color: var(--muted);
}

.year-nav a:hover {
  color: var(--accent);
}

.year-nav .current {
  color: var(--text);
}

/* ---------- predictions ---------- */

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 2px;
  white-space: nowrap;
}

.badge-pending {
  color: var(--muted);
}

.badge-correct {
  color: var(--ok);
  border-color: var(--ok);
}

.badge-wrong {
  color: var(--bad);
  border-color: var(--bad);
}

td.conf {
  font-family: var(--mono);
  font-size: 0.75rem;
  white-space: nowrap;
}

/* ---------- pagination / back ---------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
}

.pagination a {
  color: var(--muted);
  text-transform: lowercase;
}

.pagination a:hover {
  color: var(--accent);
  border-bottom-color: transparent;
}

.pg-num {
  color: var(--muted);
}

.back {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: lowercase;
}

.back:hover {
  color: var(--text);
}

/* ---------- footer ---------- */

footer {
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 0 1.5rem 2rem;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.03em;
  text-transform: lowercase;
}

footer nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

footer nav .sep {
  color: var(--border);
}

footer a {
  color: var(--muted);
}

footer a:hover {
  color: var(--accent);
  border-bottom-color: transparent;
}

#theme-toggle {
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--muted);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

#theme-toggle:hover {
  color: var(--accent);
}

/* ---------- 404 ---------- */

.notfound {
  padding: 2rem 0;
}

.notfound .big {
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--accent);
  letter-spacing: 0.06em;
  margin-bottom: 1.25rem;
}

.notfound h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.notfound p {
  color: var(--muted);
  margin-bottom: 1.1rem;
}

/* ---------- reduced motion / mobile ---------- */

@media (prefers-reduced-motion: reduce) {
  body {
    transition: none;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 15px;
  }

  header {
    padding-top: 2rem;
  }

  main {
    padding-top: 2rem;
  }

  .post-row {
    flex-direction: column;
    gap: 0.15rem;
  }

  .post-row .date {
    min-width: unset;
  }

  .search-result {
    flex-direction: column;
    gap: 0.15rem;
  }

  .search-result .date {
    min-width: unset;
  }
}
