:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #2a2118;
  --muted: #7a6f61;
  --accent: #b5651d;
  --border: #e6ddd0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f;
    --surface: #221c15;
    --text: #f0e9dd;
    --muted: #a89a86;
    --accent: #e0954f;
    --border: #3a3226;
  }
}

* { box-sizing: border-box; }

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

header {
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.search-box {
  width: 100%;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 20px;
}

.pager #page-info {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.pager .icon-btn:disabled {
  opacity: 0.4;
}

header a.back {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

main {
  padding: 8px 16px 100px;
  max-width: 720px;
  margin: 0 auto;
}

/* Catalog grid */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.catalog-item {
  display: block;
  text-decoration: none;
  color: var(--text);
}

.catalog-item img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}

.catalog-item .title {
  font-size: 0.85rem;
  margin-top: 6px;
  font-weight: 600;
}

/* Novel detail header */
.novel-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.novel-head img {
  width: 96px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.novel-head h2 { margin: 0 0 4px; font-size: 1.1rem; }
.novel-head .meta { color: var(--muted); font-size: 0.9rem; }

/* Tabs (Story / Story Info) */
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tabs button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 4px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Story Info field list */
.info-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.info-row .info-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.info-row .info-value-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.info-row .info-value {
  flex: 1;
  white-space: pre-wrap;
  font-size: 0.95rem;
}

.info-row .icon-btn {
  flex-shrink: 0;
}

/* Chapter grid: wraps into columns, never a single vertical list */
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 10px;
}

.chapter-grid a {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
}

.chapter-grid a:active { background: var(--accent); color: #fff; }

/* Reader */
.reader-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.reader-title-row h2 { margin: 0; font-size: 1.15rem; }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.icon-btn:active { background: var(--accent); color: #fff; }

.reader-content-box {
  position: relative;
}

.reader-content-box .icon-btn.copy-content {
  position: absolute;
  top: 0;
  right: 0;
}

.reader-content {
  white-space: pre-wrap;
  font-size: 1.02rem;
  padding-top: 40px;
}

/* Bottom PDF-style nav bar */
.nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.nav-bar a, .nav-bar span {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.nav-bar a {
  background: var(--accent);
  color: #fff;
}

.nav-bar span.disabled {
  color: var(--muted);
  background: transparent;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  margin-top: 40px;
}

.toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show { opacity: 1; }
