:root {
  --bg: #0f0e13;
  --bg-2: #17151d;
  --panel: #1d1a24;
  --line: #2e2a38;
  --text: #ece8f2;
  --muted: #9a93a8;
  --accent: #ffb547;
  --accent-2: #ff5e3a;
  --good: #7ddc86;
  --mid: #ffd166;
  --bad: #ff6b6b;
  --radius: 10px;
  --font: "Bricolage Grotesque", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px; }

/* ---------- Library ---------- */
.hero {
  position: relative;
  padding: 72px 0 48px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(900px 400px at 85% -10%, rgba(255, 94, 58, .18), transparent 60%),
    radial-gradient(700px 360px at 0% 0%, rgba(255, 181, 71, .12), transparent 60%);
  overflow: hidden;
}
.hero::after { /* subtle scanlines */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 3px);
}
.eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); }
.hero h1 { font-size: clamp(40px, 7vw, 84px); line-height: .95; margin: 14px 0 18px; font-weight: 800; letter-spacing: -.03em; }
.hero h1 span { color: var(--accent); }
.hero p { color: var(--muted); max-width: 560px; font-size: 18px; line-height: 1.5; margin: 0; }
.stats { display: flex; gap: 36px; margin-top: 32px; flex-wrap: wrap; }
.stats div { font-family: var(--mono); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.stats b { display: block; color: var(--text); font-family: var(--font); font-size: 30px; letter-spacing: 0; }

.section-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 56px 0 22px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-size: 28px; letter-spacing: -.01em; }

.continue {
  display: none; align-items: center; gap: 16px; margin-top: 28px; padding: 10px 18px 10px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; width: fit-content;
  transition: border-color .2s;
}
.continue:hover { border-color: var(--accent); }
.continue img { width: 34px; height: 48px; object-fit: cover; border-radius: 4px; }
.continue small { color: var(--muted); display: block; font-size: 12px; }

.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 34px 26px; }
.issue { display: block; }
.cover {
  position: relative; aspect-ratio: 1 / 1.414; border-radius: 4px 8px 8px 4px; overflow: hidden;
  background: var(--bg-2);
  box-shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 18px 30px -12px rgba(0,0,0,.8);
  transform: perspective(900px) rotateY(0deg); transform-origin: left center;
  transition: transform .45s cubic-bezier(.2,.8,.2,1), box-shadow .45s;
}
.cover::before { /* spine */
  content: ""; position: absolute; inset: 0 auto 0 0; width: 10px; z-index: 1;
  background: linear-gradient(90deg, rgba(0,0,0,.45), rgba(255,255,255,.12) 40%, transparent);
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.issue:hover .cover { transform: perspective(900px) rotateY(-14deg) translateY(-6px); box-shadow: 18px 26px 40px -16px rgba(0,0,0,.9); }
.issue h3 { margin: 14px 0 2px; font-size: 17px; }
.issue p { margin: 0; color: var(--muted); font-size: 14px; }
.badge { font-family: var(--mono); font-size: 11px; color: var(--accent); letter-spacing: .08em; }

/* Index of games */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; color: var(--text);
  padding: 10px 16px; font: inherit; width: 260px; max-width: 100%; outline: none;
}
.search:focus { border-color: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px;
  cursor: pointer; color: var(--muted); font-size: 14px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 600; }

.games { border-top: 1px solid var(--line); }
.game {
  display: grid; grid-template-columns: 54px 1fr auto auto; gap: 16px; align-items: center;
  padding: 12px 6px; border-bottom: 1px solid var(--line); transition: background .15s;
}
.game:hover { background: var(--bg-2); }
.score {
  font-family: var(--mono); font-weight: 700; font-size: 15px; text-align: center; padding: 6px 0;
  border-radius: 6px; background: var(--bg-2); border: 1px solid var(--line);
}
.score.good { color: var(--good); } .score.mid { color: var(--mid); } .score.bad { color: var(--bad); }
.score.none { color: var(--muted); font-weight: 400; font-size: 12px; }
.game .t { font-weight: 600; }
.game .g { color: var(--muted); font-size: 13px; }
.game .where { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.game .thumb { width: 36px; height: 50px; object-fit: cover; border-radius: 3px; background: var(--bg-2); }
.empty { color: var(--muted); padding: 30px 6px; }
.more { margin: 18px auto 0; display: block; }

footer { color: var(--muted); font-size: 13px; padding: 60px 0 40px; text-align: center; }

@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .shelf { grid-template-columns: repeat(2, 1fr); gap: 26px 16px; }
  .game { grid-template-columns: 48px 1fr auto; }
  .game .thumb { display: none; }
}

/* ---------- Reader ---------- */
body.reader { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--bg-2); z-index: 5;
}
.topbar .title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { color: var(--muted); font-weight: 400; margin-left: 8px; }
.spacer { flex: 1; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 8px; cursor: pointer;
  background: transparent; border: 1px solid transparent; color: var(--text);
}
.icon-btn:hover { background: var(--panel); border-color: var(--line); }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn svg { width: 20px; height: 20px; }

