:root {
  color-scheme: light dark;
  --bg: #f8f6f2;
  --surface: #ffffff;
  --surface-soft: #efece6;
  --text: #2a2825;
  --text-soft: #6b665e;
  --line: #e2ded6;
  --accent: #b9472f;
  --accent-soft: #f6e3dc;
  --accent-text: #9c3a25;
  --on-accent: #ffffff;
  --glass: rgb(248 246 242 / 0.85);
  --shadow: 0 1px 2px rgb(40 34 26 / 0.06), 0 6px 18px rgb(40 34 26 / 0.08);
  --shadow-lift: 0 2px 4px rgb(40 34 26 / 0.08), 0 14px 30px rgb(40 34 26 / 0.16);

  --reader-bg: #141518;
  --reader-text: #e6e4df;
  --reader-bar: rgb(24 25 29 / 0.92);
  --reader-line: #3a3c43;

  --font-display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Figtree', 'Segoe UI', system-ui, sans-serif;
  --gutter: clamp(16px, 3.5vw, 48px);
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 18px;
  --tap: 44px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b;
    --surface: #212226;
    --surface-soft: #2a2c31;
    --text: #e9e7e2;
    --text-soft: #a5a29b;
    --line: #34363c;
    --accent: #ee8a6f;
    --accent-soft: #3d2a25;
    --accent-text: #f4a58f;
    --on-accent: #26130d;
    --glass: rgb(23 24 27 / 0.85);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 18px rgb(0 0 0 / 0.25);
    --shadow-lift: 0 2px 4px rgb(0 0 0 / 0.35), 0 14px 30px rgb(0 0 0 / 0.45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

main { max-width: 1480px; margin: auto; padding: 0 var(--gutter) 72px; }
img { display: block; max-width: 100%; height: auto; }
a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
.masthead {
  display: flex;
  align-items: center;
  gap: 12px 28px;
  padding: 16px 0 12px;
}
.wordmark {
  font: 700 1.6rem/1 var(--font-display);
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}
.wordmark::after { content: '.'; color: var(--accent); }
.search-row { flex: 1; display: flex; gap: 8px; min-width: 0; }
.search-input, .lang-select, .chapter-picker {
  min-height: var(--tap);
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 8px 14px;
  transition: border-color 150ms, box-shadow 150ms;
}
.search-input { flex: 1; min-width: 0; font-size: 1rem; /* 16px stops iOS zooming on focus */ }
.search-input::placeholder { color: var(--text-soft); }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.lang-select { flex: 0 0 auto; max-width: 150px; color: var(--text-soft); }

/* Lists: one swipeable line on small screens */
.shelves {
  display: flex;
  gap: 6px;
  margin-inline: calc(var(--gutter) * -1);
  padding: 6px var(--gutter) 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.shelves::-webkit-scrollbar { display: none; }
.shelf {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--text-soft);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 150ms, color 150ms;
}
.shelf:hover { background: var(--surface-soft); color: var(--text); }
.shelf[aria-current='page'] { background: var(--text); color: var(--bg); font-weight: 600; }

/* Filters */
.filters { margin-bottom: 22px; border-radius: var(--radius-m); background: var(--surface); border: 1px solid var(--line); }
.filters summary {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
}
.filters summary::-webkit-details-marker { display: none; }
.filters summary::after { content: '+'; margin-left: auto; font-size: 1.3rem; font-weight: 400; color: var(--text-soft); }
.filters[open] summary::after { content: '\2212'; }
.filter-panel { display: grid; gap: 16px; padding: 4px 16px 18px; }
.filter-group { border: 0; padding: 0; margin: 0; min-width: 0; }
.filter-group legend { padding: 0 0 8px; font-size: 0.82rem; font-weight: 600; color: var(--text-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px;
  padding: 4px 12px;
  font: 500 0.88rem/1.2 var(--font-body);
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 150ms, color 150ms;
}
.chip:hover { border-color: var(--line); }
.chip[aria-pressed='true'] { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent); }

/* Cover grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(168px, 40vw), 1fr));
  gap: 26px 18px;
}
.card, .rail-item { display: block; min-width: 0; color: inherit; text-decoration: none; }
.card-cover {
  aspect-ratio: 256 / 364;
  overflow: hidden;
  border-radius: var(--radius-m);
  background: var(--surface-soft);
  box-shadow: var(--shadow);
  transition: transform 220ms var(--ease), box-shadow 220ms var(--ease);
}
.card-cover img { width: 100%; height: 100%; object-fit: cover; }
@media (hover: hover) {
  .card:hover .card-cover, .rail-item:hover .card-cover { transform: translateY(-4px); box-shadow: var(--shadow-lift); }
}
.card:active .card-cover, .rail-item:active .card-cover { transform: scale(0.98); }
.card-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  margin-top: 10px;
  font-size: 0.94rem;
  font-weight: 500;
  line-height: 1.35;
}
.card-note { display: block; margin-top: 2px; font-size: 0.82rem; color: var(--accent-text); }
.cover-missing { height: 100%; min-height: 160px; display: grid; place-items: center; color: var(--text-soft); background: var(--surface-soft); font-size: 0.88rem; }
.grid-footer { display: flex; justify-content: center; padding-top: 32px; }

/* Continue reading */
.section-label { margin: 0 0 12px; font: 600 1.1rem/1.3 var(--font-display); letter-spacing: -0.01em; }
.rail { padding: 10px 0 16px; }
.rail-track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(112px, 132px);
  gap: 14px;
  justify-content: start;
  margin-inline: calc(var(--gutter) * -1);
  padding: 4px var(--gutter) 10px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}
.rail-track::-webkit-scrollbar { display: none; }
.rail-item { scroll-snap-align: start; scroll-margin-left: var(--gutter); }

/* Buttons and messages */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 8px 18px;
  font: 600 0.94rem/1.2 var(--font-body);
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid transparent;
  border-radius: var(--radius-m);
  text-decoration: none;
  cursor: pointer;
  transition: filter 150ms, transform 120ms var(--ease), background-color 150ms;
}
.btn:hover { filter: brightness(0.96); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--on-accent); padding-inline: 24px; }
.btn-text { background: none; padding: 0; min-height: 36px; color: var(--accent-text); }
.status-block { grid-column: 1 / -1; padding: 56px 16px; text-align: center; }
.status-title { margin: 0 0 4px; font: 600 1.3rem/1.3 var(--font-display); }
.status-detail { margin: 0 0 16px; color: var(--text-soft); }
.loading { padding: 40px 0; text-align: center; color: var(--text-soft); }
.notice { margin: 18px 0; padding: 14px 16px; border-radius: var(--radius-m); background: var(--accent-soft); font-size: 0.94rem; }

