/* Gearpunk Reader — Warm Dark Theme */
:root {
  --bg:             #0f0d0a;
  --surface:        #1a1714;
  --surface-raised: #201d18;
  --border:         #2d2822;
  --text:           #cfc1a8;
  --text-dim:       #7a6e5e;
  --accent:         #c4863a;
  --accent-h:       #d49540;
  --code-bg:        #181510;
  --nav-w:          280px;
  --font:    Georgia, 'Times New Roman', serif;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 18px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.78;
  min-height: 100vh;
}

/* ── Top bar ──────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 16px; gap: 12px;
}
.menu-btn {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; gap: 5px;
  padding: 4px; color: var(--text-dim); flex-shrink: 0;
}
.menu-btn span {
  display: block; width: 22px; height: 2px;
  background: currentColor; border-radius: 1px;
  transition: background .2s;
}
.menu-btn:hover span { background: var(--text); }
.site-title {
  font-family: var(--font-ui); font-size: 13px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent); text-decoration: none; flex: 1;
}
.breadcrumb {
  font-family: var(--font-ui); font-size: 11px;
  color: var(--text-dim); letter-spacing: .06em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 160px;
}

/* ── Reading progress bar ─────────────────────────────── */
.progress {
  position: fixed; top: 52px; left: 0; right: 0;
  height: 2px; background: var(--border); z-index: 90;
}
.progress-bar {
  height: 100%; background: var(--accent);
  width: 0%; transition: width .12s linear;
}

/* ── Nav overlay ──────────────────────────────────────── */
.overlay {
  display: none; position: fixed; inset: 0;
  z-index: 150; background: rgba(0,0,0,.65);
}
.overlay.open { display: block; }

/* ── Nav drawer ───────────────────────────────────────── */
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 200;
  width: var(--nav-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform .25s ease;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.drawer-title {
  font-family: var(--font-ui); font-size: 10px; font-weight: 700;
  letter-spacing: .18em; text-transform: uppercase; color: var(--accent);
}
.drawer-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 22px; cursor: pointer; line-height: 1; padding: 0 4px;
}
.drawer-close:hover { color: var(--text); }
.nav-sec { padding: 5px 0; border-bottom: 1px solid var(--border); }
.nav-label {
  font-family: var(--font-ui); font-size: 9px; font-weight: 700;
  letter-spacing: .2em; text-transform: uppercase;
  color: var(--text-dim); padding: 8px 16px 3px;
}
.nav-a {
  display: block; padding: 7px 16px;
  font-family: var(--font-ui); font-size: 13.5px;
  color: var(--text); text-decoration: none;
  transition: color .15s, background .15s; line-height: 1.3;
}
.nav-a:hover, .nav-a.cur { color: var(--accent); }
.nav-a.cur { background: rgba(196,134,58,.06); }
.nav-a.sub { padding-left: 28px; font-size: 13px; color: var(--text-dim); }
.nav-a.sub:hover, .nav-a.sub.cur { color: var(--accent); }

/* ── Content area ─────────────────────────────────────── */
.content { max-width: 680px; margin: 0 auto; padding: 72px 22px 80px; }
@media (min-width: 640px) { .content { padding: 80px 36px 100px; } }

/* ── Typography ───────────────────────────────────────── */
article h1 {
  font-size: 1.75em; font-weight: normal;
  line-height: 1.25; margin: 2em 0 .5em; color: var(--text);
}
article h1:first-child { margin-top: .35em; }
article h2 {
  font-size: 1.2em; font-weight: normal;
  line-height: 1.3; margin: 2.5em 0 .5em; color: var(--text);
  border-bottom: 1px solid var(--border); padding-bottom: .3em;
}
article h3 {
  font-size: 1em; font-weight: 600;
  margin: 1.8em 0 .4em; color: var(--accent); letter-spacing: .02em;
}
article h4 {
  font-size: .9em; font-weight: 600; font-style: italic;
  margin: 1.4em 0 .3em; color: var(--text-dim);
}
article p { margin-bottom: 1.15em; }
article ul, article ol { margin: .3em 0 1.15em 1.5em; }
article li { margin-bottom: .35em; }
article strong { color: var(--text); font-weight: 600; }
article em { font-style: italic; }
article code {
  font-family: 'Courier New', monospace; font-size: .83em;
  background: var(--code-bg); padding: 1px 5px;
  border-radius: 3px; color: var(--accent);
}
article pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 16px; overflow-x: auto; margin: 1.5em 0;
}
article pre code {
  background: none; padding: 0;
  font-size: .82em; line-height: 1.6; color: var(--text);
}
article blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5em 0; padding: .5em 0 .5em 1.2em;
  color: var(--text-dim); font-style: italic;
}

