:root {
  --bg: #f7f6f1;
  --surface: #ffffff;
  --surface-2: #efede4;
  --text: #1d1f1c;
  --muted: #6b6e66;
  --line: #dcd9cc;
  --accent: #1f7a3a;
  --accent-soft: #e2f1e5;
  --accent-text: #14592a;
  --mark: #fff0a8;
  --code-bg: #f1f0e8;
  --screen-bg: #0d1a10;
  --screen-fg: #6dff8f;
  --shadow: 0 10px 40px rgba(20, 30, 20, .18);
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "PT Serif", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --topbar: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1210; --surface: #151a16; --surface-2: #1c231e; --text: #dfe5dc; --muted: #8e978b;
    --line: #2a332c; --accent: #5fe07f; --accent-soft: #19301f; --accent-text: #7ff09a; --mark: #4a4415;
    --code-bg: #121713; --shadow: 0 10px 40px rgba(0, 0, 0, .6); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1210; --surface: #151a16; --surface-2: #1c231e; --text: #dfe5dc; --muted: #8e978b;
  --line: #2a332c; --accent: #5fe07f; --accent-soft: #19301f; --accent-text: #7ff09a; --mark: #4a4415;
  --code-bg: #121713; --shadow: 0 10px 40px rgba(0, 0, 0, .6); color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar) + 16px); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--sans); }
a { color: var(--accent-text); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent); }
kbd { font: 600 11px/1 var(--mono); padding: 3px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; color: var(--muted); background: var(--surface); }
.muted { color: var(--muted); font-weight: 400; }
button { font: inherit; color: inherit; }

/* ---- topbar */
.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar); display: flex; align-items: center; gap: 12px; padding: 0 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; white-space: nowrap; }
.brand-mark { font: 700 13px/1 var(--mono); background: var(--screen-bg); color: var(--screen-fg); padding: 7px 6px; border-radius: 5px; letter-spacing: .5px; }
.search-trigger { margin-left: auto; display: flex; align-items: center; justify-content: space-between; gap: 24px; min-width: 260px; padding: 7px 10px 7px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer; }
.search-trigger:hover { border-color: var(--accent); }
.emu-link { flex: none; font: 600 13px var(--sans); color: var(--accent-text); text-decoration: none; padding: 7px 10px; border-radius: 8px; white-space: nowrap; }
.emu-link:hover { background: var(--accent-soft); }
.dump-seg .chip.run { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.icon-btn { border: 1px solid transparent; background: none; border-radius: 8px; width: 36px; height: 36px; cursor: pointer; font-size: 17px; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-toggle { display: none; }
.home-page .nav-toggle { display: none !important; }

/* ---- layout */
.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr) 230px; gap: 40px; max-width: 1440px; margin: 0 auto; padding: 0 24px; }
.sidebar { position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); overflow-y: auto; padding: 20px 0 40px; scrollbar-width: thin; }
.sidebar details { border-bottom: 1px solid var(--line); }
.sidebar summary { cursor: pointer; padding: 8px 4px; font: 600 14px/1.4 var(--mono); list-style: none; display: flex; justify-content: space-between; }
.sidebar summary::-webkit-details-marker { display: none; }
.sidebar summary::before { content: "▸"; color: var(--muted); margin-right: 8px; transition: transform .15s; }
.sidebar details[open] summary::before { transform: rotate(90deg); }
.sidebar summary .count { margin-left: auto; color: var(--muted); font-weight: 400; }
.sidebar ul { list-style: none; margin: 0 0 10px; padding: 0; }
.sidebar li a { display: grid; grid-template-columns: 46px 1fr; gap: 4px; padding: 5px 8px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: 13.5px; line-height: 1.35; }
.sidebar li a:hover { background: var(--surface-2); }
.sidebar li a[aria-current] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.sidebar .iss { font: 12px/1.6 var(--mono); color: var(--muted); }

