/* ==========================================================================
   VotingSite · blog
   Loaded after style.css, so every token below comes from :root there
   (--bg, --panel, --border, --text, --muted, --accent, --gold, --r, --font,
   --font-display …). Light theme rides on html[data-theme="light"].
   Mobile-first, no external fonts, no CDN.
   ========================================================================== */

/* ------------------------------------------------------------ local tokens */
.blog-grid,
.blog-article,
.blog-editor,
.blog-head {
  --blog-measure: 72ch;
  --blog-lead: 1.75;
  --blog-card-radius: var(--r-lg, 12px);
}

/* ================================================================== index == */
.blog-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 8px 0 20px;
}
.blog-head h1 { margin: 0 0 .25em; }
.blog-head p { margin: 0; max-width: 60ch; }

.blog-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px;
  margin-bottom: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.blog-filter-label { color: var(--muted); font-size: .85rem; }
.blog-filters select {
  flex: 1 1 180px;
  min-width: 0;
}

.blog-lang-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 12px 14px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: var(--r);
  background: color-mix(in srgb, var(--gold) 8%, var(--panel));
  font-size: .92rem;
}
.blog-lang-hint a {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elev, var(--panel));
  text-decoration: none;
  white-space: nowrap;
}
.blog-lang-hint a:hover { border-color: var(--accent); }
.blog-lang-hint.compact { margin: 0 0 24px; font-size: .88rem; }

.blog-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-bottom: 24px;
}

.blog-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--blog-card-radius);
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.blog-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  box-shadow: var(--shadow);
}

.blog-card-cover {
  display: block;
  aspect-ratio: 16 / 9;
  background: var(--panel-2, var(--panel));
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.blog-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.blog-card-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-family: var(--font-display);
  font-size: 2.2rem;
  letter-spacing: .08em;
  color: hsl(var(--h, 140) 60% 72%);
  background:
    linear-gradient(135deg, hsl(var(--h, 140) 40% 22% / .85), transparent 60%),
    repeating-linear-gradient(45deg, transparent 0 10px, rgb(255 255 255 / .03) 10px 20px);
}
html[data-theme="light"] .blog-card-fallback { color: hsl(var(--h, 140) 45% 32%); }

.blog-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px 16px;
}
.blog-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: .78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.blog-card-title { margin: 0; font-size: 1.12rem; line-height: 1.3; }
.blog-card-title a { color: var(--text); text-decoration: none; }
.blog-card-title a:hover { color: var(--accent); }
.blog-card-excerpt {
  margin: 0;
  color: var(--muted);
  font-size: .93rem;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.blog-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}
.blog-chips a {
  padding: 3px 9px;
  font-size: .76rem;
  color: var(--muted);
  text-decoration: none;
  background: var(--panel-2, var(--bg));
  border: 1px solid var(--border);
  border-radius: 999px;
}
.blog-chips a::before { content: "#"; opacity: .5; }
.blog-chips a:hover { color: var(--accent); border-color: var(--accent); }

/* =============================================================== article == */
.reading-progress {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 3px;
  margin: -8px 0 12px;
  background: color-mix(in srgb, var(--border) 60%, transparent);
  border-radius: 999px;
  overflow: hidden;
}
.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width .08s linear;
}
@media (prefers-reduced-motion: reduce) {
  .reading-progress span { transition: none; }
}

.blog-article {
  max-width: var(--blog-measure);
  margin: 0 auto;
}
.blog-crumbs {
  display: flex;
  gap: 8px;
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 14px;
}
.blog-crumbs a { color: var(--muted); text-decoration: none; }
.blog-crumbs a:hover { color: var(--accent); }

.blog-article-head h1 {
  font-size: clamp(1.75rem, 1.2rem + 3vw, 2.6rem);
  margin-bottom: .35em;
}
.blog-lede {
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--muted);
  margin: 0 0 18px;
}
.blog-byline {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  font-size: .9rem;
}
.blog-byline .muted { font-size: .82rem; }
.blog-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  font-family: var(--font-display);
  color: var(--accent-ink, #06170a);
  background: var(--accent);
}

.blog-cover {
  margin: 0 0 26px;
  border-radius: var(--r-lg, 12px);
  overflow: hidden;
  border: 1px solid var(--border);
}
.blog-cover img { display: block; width: 100%; height: auto; }

/* ------------------------------------------------------------ prose body -- */
.blog-body {
  font-size: 1.03rem;
  line-height: var(--blog-lead);
  overflow-wrap: break-word;
}
.blog-body > :first-child { margin-top: 0; }
.blog-body p { margin: 0 0 1.15em; }
.blog-body a { color: var(--accent); text-underline-offset: 3px; }
.blog-body .md-h {
  margin: 1.8em 0 .55em;
  scroll-margin-top: 24px;
}
.blog-body h2.md-h { font-size: 1.5rem; }
.blog-body h3.md-h { font-size: 1.22rem; }
.blog-body h4.md-h, .blog-body h5.md-h, .blog-body h6.md-h { font-size: 1.05rem; }
.blog-body .md-hr {
  border: 0;
  height: 1px;
  margin: 2.2em 0;
  background: linear-gradient(90deg, transparent, var(--border) 20%, var(--border) 80%, transparent);
}
.blog-body .md-list { margin: 0 0 1.15em; padding-left: 1.35em; }
.blog-body .md-list li { margin: .3em 0; }
.blog-body .md-list .md-list { margin: .3em 0; }
.blog-body strong { color: var(--text); }
.blog-body del { color: var(--muted); }

