/* Hacker Books — styles. Warm "paper" palette with a burnt-orange accent. */
:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f1ece3;
  --text: #1f1a14;
  --muted: #6d645a;
  --border: #e4dccf;
  --accent: #d9480f;
  --accent-ink: #ffffff;
  --accent-soft: #fde8da;
  --focus: #1c7ed6;
  --mark: #ffe8a3;
  --shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 4px 14px rgba(60, 40, 10, .06);
  --topbar-h: 56px;
  --side-w: 240px;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #15120e; --surface: #1e1a15; --surface-2: #28231c; --text: #efe8dc; --muted: #a4998a; --border: #342e25; --accent: #ff8a4c; --accent-ink: #1a0e05; --accent-soft: #3a2415; --focus: #74c0fc; --mark: #5c4a12; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3); color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #15120e; --surface: #1e1a15; --surface-2: #28231c; --text: #efe8dc; --muted: #a4998a; --border: #342e25; --accent: #ff8a4c; --accent-ink: #1a0e05; --accent-soft: #3a2415; --focus: #74c0fc; --mark: #5c4a12; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3); color-scheme: dark; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 12px); }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip:focus { position: fixed; z-index: 100; top: 8px; left: 8px; background: var(--surface); padding: 8px 12px; border-radius: 6px; }
.noscript { padding: 24px 16px; }
kbd { font: 12px ui-monospace, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; padding: 1px 6px; border-radius: 4px; }

/* ---- top bar ---- */
.topbar { position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: 8px; padding: 0 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.icon-btn { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--text); font: 600 17px var(--sans); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.logo { display: flex; align-items: center; gap: 8px; flex: none; font: 700 19px var(--serif); letter-spacing: -.01em; }
.logo:hover { text-decoration: none; }
.search { flex: 1; max-width: 560px; margin: 0 auto; display: flex; min-width: 0; }
.search input { flex: 1; min-width: 0; height: 38px; padding: 0 14px; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-right: 0; border-radius: 19px 0 0 19px; }
.search input::-webkit-search-cancel-button { display: none; }
.search-btn { width: 52px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 0 19px 19px 0; cursor: pointer; display: grid; place-items: center; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
}

/* ---- layout & sidebar ---- */
.layout { display: flex; align-items: flex-start; min-height: calc(100vh - var(--topbar-h) - 90px); }
.sidebar { flex: none; width: var(--side-w); position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 12px 8px 24px; border-right: 1px solid var(--border); transition: margin-left .2s; }
body.side-collapsed .sidebar { margin-left: calc(-1 * var(--side-w)); visibility: hidden; }
.nav { list-style: none; margin: 0; padding: 0; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 8px; color: var(--text); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); font-weight: 600; }
.nav svg { width: 20px; height: 20px; flex: none; color: var(--muted); }
.nav a.active svg { color: var(--accent); }
.nav-h { margin: 18px 12px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.topics a { padding: 6px 12px; font-size: 14px; justify-content: space-between; }
.topics .count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.scrim { display: none; }
main { flex: 1; min-width: 0; padding: 20px 24px 40px; outline: none; }

@media (max-width: 899px) {
  .sidebar { position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; height: auto; margin-left: 0 !important; visibility: visible !important; transform: translateX(-100%); background: var(--bg); transition: transform .2s; box-shadow: var(--shadow); padding-top: 16px; }
  body.drawer-open .sidebar { transform: none; }
  body.drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45); }
  main { padding: 16px; }
}
@media (max-width: 520px) {
  .hide-sm { display: none; }
  .logo-text { display: none; }
  .topbar { padding: 0 8px 0 12px; gap: 4px; }
}

