* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --header-bg: rgba(255, 255, 255, .88);
  --border: #e7e5e1;
  --ink: #1c1a16;
  --ink-muted: #75705f;
  --ink-soft: #332f26;
  --card-bg: #ffffff;
  --card-shadow: 0 8px 30px -14px rgba(30, 25, 15, .12);
  --cover-bg: repeating-linear-gradient(135deg, #f0efec, #f0efec 10px, #e4e2dc 10px, #e4e2dc 20px);
  --cover-shadow: 0 14px 34px -16px rgba(30, 25, 15, .25);
  --tag-bg: #f4e4dc;
  --tag-text: #8f3f24;
  --accent: #b3502f;
  --accent-dark: #8f3f24;
  --accent-border: #dfb7a3;
  --accent-shadow: 0 6px 16px -6px rgba(179, 80, 47, .55);
  --buy-bg: #f5f3ee;
}

[data-theme="dark"] {
  --bg: #141210;
  --header-bg: rgba(20, 18, 15, .85);
  --border: #332e26;
  --ink: #f2efe8;
  --ink-muted: #a49c8a;
  --ink-soft: #e6e1d6;
  --card-bg: #1c1913;
  --card-shadow: 0 8px 30px -14px rgba(0, 0, 0, .5);
  --cover-bg: repeating-linear-gradient(135deg, #26221b, #26221b 10px, #2d2820 10px, #2d2820 20px);
  --cover-shadow: 0 14px 34px -16px rgba(0, 0, 0, .5);
  --tag-bg: #3a2618;
  --tag-text: #e59a72;
  --accent: #d9713f;
  --accent-dark: #eb8c5c;
  --accent-border: #6b4229;
  --accent-shadow: 0 6px 16px -6px rgba(217, 113, 63, .4);
  --buy-bg: #211d16;
}

body {
  font-family: "Work Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--ink);
  transition: background .25s ease, color .25s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { text-decoration: none; color: inherit; }
button, select, input { font-family: inherit; }
button { cursor: pointer; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.serif { font-family: "Piazzolla", serif; }

/* ---------- e-reader banner ---------- */
.ereader-banner {
  background: var(--tag-bg);
  color: var(--ink);
  font-size: 14px;
  padding: 10px 24px;
  text-align: center;
}
.ereader-banner a {
  text-decoration: underline;
  color: var(--accent-dark);
  font-weight: 600;
}

/* ---------- footer link ---------- */
.site-footer a { text-decoration: underline; color: var(--ink-muted); }
.site-footer a:hover { color: var(--ink); }

/* ---------- header ---------- */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.site-header .inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  align-items: center;
}
.logo {
  font-family: "Piazzolla", serif;
  font-style: italic;
  font-weight: 600;
  font-size: 22px;
  letter-spacing: .2px;
  flex-shrink: 0;
  color: var(--ink);
}
.logo em { font-style: italic; color: var(--accent); }

.search-box {
  flex: 1 1 220px;
  min-width: 160px;
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  padding: 0 12px;
  position: relative;
}

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: -1px;
  right: -1px;
  min-width: 280px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--card-shadow), 0 12px 40px -12px rgba(0, 0, 0, .25);
  z-index: 30;
  padding: 6px;
}
.suggestions .group-label {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
  padding: 8px 10px 4px;
}
.suggestion {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--ink);
}
.suggestion:hover, .suggestion.active { background: var(--tag-bg); }
.suggestion .thumb {
  flex: 0 0 auto;
  width: 28px;
  height: 42px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--cover-bg);
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
}
.suggestion .thumb.icon {
  font-size: 14px;
  color: var(--ink-muted);
  border: 0;
  background: transparent;
}
.suggestion .text { display: flex; flex-direction: column; min-width: 0; }
.suggestion .primary {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.suggestion .primary mark {
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}
.suggestion .secondary {
  font-size: 11px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-box .icon { font-size: 13px; color: var(--ink-muted); }
.search-box input {
  border: 0;
  outline: none;
  padding: 10px 8px;
  flex: 1;
  background: transparent;
  font-size: 14px;
  color: var(--ink);
  min-width: 0;
}

.header-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.main-nav { display: flex; gap: 4px; }
.main-nav a {
  padding: 9px 14px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--ink-muted);
}
.main-nav a:hover { color: var(--ink); }
.main-nav a.active {
  font-weight: 600;
  background: var(--tag-bg);
  color: var(--accent-dark);
}
.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--ink);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---------- layout ---------- */
.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 24px 80px;
  width: 100%;
  flex: 1;
}
.page.narrow { max-width: 900px; padding-top: 40px; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-muted);
}

