:root {
  color-scheme: light;
  --paper: #fdfbf7;
  --card: #fffefa;
  --ink: #1f1a15;
  --muted: #756b5f;
  --line: #e8dfd3;
  --accent: #8d4b2f;
  --accent-soft: #f2dfd1;
  --green: #dfeada;
  --shadow: 0 20px 54px rgba(74, 53, 34, .11);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Noto Serif SC", serif;
  background:
    linear-gradient(180deg, rgba(253, 251, 247, .9), rgba(246, 241, 232, .96)),
    #f7f1e8;
}

a { color: inherit; }
button, input, select { font: inherit; }

.novel-hero {
  min-height: 230px;
  color: #fff;
  background:
    linear-gradient(120deg, rgba(51, 34, 23, .68), rgba(141, 75, 47, .24)),
    url("/static/assets/novels/banner.svg") center 52% / cover no-repeat;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  width: min(1320px, calc(100% - 44px));
  margin: 0 auto;
  padding-top: 18px;
  text-shadow: 0 3px 18px rgba(0, 0, 0, .24);
}

.brand {
  font-family: "Cormorant Garamond", serif;
  font-size: 31px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  flex-wrap: wrap;
}

.nav-links a {
  font-weight: 800;
  text-decoration: none;
  transition: transform .18s ease, opacity .18s ease;
}

.nav-links a:hover,
.nav-links .is-current {
  transform: translateY(-2px);
  opacity: .84;
}

.hero-copy {
  width: min(1320px, calc(100% - 44px));
  margin: 42px auto 0;
  text-shadow: 0 3px 18px rgba(0, 0, 0, .24);
}

.hero-copy span {
  display: inline-flex;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 800;
}

.hero-copy h1 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(42px, 7vw, 82px);
  line-height: .94;
  letter-spacing: 0;
}

.hero-copy p {
  max-width: 780px;
  margin: 12px 0 0;
  font-weight: 700;
  line-height: 1.75;
}

.novel-app {
  width: min(1320px, calc(100% - 44px));
  margin: 28px auto 0;
}

.library-view {
  display: block;
}

.library-view[hidden],
.detail-view[hidden],
.reader-view[hidden] {
  display: none !important;
}

.shelf-panel,
.detail-view,
.reader-view {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 254, 250, .92);
  box-shadow: var(--shadow);
}

.search-box,
.sort-box {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.source-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.source-panel span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.source-panel strong {
  display: block;
  margin-top: 2px;
  font-size: 18px;
}

.source-panel p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.55;
}

.source-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.source-btn {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #5c5147;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
}

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

.search-box {
  margin: 0 0 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.sort-box {
  min-width: 170px;
  margin: 0 0 16px;
}

.search-box span,
.sort-box span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.search-box input,
.sort-box select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: #fff;
  padding: 0 12px;
  outline: none;
}

