/* MemeLab blog — "Plex Observatory" reading surface.
 * Same tokens and vocabulary as app/src/ui/theme.css + components.css:
 * hairline dividers, IBM Plex, uppercase mono kickers, near-square radii.
 * Light-first; carbon-dark via prefers-color-scheme. */

:root {
  color-scheme: light;
  --bg-base: #f4f4f4;
  --bg-elevated: #ffffff;
  --bg-sunken: #f4f4f4;
  --text: #161616;
  --text-muted: #525252;
  --text-subtle: #6f6f6f;
  --accent: #0f62fe;
  --accent-2: #0043ce;
  --accent-soft: rgba(15, 98, 254, 0.08);
  --border: #e0e0e0;
  --border-strong: #c6c6c6;
  --code-bg: #f4f4f4;
  --selection: rgba(15, 98, 254, 0.18);
  --radius-sm: 2px;
  --radius-md: 4px;
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'IBM Plex Serif', Georgia, 'Times New Roman', serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --measure: 65ch;
  --page-max: 720px; /* ≈65ch of 17px Plex Sans + gutters; px so footer/mono contexts match */
  --gutter: clamp(16px, 4vw, 40px);

  /* highlight.js — restrained, IBM-ish */
  --hl-kw: #8a3ffc;
  --hl-str: #198038;
  --hl-num: #b28600;
  --hl-cm: #6f6f6f;
  --hl-fn: #0043ce;
  --hl-type: #005d5d;
  --hl-attr: #8a3800;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg-base: #161616;
    --bg-elevated: #1f1f1f;
    --bg-sunken: #262626;
    --text: #f4f4f4;
    --text-muted: #c6c6c6;
    --text-subtle: #8d8d8d;
    --accent: #78a9ff;
    --accent-2: #a6c8ff;
    --accent-soft: rgba(120, 169, 255, 0.14);
    --border: #393939;
    --border-strong: #525252;
    --code-bg: #262626;
    --selection: rgba(120, 169, 255, 0.28);
    --hl-kw: #be95ff;
    --hl-str: #42be65;
    --hl-num: #f1c21b;
    --hl-cm: #8d8d8d;
    --hl-fn: #78a9ff;
    --hl-type: #3ddbd9;
    --hl-attr: #ff832b;
  }
}

*, ::before, ::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'tnum' 1, 'kern' 1;
}
::selection { background: var(--selection); }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); text-decoration: underline; text-underline-offset: 0.15em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
img, svg { max-width: 100%; height: auto; }

.skip {
  position: absolute; left: 8px; top: -100px; z-index: 10;
  padding: 8px 12px; background: var(--bg-elevated); border: 1px solid var(--border-strong);
}
.skip:focus { top: 8px; }

/* ==== Topbar (mirrors app .topbar) ==== */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px var(--gutter);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand .mark { flex: none; display: block; border-radius: 50%; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
.brand-sub {
  font-family: var(--font-mono); font-size: 10px; font-weight: 500; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-muted); margin-top: 2px;
}
.topnav { display: flex; gap: 4px; }
.topnav a {
  display: inline-flex; align-items: center; height: 34px; padding: 0 13px;
  border-radius: var(--radius-md); border: 1px solid transparent;
  font-size: 13px; font-weight: 500; color: var(--text-muted);
}
.topnav a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }

/* ==== Page frame ==== */
.page {
  flex: 1;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: clamp(32px, 6vw, 72px) var(--gutter) clamp(48px, 8vw, 96px);
}

.kicker {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted);
  margin: 0 0 12px;
}
.kicker a { color: inherit; }
.page-title, .post-title {
  font-size: clamp(30px, 5vw, 42px); line-height: 1.12; font-weight: 600;
  letter-spacing: -0.02em; margin: 0 0 16px; text-wrap: balance;
}
.lead, .post-desc {
  font-family: var(--font-serif); font-size: 19px; line-height: 1.5;
  color: var(--text-muted); margin: 0 0 20px; text-wrap: pretty;
}
.lead code { font-size: 0.85em; }

