/* ==========================================================================
   Big Book — CIO Factory dark-luxury design system, medieval / national
   library dress: near-black dark mode (default) + parchment light mode,
   gold accent stack, illuminated-manuscript flourishes (ex libris plate,
   drop cap, fleuron dividers), card-catalogue genre tabs, an open-Codex
   detail overlay in place of a plain modal.
   ========================================================================== */

:root {
  --bb-radius: 3px;
  --bb-radius-lg: 8px;
  --bb-shadow: 0 18px 50px rgba(0,0,0,.45);
  --bb-font-display: 'Cinzel', serif;
  --bb-font-deco: 'Cinzel Decorative', 'Cinzel', serif;
  --bb-font-body: 'Cormorant Garamond', serif;
  --bb-font-ui: 'Syne', sans-serif;
  --bb-font-mono: 'IBM Plex Mono', monospace;
}

html[data-theme="dark"] {
  --bb-bg: #0a080b;
  --bb-surface: #151216;
  --bb-surface-2: #1d1a20;
  --bb-text: #ece7db;
  --bb-text-muted: #a39a8d;
  --bb-gold: #c9a84c;
  --bb-gold-bright: #e3c876;
  --bb-gold-soft: rgba(201,168,76,.35);
  --bb-gold-wash: rgba(201,168,76,.09);
  --bb-border: rgba(201,168,76,.18);
  --bb-danger: #d97a5f;
}

html[data-theme="light"] {
  --bb-bg: #efe9dc;
  --bb-surface: #fffdf9;
  --bb-surface-2: #e8dfca;
  --bb-text: #251f19;
  --bb-text-muted: #6a604f;
  --bb-gold: #856019;
  --bb-gold-bright: #6b4c12;
  --bb-gold-soft: rgba(133,96,25,.28);
  --bb-gold-wash: rgba(133,96,25,.08);
  --bb-border: rgba(133,96,25,.28);
  --bb-danger: #a8402a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bb-bg);
  color: var(--bb-text);
  font-family: var(--bb-font-body);
  transition: background .35s ease, color .35s ease;
}

body { min-height: 100vh; position: relative; overflow-x: hidden; }

a { color: inherit; text-decoration: none; }

/* grain overlay */
.bb-grain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 999;
  pointer-events: none;
  mix-blend-mode: soft-light;
  opacity: .5;
}

.bb-mono { font-family: var(--bb-font-mono); }

/* faint heraldic diaper pattern behind the hero — very low opacity, purely
   textural, never competes with content */
.bb-hero {
  position: relative;
  max-width: 680px;
  margin-bottom: 44px;
  padding-top: 8px;
}
.bb-hero::before {
  content: '';
  position: absolute;
  top: -30px; right: -220px;
  width: 420px; height: 420px;
  background-image: radial-gradient(circle, var(--bb-gold-soft) 0 1.5px, transparent 1.6px);
  background-size: 26px 26px;
  opacity: .35;
  pointer-events: none;
  z-index: -1;
}

/* ---------- header ---------- */
.bb-header {
  border-bottom: 1px solid var(--bb-border);
  background: var(--bb-bg);
  position: sticky;
  top: 0;
  z-index: 50;
}
.bb-header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bb-brand { display: flex; align-items: center; gap: 12px; }
.bb-brand-mark {
  color: var(--bb-gold);
  border: 1px solid var(--bb-border);
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--bb-radius-lg);
  position: relative;
}
.bb-brand-mark::before,
.bb-brand-mark::after {
  content: '';
  position: absolute;
  width: 5px; height: 5px;
  border: 1px solid var(--bb-gold-soft);
}
.bb-brand-mark::before { top: -1px; left: -1px; border-width: 1px 0 0 1px; }
.bb-brand-mark::after { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }
.bb-brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.bb-brand-title {
  font-family: var(--bb-font-display);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: .04em;
}
.bb-brand-sub {
  font-family: var(--bb-font-ui);
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--bb-gold);
  margin-top: 3px;
}

.bb-theme-toggle {
  width: 46px; height: 26px;
  border-radius: 20px;
  border: 1px solid var(--bb-border);
  background: var(--bb-surface-2);
  position: relative;
  cursor: pointer;
  padding: 0;
}
.bb-theme-toggle-dot {
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--bb-gold);
  transition: transform .25s ease;
}
html[data-theme="light"] .bb-theme-toggle-dot { transform: translateX(20px); }

/* ---------- layout ---------- */
.bb-shell { max-width: 1180px; margin: 0 auto; padding: 0 28px 80px; }
.bb-main { padding-top: 56px; }