.search-box input:focus,
.sort-box select:focus {
  border-color: rgba(141, 75, 47, .56);
  box-shadow: 0 0 0 4px rgba(141, 75, 47, .12);
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-row {
  display: grid;
  grid-template-columns: minmax(160px, auto) minmax(240px, 1fr) auto;
  gap: 12px 16px;
  align-items: start;
  padding-top: 16px;
  border-bottom: 1px solid var(--line);
}

.filter-chip {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #5c5147;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.filter-chip:hover,
.filter-chip:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(141, 75, 47, .38);
  outline: none;
}

.filter-chip.is-active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.shelf-panel {
  min-width: 0;
  padding: 20px;
}

.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.section-title span {
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

.section-title h2 {
  margin: 4px 0 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.1;
  letter-spacing: 0;
}

.section-title p {
  max-width: 460px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.7;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.book-card {
  min-width: 0;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 14px;
  padding: 12px;
  border: 1px solid #eee5da;
  border-radius: 14px;
  color: inherit;
  background: #fff;
  text-decoration: none;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.book-card:hover,
.book-card:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(141, 75, 47, .32);
  box-shadow: 0 14px 32px rgba(74, 53, 34, .12);
  outline: none;
}

.book-cover {
  min-height: 128px;
  display: grid;
  place-items: center;
  padding: 12px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(145deg, var(--cover-a), var(--cover-b));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}

.book-cover b {
  writing-mode: vertical-rl;
  letter-spacing: 3px;
  font-size: 20px;
}

.book-meta {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 7px;
}

.book-meta h3 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

.book-meta p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.55;
}

.book-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.book-tags span {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 900;
}

.detail-view {
  padding: 24px;
}

.detail-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 28px;
}

.detail-cover {
  min-height: 310px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(145deg, var(--cover-a), var(--cover-b));
}

.detail-cover b {
  writing-mode: vertical-rl;
  font-size: 32px;
  letter-spacing: 5px;
}

.detail-copy h2 {
  margin: 0;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.05;
  letter-spacing: 0;
}

.detail-copy p {
  color: #574c42;
  line-height: 1.9;
  font-weight: 700;
}

.detail-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
}

.detail-stats span {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border-radius: 999px;
  color: #5a4838;
  background: #f3eadf;
  font-size: 13px;
  font-weight: 900;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.primary-btn,
.ghost-btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border-radius: 999px;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
}

.primary-btn {
  border: 1px solid var(--accent);
  color: #fff;
  background: var(--accent);
}

.ghost-btn {
  border: 1px solid var(--line);
  color: #4e4339;
  background: #fff;
}

.chapter-list {
  margin-top: 24px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.chapter-list h3 {
  margin: 0 0 12px;
}

.chapter-list button {
  width: 100%;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-bottom: 1px solid #eee5da;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.reader-view {
  overflow: hidden;
}

.reader-toolbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 254, 250, .96);
}

.reader-toolbar div {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.reader-toolbar button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #4e4339;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
}

.reader-page {
  max-width: 820px;
  min-height: 68vh;
  margin: 0 auto;
  padding: 46px 34px 64px;
  font-size: var(--reader-size, 19px);
  line-height: 2.05;
}

.reader-page h2 {
  margin: 0 0 28px;
  font-size: calc(var(--reader-size, 19px) * 1.55);
  line-height: 1.25;
  letter-spacing: 0;
}

.reader-page p {
  margin: 0 0 1.2em;
}

.reader-view.theme-night {
  color: #d8d0c3;
  background: #15120f;
}

.reader-view.theme-night .reader-toolbar {
  border-bottom-color: #2b251f;
  background: rgba(21, 18, 15, .96);
}

.reader-view.theme-night .reader-toolbar button {
  color: #e3d9ca;
  border-color: #3a3128;
  background: #211c17;
}

.reader-view.theme-green {
  color: #223024;
  background: #edf5e7;
}

.reader-view.theme-green .reader-toolbar {
  background: rgba(237, 245, 231, .96);
}

.empty-state {
  padding: 46px 20px;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.poem {
  width: min(1320px, calc(100% - 44px));
  margin: 36px auto 28px;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

@media (max-width: 1080px) {
  .filter-row { grid-template-columns: 1fr; }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .topbar {
    width: min(100% - 28px, 1320px);
    align-items: flex-start;
    flex-direction: column;
  }
  .novel-app,
  .hero-copy { width: min(100% - 28px, 1320px); }
  .source-panel { align-items: flex-start; flex-direction: column; }
  .source-actions { justify-content: flex-start; }
  .book-grid { grid-template-columns: 1fr; }
  .section-title { align-items: flex-start; flex-direction: column; }
  .detail-layout { grid-template-columns: 1fr; }
  .detail-cover { min-height: 230px; }
  .reader-toolbar { align-items: flex-start; flex-direction: column; }
  .reader-page { padding: 34px 20px 52px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
