/* ── Design tokens ──────────────────────────────────────────── */
:root {
  --bg:         #001010;
  --surface:    #102e21;
  --surface-gray: #1e1e1e;
  --border:     #4e4e4e;
  --text:       #FCFCFA;
  --text-muted: #90a4ae;
  --accent:     #FF6188;
  --link:       #FFD866;
  --link-hover: #FF6188;
  --tag:        #78DCE8;
  --category:   #AB9DF2;
  --h1-color:   #A9DC76;
  --code-bg:    #171F2E;
  --code-text:  #FCFCFA;
  --font-ui:    'Montserrat', sans-serif;
  --font-body:  'Source Sans 3', sans-serif;
  --font-mono:  Consolas, 'DejaVu Sans Mono', 'Courier New', monospace;
}

/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.75;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
::selection { background: var(--accent); color: var(--text); }

/* ── Typography ──────────────────────────────────────────────── */
a { color: var(--link); text-decoration: none; transition: color 0.15s; }
a:hover, a:focus { color: var(--link-hover); text-decoration: underline; }

h1, h2, h3, h4, h5, h6 { font-family: var(--font-ui); line-height: 1.3; margin-block: 0.8em 0.3em; }
h1 { font-size: 2rem; color: var(--h1-color); }
h2 { font-size: 1.5rem; color: var(--h1-color); }
h3 { font-size: 1.25rem; color: var(--text); }
h4, h5, h6 { font-size: 1rem; color: var(--text); }

p { margin-block: 0.6em; }

blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--text-muted);
  margin-block: 0.7em;
  font-style: italic;
}

ul, ol { padding-left: 1.5rem; margin-block: 0.5em; }
li { margin-block: 0.2em; }

hr { border: none; border-top: 1px solid var(--border); margin-block: 1.2em; }

img { max-width: 100%; height: auto; border-radius: 4px; }

figure { display: flex; flex-direction: column; align-items: center; margin-block: 1em; }
figcaption { color: var(--text-muted); font-size: 0.875rem; margin-top: 0.4rem; text-align: center; }

/* ── Code ────────────────────────────────────────────────────── */
code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.875em;
}
pre {
  background: var(--code-bg);
  padding: 1.25rem;
  border-radius: 6px;
  overflow-x: auto;
  max-width: 100%;
  margin-block: 0.8em;
  border: 1px solid var(--border);
}
pre code { background: none; padding: 0; font-size: 0.875rem; }

/* ── Tables ──────────────────────────────────────────────────── */
table { border-collapse: collapse; width: 100%; margin-block: 0.8em; font-size: 0.95rem; }
thead { background: #1a1719; }
th { color: var(--text); padding: 0.5rem 0.75rem; text-align: left; font-family: var(--font-ui); font-size: 0.875rem; }
td { border: 1px solid var(--border); padding: 0.5rem 0.75rem; }
tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

/* ── Layout ──────────────────────────────────────────────────── */
.main { max-width: 760px; width: 100%; margin: 0 auto; padding: 1.5rem 1.5rem; flex: 1; }
.main--wide { max-width: 1060px; }
.main--home { max-width: 860px; }

/* ── Post layout with TOC sidebar ───────────────────────────── */
.post-layout {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 3rem;
  align-items: start;
}
/* Prevent grid children from expanding beyond their column width */
.post-layout > * { min-width: 0; }

/* ── TOC sidebar ─────────────────────────────────────────────── */
.toc-sidebar { position: relative; }
.toc-sidebar__inner {
  position: sticky;
  top: 5rem;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
}
.toc-sidebar__title {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-block: 0 0.75rem;
}
#toc-nav ul { list-style: none; padding: 0; margin: 0; }
#toc-nav li { margin-block: 0; }
#toc-nav ul ul { padding-left: 0.75rem; }
#toc-nav a {
  display: block;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-family: var(--font-body);
  padding: 0.18rem 0 0.18rem 0.6rem;
  line-height: 1.4;
  border-left: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
#toc-nav a:hover { color: var(--link-hover); text-decoration: none; }
#toc-nav a.active { color: var(--link); border-left-color: var(--link); }

/* ── Home page layout ────────────────────────────────────────── */
.home-layout {
  display: grid;
  grid-template-columns: 1fr 230px;
  gap: 2rem;
  align-items: start;
}
.home-layout > * { min-width: 0; }
.home-all-posts { margin-block-start: 0.75rem; font-family: var(--font-ui); font-size: 0.9rem; }
.home-all-posts a { color: var(--accent); }
.home-all-posts a:hover { color: var(--link-hover); text-decoration: none; }

/* ── Home sidebar ────────────────────────────────────────────── */
.home-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: sticky;
  top: 3rem;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
}

