:root {
  color-scheme: dark;
  --bg: #0f0f14;
  --panel: #17171f;
  --border: #2a2a36;
  --text: #ececf1;
  --muted: #9ca3af;
  --accent: #f59e0b;
  --sidebar-w: min(320px, 88vw);
  --topbar-h: 52px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  background: rgba(15,15,20,.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.topbar-inner {
  display: flex; align-items: center; gap: .75rem;
  max-width: 960px; margin: 0 auto; padding: .6rem 1rem;
}
.brand { color: var(--accent); font-weight: 700; text-decoration: none; white-space: nowrap; }
.chapter-label { flex: 1; color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: .35rem; }

.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: calc(100vh - var(--topbar-h)); }

.sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 10;
  transform: translateX(0); transition: transform .2s ease;
}
.sidebar-head { padding: 1rem; border-bottom: 1px solid var(--border); }
.sidebar-head h1 { margin: 0 0 .25rem; font-size: 1.05rem; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: .85rem; line-height: 1.45; }
#chapter-search {
  width: 100%; margin-top: .75rem; padding: .55rem .7rem;
  border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.chapter-list {
  list-style: none; margin: 0; padding: .35rem; overflow: auto; flex: 1;
}
.chapter-list li { margin: 0; }
.chapter-list button {
  width: 100%; text-align: left; padding: .55rem .65rem; margin-bottom: .2rem;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer;
}
.chapter-list button:hover { background: rgba(255,255,255,.04); }
.chapter-list button.active { border-color: var(--accent); background: rgba(245,158,11,.12); }

.reader {
  margin-left: var(--sidebar-w);
  max-width: 960px; padding: 1rem 1rem 5rem;
}
.status {
  padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem;
  background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.35);
}
.pages { display: flex; flex-direction: column; gap: .5rem; align-items: center; }
.pages img {
  width: 100%; max-width: 820px; height: auto; display: block;
  background: #000; border-radius: 4px;
}
.pager {
  position: fixed; left: var(--sidebar-w); right: 0; bottom: 0;
  display: flex; justify-content: center; gap: .5rem;
  padding: .75rem; background: linear-gradient(transparent, rgba(15,15,20,.95) 35%);
}
.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: .55rem 1rem; cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #111; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.dialog {
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel); color: var(--text); padding: 0; max-width: 520px; width: calc(100% - 2rem);
}
.dialog form { padding: 1.25rem; }
.dialog h2 { margin: 0 0 .5rem; }
.dialog label { display: block; margin: .75rem 0 .35rem; font-size: .9rem; }
.dialog textarea {
  width: 100%; padding: .65rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: ui-monospace, monospace; font-size: .78rem;
}
.dialog-actions { display: flex; justify-content: space-between; gap: .5rem; margin-top: 1rem; }
.dialog::backdrop { background: rgba(0,0,0,.55); }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .reader { margin-left: 0; }
  .pager { left: 0; }
  .topbar-inner { padding-inline: .75rem; }
}