.blog-body .md-quote {
  margin: 1.5em 0;
  padding: .1px 16px;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--r) var(--r) 0;
  background: color-mix(in srgb, var(--accent) 7%, var(--panel));
  color: var(--text);
}
.blog-body .md-quote p:last-child { margin-bottom: 1.15em; }

.blog-body .md-code-inline {
  padding: .12em .38em;
  font-family: var(--font-mono, monospace);
  font-size: .88em;
  background: var(--panel-2, var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--r-sm, 5px);
}
.blog-body .md-code {
  position: relative;
  margin: 1.5em 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--font-mono, monospace);
  font-size: .88rem;
  line-height: 1.6;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  tab-size: 2;
}
.blog-body .md-code code { background: none; border: 0; padding: 0; font: inherit; }
.blog-body .md-code[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 0;
  right: 0;
  padding: 2px 8px;
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--panel-2, var(--bg));
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 0 var(--r) 0 var(--r-sm, 5px);
}

.blog-body .md-img,
.blog-body .md-figure img {
  max-width: 100%;
  height: auto;
  border-radius: var(--r);
}
.blog-body .md-figure {
  margin: 1.8em 0;
  text-align: center;
}
.blog-body .md-figure img {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
}
.blog-body .md-figure figcaption {
  margin-top: 8px;
  font-size: .84rem;
  color: var(--muted);
  font-style: italic;
}

.blog-body .md-table-wrap {
  margin: 1.6em 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.blog-body .md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
}
.blog-body .md-table th,
.blog-body .md-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.blog-body .md-table th {
  background: var(--panel-2, var(--panel));
  font-family: var(--font-display);
  font-weight: 600;
  white-space: nowrap;
}
.blog-body .md-table tbody tr:last-child td { border-bottom: 0; }
.blog-body .md-table tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }

.blog-article-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 32px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------- prev/next -- */
.blog-prevnext {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  max-width: var(--blog-measure);
  margin: 26px auto;
}
.blog-prevnext-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.blog-prevnext-item span { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.blog-prevnext-item.next { text-align: right; }
.blog-prevnext-item:hover { border-color: var(--accent); }

.blog-related { margin-top: 36px; }

/* ================================================================ editor == */
.blog-editor {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
}
.blog-editor-main h1 { margin-bottom: .6em; }
.blog-editor textarea.mono {
  font-family: var(--font-mono, monospace);
  font-size: .9rem;
  line-height: 1.6;
  min-height: 320px;
  resize: vertical;
  tab-size: 2;
}
.blog-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.blog-charcount {
  margin-top: 6px;
  font-size: .8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.blog-charcount.warn { color: var(--gold); }
.blog-charcount.over { color: var(--danger); font-weight: 600; }

.blog-editor-preview {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
}
.blog-editor-preview .card-title { display: flex; align-items: baseline; gap: 8px; }
.blog-editor-preview .blog-body { font-size: .96rem; }

.blog-admin-table td .btn { margin: 2px 0; }
.blog-admin-table .danger { color: var(--danger); }
.blog-admin-table .danger:hover { border-color: var(--danger); }

/* ============================================================== responsive */
@media (min-width: 640px) {
  .blog-head { flex-direction: row; align-items: flex-end; justify-content: space-between; }
  .blog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .blog-prevnext { grid-template-columns: 1fr 1fr; }
  .blog-body { font-size: 1.06rem; }
}

@media (min-width: 1000px) {
  .blog-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .blog-editor { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
  /* first card of an index page reads as the lead story */
  .blog-grid > .blog-card:first-child:nth-last-child(n + 5) {
    grid-column: span 2;
    flex-direction: row;
  }
  .blog-grid > .blog-card:first-child:nth-last-child(n + 5) .blog-card-cover {
    flex: 0 0 46%;
    aspect-ratio: auto;
    border-bottom: 0;
    border-right: 1px solid var(--border);
  }
  .blog-grid > .blog-card:first-child:nth-last-child(n + 5) .blog-card-title { font-size: 1.45rem; }
  .blog-grid > .blog-card:first-child:nth-last-child(n + 5) .blog-card-body { padding: 20px 22px; justify-content: center; }
}

@media print {
  .reading-progress, .blog-prevnext, .blog-related, .blog-filters, .blog-chips { display: none; }
  .blog-article { max-width: none; }
}