.bb-eyebrow {
  font-family: var(--bb-font-ui);
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--bb-gold);
  margin: 0 0 14px;
}
.bb-hero-title {
  font-family: var(--bb-font-display);
  font-size: 46px;
  font-weight: 600;
  margin: 0 0 14px;
  letter-spacing: .01em;
}
.bb-hero-lede {
  font-size: 20px;
  line-height: 1.5;
  color: var(--bb-text-muted);
  margin: 0;
}

/* ---------- search panel ---------- */
.bb-search-panel {
  background: var(--bb-surface);
  border: 1px solid var(--bb-border);
  border-radius: var(--bb-radius-lg);
  padding: 30px;
  margin-bottom: 48px;
  position: relative;
}
.bb-search-panel::before,
.bb-search-panel::after {
  content: '';
  position: absolute;
  width: 10px; height: 10px;
  border-color: var(--bb-gold-soft);
  border-style: solid;
  pointer-events: none;
}
.bb-search-panel::before { top: 8px; left: 8px; border-width: 1px 0 0 1px; }
.bb-search-panel::after { bottom: 8px; right: 8px; border-width: 0 1px 1px 0; }

.bb-search-form { display: flex; flex-direction: column; gap: 20px; }
.bb-field { display: flex; flex-direction: column; gap: 7px; }
.bb-field-row { display: grid; gap: 18px; }
.bb-field-row-3 { grid-template-columns: repeat(3, 1fr); }
.bb-field-row-4 { grid-template-columns: repeat(4, 1fr); }

label {
  font-family: var(--bb-font-ui);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--bb-text-muted);
}

input[type="text"], input[type="number"], select {
  background: var(--bb-surface-2);
  border: 1px solid var(--bb-border);
  border-radius: var(--bb-radius);
  color: var(--bb-text);
  font-family: var(--bb-font-body);
  font-size: 17px;
  padding: 11px 13px;
  outline: none;
  width: 100%;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus { border-color: var(--bb-gold); }
input[type="range"] { width: 100%; accent-color: var(--bb-gold); }

/* ---------- author's ledger lookup ---------- */
.bb-author-lookup { position: relative; }
.bb-author-lookup-row { display: flex; gap: 10px; }
.bb-author-suggestions {
  position: relative;
  background: var(--bb-surface-2);
  border: 1px solid var(--bb-border);
  border-radius: var(--bb-radius);
  margin-top: -2px;
  overflow: hidden;
}
.bb-author-suggestion {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--bb-border);
  font-family: var(--bb-font-body);
  font-size: 16px;
}
.bb-author-suggestion:last-child { border-bottom: none; }
.bb-author-suggestion:hover { background: var(--bb-gold-wash); color: var(--bb-gold); }
.bb-author-suggestion-id {
  font-family: var(--bb-font-mono);
  font-size: 10px;
  color: var(--bb-text-muted);
  letter-spacing: .04em;
}
.bb-author-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.bb-author-chips:empty { display: none; }
.bb-author-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bb-gold-wash);
  border: 1px solid var(--bb-gold-soft);
  color: var(--bb-text);
  font-family: var(--bb-font-ui);
  font-size: 12px;
  border-radius: 20px;
  padding: 6px 8px 6px 13px;
}
.bb-author-chip-remove {
  background: transparent;
  border: none;
  color: var(--bb-gold);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
}

/* ---------- genre badges (card-catalogue tabs) ---------- */
.bb-genre-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.bb-genre-badge {
  font-family: var(--bb-font-ui);
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: var(--bb-surface-2);
  color: var(--bb-text-muted);
  border: 1px solid var(--bb-border);
  border-top-width: 3px;
  border-radius: 0 0 var(--bb-radius) var(--bb-radius);
  padding: 8px 13px 7px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .1s ease;
}
.bb-genre-badge:hover { border-color: var(--bb-gold); color: var(--bb-text); }
.bb-genre-badge:active { transform: translateY(1px); }
.bb-genre-badge.is-active {
  background: var(--bb-gold);
  color: #14120f;
  border-color: var(--bb-gold);
}

.bb-hint { margin: 0; font-size: 12px; color: var(--bb-text-muted); font-family: var(--bb-font-ui); }

