:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --line: #d9dee3;
  --text: #20252b;
  --muted: #66717d;
  --accent: #0b6fcb;
  --accent-soft: #e5f2ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.side-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

h1 {
  font-size: 18px;
  margin: 0 0 10px;
  line-height: 1.3;
}

.chapter-count {
  font-size: 13px;
  color: var(--muted);
}

.chapter-list {
  overflow: auto;
  padding: 8px;
}

.chapter-button {
  width: 100%;
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 8px;
  align-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 10px 8px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.chapter-button:hover { background: #f0f3f5; }

.chapter-button.active {
  background: var(--accent-soft);
  color: #064f91;
  font-weight: 600;
}

.chapter-index {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chapter-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-badge {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
}

.toolbar-title {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

button,
select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
  font: inherit;
  cursor: pointer;
}

button:hover,
select:hover { border-color: #aeb8c2; }

button:disabled {
  color: #a0a9b2;
  cursor: not-allowed;
  background: #f4f5f6;
}

.reader {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 18px 16px 48px;
}

.reader.thumb {
  width: min(1280px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  align-items: start;
}

.page {
  display: block;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto 12px;
  background: #e9edf1;
  border: 1px solid var(--line);
}

.reader.thumb .page {
  margin: 0;
  max-height: 360px;
  object-fit: contain;
}

.empty {
  padding: 56px 18px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    max-height: 38vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .toolbar { flex-wrap: wrap; }

  .toolbar-title { flex-basis: 100%; }
}
