:root {
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-heading: "Acme", var(--font-body);
  --max-width: 1296px;
  --radius: 10px;

  --bg: #f7f7f5;
  --bg-elevated: #ffffff;
  --text: #1c1c1e;
  --text-muted: #6b6b6f;
  --accent: #2e7d32;
  --accent-contrast: #ffffff;
  --border: #e4e3e0;
}

[data-theme="dark"] {
  --bg: #16161a;
  --bg-elevated: #1f1f24;
  --text: #f1f1f2;
  --text-muted: #a3a3a8;
  --accent: #66bb6a;
  --accent-contrast: #16161a;
  --border: #2c2c33;
}

* { box-sizing: border-box; }

@font-face {
  font-family: "Acme";
  src: url("/assets/fonts/acme-v21-latin-regular.eot");
  src: url("/assets/fonts/acme-v21-latin-regular.eot?#iefix") format("embedded-opentype"),
       url("/assets/fonts/acme-v21-latin-regular.woff2") format("woff2"),
       url("/assets/fonts/acme-v21-latin-regular.woff") format("woff"),
       url("/assets/fonts/acme-v21-latin-regular.ttf") format("truetype"),
       url("/assets/fonts/acme-v21-latin-regular.svg#Acme") format("svg");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

body { margin: 0; font-family: var(--font-body); background: var(--bg); color: var(--text); line-height: 1.55; }
body.bg-white { background: var(--bg-elevated); color: var(--text); }

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--accent-contrast); padding: .5rem 1rem; z-index: 1000;
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* Header */
.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  display: flex; align-items: center; gap: 1rem; padding: .75rem 1.25rem; flex-wrap: wrap;
}
.logo { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo img { display: block; }

.nav-toggle {
  display: none; flex-direction: column; gap: 4px; background: none; border: 0; cursor: pointer; padding: .5rem;
  margin-left: auto;
}
.nav-toggle span { width: 22px; height: 2px; background: var(--text); display: block; }

.site-nav { display: flex; align-items: center; gap: 1.5rem; margin-left: auto; }
.site-nav ul { list-style: none; display: flex; gap: 1.25rem; margin: 0; padding: 0; }
.site-nav ul a { color: var(--text); font-weight: 500; }
.nav-tools { display: flex; align-items: center; gap: .75rem; }
.lang-switch { display: flex; align-items: center; gap: .35rem; color: var(--text); font-size: .9rem; }
.lang-switch img { border-radius: 2px; }

.theme-toggle {
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text);
}
.icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: block; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}

@media (max-width: 780px) {
  .nav-toggle { display: flex; }
  .site-nav {
    display: none; flex-direction: column; align-items: flex-start; width: 100%;
    order: 3; padding-top: .75rem; gap: 1rem;
  }
  .site-nav.open { display: flex; }
  .site-nav ul { flex-direction: column; gap: .75rem; }
}

/* Home intro */
.home-intro { text-align: center; padding: 3rem 1.25rem 2rem; background: var(--bg-elevated); color: var(--text); }
.home-intro .avatar {
  display: block; aspect-ratio: 1 / 1; width: 33.3333%; max-width: 100%; height: auto;
  margin: 0 auto 1.5rem; padding: 0;
}
.home-intro h1 { font-family: var(--font-heading); font-size: clamp(2.5rem, 5vw, 4rem); color: var(--accent); margin: 0 0 1.5rem; }
.home-intro h2 { font-weight: 500; color: var(--text-muted); font-size: 1.1rem; margin-top: 0; }
.home-intro p { max-width: 640px; margin: 1rem auto 0; color: var(--text-muted); }

/* Category sections */
.category-section { padding: 2rem 1.25rem 1rem; scroll-margin-top: 80px; }
.category-section:nth-of-type(2) { background: var(--bg-elevated); color: var(--text); }
.category-section:nth-of-type(2) .post-card { background: var(--bg); }
.category-title {
  font-family: var(--font-heading); font-size: clamp(2rem, 4vw, 3rem); font-weight: 500; color: var(--accent);
  border-bottom: 0; display: block; text-align: center; margin-bottom: 1.5rem; line-height: 1.2;
}
.category-title a { color: inherit; text-decoration: none; }
.category-title a:hover { text-decoration: underline; }

.post-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.5rem; margin-bottom: 1rem;
}

/* Tag-grouped category pages */
.tag-jump {
  display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem .75rem; margin: 1rem 0 2rem;
}
.tag-jump a {
  font-size: 1rem; font-weight: 600; padding: .4rem .9rem; border: 2px solid var(--border);
  border-radius: 999px; color: var(--text);
}
.tag-jump a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.tag-group { padding-top: 1.5rem; scroll-margin-top: 90px; }
.tag-group + .tag-group { border-top: 1px solid var(--border); margin-top: 1rem; }
.tag-group-title {
  font-family: var(--font-heading); font-size: 2rem; font-weight: 600; color: var(--accent);
  text-align: center; margin: 0 0 1.25rem;
}

/* Fixed-position random preview grid (alternative to the carousel): up to 4
   slots per rubric, always spanning the full width; cross-fade to a
   newly-picked random post every 5s. Slot *count* (not just column width)
   drops from 4 to 3/2/1 as the window narrows - see the matching
   breakpoints in initRandomPreview()'s getVisibleCount() in main.js. */
.preview-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5rem; margin-bottom: 1rem;
}
.preview-slot { transition: opacity .5s ease; min-width: 0; }
.preview-slot.is-fading { opacity: 0; }
.preview-slot.is-hidden { display: none; }