/* ── Scene / section break ────────────────────────────── */
.scene-break {
  text-align: center; margin: 2.5em 0;
  color: var(--text-dim); font-size: .8em; letter-spacing: .5em;
}
.scene-break::before { content: '· · ·'; }

/* ── In-page TOC ──────────────────────────────────────── */
.toc {
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: 6px; padding: 16px 20px; margin: 0 0 2.5em;
}
.toc-title {
  font-family: var(--font-ui); font-size: 9px; font-weight: 700;
  letter-spacing: .2em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 10px;
}
.toc ol { list-style: none; padding: 0; margin: 0; }
.toc li { margin-bottom: 1px; }
.toc a {
  font-family: var(--font-ui); font-size: 12.5px;
  color: var(--text-dim); text-decoration: none;
  display: block; padding: 2px 0;
  transition: color .15s; line-height: 1.4;
}
.toc a:hover { color: var(--accent); }
.toc .t2 { padding-left: 0; }
.toc .t3 { padding-left: 14px; font-size: 12px; }
.toc .t4 { padding-left: 28px; font-size: 11.5px; }

/* ── Chapter prev/next ────────────────────────────────── */
.ch-nav {
  display: flex; justify-content: space-between;
  margin-top: 3em; padding-top: 1.5em;
  border-top: 1px solid var(--border); gap: 12px;
}
.ch-nav a {
  font-family: var(--font-ui); font-size: 12.5px;
  color: var(--text-dim); text-decoration: none;
  padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 4px; transition: color .15s, border-color .15s;
  line-height: 1.35; max-width: 46%;
}
.ch-nav a:hover { color: var(--accent); border-color: var(--accent); }
.ch-nav .nxt { margin-left: auto; text-align: right; }
.ch-nav small {
  display: block; font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; opacity: .6; margin-bottom: 2px;
}

/* ── Index / landing ──────────────────────────────────── */
.hero {
  padding: 36px 0 28px; border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}
.hero h1 {
  font-size: 2.1em; font-weight: normal;
  color: var(--text); margin-bottom: 8px; letter-spacing: -.01em;
}
.hero p {
  font-family: var(--font-ui); font-size: 13px;
  color: var(--text-dim); line-height: 1.6;
}
.sec-label {
  font-family: var(--font-ui); font-size: 9px; font-weight: 700;
  letter-spacing: .2em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 10px; margin-top: 28px;
  display: block;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 9px; margin-bottom: 4px;
}
.card {
  display: block; padding: 13px 15px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 5px; text-decoration: none;
  transition: border-color .15s, background .15s;
}
.card:hover { border-color: var(--accent); background: rgba(196,134,58,.04); }
.card-title { font-size: 14px; color: var(--text); line-height: 1.3; margin-bottom: 2px; }
.card-sub { font-family: var(--font-ui); font-size: 11px; color: var(--text-dim); }

/* ── Chapter metadata ─────────────────────────────────── */
.ch-meta {
  font-family: var(--font-ui); font-size: 11px;
  color: var(--text-dim); letter-spacing: .04em;
  text-align: center; margin-top: 2.5em; padding-bottom: .5em;
}

/* ── Changelog ───────────────────────────────────────── */
.changelog-entry { margin-bottom: 2em; }
.changelog-date {
  font-family: var(--font-ui); font-size: 12px; font-weight: 700;
  color: var(--accent); letter-spacing: .08em;
  margin-bottom: 8px;
}
.changelog-entry ul {
  list-style: none; padding: 0; margin: 0;
}
.changelog-entry li {
  font-size: .9em; color: var(--text-dim);
  padding: 4px 0 4px 16px; line-height: 1.5;
  border-left: 2px solid var(--border);
}

@media print {
  .topbar, .drawer, .overlay, .progress { display: none; }
  .content { padding-top: 0; }
}