.page-title {
  font-family: "Piazzolla", serif;
  font-size: 22px;
  margin: 0;
  font-weight: 600;
}
.section-label {
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 14px;
  font-weight: 600;
}

/* ---------- home ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  animation: fadeUp .5s ease both;
}
.sort-tabs {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: var(--card-bg);
}
.sort-tabs a {
  padding: 9px 14px;
  font-size: 13px;
  color: var(--ink-muted);
}
.sort-tabs a.active {
  background: var(--accent);
  color: #fffdf8;
  font-weight: 600;
}

.featured {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card-bg);
  box-shadow: var(--card-shadow);
  padding: 26px;
  margin-bottom: 36px;
  display: flex;
  gap: 26px;
  flex-wrap: wrap;
  align-items: stretch;
  animation: fadeUp .55s ease .05s both;
}
.featured .cover { flex: 0 0 auto; width: 130px; }
.featured .body {
  flex: 1 1 300px;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.featured .kicker {
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
  font-weight: 600;
}
.featured h2 {
  margin: 0 0 4px;
  font-family: "Piazzolla", serif;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.15;
}
.featured .author { margin: 0 0 10px; font-size: 13px; color: var(--ink-muted); }
.featured .blurb {
  margin: 0 0 16px;
  font-family: "Piazzolla", serif;
  font-style: italic;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-soft);
  max-width: 48ch;
}

.btn-primary {
  display: inline-block;
  border: 0;
  background: var(--accent);
  color: #fffdf8;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--accent-shadow);
}
.btn-outline {
  display: inline-block;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent-dark);
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}

/* ---------- book grid ---------- */
.book-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  animation: fadeUp .55s ease .1s both;
}
.book-card { display: flex; flex-direction: column; gap: 9px; }
.book-card:hover { opacity: .82; }
.book-card .title { font-size: 14px; font-weight: 600; line-height: 1.25; color: var(--ink); }
.book-card .author { font-size: 12px; color: var(--ink-muted); margin: 1px 0 4px; }
.book-card .blurb {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--cover-bg);
  position: relative;
  overflow: hidden;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .format-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  font-family: ui-monospace, monospace;
  font-size: 8px;
  color: var(--ink-muted);
  background: var(--card-bg);
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

/* ---------- catalog ---------- */
.catalog-layout {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.filters {
  flex: 0 0 240px;
  min-width: 220px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card-bg);
  box-shadow: var(--card-shadow);
  padding: 20px;
  position: sticky;
  top: 88px;
  animation: fadeUp .5s ease both;
}
.filters .head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.filters .head span { font-family: "Piazzolla", serif; font-size: 16px; font-weight: 600; }
.filters .head a { font-size: 12px; color: var(--ink-muted); }
.filters .head a:hover { color: var(--accent); }
.filters .group-label {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 9px;
  font-weight: 600;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 22px; }
.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  padding: 5px 12px;
  display: inline-block;
}
.chip:hover { border-color: var(--accent); color: var(--accent-dark); }
.chip.active {
  background: var(--tag-bg);
  border-color: var(--accent-border);
  color: var(--tag-text);
  font-weight: 600;
}
.results { flex: 1 1 480px; min-width: 280px; animation: fadeUp .55s ease .05s both; }
.results-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 18px;
}
.results-head .count { font-size: 13px; color: var(--ink-muted); }
.empty {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 40px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 14px;
}

