/* shadcn/ui inspired design tokens */
:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --radius: 0.5rem;
}

/* Dark theme: applied either when the user picks it explicitly (data-theme="dark")
 * or when "system" mode is active and the OS prefers dark. */
:root[data-theme="dark"],
:root[data-theme="system"] {
  color-scheme: light dark;
}
:root[data-theme="dark"] {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 10% 3.9%;
  --card-foreground: 0 0% 98%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 3.7% 15.9%;
  --accent-foreground: 0 0% 98%;
  --border: 240 3.7% 15.9%;
  --input: 240 3.7% 15.9%;
  --ring: 240 4.9% 83.9%;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"], :root:not([data-theme]) {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --card: 240 10% 3.9%;
    --card-foreground: 0 0% 98%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --secondary: 240 3.7% 15.9%;
    --secondary-foreground: 0 0% 98%;
    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 64.9%;
    --accent: 240 3.7% 15.9%;
    --accent-foreground: 0 0% 98%;
    --border: 240 3.7% 15.9%;
    --input: 240 3.7% 15.9%;
    --ring: 240 4.9% 83.9%;
  }
}

* { border-color: hsl(var(--border)); }

body {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, ui-sans-serif, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeSpeed;
}

/* shadcn-style components */
.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .375rem;
  font-size: 0.875rem; font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: calc(var(--radius) - 2px);
  transition: background-color .15s, color .15s, border-color .15s;
  cursor: pointer; user-select: none; white-space: nowrap;
  border: 1px solid transparent;
}
.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { background: hsl(var(--primary) / 0.9); }
.btn-outline { border-color: hsl(var(--border)); background: transparent; color: hsl(var(--foreground)); }
.btn-outline:hover { background: hsl(var(--accent)); }
.btn-ghost { background: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover { background: hsl(var(--accent)); }
.btn[disabled] { opacity: .5; pointer-events: none; }

.input, .select {
  display: block; width: 100%;
  background: transparent;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
}
.input:focus, .select:focus {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.badge {
  display: inline-flex; align-items: center;
  font-size: 0.75rem; font-weight: 500;
  padding: 0.125rem 0.625rem;
  border-radius: 9999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}
.badge-outline { background: transparent; }
.badge-destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); border-color: transparent; }

.table-shadcn { width: 100%; border-collapse: separate; border-spacing: 0; }
.table-shadcn thead th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.4);
}
.table-shadcn tbody td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  font-size: 0.875rem;
  vertical-align: top;
}
.table-shadcn tbody tr:hover { background: hsl(var(--muted) / 0.4); }
.table-shadcn tbody tr:last-child td { border-bottom: none; }

.muted { color: hsl(var(--muted-foreground)); }
.link { color: hsl(var(--primary)); text-decoration: underline; text-underline-offset: 2px; }
.link:hover { text-decoration-thickness: 2px; }