.bb-field-toggle { justify-content: center; }
.bb-switch { display: inline-flex; align-items: center; cursor: pointer; width: fit-content; }
.bb-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.bb-switch-track {
  width: 44px; height: 24px;
  border-radius: 20px;
  border: 1px solid var(--bb-border);
  background: var(--bb-surface-2);
  position: relative;
  display: inline-block;
}
.bb-switch-dot {
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--bb-text-muted);
  transition: transform .2s ease, background .2s ease;
}
.bb-switch input:checked + .bb-switch-track .bb-switch-dot {
  transform: translateX(20px);
  background: var(--bb-gold);
}
.bb-switch input:checked + .bb-switch-track { border-color: var(--bb-gold); }

.bb-search-actions { display: flex; gap: 14px; margin-top: 6px; }

.bb-btn {
  font-family: var(--bb-font-ui);
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  border-radius: var(--bb-radius);
  padding: 13px 22px;
  cursor: pointer;
  border: 1px solid var(--bb-gold);
  transition: opacity .2s ease, transform .1s ease;
}
.bb-btn:active { transform: translateY(1px); }
.bb-btn-primary { background: var(--bb-gold); color: #14120f; }
.bb-btn-primary:hover { opacity: .88; }
.bb-btn-ghost { background: transparent; color: var(--bb-text-muted); border-color: var(--bb-border); }
.bb-btn-ghost:hover { color: var(--bb-text); border-color: var(--bb-gold); }
.bb-btn-outline { background: transparent; color: var(--bb-gold); }
.bb-btn-outline:hover { background: var(--bb-gold-wash); }
.bb-btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- results ---------- */
.bb-results-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 18px;
  font-family: var(--bb-font-ui);
}
.bb-results-count { font-size: 13px; letter-spacing: .08em; color: var(--bb-text-muted); margin: 0; text-transform: uppercase; }
.bb-results-status { font-size: 13px; color: var(--bb-gold); margin: 0; min-height: 1em; }

.bb-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 22px;
}

.bb-book-card {
  background: var(--bb-surface);
  border: 1px solid var(--bb-border);
  border-radius: var(--bb-radius-lg);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  display: flex;
  flex-direction: column;
  transition: border-color .2s ease, transform .2s ease;
}
.bb-book-card:hover { border-color: var(--bb-gold); transform: translateY(-3px); }
.bb-book-card-cover-wrap {
  aspect-ratio: 2 / 3;
  background: var(--bb-surface-2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  position: relative;
}
.bb-book-card-cover-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bb-book-card-cover-wrap .bb-no-cover {
  font-family: var(--bb-font-display);
  color: var(--bb-text-muted);
  font-size: 12px;
  padding: 10px;
  text-align: center;
}
.bb-book-card-rating {
  position: absolute; top: 8px; right: 8px;
  background: rgba(9,8,11,.78);
  color: var(--bb-gold);
  font-family: var(--bb-font-mono);
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 20px;
  border: 1px solid var(--bb-gold-soft);
}
.bb-book-card-body { padding: 12px 13px 15px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.bb-book-card-title { font-family: var(--bb-font-display); font-size: 15px; line-height: 1.3; margin: 0; }
.bb-book-card-author { font-family: var(--bb-font-ui); font-size: 11px; color: var(--bb-text-muted); margin: 0; text-transform: uppercase; letter-spacing: .04em; }

.bb-load-more-wrap { display: flex; justify-content: center; margin-top: 36px; }

.bb-empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--bb-text-muted);
  font-family: var(--bb-font-display);
  font-size: 18px;
}

/* ---------- footer ---------- */
.bb-footer {
  border-top: 1px solid var(--bb-border);
  margin-top: 30px;
  padding-top: 22px;
  font-family: var(--bb-font-ui);
  font-size: 12px;
  color: var(--bb-text-muted);
  text-align: center;
}
.bb-footer a { color: var(--bb-gold); }
.bb-footer a:hover { text-decoration: underline; }

/* ---------- The Codex: signature open-book overlay ---------- */
.bb-codex-room {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 30px;
}
.bb-codex-room.is-open { display: flex; }
.bb-codex-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4,3,5,.82);
  backdrop-filter: blur(2px);
}