.pagination {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  margin-top: 32px;
  font-size: 13px;
  color: var(--ink-muted);
}
.pagination a {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--ink-muted);
  padding: 7px 13px;
  border-radius: 7px;
}
.pagination a:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- fragment page ---------- */
.book-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
  animation: fadeUp .5s ease both;
}
.book-nav .back { font-size: 13px; color: var(--ink-muted); }
.book-nav .back:hover { color: var(--ink); }
.book-nav .prev-next { display: flex; gap: 10px; }
.book-nav .prev-next a {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink-muted);
  padding: 7px 13px;
  border-radius: 7px;
  font-size: 13px;
}
.book-nav .prev-next a:hover { border-color: var(--accent); color: var(--accent); }

.fragment-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card-bg);
  box-shadow: var(--card-shadow);
  padding: 44px 48px;
  margin-bottom: 18px;
  animation: fadeUp .6s ease both;
}
@media (max-width: 640px) {
  .fragment-card { padding: 28px 22px; }
}
.fragment-card .kicker {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 24px;
  text-align: center;
}

.fragment { overflow: hidden; position: relative; }
.fragment.collapsed { max-height: 560px; }
.fragment.collapsed::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 120px;
  background: linear-gradient(transparent, var(--card-bg));
}
.fragment p, .fragment div {
  font-family: "Piazzolla", serif;
  margin: 0 0 18px;
  font-size: 18px;
  line-height: 1.9;
  color: var(--ink-soft);
}
.fragment h1, .fragment h2, .fragment h3, .fragment .chapter_title {
  font-family: "Piazzolla", serif;
  color: var(--ink);
  line-height: 1.3;
}
.fragment img {
  max-width: min(100%, 420px);
  height: auto;
  display: block;
  margin: 18px auto;
  border-radius: 6px;
}
.fragment sup { font-size: .7em; }

.expand-row { text-align: center; margin-bottom: 36px; }
.expand-btn {
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-size: 15px;
  font-weight: 600;
  padding: 10px 4px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-bottom: 1px solid var(--accent-border);
}
.expand-btn:hover { color: var(--accent); border-bottom-color: var(--accent); }
.expand-btn .chevron { display: inline-block; transition: transform .25s ease; }
.expand-btn.open .chevron { transform: rotate(180deg); }

/* ---------- book hero ---------- */
.book-hero {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.book-hero .cover {
  flex: 0 0 auto;
  width: 110px;
  box-shadow: var(--cover-shadow);
  border-radius: 5px;
  animation: fadeUp .55s ease both;
}
.book-hero .body { flex: 1 1 340px; min-width: 260px; animation: fadeUp .6s ease .05s both; }
.tags { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.tag {
  font-size: 11px;
  font-weight: 500;
  color: var(--tag-text);
  background: var(--tag-bg);
  border-radius: 999px;
  padding: 4px 11px;
}
.book-hero h1 {
  font-family: "Piazzolla", serif;
  font-weight: 700;
  font-size: 24px;
  line-height: 1.15;
  margin: 0 0 6px;
  letter-spacing: -.1px;
}
.book-hero .author { font-size: 14px; color: var(--ink-muted); margin: 0 0 10px; }
.book-hero .blurb {
  font-family: "Piazzolla", serif;
  font-style: italic;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0;
  max-width: 56ch;
}

/* ---------- buy box ---------- */
.buy-box {
  border-radius: 12px;
  background: var(--buy-bg);
  padding: 28px 30px;
  margin-bottom: 56px;
  animation: fadeUp .55s ease .2s both;
}
.buy-box h3 {
  font-family: "Piazzolla", serif;
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 5px;
}
.buy-box .sub { font-size: 14px; color: var(--ink-muted); margin-bottom: 20px; }
.buy-box .buttons { display: flex; gap: 12px; flex-wrap: wrap; }
.buy-box .disclosure {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--ink-muted);
}
.buy-box .disclosure .i {
  font-family: ui-monospace, monospace;
  font-size: 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  background: var(--card-bg);
}

/* ---------- similar ---------- */
.similar { animation: fadeUp .55s ease .25s both; }
.similar .grid {
  display: grid;
  gap: 22px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