/* ---- page headings, chips ---- */
.page-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-bottom: 4px; }
.page-h h1 { font: 700 26px var(--serif); }
.sub { color: var(--muted); margin: 4px 0 14px; max-width: 70ch; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; align-items: center; }
.chips .lbl { font-size: 12px; color: var(--muted); margin-right: 2px; text-transform: uppercase; letter-spacing: .06em; }
.chip { display: inline-block; padding: 4px 12px; font-size: 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.chip:hover { background: var(--surface-2); text-decoration: none; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip.topic { background: var(--accent-soft); border-color: transparent; }
.btn { display: inline-block; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 600 14px var(--sans); cursor: pointer; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.hero-stats { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.empty { max-width: 60ch; padding: 32px 0; color: var(--muted); }
.empty h2 { color: var(--text); font: 700 22px var(--serif); margin-bottom: 8px; }
.empty p { margin: 8px 0; }
.end { text-align: center; color: var(--muted); padding: 24px 0; font-size: 13px; }

/* ---- book grid & cards ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 16px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 12px; } }
.card { display: block; border-radius: 8px; min-width: 0; }
.card:hover { text-decoration: none; }
.card:hover .cover { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(0,0,0,.15), 0 10px 24px rgba(60,40,10,.22); }
.cover { position: relative; aspect-ratio: 2 / 3; width: 100%; border-radius: 3px 6px 6px 3px; overflow: hidden; background: var(--surface-2); box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; container-type: inline-size; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* spine highlight on covers, like a real book */
.cover::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 5%; background: linear-gradient(90deg, rgba(255,255,255,.28), rgba(0,0,0,.12)); pointer-events: none; }
.cover.ph { display: flex; flex-direction: column; justify-content: space-between; padding: 12% 11% 10% 14%; color: #fff7ea; background: linear-gradient(160deg, hsl(var(--h) 42% 34%), hsl(var(--h) 46% 22%)); }
.ph-t { font: 700 11.5cqw/1.15 var(--serif); display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.ph-rule { width: 28%; height: 2px; background: currentColor; opacity: .55; margin: 6% 0; }
.ph-a { font: italic 8cqw/1.2 var(--serif); opacity: .85; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { position: absolute; z-index: 1; right: 6px; bottom: 6px; padding: 1px 7px; font-size: 11px; font-weight: 600; border-radius: 4px; background: rgba(20, 14, 6, .78); color: #fff; font-variant-numeric: tabular-nums; }
.card h3 { margin-top: 8px; font: 600 14px/1.3 var(--sans); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .au { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .rec { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.card .rec b { color: var(--accent); font-weight: 600; }
.sentinel { height: 1px; }

/* ---- book page ---- */
.book { display: grid; grid-template-columns: minmax(180px, 280px) 1fr; gap: 28px 36px; align-items: start; max-width: 1000px; }
.book > * { min-width: 0; }
.book .cover { max-width: 280px; }
.book h1 { font: 700 30px/1.15 var(--serif); }
.book .st { font: italic 18px var(--serif); color: var(--muted); margin: 4px 0 0; }
.book .by { margin: 10px 0 0; font-size: 16px; }
.book .by span { color: var(--muted); }
.stats { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 18px 0; padding: 14px 0; border-block: 1px solid var(--border); }
.stat b { display: block; font: 700 24px var(--serif); font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.desc { max-width: 65ch; }
.links { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.sec { grid-column: 1 / -1; }
.sec h2 { font: 700 20px var(--serif); margin: 12px 0 10px; }
.chart { width: 100%; max-width: 640px; height: auto; display: block; }
.chart rect.bar { fill: var(--accent); opacity: .85; }
.chart rect.bar:hover { opacity: 1; }
.chart text { fill: var(--muted); font: 11px var(--sans); }
.chart line { stroke: var(--border); }
.comments { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; max-width: 760px; }
.comment { padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.comment-h { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.comment-h a:hover { color: var(--accent); }
.comment-h .who { color: var(--text); font-weight: 600; }
.comment p { margin: 0; overflow-wrap: anywhere; }
.comment mark { background: var(--mark); color: inherit; padding: 0 2px; border-radius: 3px; }
.comment .thread { display: inline-block; margin-top: 6px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 16px; overflow-x: auto; padding: 4px 4px 14px; scroll-snap-type: x proximity; }
.row .card { flex: none; width: 130px; scroll-snap-align: start; }
@media (max-width: 700px) {
  .book { grid-template-columns: minmax(0, 1fr); }
  .book .cover { max-width: 200px; }
  .book h1 { font-size: 25px; }
}

/* ---- about ---- */
.prose { max-width: 70ch; }
.prose h1 { font: 700 28px var(--serif); margin-bottom: 12px; }
.prose h2 { font: 700 20px var(--serif); margin: 26px 0 8px; }
.prose p, .prose li { margin: 8px 0; }
.prose a { color: var(--accent); text-decoration: underline; }

/* ---- skeleton / footer / dialog ---- */
.skel { height: 60vh; display: grid; place-items: center; color: var(--muted); }
.footer { padding: 20px 16px 28px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; text-align: center; }
.footer p { margin: 2px 0; }
dialog { max-width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h2 { font: 700 20px var(--serif); margin-bottom: 12px; }
.keys { margin: 0 0 16px; }
.keys > div { display: flex; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.keys dt { width: 110px; flex: none; }
.keys dd { margin: 0; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* keyboard focus on cards: ring the cover, not the whole link */
.card:focus-visible { outline: none; }
.card:focus-visible .cover { outline: 3px solid var(--focus); outline-offset: 3px; }
/* wrapper for related books: no box of its own so an empty one adds no grid gap */
#related { display: contents; }