.bb-codex {
  position: relative;
  z-index: 2;
  width: min(960px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  display: flex;
  background: var(--bb-surface);
  border: 1px solid var(--bb-border);
  border-radius: var(--bb-radius-lg);
  box-shadow: var(--bb-shadow);
  transform: perspective(1600px) rotateY(-8deg) scale(.94);
  opacity: 0;
  transform-origin: left center;
  transition: transform .38s cubic-bezier(.2,.8,.2,1), opacity .3s ease;
}
.bb-codex-room.is-open .bb-codex {
  transform: perspective(1600px) rotateY(0deg) scale(1);
  opacity: 1;
}
.bb-codex-close {
  position: absolute;
  top: 14px; right: 16px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bb-surface-2);
  border: 1px solid var(--bb-gold-soft);
  color: var(--bb-text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  z-index: 3;
}
.bb-codex-close:hover { color: var(--bb-gold); border-color: var(--bb-gold); }
.bb-codex-page {
  padding: 34px 32px;
  flex: 1;
  min-width: 0;
}
.bb-codex-page-left {
  flex: 0 0 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--bb-gold-wash);
}
.bb-codex-cover-frame {
  width: 100%;
  aspect-ratio: 2/3;
  background: var(--bb-surface-2);
  border: 1px solid var(--bb-border);
  overflow: hidden;
  border-radius: var(--bb-radius);
}
.bb-codex-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.bb-codex-rating {
  font-family: var(--bb-font-mono);
  color: var(--bb-gold);
  font-size: 14px;
  letter-spacing: .06em;
}
.bb-codex-facts {
  width: 100%;
  margin: 4px 0 0;
  font-family: var(--bb-font-ui);
  font-size: 11px;
  border-top: 1px solid var(--bb-border);
  padding-top: 12px;
}
.bb-codex-facts div { display: flex; justify-content: space-between; padding: 4px 0; gap: 10px; }
.bb-codex-facts dt { color: var(--bb-text-muted); text-transform: uppercase; letter-spacing: .06em; }
.bb-codex-facts dd { margin: 0; color: var(--bb-text); text-align: right; font-family: var(--bb-font-mono); }

.bb-codex-spine { width: 1px; background: var(--bb-border); }
.bb-codex-page-right { display: flex; flex-direction: column; }

.bb-exlibris {
  font-family: var(--bb-font-deco);
  font-size: 11px;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--bb-gold-soft);
  margin: 0 0 10px;
}
.bb-codex-title { font-family: var(--bb-font-display); font-size: 30px; margin: 0 0 8px; line-height: 1.2; }
.bb-codex-subtitle { font-size: 19px; color: var(--bb-text-muted); margin: 0 0 10px; font-style: italic; }
.bb-codex-status { font-family: var(--bb-font-ui); font-size: 12px; color: var(--bb-gold); min-height: 1em; margin: 0 0 12px; }

.bb-codex-description {
  font-size: 17px;
  line-height: 1.6;
  color: var(--bb-text);
  margin-bottom: 10px;
}
/* illuminated drop cap on the book's description — a small nod to
   manuscript illumination without resorting to gimmicky artwork */
.bb-codex-description.has-dropcap::first-letter {
  font-family: var(--bb-font-deco);
  font-size: 3.4em;
  float: left;
  line-height: .82;
  padding: .04em .08em 0 0;
  color: var(--bb-gold);
}

.bb-fleuron {
  text-align: center;
  color: var(--bb-gold-soft);
  font-size: 15px;
  margin: 8px 0 20px;
}

.bb-similar h3 {
  font-family: var(--bb-font-ui);
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--bb-gold);
  margin: 0 0 14px;
}
.bb-similar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 14px;
}
.bb-similar-card { cursor: pointer; }
.bb-similar-card-cover {
  aspect-ratio: 2/3;
  background: var(--bb-surface-2);
  border: 1px solid var(--bb-border);
  border-radius: var(--bb-radius);
  overflow: hidden;
  margin-bottom: 6px;
}
.bb-similar-card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bb-similar-card-title { font-size: 12px; font-family: var(--bb-font-ui); line-height: 1.3; }

/* ---------- toast ---------- */
.bb-toast-container {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.bb-toast {
  background: var(--bb-surface);
  border: 1px solid var(--bb-gold);
  color: var(--bb-text);
  font-family: var(--bb-font-ui);
  font-size: 13px;
  padding: 12px 20px;
  border-radius: var(--bb-radius);
  box-shadow: var(--bb-shadow);
  animation: bb-toast-in .2s ease;
}
.bb-toast.is-error { border-color: var(--bb-danger); }
@keyframes bb-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 720px) {
  .bb-hero-title { font-size: 32px; }
  .bb-field-row-3, .bb-field-row-4 { grid-template-columns: 1fr 1fr; }
  .bb-codex { flex-direction: column; max-height: 92vh; }
  .bb-codex-page-left { flex: none; }
  .bb-codex-spine { width: 100%; height: 1px; }
}
@media (max-width: 480px) {
  .bb-field-row-3, .bb-field-row-4 { grid-template-columns: 1fr; }
}