/* Title page */
.back-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  margin: 8px 0;
  color: var(--text-soft);
  font-weight: 500;
  text-decoration: none;
}
.back-link:hover { color: var(--text); }
.detail { display: grid; grid-template-columns: minmax(200px, 300px) minmax(0, 1fr); gap: clamp(24px, 4vw, 56px); align-items: start; }
.detail-cover { position: sticky; top: 84px; overflow: hidden; border-radius: var(--radius-l); box-shadow: var(--shadow-lift); }
.detail-cover img { width: 100%; }
.detail-title {
  margin: 0 0 8px;
  font: 700 clamp(1.7rem, 1.2rem + 2vw, 3rem)/1.12 var(--font-display);
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.detail-people { margin: 0; font-weight: 500; }
.detail-facts { margin: 0; color: var(--text-soft); text-transform: capitalize; font-size: 0.94rem; }
.detail-description { max-width: 68ch; margin: 16px 0 2px; white-space: pre-line; color: var(--text); }
.detail-description.is-collapsed {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  overflow: hidden;
}
.tag-list { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; padding: 0; }
.tag-list li { padding: 3px 10px; border-radius: 999px; background: var(--surface-soft); color: var(--text-soft); font-size: 0.82rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0 24px; }
.chapter-language { display: flex; align-items: center; gap: 10px; margin-top: 18px; color: var(--text-soft); }
.chapter-list { list-style: none; margin: 0; padding: 0; border-radius: var(--radius-m); background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.chapter-list li + li { border-top: 1px solid var(--line); }
.chapter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 14px;
  min-height: 52px;
  padding: 8px 16px;
  color: inherit;
  text-decoration: none;
  transition: background-color 120ms;
}
.chapter-row:hover { background: var(--surface-soft); }
.chapter-number { min-width: 68px; font-weight: 600; }
.chapter-meta { flex: 1 1 160px; min-width: 0; color: var(--text-soft); font-size: 0.88rem; overflow-wrap: anywhere; }
.chapter-flag { font-size: 0.8rem; font-weight: 600; color: var(--accent-text); }
.chapter-flag.is-external { color: var(--text-soft); font-weight: 500; }

/* Reader: a calm dark room whatever the site theme */
body.is-reading { background: var(--reader-bg); color: var(--reader-text); }
body.is-reading main { max-width: none; padding: 0; }
body.is-reading .status-detail, body.is-reading .loading { color: var(--reader-text); }
.reader-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: var(--reader-bar);
  color: var(--reader-text);
  backdrop-filter: blur(10px);
  transition: transform 220ms var(--ease);
}
.reader-bar.is-hidden { transform: translateY(-100%); }
.reader-title {
  flex: 1 1 0;
  min-width: 0;
  color: inherit;
  font-size: 0.94rem;
  font-weight: 500;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reader-controls { display: flex; flex: 0 0 auto; gap: 6px; align-items: center; }
.reader-bar .btn, .reader-bar .chapter-picker {
  min-height: 38px;
  padding: 4px 12px;
  color: var(--reader-text);
  background: transparent;
  border: 1px solid var(--reader-line);
  border-radius: var(--radius-s);
  font-size: 0.88rem;
  font-weight: 500;
}
.reader-bar .chapter-picker { max-width: 112px; }
.reader-bar .chapter-picker option { color: #111; background: #fff; }
.reader-bar .btn:hover { background: var(--reader-line); filter: none; }
.strip { max-width: 820px; margin: auto; }
.page-frame { margin: 0; min-height: 40vh; display: grid; place-items: center; }
.page-frame.is-loaded { min-height: 0; }
.page-image { width: 100%; }
.page-retry { margin: 40px; }
.paged { max-width: 1000px; margin: auto; }
.paged-stage { display: flex; justify-content: center; cursor: pointer; user-select: none; touch-action: manipulation; }
.paged-stage .page-frame { width: 100%; }
.paged-stage .page-image { width: auto; max-height: calc(100dvh - 92px); margin: auto; }
.paged-controls { padding: 8px; text-align: center; font-size: 0.88rem; color: var(--reader-text); }
.chapter-end { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; padding: 44px 16px calc(72px + env(safe-area-inset-bottom)); }
.chapter-end .btn:not(.btn-primary) { background: transparent; color: var(--reader-text); border-color: var(--reader-line); }

.chapter-credit { flex-basis: 100%; margin: 0 0 6px; text-align: center; font-size: 0.88rem; color: var(--reader-text); opacity: 0.8; }
.site-credit { padding: 0 var(--gutter) 28px; text-align: center; font-size: 0.82rem; color: var(--text-soft); }
.site-credit a { color: inherit; }
body.is-reading .site-credit { display: none; }

/* Laptop and up: keep search within reach while browsing */
@media (min-width: 768px) {
  .masthead {
    position: sticky;
    top: 0;
    z-index: 4;
    margin-inline: calc(var(--gutter) * -1);
    padding-inline: var(--gutter);
    background: var(--glass);
    backdrop-filter: blur(12px);
  }
  .search-row { max-width: 640px; }
  .filter-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-group:nth-child(n + 3) { grid-column: 1 / -1; }
}

/* Phones */
@media (max-width: 640px) {
  .masthead { flex-direction: column; align-items: stretch; padding-top: 12px; }
  .lang-select { max-width: 104px; padding-inline: 8px; }
  .detail { grid-template-columns: 1fr; }
  .detail-cover { position: static; width: min(46vw, 190px); justify-self: center; }
  .detail-actions .btn-primary { flex: 1 1 100%; min-height: 50px; font-size: 1rem; }
  .reader-title { display: none; }
  .reader-bar { justify-content: space-between; padding-inline: 8px; }
  .reader-controls { flex: 1; justify-content: space-between; }
}

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

/* Filters: exclude state, text fields and the 18+ confirmation */
.chip[aria-pressed='mixed'] { background: transparent; color: var(--text-soft); border-color: var(--text-soft); text-decoration: line-through; }
.filter-hint { margin: 0; font-size: 0.82rem; color: var(--text-soft); }
.filter-fields { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px 16px 14px; }
.filter-field { display: grid; gap: 4px; flex: 1 1 160px; font-size: 0.82rem; font-weight: 600; color: var(--text-soft); }
.filter-field input {
  min-height: var(--tap);
  min-width: 0;
  padding: 8px 12px;
  font: 400 1rem var(--font-body);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
}
.age-gate { max-width: 460px; margin: 24px auto; padding: 22px; border-radius: var(--radius-l); background: var(--surface); border: 1px solid var(--line); color: var(--text); text-align: center; }
.age-gate p { margin: 8px 0 18px; }
.age-gate-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