.prose-md {
  font-family: charter, 'Georgia', cambria, 'Times New Roman', times, serif;
  font-size: 1.2rem;
  line-height: 1.85;
  color: hsl(var(--fg));
  word-break: break-word;
}
.prose-md p { margin: 0 0 1.35rem; }
.prose-md h1, .prose-md h2, .prose-md h3, .prose-md h4 {
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.prose-md h1 { font-size: 1.85rem; margin: 2.25rem 0 0.75rem; font-weight: 800; }
.prose-md h2 { font-size: 1.45rem; margin: 2rem 0 0.65rem; }
.prose-md h3 { font-size: 1.2rem; margin: 1.75rem 0 0.5rem; }
.prose-md h4 { font-size: 1.05rem; margin: 1.5rem 0 0.4rem; }
.prose-md a { color: hsl(var(--primary)); text-decoration: underline; text-decoration-color: hsl(var(--primary) / 0.3); text-underline-offset: 2px; }
.prose-md a:hover { text-decoration-color: hsl(var(--primary)); }
.prose-md strong { font-weight: 700; }
.prose-md em { font-style: italic; }
.prose-md code {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', monospace;
  background: hsl(var(--muted));
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.85em;
}
.prose-md pre {
  background: hsl(220 15% 13%);
  color: hsl(220 10% 85%);
  padding: 1.15rem 1.35rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.6;
  margin: 1.35rem 0;
}
.prose-md pre code { padding: 0; background: none; color: inherit; font-size: inherit; border-radius: 0; }
.prose-md blockquote {
  border-left: 3px solid hsl(var(--border));
  padding: 0.5rem 1.25rem;
  margin: 1.35rem 0;
  color: hsl(var(--muted-foreground));
  font-style: italic;
  background: hsl(var(--muted) / 0.35);
  border-radius: 0 6px 6px 0;
}
.prose-md blockquote p { margin-bottom: 0.5rem; }
.prose-md blockquote p:last-child { margin-bottom: 0; }
.prose-md ul, .prose-md ol { margin: 0 0 1.35rem; padding-left: 1.75rem; }
.prose-md li { margin-bottom: 0.4rem; }
.prose-md li > ul, .prose-md li > ol { margin-top: 0.4rem; margin-bottom: 0; }
.prose-md hr { border: none; border-top: 1px solid hsl(var(--border)); margin: 2rem 0; }
.prose-md table { width: 100%; border-collapse: collapse; margin: 1.35rem 0; font-size: 0.92rem; font-family: ui-sans-serif, system-ui, sans-serif; }
.prose-md table th, .prose-md table td { padding: 0.55rem 0.85rem; border: 1px solid hsl(var(--border)); text-align: left; }
.prose-md table th { background: hsl(var(--muted)); font-weight: 600; font-size: 0.85rem; }
.prose-md table tr:nth-child(even) { background: hsl(var(--muted) / 0.3); }
.prose-md img, .prose-md figure img {
  max-width: 100%; height: auto;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  margin: 1rem 0;
}
.prose-md figcaption { font-size: 0.8125rem; color: hsl(var(--muted-foreground)); text-align: center; margin-top: 0.25rem; }

.thumb {
  display: inline-flex; align-items: center; justify-content: center;
  width: 5.5rem; height: 4rem; overflow: hidden;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.5);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-placeholder, .thumb-empty::after {
  font-size: 0.625rem; color: hsl(var(--muted-foreground));
}
.thumb-empty::after { content: 'no image'; }
.hero-image {
  width: 100%; max-height: 400px; object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  margin-bottom: 1.5rem;
}

/* ─── Site shell ─── */
.site-header { border-bottom: 1px solid hsl(var(--border)); background: hsl(var(--background)); position: sticky; top: 0; z-index: 10; }
.site-header-inner { max-width: 1200px; margin: 0 auto; padding: 0.875rem 1.5rem; display: flex; align-items: center; gap: 1.5rem; }
.brand { display: flex; align-items: center; gap: 0.5rem; text-decoration: none; color: inherit; }
.brand-mark { display: inline-flex; width: 30px; height: 30px; border-radius: 8px; background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); align-items: center; justify-content: center; font-weight: 700; font-size: 0.95rem; }
.brand-name { font-weight: 700; font-size: 1rem; letter-spacing: -0.01em; }
.site-nav { display: flex; gap: 1.25rem; flex: 1; }
.site-nav a { text-decoration: none; color: hsl(var(--muted-foreground)); font-size: 0.9rem; font-weight: 500; padding-bottom: 0.25rem; border-bottom: 2px solid transparent; }
.site-nav a:hover { color: hsl(var(--foreground)); }
.site-nav a.active { color: hsl(var(--foreground)); border-bottom-color: hsl(var(--foreground)); }
.site-main { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem 3rem; }
.site-footer { max-width: 1200px; margin: 0 auto; padding: 1.5rem; color: hsl(var(--muted-foreground)); font-size: 0.8125rem; border-top: 1px solid hsl(var(--border)); }

/* ─── Page header / view toggle ─── */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-title { font-family: 'Charter', 'Source Serif Pro', Georgia, ui-serif, serif; font-size: 2.25rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; margin: 0 0 0.25rem; }
.view-toggle { display: inline-flex; border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 2px); overflow: hidden; }
.view-toggle a { padding: 0.4rem 0.875rem; font-size: 0.8125rem; font-weight: 500; color: hsl(var(--muted-foreground)); text-decoration: none; }
.view-toggle a.active { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }

/* ─── Filter collapse ─── */
.filter-collapse { margin-bottom: 1.25rem; }
.filter-collapse summary { padding: 0.875rem 1rem; cursor: pointer; display: flex; justify-content: space-between; align-items: center; list-style: none; font-weight: 500; font-size: 0.9rem; }
.filter-collapse summary::-webkit-details-marker { display: none; }
.filter-collapse summary::after { content: '▼'; font-size: 0.625rem; color: hsl(var(--muted-foreground)); transition: transform .15s; }
.filter-collapse[open] summary::after { transform: rotate(180deg); }

