:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --ink: #15171c;
  --ink-soft: #4a5161;
  --muted: #7a8292;
  --line: #e4e7ec;
  --accent: #1d5bd8;
  --accent-soft: #e8effc;
  --chip: #c2410c;
  --radius: 10px;
  --measure: 44rem;
  --wide: 72rem;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.65 var(--sans);
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; height: auto; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.015em; }
h1 { font-size: 2.1rem; margin: 0 0 .5rem; }
h2 { font-size: 1.45rem; margin: 2.6rem 0 .8rem; }
h3 { font-size: 1.15rem; margin: 2rem 0 .6rem; }

code, kbd, pre { font-family: var(--mono); font-size: .88em; }
:not(pre) > code { background: var(--bg-soft); border: 1px solid var(--line); padding: .05em .35em; border-radius: 5px; }
pre { background: var(--bg-soft); border: 1px solid var(--line); padding: 1rem; border-radius: var(--radius); overflow-x: auto; }

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

/* Header */
.site-header { border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 1rem; }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.brand span { color: var(--muted); font-weight: 500; }
.nav { display: flex; gap: 1.4rem; font-size: .95rem; }
.nav a { color: var(--ink-soft); text-decoration: none; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); }
.nav .chip-link { font-family: var(--mono); font-weight: 600; color: var(--chip); }