@media (max-width: 1100px) {
  .preview-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 800px) {
  .preview-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 500px) {
  .preview-grid { grid-template-columns: 1fr; }
}
.post-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.post-card-media { display: block; aspect-ratio: 3/2; overflow: hidden; background: var(--border); }
.post-card-media picture { display: block; width: 100%; height: 100%; }
.post-card-media img,
.post-card-media-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.post-card-media-placeholder {
  display: flex; align-items: center; justify-content: center; width: 100%; height: 100%;
  padding: 1rem; text-align: center; font-weight: 600; color: var(--text-muted);
  background: linear-gradient(135deg, var(--border), transparent);
}
.post-card-body { padding: 1rem; display: flex; flex-direction: column; gap: .35rem; }
.post-card-taxo { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); display: flex; gap: .5rem; margin: 0; }
.post-card-body h3 { margin: 0; font-size: 1.05rem; }
.post-card-body h3 a { color: var(--text); }
.post-card-meta { font-size: .8rem; color: var(--text-muted); margin: 0; }
.post-card-excerpt { margin: 0; color: var(--text-muted); font-size: .92rem; }
.post-card-excerpt a { color: inherit; }
.read-more { font-size: .85rem; font-weight: 600; }

/* Single post */
.post { padding: 2.5rem 1.25rem 3rem; max-width: var(--max-width); }
.breadcrumb { font-size: .85rem; color: var(--text-muted); }
.post-meta { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .85rem; color: var(--text-muted); margin-bottom: .5rem; }
.post-tag {
  background: var(--accent); color: var(--accent-contrast); padding: .1rem .55rem; border-radius: 999px; font-weight: 600; font-size: .75rem;
}
.post h1 { font-family: var(--font-heading); color: var(--accent); margin: .25rem 0 1.25rem; font-size: clamp(2rem, 4vw, 3rem); }
.post-image { max-width: 100%; width: auto; height: auto; border-radius: var(--radius); margin: 0 auto 1.5rem; display: block; }
.post-body { font-size: 1.05rem; }

/* Arbitrary rich HTML body (post.bodyHtml) - reasonable defaults for
   whatever markup an author drops in, since content isn't controlled here. */
.post-body-html { font-size: 1.05rem; }
.post-body-html :first-child { margin-top: 0; }
.post-body-html :last-child { margin-bottom: 0; }
.post-body-html img, .post-body-html video, .post-body-html iframe {
  max-width: 100%; height: auto; border-radius: var(--radius); display: block; margin: 1rem 0;
}
.post-body-html h1, .post-body-html h2, .post-body-html h3,
.post-body-html h4, .post-body-html h5, .post-body-html h6 {
  font-family: var(--font-heading); color: var(--text); line-height: 1.25; margin: 1.75rem 0 .75rem;
}
.post-body-html p { margin: 0 0 1rem; }
.post-body-html ul, .post-body-html ol { margin: 0 0 1rem; padding-left: 1.5rem; }
.post-body-html blockquote {
  margin: 1rem 0; padding: .5rem 1rem; border-left: 3px solid var(--accent); color: var(--text-muted);
}
.post-body-html pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; overflow-x: auto; font-size: .9rem;
}
.post-body-html code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.post-body-html table { width: 100%; border-collapse: collapse; margin: 0 0 1rem; }
.post-body-html th, .post-body-html td { border: 1px solid var(--border); padding: .5rem .75rem; text-align: left; }
.back-link { margin-top: 2rem; }

.page-content { padding: 2.5rem 1.25rem 3rem; max-width: 700px; }

/* Hints (collapsible) */
.hints {
  margin: 1.5rem 0; border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem 1rem; background: var(--bg-elevated);
}
.hints summary {
  cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: .5rem;
}
.hints summary::-webkit-details-marker { display: none; }
.hints summary::before { content: "▸"; color: var(--accent); transition: transform .2s ease; }
.hints[open] summary::before { transform: rotate(90deg); }
.hints p { margin: .75rem 0 .25rem; color: var(--text-muted); }

/* Lightbox */
.post-image-trigger {
  position: relative; display: flex; justify-content: center; width: 100%;
  padding: 0; border: 0; background: none; cursor: zoom-in;
}
.post-image-trigger picture { display: block; max-width: 100%; }

.lightbox {
  position: fixed; inset: 0; z-index: 1000; background: rgba(0, 0, 0, .88);
  display: flex; align-items: center; justify-content: center; padding: 2rem;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 4px; box-shadow: 0 10px 40px rgba(0, 0, 0, .5); }
.lightbox-close {
  position: absolute; top: 1rem; right: 1.25rem; background: none; border: 0; color: #fff;
  font-size: 2.25rem; line-height: 1; cursor: pointer; padding: .25rem .5rem;
}

/* Footer */
.site-footer { background: var(--bg); border-top: 1px solid var(--border); margin-top: 3rem; padding: 1.5rem 0; color: var(--text-muted); font-size: .85rem; }
.footer-inner { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .75rem; }

/* ------------------------------------------------------------------ */
/* Utilities - small Bootstrap-like helper classes on top of the theme */
/* custom properties defined at the top of this file (:root /          */
/* [data-theme="dark"]), so they follow light/dark mode automatically. */
/* ------------------------------------------------------------------ */
.text-accent  { color: var(--accent) !important; }
.text-muted   { color: var(--text-muted) !important; }
.text-body    { color: var(--text) !important; }
.text-on-accent { color: var(--accent-contrast) !important; }

.bg-accent    { background-color: var(--accent) !important; color: var(--accent-contrast) !important; }
.bg-body      { background-color: var(--bg) !important; }
.bg-elevated  { background-color: var(--bg-elevated) !important; }

.border-accent { border-color: var(--accent) !important; }

.font-heading { font-family: var(--font-heading) !important; }

.rounded      { border-radius: var(--radius) !important; }
.rounded-circle { border-radius: 50% !important; }