/* ─── Article card (Medium-style) ─── */
.article-list { display: flex; flex-direction: column; }
.article-card {
  display: grid; grid-template-columns: 1fr 200px;
  gap: 2rem; align-items: flex-start;
  padding: 1.75rem 0;
  border-bottom: 1px solid hsl(var(--border));
  transition: background-color .12s;
}
.article-card:hover { background: hsl(var(--muted) / 0.3); }
.article-card-body { min-width: 0; }
.article-meta { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8125rem; color: hsl(var(--muted-foreground)); margin-bottom: 0.5rem; }

.article-tracks {
  display: flex; gap: 0.25rem;
  margin-bottom: 0.4rem;
}
.track-chip {
  --track-color: 220 8% 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.5625rem; font-weight: 700; letter-spacing: 0.02em;
  padding: 0 0.4rem; height: 18px;
  border-radius: 4px;
  background: hsl(var(--track-color) / 0.15);
  color: hsl(var(--track-color));
  text-decoration: none;
  border: 1px solid hsl(var(--track-color) / 0.25);
}
.track-chip:hover {
  background: hsl(var(--track-color) / 0.28);
  border-color: hsl(var(--track-color) / 0.5);
}
.avatar { width: 22px; height: 22px; border-radius: 9999px; background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); display: inline-flex; align-items: center; justify-content: center; font-size: 0.625rem; font-weight: 700; letter-spacing: 0.02em; }
.meta-author { color: hsl(var(--foreground)); font-weight: 500; }
.meta-pub { color: hsl(var(--foreground)); }
.meta-dot { color: hsl(var(--muted-foreground)); }

.article-link { display: block; text-decoration: none; color: inherit; }
.article-link:hover .article-title { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.article-title { font-family: 'Charter', 'Source Serif Pro', Georgia, ui-serif, serif; font-size: 1.5rem; font-weight: 700; line-height: 1.25; letter-spacing: -0.015em; margin: 0 0 0.375rem; color: hsl(var(--foreground)); }
.article-subtitle { font-size: 1rem; color: hsl(var(--muted-foreground)); margin: 0; line-height: 1.5; }

.article-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; font-size: 0.8125rem; margin-top: 0.875rem; }
.article-tags { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; margin-left: auto; }
.tag-chip { text-decoration: none; }
.tag-chip:hover { background: hsl(var(--accent)); }

.article-thumb {
  display: block; width: 200px; aspect-ratio: 4/3;
  background: hsl(var(--muted) / 0.5);
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--border));
  overflow: hidden; flex-shrink: 0;
}
.article-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.article-thumb.is-empty::after { content: 'no image'; display: flex; align-items: center; justify-content: center; height: 100%; font-size: 0.75rem; color: hsl(var(--muted-foreground)); }

@media (max-width: 720px) {
  .article-card { grid-template-columns: 1fr; gap: 1rem; }
  .article-thumb { width: 100%; max-width: 360px; }
  .page-title { font-size: 1.875rem; }
}

/* ─── Pagination ─── */
.pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 1.5rem; font-size: 0.875rem; }

/* ─── Wiki ─── */
.topic-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.topic-card {
  display: flex; flex-direction: column; gap: 0.5rem;
  padding: 1.25rem;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  text-decoration: none; color: inherit;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.topic-card:hover {
  border-color: hsl(var(--ring));
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -4px rgba(0,0,0,0.08);
}
.topic-icon, .topic-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: 10px;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  font-weight: 700; font-size: 0.75rem; letter-spacing: 0.02em;
}
.topic-badge { width: 44px; height: 44px; font-size: 0.875rem; }
.topic-title { font-size: 1.125rem; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.topic-desc { color: hsl(var(--muted-foreground)); font-size: 0.875rem; margin: 0; line-height: 1.5; flex: 1; }
.topic-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.topic-keywords { font-size: 0.6875rem; }

.wiki-layout {
  display: grid; gap: 2rem;
  grid-template-columns: minmax(0, 1fr) 260px;
}
.wiki-side .side-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: hsl(var(--muted-foreground)); margin: 0 0 0.5rem; font-weight: 600; }
.wiki-side .side-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.375rem; font-size: 0.875rem; }
.wiki-side .side-list a { color: hsl(var(--foreground)); text-decoration: none; }
.wiki-side .side-list a:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .wiki-layout { grid-template-columns: 1fr; }
  .wiki-side { order: -1; }
}