/* Bio card */
.bio-card {
  background: var(--surface-gray);
  border: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  padding: 1rem;
  text-align: center;
}
.bio-card__name {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 0.15rem;
}
.bio-card__desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.bio-card__info {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: left;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.bio-card__info li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  margin: 0;
}
.bio-card__info a,
.bio-card__info span { color: var(--text-muted); white-space: nowrap; }
.bio-card__info a:hover { color: var(--link-hover); text-decoration: none; }
.obf-email::before { content: attr(data-u) "@" attr(data-d); color: var(--text-muted); }
.bio-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  fill: var(--text-muted);
}

/* Sidebar sections (Posts / Tags / Categories) */
.sidebar-section {
  background: var(--surface-gray);
  border: 1px solid var(--border);
  border-top: none;
  padding: 0.75rem 1rem;
}
.sidebar-section:last-child { border-radius: 0 0 6px 6px; }
.sidebar-section__title {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  margin: 0 0 0.5rem;
}
.sidebar-section__title a { color: inherit; }
.sidebar-section__title a:hover { color: var(--link-hover); text-decoration: none; }
.sidebar-posts {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.sidebar-posts li { margin: 0; }
.sidebar-posts a {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.3;
  display: block;
}
.sidebar-posts a:hover { color: var(--link-hover); text-decoration: none; }
.sidebar-taxo {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  list-style: none;
  padding: 0;
  margin: 0;
}
.sidebar-taxo li { margin: 0; }
.sidebar-taxo .tag  { font-size: 0.75rem; }
.sidebar-taxo .category { font-size: 0.75rem; }

/* ── Archive page ────────────────────────────────────────────── */
.archive { max-width: 720px; }
.archive__key {
  display: block;
  font-family: var(--font-ui);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  margin-block: 2rem 0.6rem;
}
.archive__ul {
  list-style: none;
  padding: 0 0 0 1.25rem;
  margin: 0;
  border-left: 2px solid var(--border);
}
.archive__li {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding-block: 0.3rem;
}
.archive__meta { flex-shrink: 0; min-width: 3.5rem; }
.archive__date { font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-muted); }
.archive__title { color: var(--text); font-size: 0.95rem; }
.archive__title:hover { color: var(--link-hover); text-decoration: none; }

/* ── Hero header (home page) ─────────────────────────────────── */
.home-hero {
  width: 100%;
  height: 200px;
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
}
.home-hero__inner {
  text-align: center;
  padding: 1rem 2rem;
  background: rgba(34, 31, 34, 0.55);
  border-radius: 6px;
}
.home-hero__title {
  font-family: var(--font-ui);
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  margin: 0;
  letter-spacing: 0.03em;
}
.home-hero__sub {
  color: rgba(255,255,255,0.75);
  font-size: 0.9rem;
  margin: 0.3rem 0 0;
}

/* ── Navbar ──────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.3rem 1.5rem;
  line-height: 1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar__brand {
  font-family: var(--font-ui);
  font-weight: 700;
  color: var(--text);
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}
.navbar__brand:hover { color: var(--text); text-decoration: none; }
.navbar__links {
  list-style: none;
  display: flex;
  gap: 1.5rem;
  margin-left: auto;
}
.navbar__links a {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.9rem;
}
.navbar__links a:hover { color: var(--link-hover); text-decoration: none; }

/* ── Post list (index, section, taxonomy) ────────────────────── */
.section__title {
  margin-block-end: 0.75rem;
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 1.4rem;
}
.post-card {
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}
.post-card:last-child { border-bottom: none; }
.post-card__title a {
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 1.15rem;
  font-weight: 700;
}
.post-card__title a:hover { color: var(--link-hover); text-decoration: none; }
.post-card__date {
  color: var(--text-muted);
  font-size: 0.85rem;
  display: block;
  margin-block: 0.3rem 0.5rem;
  font-family: var(--font-mono);
}
.post-card__desc { color: var(--text-muted); font-size: 0.95rem; margin-block: 0.3rem; }
.post-card__tags {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-block: 0.5rem 0;
  padding: 0;
}

/* ── Tags and categories ─────────────────────────────────────── */
.tag { color: var(--tag); font-size: 0.85rem; font-family: var(--font-mono); }
.tag:hover { color: var(--accent); text-decoration: none; }
.category {
  color: var(--category);
  font-size: 0.85rem;
  font-family: var(--font-ui);
  font-weight: 600;
}
.category:hover { color: var(--accent); text-decoration: none; }