.stage { position: relative; flex: 1; display: flex; min-height: 0; }
.book-area {
  position: relative; flex: 1; min-width: 0; display: grid; place-items: center; padding: 22px 64px;
  background: radial-gradient(ellipse at center, #221f2b 0%, var(--bg) 70%);
}
#book { margin: 0 auto; }
.page { background: #fff; }
.page img { width: 100%; height: 100%; display: block; object-fit: cover; user-select: none; -webkit-user-drag: none; }
.page.--left { box-shadow: inset -20px 0 30px -20px rgba(0,0,0,.35); }
.page.--right { box-shadow: inset 20px 0 30px -20px rgba(0,0,0,.35); }

.nav-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); width: 46px; height: 46px; border-radius: 50%;
  background: rgba(29, 26, 36, .85); border: 1px solid var(--line); cursor: pointer; display: grid; place-items: center; z-index: 3;
}
.nav-arrow:hover { border-color: var(--accent); color: var(--accent); }
.nav-arrow.prev { left: 10px; } .nav-arrow.next { right: 10px; }
.nav-arrow svg { width: 22px; height: 22px; }

.bottombar {
  display: flex; align-items: center; gap: 14px; padding: 10px 18px; border-top: 1px solid var(--line); background: var(--bg-2);
}
.bottombar input[type=range] { flex: 1; accent-color: var(--accent); }
.pageno { font-family: var(--mono); font-size: 13px; color: var(--muted); white-space: nowrap; min-width: 92px; text-align: right; }

.drawer {
  width: 0; overflow: hidden; background: var(--bg-2); border-right: 1px solid var(--line); transition: width .25s ease;
  display: flex; flex-direction: column;
}
.drawer.open { width: 320px; }
.drawer-inner { width: 320px; overflow-y: auto; flex: 1; padding: 8px 0 30px; }
.drawer h4 { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 16px 18px 8px; }
.toc a { display: flex; gap: 10px; align-items: baseline; padding: 7px 18px; font-size: 14px; border-left: 2px solid transparent; }
.toc a:hover { background: var(--panel); }
.toc a.active { border-left-color: var(--accent); background: var(--panel); }
.toc a .pg { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.toc a.sec { font-weight: 700; margin-top: 4px; }
.toc a.sub { padding-left: 32px; color: #cfc9d9; }
.toc .sc { font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--bg); }
.toc .sc.good { color: var(--good); } .toc .sc.mid { color: var(--mid); } .toc .sc.bad { color: var(--bad); }

.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 6px 18px; }
.thumbs button { background: none; border: 2px solid transparent; padding: 0; cursor: pointer; border-radius: 4px; position: relative; }
.thumbs button.active { border-color: var(--accent); }
.thumbs img { width: 100%; aspect-ratio: 1/1.414; object-fit: cover; display: block; border-radius: 2px; background: var(--panel); }
.thumbs span { position: absolute; bottom: 3px; right: 4px; font-family: var(--mono); font-size: 10px; background: rgba(0,0,0,.7); padding: 0 4px; border-radius: 3px; }

.tabs { display: flex; gap: 4px; padding: 12px 14px 4px; }
.tabs button { flex: 1; background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 8px; cursor: pointer; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--text); border-color: var(--accent); }

/* Zoom overlay */
.zoom {
  position: fixed; inset: 0; background: rgba(8, 7, 11, .96); z-index: 50; display: none; overflow: hidden;
  touch-action: none; cursor: grab;
}
.zoom.open { display: block; }
.zoom.dragging { cursor: grabbing; }
.zoom img { position: absolute; top: 0; left: 0; transform-origin: 0 0; user-select: none; -webkit-user-drag: none; max-width: none; background: #fff; }
.zoom .zbar {
  position: absolute; top: 14px; right: 14px; display: flex; gap: 6px; z-index: 2;
  background: rgba(29, 26, 36, .9); border: 1px solid var(--line); border-radius: 10px; padding: 4px;
}
.zoom .zhint { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); color: var(--muted); font-size: 13px; background: rgba(29,26,36,.9); padding: 6px 12px; border-radius: 999px; pointer-events: none; }
.zoom .zpage { position: absolute; top: 20px; left: 18px; font-family: var(--mono); color: var(--muted); font-size: 13px; }

.loading { color: var(--muted); font-family: var(--mono); font-size: 13px; }

@media (max-width: 760px) {
  .book-area { padding: 10px 8px; }
  .nav-arrow { display: none; }
  .drawer.open { position: absolute; inset: 0 auto 0 0; z-index: 10; width: min(320px, 88vw); }
  .topbar .title small { display: none; }
  .hide-sm { display: none; }
}