/* ─── Article backlinks ─── */
.article-backlinks { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 0.75rem; align-items: center; }
.article-backlinks .label { font-size: 0.75rem; color: hsl(var(--muted-foreground)); margin-right: 0.25rem; }
.article-backlinks a.badge { text-decoration: none; }
.article-backlinks a.badge:hover { background: hsl(var(--accent)); }

/* ─── Entity (author/publication) page ─── */
.meta-link { display: inline-flex; align-items: center; gap: 0.375rem; text-decoration: none; color: inherit; }
.meta-link:hover .meta-author, .meta-link:hover.meta-pub { text-decoration: underline; text-underline-offset: 2px; }

.entity-header { display: flex; align-items: center; gap: 1.25rem; margin-bottom: 1.5rem; }
.entity-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 72px; height: 72px;
  border-radius: 9999px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-weight: 700; font-size: 1.5rem; letter-spacing: 0.02em;
  flex-shrink: 0;
}
.entity-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0;
  margin: 0 0 1.5rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  overflow: hidden;
  background: hsl(var(--card));
}
.entity-stats > div { padding: 0.875rem 1rem; border-right: 1px solid hsl(var(--border)); }
.entity-stats > div:last-child { border-right: none; }
.entity-stats dt { font-size: 0.6875rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; color: hsl(var(--muted-foreground)); margin: 0 0 0.25rem; }
.entity-stats dd { font-size: 1.25rem; font-weight: 700; margin: 0; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

.entity-meta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1rem;
}
@media (max-width: 720px) {
  .entity-meta-row { grid-template-columns: 1fr; }
}

/* ─── Article Detail ─── */
.article-detail {
  padding: 2.5rem 3rem;
}
.article-detail header { margin-bottom: 1.75rem; }
.article-detail .prose-md img {
  display: block;
  margin: 1.5rem auto;
  border-radius: 8px;
}
.article-detail .article-backlinks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  align-items: center;
  margin-top: 0.75rem;
}
.article-detail .article-backlinks .label {
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
}
@media (max-width: 720px) {
  .article-detail { padding: 1.5rem 1.25rem; }
}

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8125rem; }