/* Footer */
.site-footer { border-top: 1px solid var(--line); margin-top: 5rem; padding: 2rem 0 3rem; color: var(--muted); font-size: .9rem; }
.site-footer .wrap { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.site-footer a { color: var(--ink-soft); }
.site-footer .privacy { flex-basis: 100%; margin: .5rem 0 0; font-size: .8rem; }

/* Home hero */
.hero { display: flex; align-items: center; gap: 2rem; padding: 4rem 0 3rem; }
.hero img { width: 128px; height: 128px; border-radius: 50%; object-fit: cover; flex: none; border: 4px solid var(--bg); box-shadow: 0 0 0 1px var(--line), 0 6px 24px rgba(20, 30, 60, .08); }
.hero h1 { font-size: 1.9rem; }
.hero p { margin: .2rem 0; color: var(--ink-soft); font-size: 1.08rem; max-width: 40rem; }

/* Post list */
.section-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; margin: 1rem 0 .5rem; }
.post-list { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.post-list li { border-bottom: 1px solid var(--line); }
.post-list a { display: grid; grid-template-columns: 8.5rem 1fr; gap: 1.5rem; padding: 1.5rem 0; text-decoration: none; color: inherit; }
.post-list time { color: var(--muted); font-size: .9rem; padding-top: .2rem; font-variant-numeric: tabular-nums; }
.post-list h2 { margin: 0 0 .3rem; font-size: 1.25rem; }
.post-list a:hover h2 { color: var(--accent); }
.post-list p { margin: 0; color: var(--ink-soft); }
.empty { color: var(--muted); padding: 2rem 0; }

.pager { display: flex; justify-content: space-between; margin-top: 2rem; }

/* Article */
.article { padding: 3.5rem 0 1rem; }
.article header { margin-bottom: 2rem; }
.meta { color: var(--muted); font-size: .92rem; }
.prose > :first-child { margin-top: 0; }
.prose img { border-radius: var(--radius); }
.prose blockquote { margin: 1.5rem 0; padding: .2rem 1.2rem; border-left: 3px solid var(--accent); color: var(--ink-soft); }
.prose table { border-collapse: collapse; width: 100%; font-size: .95rem; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: .5rem .6rem; text-align: left; }
.back { display: inline-block; margin-top: 3rem; }

.callout { display: flex; gap: 1rem; align-items: center; background: var(--accent-soft); border-radius: var(--radius); padding: 1rem 1.2rem; margin: 2rem 0; text-decoration: none; color: var(--ink); }
.callout img { width: 56px; border-radius: 6px; }
.callout strong { display: block; }

/* 6502 section */
.chip-head { background: linear-gradient(180deg, #fbfaf7 0%, #ffffff 100%); border-bottom: 1px solid var(--line); }
.chip-head .wrap { padding-top: 2.5rem; }
.chip-kicker { font-family: var(--mono); color: var(--chip); font-weight: 600; font-size: .9rem; letter-spacing: .02em; }
.chip-head h1 { margin-top: .3rem; }
.chip-head .lede { color: var(--ink-soft); max-width: 46rem; margin: 0 0 1.5rem; }

.subnav { display: flex; gap: .3rem; overflow-x: auto; scrollbar-width: none; margin: 0 -.5rem; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a { white-space: nowrap; padding: .7rem .8rem; color: var(--ink-soft); text-decoration: none; font-size: .95rem; border-bottom: 2px solid transparent; }
.subnav a:hover { color: var(--ink); }
.subnav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--chip); font-weight: 600; }

.chip-body { padding-top: 2.5rem; }

.figure { margin: 1.8rem 0; }
.figure img { display: block; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .5rem; }
.figure figcaption { color: var(--muted); font-size: .88rem; margin-top: .5rem; }
.figure.center img { margin: 0 auto; }
.figure.center figcaption { text-align: center; }

.split { display: grid; grid-template-columns: 1fr auto; gap: 2rem; align-items: start; margin: 1.5rem 0; }
.split.left { grid-template-columns: auto 1fr; }
.split p:first-child { margin-top: 0; }
.split .figure { margin: 0; }
.pair { display: flex; gap: 1rem; flex-wrap: wrap; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.card { display: block; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s; }
.card:hover { border-color: #c9d3e6; box-shadow: 0 4px 18px rgba(20, 40, 90, .07); }
.card strong { display: block; color: var(--ink); margin-bottom: .2rem; }
.card span { color: var(--ink-soft); font-size: .93rem; }

.overview { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 3rem; align-items: start; }
.overview .thumb { position: sticky; top: 1.5rem; }
.overview .thumb img { border-radius: 8px; border: 1px solid var(--line); display: block; }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: .8rem; margin: 1.5rem 0; padding: 0; list-style: none; }
.facts li { background: var(--bg-soft); border-radius: 8px; padding: .8rem 1rem; }
.facts b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.facts span { color: var(--muted); font-size: .85rem; }

.downloads { list-style: none; padding: 0; margin: 1rem 0; border-top: 1px solid var(--line); }
.downloads li { display: flex; justify-content: space-between; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid var(--line); }
.downloads small { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.note { background: var(--bg-soft); border-radius: var(--radius); padding: .9rem 1.1rem; color: var(--ink-soft); font-size: .95rem; }

/* "Why this page exists" box on the 6502 overview */
.origin { background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; padding: 1rem 1.3rem; margin: 0 0 1.75rem; }
.origin h2 { margin: 0 0 .5rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.origin p { margin: .6rem 0; }
.origin code { font-size: .9em; }

/* Deep zoom viewer */
.viewer-wrap { position: relative; }
.viewer { width: 100%; height: min(78vh, 900px); min-height: 420px; background: #1b1d22; border-radius: var(--radius); overflow: hidden; }
.viewer.light { background: #ffffff; border: 1px solid var(--line); }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 0 0 .8rem; color: var(--ink-soft); font-size: .93rem; }
.viewer-bar .hint { color: var(--muted); }
.btn { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: .4rem .8rem; font: inherit; font-size: .9rem; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: #c9d3e6; }

@media (max-width: 760px) {
  body { font-size: 16px; }
  h1 { font-size: 1.7rem; }
  .hero { flex-direction: column; align-items: flex-start; gap: 1.2rem; padding-top: 2.5rem; }
  .hero img { width: 96px; height: 96px; }
  .post-list a { grid-template-columns: 1fr; gap: .3rem; }
  .overview { grid-template-columns: 1fr; }
  .overview .thumb { position: static; max-width: 240px; }
  .split, .split.left { grid-template-columns: 1fr; }
  .nav { gap: 1rem; }
  .brand span { display: none; }
  .site-header .wrap { height: 56px; }
  .viewer { height: 70vh; }
}

/* Research paper */
.paper { max-width: var(--measure); margin: 0 auto; }
.paper .byline { color: var(--ink-soft); margin: 0 0 1.5rem; }
.paper p { text-align: justify; hyphens: auto; }
.paper .toc ol { margin: .3rem 0 0; padding-left: 1.3rem; }
.paper .toc ol ol { margin: 0; }
.paper .refs { padding-left: 1.6rem; }
.paper .refs li { margin-bottom: .3rem; }
.lang-switch { display: flex; gap: .5rem; margin-bottom: 1.5rem; }
.lang-switch a, .lang-switch span { padding: .3rem .8rem; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; font-size: .9rem; }
.lang-switch span { background: var(--ink); color: #fff; border-color: var(--ink); }
.figure.center img { max-height: 760px; width: auto; }
.paper .pair { justify-content: center; align-items: flex-end; gap: 1.5rem; }
.paper .pair .figure { flex: 1 1 14rem; margin: 1.2rem 0; }

/* Images floated beside the text in imported posts; stacked on phones. */
.prose img.float-right { float: right; margin: .3rem 0 1rem 1.5rem; height: auto; }
.prose h2, .prose h3, .prose figure { clear: both; }
.prose::after { content: ""; display: block; clear: both; }
@media (max-width: 600px) {
  .prose img.float-right { float: none; display: block; margin: 1rem auto; }
}

/* Email shown as text with a copy button, no mailto popups. */
.email { display: inline-flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.email-addr { font-weight: 600; color: var(--ink); user-select: all; }
.copy-email { font: inherit; font-size: .78rem; line-height: 1; padding: .3rem .55rem; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: var(--ink-soft); cursor: pointer; }
.copy-email:hover { border-color: var(--accent); color: var(--accent); }

/* Article top back link and closing box. */
.back-top { margin: 0 0 1.5rem; font-size: .92rem; text-decoration: none; }
.back-top:hover { text-decoration: underline; }
.article-end { margin-top: 3.5rem; padding: 1.4rem 1.5rem; background: var(--bg-soft); border-left: 3px solid var(--accent); border-radius: var(--radius); }
.article-end p { margin: 0 0 .7rem; color: var(--ink-soft); }
.article-end p:last-child { margin-bottom: 0; }
.article-end-title { font-weight: 700; color: var(--ink) !important; font-size: 1.1rem; }
.article-end-email { font-size: 1.1rem; }
.article-end-more { font-size: .92rem; }

/* Visitor statistics (/stats/, staff only) */
.stats { padding-top: 2.5rem; }
.stats-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.stats .range { display: flex; gap: .3rem; font-size: .92rem; }
.stats .range a { padding: .3rem .7rem; border-radius: 999px; text-decoration: none; color: var(--ink-soft); border: 1px solid var(--line); }
.stats .range a[aria-current="page"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.stats .tiles { display: flex; flex-wrap: wrap; gap: .8rem; margin: 1.5rem 0; }
.stats .tile { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1.1rem; min-width: 9rem; }
.stats .tile strong { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stats .tile span { color: var(--muted); font-size: .85rem; }
.stats .tile.small strong { font-size: 1.1rem; }
.stats .chart { display: flex; align-items: flex-end; gap: 2px; height: 120px; border-bottom: 1px solid var(--line); }
.stats .col { flex: 1; position: relative; height: 100%; min-width: 2px; }
.stats .col span { position: absolute; bottom: 0; left: 0; right: 0; display: block; border-radius: 2px 2px 0 0; }
.stats .col .all { background: var(--accent-soft); }
.stats .col .ext { background: var(--accent); }
.stats .col:hover .all { filter: brightness(.9); }
.stats table { border-collapse: collapse; width: 100%; font-size: .92rem; margin-top: .5rem; }
.stats th, .stats td { border-bottom: 1px solid var(--line); padding: .45rem .6rem; text-align: left; vertical-align: top; }
.stats th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.stats .num { text-align: right; font-variant-numeric: tabular-nums; }
.stats time { color: var(--muted); white-space: nowrap; }
.stats td a { word-break: break-all; }