/* ==== Feed ==== */
.cards { list-style: none; margin: 32px 0 0; padding: 0; border-top: 1px solid var(--border); }
.card { padding: 28px 0; border-bottom: 1px solid var(--border); }
.card-meta, .post-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.02em;
  color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.dot { color: var(--border-strong); }
.card-title { font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -0.015em; margin: 8px 0 8px; }
.card-title a { color: var(--text); }
.card-title a:hover { color: var(--accent); }
.card-desc { margin: 0 0 12px; color: var(--text-muted); text-wrap: pretty; }
.empty { color: var(--text-subtle); font-style: italic; }

.tags { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; }
.tag {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.04em; color: var(--text-muted);
}
.tag:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.tag .count { color: var(--text-subtle); }
.tagcloud { margin-top: 40px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.tagcloud .kicker { margin: 0 8px 0 0; }

/* ==== Post ==== */
.post-head { padding-bottom: 24px; border-bottom: 1px solid var(--border); margin-bottom: 32px; }
.post-meta { margin-bottom: 14px; }
.author { color: var(--text); font-weight: 500; }
.hero { margin: 0 0 32px; }
.hero img { display: block; width: 100%; border: 1px solid var(--border); border-radius: var(--radius-md); }

.prose > * { margin: 0 0 1.25em; }
.prose h2, .prose h3, .prose h4 { position: relative; line-height: 1.25; letter-spacing: -0.015em; font-weight: 600; margin: 2em 0 0.7em; text-wrap: balance; }
.prose h2 { font-size: 26px; padding-top: 0.6em; border-top: 1px solid var(--border); }
.prose h3 { font-size: 21px; }
.prose h4 { font-size: 17px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; font-size: 13px; color: var(--text-muted); }
.prose .anchor { position: absolute; left: -1.2em; color: var(--border-strong); font-weight: 400; opacity: 0; }
.prose h2:hover .anchor, .prose h3:hover .anchor, .prose h4:hover .anchor { opacity: 1; }
.prose p, .prose li { text-wrap: pretty; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: 0.35em; }
.prose strong { font-weight: 600; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2.5em 0; }
.prose blockquote {
  margin: 1.5em 0; padding: 4px 0 4px 20px; border-left: 2px solid var(--accent);
  font-family: var(--font-serif); color: var(--text-muted);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose img { display: block; border: 1px solid var(--border); border-radius: var(--radius-md); }
.prose figure { margin: 1.75em 0; }
.prose figcaption { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* Code */
code, kbd, samp { font-family: var(--font-mono); font-size: 0.875em; }
.prose :not(pre) > code {
  padding: 0.1em 0.35em; background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow-wrap: anywhere;
}
pre.code {
  position: relative; margin: 1.5em 0; padding: 16px 18px;
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-md);
  overflow-x: auto; line-height: 1.55; font-size: 14px;
  -webkit-overflow-scrolling: touch;
}
pre.code code { font-size: inherit; display: block; min-width: max-content; }
pre.code[data-lang]::before {
  content: attr(data-lang); position: absolute; top: 6px; right: 10px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-subtle);
}
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-meta { color: var(--hl-kw); }
.hljs-string, .hljs-regexp, .hljs-addition { color: var(--hl-str); }
.hljs-number, .hljs-literal, .hljs-symbol { color: var(--hl-num); }
.hljs-comment, .hljs-quote { color: var(--hl-cm); font-style: italic; }
.hljs-title, .hljs-function .hljs-title, .hljs-section { color: var(--hl-fn); }
.hljs-type, .hljs-class .hljs-title, .hljs-title.class_ { color: var(--hl-type); }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-name, .hljs-deletion { color: var(--hl-attr); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

/* Tables — hairlines, tabular figures, horizontal scroll */
.table-wrap { overflow-x: auto; margin: 1.5em 0; border: 1px solid var(--border); border-radius: var(--radius-md); }
table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
th { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 500; color: var(--text-muted); background: var(--bg-sunken); }
tbody tr:last-child td { border-bottom: 0; }
td[align='right'], th[align='right'] { text-align: right; }

.post-foot {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px;
  margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--border);
  font-size: 14px; font-weight: 500;
}

/* ==== Footer ==== */
.footer { border-top: 1px solid var(--border); background: var(--bg-elevated); }
.footer-inner {
  max-width: var(--page-max); margin: 0 auto; padding: 18px var(--gutter);
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted);
}
.footer nav { display: flex; gap: 16px; }
.footer a { color: var(--text-muted); }
.footer a:hover { color: var(--accent); }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .brand-sub { display: none; }
  .topnav a { padding: 0 9px; }
  .prose .anchor { display: none; }
  pre.code { margin-left: calc(-1 * var(--gutter)); margin-right: calc(-1 * var(--gutter)); border-radius: 0; border-left: 0; border-right: 0; }
}
@media print { .topbar, .footer, .post-foot, .tagcloud { display: none; } body { background: #fff; } }

/* ==== Feed cards with hero thumbnails ==== */
.card.has-thumb { display: block; }
.card-thumb { display: block; margin: 0 0 18px; }
.card-thumb img {
  display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover;
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-sunken);
}
.card-thumb:hover img { border-color: var(--border-strong); }
.card-body { min-width: 0; }

/* ==== CTA card (quiet, not a banner) ==== */
.cta-card {
  margin-top: 48px; padding: 20px 22px;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.cta-card .kicker { margin-bottom: 6px; }
.cta-copy { margin: 0 0 14px; color: var(--text-muted); text-wrap: pretty; font-size: 15px; }
.cta-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; height: 36px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500; color: var(--text); background: var(--bg-elevated);
}
.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

/* ==== Share row ==== */
.share { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.share .kicker { margin-bottom: 10px; }
.share-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.share-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 10px 0 6px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  font: inherit; font-size: 13px; font-weight: 500; line-height: 1; color: var(--text-muted);
  background: var(--bg-elevated); cursor: pointer; text-decoration: none;
}
.share-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.share-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.share-btn[hidden] { display: none; }
.share-icon { flex: none; display: block; }
.share-icon .disc { fill: var(--text); }
.share-icon .glyph { fill: var(--bg-base); }
.share-icon [fill="none"] { fill: none; stroke: var(--text); }
.share-btn.is-copied { border-color: var(--accent); color: var(--accent); }
@media print { .cta-card, .share { display: none; } }

/* ==== Share strip (icon-only, under the post meta) ==== */
.share-top { margin-top: 14px; }
.share-strip { gap: 4px; }
.share-strip .share-btn { width: 32px; padding: 0; justify-content: center; gap: 0; }
.share-strip .share-label { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.share-strip .share-btn.is-copied .share-icon .disc { fill: var(--accent); }
@media print { .share-top { display: none; } }

/* ==== Breadcrumb ==== */
.crumbs { margin: 0 0 14px; font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.04em; color: var(--text-subtle); }
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; }
.crumbs li { display: inline-flex; align-items: center; min-width: 0; }
.crumbs li + li::before { content: '/'; margin: 0 8px; color: var(--border-strong); }
.crumbs a { color: var(--text-muted); }
.crumbs a:hover { color: var(--accent); }
.crumbs [aria-current='page'] { color: var(--text-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28ch; }

/* ==== Post meta: updated ==== */
.post-meta .updated { color: var(--text-subtle); }

/* ==== More posts (prev/next + related) ==== */
.more { margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border); }
.more .kicker { margin-top: 24px; }
.pn { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pn-link { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-elevated); color: var(--text); }
.pn-link:hover { border-color: var(--accent); text-decoration: none; }
.pn-next { text-align: right; align-items: flex-end; }
.pn-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-subtle); }
.pn-title { font-size: 15px; line-height: 1.3; font-weight: 500; }
.cards-compact .card-title { font-size: 19px; }
.cards-compact .card-desc { font-size: 15px; }
@media (max-width: 560px) { .pn { grid-template-columns: 1fr; } .pn-next { text-align: left; align-items: flex-start; } }

/* ==== 404 ==== */
.notfound .cta-actions { margin-top: 24px; }