.content { padding: 36px 0 80px; min-width: 0; }
.content.wide { grid-column: 2 / 4; }
.toc { position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); overflow-y: auto; padding: 40px 0; font-size: 13px; }
.toc h2 { font: 600 11px/1 var(--sans); text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0 0 10px; }
.toc ul { list-style: none; margin: 0 0 24px; padding: 0; border-left: 1px solid var(--line); }
.toc li a { display: block; padding: 4px 12px; color: var(--muted); text-decoration: none; line-height: 1.35; margin-left: -1px; border-left: 2px solid transparent; }
.toc li.l3 a { padding-left: 24px; }
.toc li a:hover { color: var(--text); }
.toc li a.active { color: var(--accent-text); border-left-color: var(--accent); }

/* ---- article */
.article { max-width: 760px; }
.listing-page { max-width: none; }
.article-head { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.kicker { margin: 0 0 6px; font: 600 13px/1.4 var(--mono); color: var(--muted); }
.kicker a { color: var(--accent-text); text-decoration: none; }
.article h1 { font: 700 clamp(28px, 4vw, 40px)/1.15 var(--sans); margin: 0 0 10px; letter-spacing: -.5px; text-wrap: balance; }
.byline { margin: 0 0 14px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent-text); }
.chip.primary, .chip.on { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.chip.ext::after { content: "↗"; font-size: 11px; opacity: .7; }
.siblings { display: flex; flex-wrap: wrap; gap: 6px; margin: -10px 0 20px; }

.prose { font: 17.5px/1.7 var(--serif); hyphens: auto; overflow-wrap: break-word; }
.prose p { margin: 0 0 1em; }
.prose h2, .prose h3 { font-family: var(--sans); line-height: 1.25; margin: 2em 0 .7em; }
.prose h2 { font-size: 22px; letter-spacing: -.2px; }
.prose h3 { font-size: 18px; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose dl dt { font-family: var(--sans); font-weight: 600; margin-top: 1em; }
.prose figure { margin: 6px 0 18px; text-align: center; }
.prose figure.mw-halign-right { float: right; margin: 6px 0 16px 24px; max-width: 45%; }
.prose figure.mw-halign-left { float: left; margin: 6px 24px 16px 0; max-width: 45%; }
.prose figure img, .prose img { max-width: 100%; height: auto; background: #fff; border-radius: 4px; border: 1px solid var(--line); padding: 4px; cursor: zoom-in; }
.prose a.img-link { display: inline-block; }
.prose h2, .prose h3, .prose .table-wrap, .prose pre, .listings { clear: both; }
.prose pre { font: 13.5px/1.5 var(--mono); background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; overflow-x: auto; tab-size: 8; hyphens: none; }
.listing pre { font-size: 14px; }
body.wrap .listing pre { white-space: pre-wrap; }
.table-wrap { overflow-x: auto; margin: 0 0 1.4em; }
.prose table { border-collapse: collapse; font: 14px/1.45 var(--sans); }
.prose table[data-center] { margin: 0 auto; }
.prose td, .prose th { border: 1px solid var(--line); padding: 5px 9px; vertical-align: top; }
.prose th { background: var(--surface-2); }
.prose table.fixed td { font-family: var(--mono); font-size: 13px; }

.listings { margin-top: 40px; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.listings h2 { font-size: 16px; margin: 0 0 12px; }
.listings ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.listings li { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.listings li a:first-child { flex: 1; padding: 9px 12px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 14px; }
.listings li a:first-child:hover { color: var(--accent-text); }
.lst-icon { color: var(--accent); margin-right: 8px; }
.listings .dl { font: 12px var(--mono); padding: 9px 12px; color: var(--muted); text-decoration: none; border-left: 1px solid var(--line); }
.listings .dl:hover { color: var(--accent-text); }
.copyright { margin-top: 40px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 16px; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 760px; margin-top: 32px; }
.pager a { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 600; background: var(--surface); }
.pager a:hover { border-color: var(--accent); }
.pager small { font: 12px var(--mono); color: var(--muted); }
.pager .next { text-align: right; }

/* ---- home */
.home { max-width: 1100px; margin: 0 auto; padding: 0 24px 60px; }
.hero { display: grid; grid-template-columns: 1fr 340px; gap: 48px; align-items: center; padding: 56px 0 36px; }
.hero h1 { font: 700 clamp(32px, 5vw, 52px)/1.05 var(--sans); letter-spacing: -1px; margin: 0 0 16px; text-wrap: balance; }
.lead { font: 19px/1.55 var(--serif); color: var(--muted); margin: 0 0 20px; max-width: 620px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 0 0 26px; font-size: 14px; color: var(--muted); }
.stats b { color: var(--text); font: 600 18px var(--mono); margin-right: 4px; }
.hero-search { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 560px; padding: 14px 16px 14px 20px; font-size: 17px; border: 2px solid var(--accent); border-radius: 12px; background: var(--surface); color: var(--muted); cursor: pointer; box-shadow: 0 4px 0 var(--accent-soft); }
.hero-search:hover { color: var(--text); }
.hero-screen { margin: 0; background: var(--screen-bg); color: var(--screen-fg); font: 15px/1.5 var(--mono); padding: 22px 24px; border-radius: 14px; border: 10px solid #2b2e27; box-shadow: inset 0 0 40px rgba(109, 255, 143, .12), var(--shadow); text-shadow: 0 0 6px rgba(109, 255, 143, .55); min-height: 220px; }
.cursor { animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor { animation: none; } }

.timeline { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 14px; position: sticky; top: var(--topbar); background: var(--bg); z-index: 5; scrollbar-width: thin; }
.timeline a { flex: 1 0 auto; display: flex; flex-direction: column; align-items: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); text-decoration: none; color: var(--text); }
.timeline a b { font: 600 15px var(--mono); }
.timeline a span { font-size: 12px; color: var(--muted); }
.timeline a:hover { border-color: var(--accent); }

.catalog-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 6px 0 12px; }
#filter { flex: 1; min-width: 220px; font: inherit; padding: 9px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); }
#filter:focus, .search-box input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.sort { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.sort button { border: 0; background: var(--surface); padding: 8px 12px; font-size: 13px; cursor: pointer; color: var(--muted); }
.sort button + button { border-left: 1px solid var(--line); }
.sort button.on { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.catalog-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.catalog-table thead th { text-align: left; font: 600 11px var(--sans); text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); }
.catalog-table .year-row th { text-align: left; font: 700 14px var(--mono); padding: 14px 14px 6px; color: var(--accent-text); background: var(--surface-2); }
.catalog-table td { padding: 9px 14px; border-top: 1px solid var(--line); vertical-align: top; }
.catalog-table tr:hover td { background: var(--accent-soft); }
.c-issue { font: 13px/1.7 var(--mono); color: var(--muted); white-space: nowrap; width: 90px; }
.c-title a { font-weight: 600; color: var(--text); text-decoration: none; }
.c-title a:hover { color: var(--accent-text); text-decoration: underline; }
.c-author { color: var(--muted); font-size: 14px; }
.c-extra { white-space: nowrap; text-align: right; width: 110px; }
.badge { font: 12px var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
.catalog.flat .year-row { display: none; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.linkish { background: none; border: 0; color: var(--accent-text); text-decoration: underline; cursor: pointer; padding: 0; }
.foot { margin-top: 40px; font-size: 13px; color: var(--muted); }

/* ---- search modal */
.search-modal { position: fixed; inset: 0; z-index: 100; }
.search-backdrop { position: absolute; inset: 0; background: rgba(10, 15, 10, .45); backdrop-filter: blur(2px); }
.search-panel { position: relative; margin: 8vh auto 0; width: min(760px, calc(100% - 24px)); max-height: 80vh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.search-box { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.search-box input { flex: 1; font: 18px var(--sans); border: 0; background: none; color: var(--text); padding: 8px 6px; border-radius: 6px; }
.search-box input::-webkit-search-cancel-button { display: none; }
.search-filters { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.search-filters:empty { display: none; }
.search-filters .chip { font-size: 12px; padding: 2px 9px; }
.search-results { overflow-y: auto; padding: 6px; }
.search-results .hint { padding: 22px; color: var(--muted); text-align: center; font-size: 14px; }
.result { display: block; padding: 10px 12px; border-radius: 8px; text-decoration: none; color: var(--text); }
.result + .result { margin-top: 2px; }
.result.sel, .result:hover { background: var(--accent-soft); }
.result .r-meta { font: 12px var(--mono); color: var(--muted); display: flex; gap: 10px; }
.result .r-type { color: var(--accent-text); }
.result .r-title { font-weight: 600; margin: 2px 0; }
.result .r-ex { font-size: 14px; color: var(--muted); line-height: 1.5; }
.result .r-sub { font-size: 13px; color: var(--muted); margin-top: 4px; padding-left: 10px; border-left: 2px solid var(--line); }
.result mark, .prose mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.search-foot { display: flex; gap: 16px; padding: 8px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.search-more { display: block; margin: 8px auto; }

/* ---- binary dumps */
:root { --warn: #a07a10; --warn-line: #c99a1e; --err: #b23a2f; --err-line: #c8483c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --warn: #e0b84a; --err: #ff8a7e; } }
:root[data-theme="dark"] { --warn: #e0b84a; --err: #ff8a7e; }
.dump-bar { margin: 18px 0 8px; padding: 12px 14px; border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 10px; background: var(--surface); font: 14px/1.5 var(--sans); hyphens: none; }
.dump-bar.s-ok { border-left-color: var(--accent); }
.dump-bar.s-warn { border-left-color: var(--warn-line); }
.dump-bar.s-err { border-left-color: var(--err-line); }
.dump-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-bottom: 8px; }
.dump-status { font-size: 13px; color: var(--muted); }
.s-ok .dump-status { color: var(--accent-text); }
.s-warn .dump-status { color: var(--warn); }
.s-err .dump-status { color: var(--err); }
.dump-files { display: flex; flex-direction: column; gap: 6px; }
.dump-seg { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.dump-seg .mono { font: 13px var(--mono); color: var(--muted); margin-right: 4px; }
.dump-seg .chip { font: 600 12px var(--mono); padding: 2px 10px; }
.dump-bar details { margin-top: 8px; }
.dump-bar summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.dump-notes { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; max-height: 320px; overflow-y: auto; }
.dump-notes li { padding: 3px 0 3px 22px; position: relative; border-top: 1px dashed var(--line); overflow-wrap: anywhere; }
.dump-notes li::before { position: absolute; left: 2px; font-weight: 700; }
.dump-notes .n-ok::before { content: "✓"; color: var(--accent); }
.dump-notes .n-fix::before { content: "✎"; color: var(--muted); }
.dump-notes .n-warn::before { content: "⚠"; color: var(--warn-line); }
.dump-notes .n-err::before { content: "✗"; color: var(--err-line); }

/* ---- lightbox */
.lightbox { position: fixed; inset: 0; z-index: 120; background: rgba(0, 0, 0, .82); display: flex; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 6px; }

/* ---- responsive */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 250px minmax(0, 1fr); gap: 32px; }
  .toc { display: none; }
  .content.wide { grid-column: 2; }
}
@media (max-width: 860px) {
  .layout { display: block; padding: 0 16px; }
  .nav-toggle { display: inline-block; }
  .sidebar { position: fixed; top: var(--topbar); left: 0; bottom: 0; height: auto; width: min(320px, 86vw); background: var(--bg); border-right: 1px solid var(--line); z-index: 30; padding: 12px 12px 40px; transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  .search-trigger { min-width: 0; gap: 10px; }
  .search-trigger kbd, .brand .muted { display: none; }
  .hero { grid-template-columns: 1fr; padding-top: 32px; gap: 28px; }
  .hero-screen { display: none; }
  .home { padding: 0 16px 48px; }
  .prose { font-size: 17px; }
  .prose figure.mw-halign-right, .prose figure.mw-halign-left { float: none; margin: 6px 0 18px; max-width: 100%; }
  .c-author, .catalog-table thead th:nth-child(3) { display: none; }
  .c-extra { width: auto; }
  .catalog-table td { padding: 8px 10px; }
  .c-issue { width: 72px; font-size: 12px; }
  .c-title { overflow-wrap: anywhere; }
  .pager { grid-template-columns: 1fr; }
  .search-foot { display: none; }
}
@media (max-width: 480px) {
  .brand-text { display: none; }
  .emu-link { padding: 7px 4px; }
  .search-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .c-extra, .catalog-table thead th:nth-child(4) { display: none; }
}