/* ── Post page ───────────────────────────────────────────────── */
.post__header { margin-block-end: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.post__title {
  font-size: 2rem;
  color: var(--accent);
  font-family: var(--font-ui);
  margin-block: 0 0.75rem;
}
.post__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}
.post__meta time { font-family: var(--font-mono); }
.post__meta-group { display: flex; align-items: center; gap: 0.25rem; }
.post__meta-label { font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-muted); }
.post__tags, .post__categories { list-style: none; display: flex; gap: 0.5rem; flex-wrap: wrap; padding: 0; }

/* ── TeX / LaTeX logo ────────────────────────────────────────── */
.logo-tex, .logo-latex { font-family: 'Computer Modern', 'Latin Modern Roman', serif; letter-spacing: 0; white-space: nowrap; }
.logo-tex__e { vertical-align: -0.25ex; margin: 0 -0.1em; }
.logo-latex__a { font-size: 0.72em; vertical-align: 0.3ex; margin: 0 -0.08em 0 -0.3em; }

/* ── Footnotes ───────────────────────────────────────────────── */
section[role="doc-endnotes"] {
  border-top: 1px solid var(--border);
  margin-top: 2rem;
  padding-top: 0.75rem;
}

/* ── Typst inline decorations ────────────────────────────────── */
mark {
  background: #ffda6640;
  color: var(--text);
  border-radius: 2px;
  padding: 0 0.1em;
}


/* ── Typst HTML content overrides ───────────────────────────────
   Typst HTML export uses semantic elements; these rules ensure
   they match the blog's design tokens. */
.typst-content h1 { margin-block-start: 0; }
.typst-content p:first-child { margin-block-start: 0; }

/* Theorem boxes from theorion/cosmos use light-coloured backgrounds.
   The blog's default text colour (#FCFCFA) is invisible against them,
   so we reset to dark text here.
   :not([class]) excludes zebraw's classed divs (ec-line, ec-header, etc.)
   which also carry background: in their inline style. */
.typst-content div[style*="background:"]:not([class]) { color: #1a1a1a; }
.typst-content div[style*="background:"]:not([class]) a { color: #1a6bbf; }

/* ── Two-column layout ───────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1em;
  margin-block: 0.8em;
}
@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }

/* ── mysect (left-border section box) ───────────────────────── */
.mysect {
  padding: 0.5rem 1rem;
  margin-block: 0.8rem;
  background: var(--surface-gray);
}
.mysect__title {
  font-family: var(--font-ui);
  font-weight: 700;
  margin-bottom: 0.3rem;
}

/* ── mybox (titled content box) ─────────────────────────────── */
.mybox {
  border-radius: 4px;
  overflow: hidden;
  margin-block: 0.8rem;
}
.mybox__title {
  color: #1a1a1a;
  font-family: var(--font-ui);
  font-weight: 700;
  padding: 0.3rem 0.75rem;
}
.mybox__body {
  padding: 0.6rem 0.75rem;
  background: var(--surface-gray);
}

/* ── Link card (OGP preview) ─────────────────────────────────── */
.link-card-wrap { display: contents; }
.link-card {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-block: 1rem;
  color: inherit;
  text-decoration: none;
  background: var(--surface-gray);
  transition: border-color 0.15s;
}
.link-card:hover { border-color: var(--link); text-decoration: none; color: inherit; }
.link-card__image { flex-shrink: 0; width: 160px; }
.link-card__image img { width: 100%; height: 100%; object-fit: cover; border-radius: 0; display: block; }
.link-card__body {
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}
.link-card__title {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-card__desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-card__url {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: auto;
}
@media (max-width: 640px) {
  .link-card__image { width: 100px; }
}

/* ── Taxonomy list pages ─────────────────────────────────────── */
.taxo-list__items {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-block: 1rem;
  padding: 0;
}
.taxo-list__count { color: var(--text-muted); font-size: 0.8rem; margin-left: 0.2em; }

/* ── Paginator ───────────────────────────────────────────────── */
.paginator {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-block: 1.2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Footer ──────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  border-top: 1px solid var(--border);
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .post-layout { grid-template-columns: 1fr; }
  .toc-sidebar { display: none; }
  .home-layout { grid-template-columns: 1fr; }
  .home-sidebar { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .navbar { flex-wrap: wrap; gap: 0.75rem; padding: 0.75rem 1rem; }
  .navbar__links { gap: 1rem; }
  .main { padding: 1.5rem 1rem; }
  .post__title { font-size: 1.5rem; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
}