/* ─── Freshness badge & sparkline ─── */
.freshness-badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border-radius: 9999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  text-decoration: none;
  font-size: 0.8125rem;
  white-space: nowrap;
  transition: border-color .15s, background .15s;
}
.freshness-badge:hover { border-color: hsl(var(--ring)); background: hsl(var(--accent)); }
.freshness-badge .dot { width: 6px; height: 6px; border-radius: 9999px; background: hsl(var(--muted-foreground)); }
.freshness-badge .dot-live { background: #22c55e; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); animation: pulse-dot 2s infinite; }
@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
  70%  { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.sparkline-card {
  display: inline-flex; flex-direction: column; gap: 0.5rem;
  padding: 0.875rem 1rem;
  margin: 0;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  min-width: 280px;
}
.sparkline-card figcaption { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.sparkline { width: 100%; height: 48px; color: hsl(var(--primary)); display: block; }

/* ─── Reading progress bar (article detail) ─── */
.reading-progress {
  position: fixed; top: 0; left: 0; right: 0;
  height: 3px;
  background: hsl(var(--border) / 0.4);
  z-index: 100;
  pointer-events: none;
}
.reading-progress-bar {
  height: 100%;
  width: 0;
  background: hsl(var(--primary));
  transition: width 60ms linear;
  will-change: width;
}

/* ─── Sticky condensed article header ─── */
.sticky-meta {
  position: fixed;
  top: 3px; /* sit beneath the progress bar */
  left: 0; right: 0;
  background: hsl(var(--background) / 0.92);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid hsl(var(--border));
  z-index: 50;
  transform: translateY(-110%);
  transition: transform .18s ease;
  pointer-events: none;
}
.sticky-meta.is-visible {
  transform: translateY(0);
  pointer-events: auto;
}
.sticky-meta-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem 1.5rem;
  display: flex; align-items: center; gap: 0.625rem;
  font-size: 0.875rem;
  min-height: 40px;
}
.sticky-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.sticky-read { font-size: 0.8125rem; flex-shrink: 0; }

@media (prefers-reduced-motion: reduce) {
  .reading-progress-bar { transition: none; }
  .sticky-meta { transition: none; }
}

/* ─── Related articles ─── */
.related-section { margin-top: 2rem; display: flex; flex-direction: column; gap: 2rem; }
.related-block { }
.related-heading {
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: hsl(var(--muted-foreground));
  margin: 0 0 0.875rem;
}
.related-heading a { color: hsl(var(--foreground)); text-decoration: none; }
.related-heading a:hover { text-decoration: underline; }
.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.related-card {
  display: flex; flex-direction: column;
  text-decoration: none; color: inherit;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.related-card:hover {
  border-color: hsl(var(--ring));
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -4px rgba(0,0,0,0.08);
}
.related-thumb { aspect-ratio: 16/10; background: hsl(var(--muted) / 0.5); position: relative; }
.related-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.related-thumb.is-empty::after { content: 'no image'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
.related-body { padding: 0.75rem 0.875rem; display: flex; flex-direction: column; gap: 0.375rem; flex: 1; }
.related-meta { display: flex; align-items: center; gap: 0.375rem; }
.avatar-xs { width: 16px; height: 16px; font-size: 0.5rem; }
.related-title {
  font-family: 'Charter', 'Source Serif Pro', Georgia, ui-serif, serif;
  font-size: 0.95rem; line-height: 1.3; font-weight: 700; letter-spacing: -0.01em;
  margin: 0;
  color: hsl(var(--foreground));
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.related-foot { display: flex; align-items: center; gap: 0.375rem; font-size: 0.75rem; margin-top: auto; }

/* ─── Tag cloud ─── */
.tag-cloud {
  display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem;
  align-items: baseline;
  padding: 1.25rem;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  line-height: 1.7;
}
.tag-cloud-item {
  display: inline-flex; align-items: baseline; gap: 0.25rem;
  text-decoration: none;
  color: hsl(var(--foreground));
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  transition: background-color .12s, color .12s;
}
.tag-cloud-item:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); opacity: 1 !important; }
.tag-cloud-count { font-size: 0.625rem; color: hsl(var(--muted-foreground)); font-weight: 400; }

/* ─── Theme toggle ─── */
.theme-toggle {
  display: inline-flex; align-items: center;
  border: 1px solid hsl(var(--border));
  border-radius: 9999px;
  padding: 2px;
  background: hsl(var(--card));
  gap: 2px;
}
.theme-toggle button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: transparent;
  border: 0;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  border-radius: 9999px;
  padding: 0;
  font: inherit;
  transition: background-color .15s, color .15s;
}
.theme-toggle button:hover { color: hsl(var(--foreground)); }
.theme-toggle button[aria-pressed="true"] {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.theme-toggle svg { width: 16px; height: 16px; display: block; }

/* ─── Accessibility primitives ─── */
.skip-link {
  position: absolute;
  top: 0; left: 0;
  padding: 0.625rem 1rem;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: 0 0 var(--radius) 0;
  transform: translateY(-150%);
  transition: transform .15s;
  z-index: 200;
}
.skip-link:focus { transform: translateY(0); outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }

/* Visible focus rings for keyboard users only. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
  border-radius: 4px;
}
.btn:focus-visible, .badge:focus-visible, .input:focus-visible, .select:focus-visible,
.tag-cloud-item:focus-visible, .topic-card:focus-visible, .article-link:focus-visible,
.related-card:focus-visible, .meta-link:focus-visible, .freshness-badge:focus-visible,
.theme-toggle button:focus-visible, .view-toggle a:focus-visible, .site-nav a:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

/* Hide content visually but expose to assistive tech. */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Make sure article main can receive programmatic focus without showing a halo. */
#main:focus { outline: none; }

/* ─── Insights dashboard ─── */
.kpi-grid {
  display: grid; gap: 0.875rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.kpi-card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 1rem 1.125rem;
  display: flex; flex-direction: column; gap: 0.25rem;
}
.kpi-label {
  font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
}
.kpi-value {
  font-size: 1.875rem; font-weight: 700; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  display: flex; align-items: baseline; gap: 0.375rem;
  line-height: 1.1;
}
.kpi-sub { font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
.kpi-trend { font-size: 0.875rem; font-weight: 700; }
.kpi-trend-up { color: #16a34a; }
.kpi-trend-down { color: hsl(var(--destructive)); }

.insights-row {
  display: grid; gap: 1rem;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 900px) {
  .insights-row { grid-template-columns: 1fr; }
}
.insights-block { padding: 1.125rem 1.25rem; }
.block-heading {
  font-size: 0.8125rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: hsl(var(--muted-foreground));
  margin: 0 0 0.875rem;
}

/* horizontal bar chart */
.chart-bar { display: flex; flex-direction: column; gap: 0.5rem; }
.chart-bar-row { display: grid; grid-template-columns: 9rem 1fr 5rem; gap: 0.75rem; align-items: center; }
.chart-bar-label { font-size: 0.8125rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-bar-label a { color: inherit; text-decoration: none; }
.chart-bar-label a:hover { text-decoration: underline; }
.chart-bar-track { height: 14px; background: hsl(var(--muted) / 0.5); border-radius: 4px; overflow: hidden; }
.chart-bar-fill { height: 100%; background: hsl(var(--primary)); border-radius: 4px; transition: width .25s ease; }
.chart-bar-value { font-size: 0.8125rem; font-variant-numeric: tabular-nums; text-align: right; display: flex; gap: 0.375rem; align-items: baseline; justify-content: flex-end; }

/* line chart */
.chart-line-figure { margin: 0; }
.chart-line-figure svg { width: 100%; height: auto; max-height: 240px; }
.chart-line-legend { display: flex; flex-wrap: wrap; gap: 0.625rem 1rem; margin-top: 0.625rem; font-size: 0.75rem; }
.chart-line-key { display: inline-flex; align-items: center; gap: 0.375rem; }
.chart-line-key .swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-line-key a { color: hsl(var(--foreground)); text-decoration: none; }
.chart-line-key a:hover { text-decoration: underline; }

.mom-up   { color: #16a34a; font-weight: 600; }
.mom-down { color: hsl(var(--destructive)); font-weight: 600; }
.mom-flat { color: hsl(var(--muted-foreground)); }

/* gap analysis list */
.gap-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.625rem; }
.gap-list li { padding: 0.625rem 0.75rem; border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 2px); }
.gap-title { font-weight: 600; text-decoration: none; color: hsl(var(--foreground)); }
.gap-title:hover { text-decoration: underline; }
.gap-meta { font-size: 0.75rem; color: hsl(var(--muted-foreground)); margin-top: 0.25rem; }
.gap-meta a { color: inherit; text-decoration: none; }
.gap-meta a:hover { text-decoration: underline; }

/* ─── Activity heatmap ─── */
.heatmap-figure { margin: 0; display: flex; flex-direction: column; gap: 0.625rem; }
.heatmap-figure svg { width: 100%; height: auto; max-height: 160px; }
.heatmap-cell { transition: opacity .12s; }
.heatmap-cell:hover { opacity: 0.85; stroke: hsl(var(--ring)); stroke-width: 1; }
.heatmap-l0 { fill: hsl(var(--muted) / 0.6); }
.heatmap-l1 { fill: hsl(var(--primary) / 0.18); }
.heatmap-l2 { fill: hsl(var(--primary) / 0.35); }
.heatmap-l3 { fill: hsl(var(--primary) / 0.55); }
.heatmap-l4 { fill: hsl(var(--primary) / 0.78); }
.heatmap-l5 { fill: hsl(var(--primary) / 1); }
.heatmap-legend {
  display: flex; align-items: center; gap: 0.375rem;
  font-size: 0.75rem;
}
.heatmap-swatch {
  display: inline-block; width: 11px; height: 11px;
  border-radius: 2px;
}
.heatmap-swatch.heatmap-l0 { background: hsl(var(--muted) / 0.6); }
.heatmap-swatch.heatmap-l1 { background: hsl(var(--primary) / 0.18); }
.heatmap-swatch.heatmap-l2 { background: hsl(var(--primary) / 0.35); }
.heatmap-swatch.heatmap-l3 { background: hsl(var(--primary) / 0.55); }
.heatmap-swatch.heatmap-l4 { background: hsl(var(--primary) / 0.78); }
.heatmap-swatch.heatmap-l5 { background: hsl(var(--primary) / 1); }

/* ─── Read-tracker (client-side) ─── */
.article-card.is-read .article-title,
tr.is-read .link {
  color: hsl(var(--muted-foreground));
}
.article-card.is-read .article-thumb { opacity: 0.55; }
.article-card.is-read::before {
  content: '✓';
  position: absolute; top: 1.25rem; right: -1rem;
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9999px;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  font-size: 0.625rem; font-weight: 700;
}
.article-card { position: relative; }
.related-card.is-read .related-title { color: hsl(var(--muted-foreground)); }
.related-card.is-read .related-thumb { opacity: 0.5; }
tr.is-read td { background: hsl(var(--muted) / 0.25); }

body.hide-read .article-list .article-card.is-read,
body.hide-read .table-shadcn tr.is-read {
  display: none;
}

#hide-read-toggle {
  display: inline-flex; align-items: center; gap: 0.5rem;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
}
#hide-read-toggle .hr-count { font-size: 0.6875rem; }
#hide-read-toggle[aria-pressed="true"] {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-color: transparent;
}

/* ─── Keyboard navigation ─── */
.is-kb-focused {
  box-shadow: 0 0 0 2px hsl(var(--ring)), 0 0 0 4px hsl(var(--background));
  border-radius: var(--radius);
  transition: box-shadow .12s;
}
tr.is-kb-focused td:first-child { box-shadow: inset 3px 0 0 0 hsl(var(--ring)); }

.kb-help {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  z-index: 200;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.kb-help.is-open { display: flex; animation: kb-fade .15s ease-out; }
@keyframes kb-fade { from { opacity: 0; } to { opacity: 1; } }

.kb-help-panel {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  width: min(440px, calc(100% - 2rem));
  box-shadow: 0 12px 40px -8px rgba(0,0,0,0.3);
}
.kb-help-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.kb-help-header h2 {
  margin: 0; font-size: 1rem; font-weight: 700; letter-spacing: -0.01em;
}
.kb-help-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.625rem 1rem;
  margin: 0;
  align-items: center;
  font-size: 0.875rem;
}
.kb-help-list dt { display: flex; gap: 0.25rem; }
.kb-help-list dd { margin: 0; color: hsl(var(--muted-foreground)); }

kbd {
  display: inline-block;
  padding: 0.0625rem 0.4rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  font-weight: 600;
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border));
  border-bottom-width: 2px;
  border-radius: 4px;
  line-height: 1.2;
  min-width: 1.2em;
  text-align: center;
}

.kb-help-trigger { font-size: inherit; }
.kb-help-trigger kbd { font-size: 0.6875rem; padding: 0 0.3rem; }

/* ─── Track tabs (clean segmented style) ─── */
.track-tabs {
  display: flex; gap: 0.25rem;
  margin: 0.5rem 0 1.25rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 1px;
  scrollbar-width: thin;
}
.track-tab {
  --track-color: 220 6% 50%;
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.875rem;
  text-decoration: none;
  color: hsl(var(--muted-foreground));
  font-size: 0.8125rem; font-weight: 500;
  white-space: nowrap;
  border-radius: 9999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  transition: color .12s, background .12s, border-color .12s;
}
.track-tab:hover {
  color: hsl(var(--foreground));
  background: hsl(var(--accent));
  border-color: hsl(var(--track-color) / 0.4);
}
.track-tab.is-active {
  color: hsl(var(--track-color));
  background: hsl(var(--track-color) / 0.10);
  border-color: hsl(var(--track-color) / 0.5);
  font-weight: 600;
}
.track-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 9999px;
  background: hsl(var(--track-color));
  flex-shrink: 0;
}
.track-dot-all {
  background: linear-gradient(135deg, hsl(212 90% 55%), hsl(275 70% 60%) 50%, hsl(24 90% 55%));
}
.track-tab-count {
  font-size: 0.6875rem;
  color: hsl(var(--muted-foreground));
  background: hsl(var(--muted));
  padding: 0.05rem 0.45rem;
  border-radius: 9999px;
  min-width: 1.5em;
  text-align: center;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.track-tab.is-active .track-tab-count {
  background: hsl(var(--track-color) / 0.2);
  color: hsl(var(--track-color));
}
.track-tab-icon { display: none; } /* legacy slot, no longer used */

.track-pill {
  --track-color: 220 8% 50%;
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.25rem 0.625rem 0.25rem 0.25rem;
  border-radius: 9999px;
  background: hsl(var(--track-color) / 0.12);
  color: hsl(var(--track-color));
  font-size: 0.75rem; font-weight: 600;
  text-decoration: none;
  letter-spacing: 0.01em;
}
.track-pill:hover { background: hsl(var(--track-color) / 0.2); }

/* ─── Cross-track matrix table ─── */
.track-mx-table {
  width: auto; border-collapse: separate; border-spacing: 4px;
  font-variant-numeric: tabular-nums;
}
.track-mx-table th {
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem; font-weight: 600;
  text-align: center;
  color: hsl(var(--track-color));
}
.track-mx-table tbody th { text-align: right; min-width: 8rem; }
.track-mx-table td {
  padding: 0.625rem 0.875rem;
  border-radius: 6px;
  text-align: center;
  min-width: 5rem;
  background: hsl(var(--muted) / 0.4);
  font-size: 0.875rem;
}

.cross-pairs-details { margin-top: 1.25rem; }
.cross-pairs-details summary {
  cursor: pointer; font-size: 0.875rem; font-weight: 500;
  padding: 0.5rem 0; list-style: none;
  display: flex; align-items: center; gap: 0.375rem;
}
.cross-pairs-details summary::after { content: '▾'; font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
.cross-pairs-details[open] summary::after { content: '▴'; }
.cross-pairs { display: flex; flex-direction: column; gap: 1.25rem; margin-top: 0.75rem; }
.cross-pair-title {
  display: flex; align-items: center; gap: 0.375rem;
  font-size: 0.875rem; font-weight: 600;
  margin: 0 0 0.375rem;
}
.cross-pair-list {
  list-style: decimal inside;
  margin: 0; padding: 0;
  font-size: 0.8125rem;
  display: flex; flex-direction: column; gap: 0.25rem;
}
.cross-pair-list a { color: hsl(var(--foreground)); text-decoration: none; font-weight: 500; }
.cross-pair-list a:hover { text-decoration: underline; }

/* ─── Mobile viewport polish ─── */
/* SVG charts: keep aspect ratio + horizontal scroll if too narrow. */
.chart-line-figure,
.matrix-figure,
.dowhour-figure,
.heatmap-figure {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.matrix-figure svg { min-width: 520px; }
.dowhour-figure svg { min-width: 460px; }
.chart-line-figure svg { min-width: 360px; }

/* Track tabs already have overflow-x:auto. Ensure on tiny screens chips still readable. */
@media (max-width: 600px) {
  .track-tab { padding: 0.5rem 0.625rem; font-size: 0.8125rem; }
  .track-tab-icon { width: 22px; height: 18px; font-size: 0.5625rem; }
  .track-tab-count { padding: 0 0.3rem; font-size: 0.625rem; }

  .chart-bar-row {
    grid-template-columns: 1fr;
    gap: 0.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px dashed hsl(var(--border));
  }
  .chart-bar-label { white-space: normal; }
  .chart-bar-value { justify-content: flex-start; }

  .entity-stats { grid-template-columns: repeat(2, 1fr); }
  .entity-stats > div { border-right: none; border-bottom: 1px solid hsl(var(--border)); }
  .entity-stats > div:nth-child(odd) { border-right: 1px solid hsl(var(--border)); }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-value { font-size: 1.375rem; }

  .article-thumb { aspect-ratio: 16/9; }
  .article-card { padding: 1.25rem 0; }
  .page-title { font-size: 1.625rem; }

  /* Track matrix table: allow horizontal scroll wrapper */
  .track-mx-table { display: block; overflow-x: auto; white-space: nowrap; }
}

@media (max-width: 420px) {
  .site-header-inner { padding: 0.625rem 1rem; gap: 0.75rem; }
  .site-main { padding: 1.25rem 1rem 2rem; }
  .brand-name { display: none; }
  .freshness-badge { padding: 0.3rem 0.55rem; font-size: 0.75rem; }
}

/* ─── Topic co-occurrence matrix ─── */
.matrix-figure { margin: 0; display: flex; flex-direction: column; gap: 0.625rem; width: 100%; }
.matrix-figure svg { width: 100%; height: auto; display: block; }
.matrix-cell { transition: opacity .12s; }
.matrix-cell:hover { stroke: hsl(var(--ring)); stroke-width: 2; }
.matrix-diag {
  fill: hsl(var(--primary));
  stroke: hsl(var(--background));
  stroke-width: 1;
}
.matrix-diag:hover { stroke: hsl(var(--ring)); stroke-width: 2; }
.matrix-legend {
  display: flex; align-items: center; gap: 0.375rem;
  font-size: 0.75rem;
  flex-wrap: wrap;
}

/* ─── DOW × hour publishing heatmap ─── */
.dowhour-figure { margin: 0; display: flex; flex-direction: column; gap: 0.625rem; }
.dowhour-figure svg { width: 100%; height: auto; max-height: 200px; }

/* ─── Skeleton loading animation ─── */
.skeleton-block {
  background: hsl(var(--muted));
  border-radius: var(--radius);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.7; }
}
