:root {
  color-scheme: dark;
  --bg: #080706;
  --panel: #0f0d0b;
  --panel-soft: #15110e;
  --line: rgba(216, 181, 112, 0.16);
  --gold: #d8b570;
  --gold-soft: #aa8952;
  --blood: #8e1b1b;
  --blood-bright: #b42424;
  --text: #f4eee4;
  --muted: #9c9184;
  --serif: Georgia, 'Times New Roman', serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -10%, rgba(142, 27, 27, 0.14), transparent 35rem),
    linear-gradient(180deg, #090807 0%, var(--bg) 100%);
  color: var(--text);
  font-family: var(--sans);
}
body.reader-open { overflow: hidden; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.ambient {
  position: fixed;
  width: 26rem;
  height: 26rem;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.1;
  pointer-events: none;
}
.ambient-one { top: 10%; left: -13rem; background: var(--blood-bright); }
.ambient-two { right: -13rem; bottom: 4%; background: var(--gold); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 0.85rem;
  color: var(--gold);
  font-size: 0.67rem;
  font-weight: 700;
  letter-spacing: 0.27em;
  text-transform: uppercase;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  position: relative;
  z-index: 2;
}
.login-card {
  width: min(100%, 31rem);
  padding: clamp(2rem, 6vw, 3.5rem);
  text-align: center;
  background: linear-gradient(145deg, rgba(22, 18, 14, 0.96), rgba(10, 9, 8, 0.98));
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  box-shadow: 0 2rem 7rem rgba(0, 0, 0, 0.55), inset 0 1px rgba(255, 255, 255, 0.03);
}
.login-logo { width: 6.4rem; height: 6.4rem; object-fit: contain; margin-bottom: 1.3rem; }
.login-card h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 8vw, 3.25rem);
  font-weight: 400;
  line-height: 1.02;
}
.login-card h1 em, .hero h1 em { color: var(--gold); font-weight: 400; }
.login-copy { margin: 1.25rem auto 2rem; color: var(--muted); line-height: 1.65; }
.login-card form { text-align: left; }
.login-card label { display: block; margin-bottom: 0.55rem; color: #c9bcad; font-size: 0.76rem; letter-spacing: 0.08em; text-transform: uppercase; }
.code-field { position: relative; }
.code-field input {
  width: 100%;
  height: 3.45rem;
  padding: 0 4.3rem 0 1rem;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 0.75rem;
  outline: none;
  background: rgba(255,255,255,0.035);
  color: var(--text);
  transition: border-color 160ms, box-shadow 160ms;
}
.code-field input:focus { border-color: var(--gold-soft); box-shadow: 0 0 0 3px rgba(216,181,112,0.08); }
.reveal-button {
  position: absolute;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  padding: 0.55rem 0.7rem;
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  font-size: 0.75rem;
}
.primary-button {
  border: 0;
  border-radius: 0.75rem;
  background: linear-gradient(135deg, var(--blood-bright), #701313);
  color: white;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 0.7rem 2.2rem rgba(142, 27, 27, 0.28);
  transition: transform 160ms, filter 160ms;
}
.primary-button:hover { transform: translateY(-1px); filter: brightness(1.08); }
.primary-button:disabled { cursor: wait; opacity: 0.65; }
.login-button { width: 100%; height: 3.45rem; margin-top: 0.9rem; }
.form-message { min-height: 1.3rem; margin: 0.65rem 0 0; color: #ef7d7d; text-align: center; font-size: 0.8rem; }
.login-help { margin: 1rem 0 0; color: #736a61; font-size: 0.72rem; }

.app-shell { position: relative; z-index: 1; }
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 4.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem clamp(1rem, 4vw, 4rem);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(8, 7, 6, 0.84);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 0.65rem; color: var(--text); text-decoration: none; font-family: var(--serif); font-size: 1.08rem; }
.brand img { width: 3.15rem; height: 3.15rem; object-fit: contain; }
.brand b { color: var(--gold); font-weight: 400; }
.header-actions { display: flex; align-items: center; gap: 0.75rem; }
.member-pill { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.5rem 0.7rem; border: 1px solid var(--line); border-radius: 999px; color: #c4b7a6; font-size: 0.71rem; }
.member-pill i { width: 0.4rem; height: 0.4rem; border-radius: 50%; background: #65bb74; box-shadow: 0 0 0.65rem #65bb74; }
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.35rem;
  padding: 0 0.9rem;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 0.6rem;
  background: rgba(255,255,255,0.03);
  color: #d5cabd;
  text-decoration: none;
  cursor: pointer;
}
.ghost-button:hover { border-color: var(--gold-soft); color: var(--gold); }

main { width: min(100% - 2rem, 88rem); margin: 0 auto; }
.hero { padding: clamp(4rem, 10vw, 8rem) 0 clamp(3.5rem, 8vw, 6rem); text-align: center; }
.hero h1 { margin: 0; font-family: var(--serif); font-size: clamp(2.65rem, 7vw, 6rem); font-weight: 400; line-height: 0.98; letter-spacing: -0.035em; }
.hero-copy { max-width: 38rem; margin: 1.7rem auto 2.6rem; color: var(--muted); line-height: 1.75; }
.stats { max-width: 39rem; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 1rem; background: rgba(255,255,255,0.018); }
.stats div { display: flex; flex-direction: column; gap: 0.3rem; padding: 1.25rem 0.6rem; }
.stats div + div { border-left: 1px solid var(--line); }
.stats strong { font-family: var(--serif); color: var(--gold); font-size: 1.7rem; font-weight: 400; }
.stats span { color: #81776e; font-size: 0.65rem; letter-spacing: 0.08em; text-transform: uppercase; }
.evolution-stats { max-width: 34rem; grid-template-columns: minmax(0, 1fr); }
.evolution-stats strong { font-size: clamp(1.2rem, 3vw, 1.8rem); }

.library-panel { padding: clamp(1.5rem, 4vw, 3rem); margin-bottom: 5rem; border: 1px solid rgba(255,255,255,0.07); border-radius: 1.5rem; background: linear-gradient(145deg, rgba(18,15,12,0.92), rgba(10,9,8,0.95)); box-shadow: 0 2rem 7rem rgba(0,0,0,0.25); }
.panel-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.panel-heading h2 { margin: 0; font-family: var(--serif); font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 400; }
.result-count { margin: 0 0 0.35rem; color: var(--muted); font-size: 0.78rem; }
.toolbar { display: grid; grid-template-columns: minmax(14rem, 1fr) 13rem 11rem; gap: 0.7rem; margin-bottom: 2rem; }
.toolbar input, .toolbar select {
  width: 100%;
  height: 3rem;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 0.7rem;
  outline: none;
  background: #0b0a09;
  color: #d5cbbf;
}
.toolbar input:focus, .toolbar select:focus { border-color: var(--gold-soft); }
.toolbar select { padding: 0 0.8rem; cursor: pointer; }
.search-field { position: relative; }
.search-field svg { position: absolute; top: 50%; left: 0.9rem; width: 1rem; transform: translateY(-50%); fill: none; stroke: #756b61; stroke-width: 1.7; }
.search-field input { padding: 0 1rem 0 2.6rem; }

.book-grid, .loading-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.15rem; }
.loading-grid div { height: 27rem; border-radius: 0.9rem; background: linear-gradient(100deg, rgba(255,255,255,0.025) 20%, rgba(255,255,255,0.065) 40%, rgba(255,255,255,0.025) 60%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position-x: -200%; } }
.book-card { min-width: 0; overflow: hidden; display: flex; flex-direction: column; border: 1px solid rgba(255,255,255,0.07); border-radius: 0.95rem; background: rgba(255,255,255,0.018); transition: transform 180ms, border-color 180ms, box-shadow 180ms; }
.book-card:hover { transform: translateY(-4px); border-color: rgba(216,181,112,0.3); box-shadow: 0 1.2rem 2.8rem rgba(0,0,0,0.32); }
.cover-button { position: relative; display: block; width: 100%; aspect-ratio: 0.74; overflow: hidden; padding: 0; border: 0; background: #17130f; color: inherit; text-decoration: none; cursor: pointer; }
.cover-button img { width: 100%; height: 100%; display: block; object-fit: cover; object-position: top center; transition: transform 300ms, filter 300ms; }
.cover-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(8,7,6,0.7); color: var(--gold); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0; transition: opacity 180ms; }
.cover-button:hover .cover-overlay { opacity: 1; }
.cover-button:hover img { transform: scale(1.035); filter: brightness(0.7); }
.book-card-body { min-height: 15rem; display: flex; flex-direction: column; padding: 1.05rem; }
.category-tag { align-self: flex-start; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 0.65rem; color: var(--gold); font-size: 0.59rem; font-weight: 700; letter-spacing: 0.13em; text-transform: uppercase; }
.book-card h3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin: 0; font-family: var(--serif); font-size: 1.07rem; font-weight: 400; line-height: 1.28; }
.author { margin: 0.55rem 0 1rem; color: var(--muted); font-size: 0.74rem; line-height: 1.35; }
.book-meta { display: flex; justify-content: space-between; gap: 0.4rem; margin-top: auto; padding-top: 0.8rem; border-top: 1px solid rgba(255,255,255,0.06); color: #70675f; font-size: 0.65rem; }
.card-actions { display: grid; grid-template-columns: 1fr 2.6rem; gap: 0.5rem; margin-top: 0.8rem; }
.read-button, .download-button { min-height: 2.55rem; border-radius: 0.6rem; cursor: pointer; }
.read-button { display: grid; place-items: center; border: 1px solid rgba(216,181,112,0.25); background: rgba(216,181,112,0.06); color: var(--gold); font-size: 0.72rem; font-weight: 700; text-decoration: none; text-transform: uppercase; letter-spacing: 0.08em; }
.read-button:hover { background: var(--gold); color: #100d09; }
.download-button { display: grid; place-items: center; border: 1px solid rgba(255,255,255,0.08); color: #b5aa9e; text-decoration: none; }
.download-button:hover { border-color: var(--gold-soft); color: var(--gold); }
.empty-state { padding: 5rem 1rem; text-align: center; }
.empty-state span { color: var(--gold); font-size: 2.5rem; }
.empty-state h3 { margin: 0.8rem 0 0.35rem; font-family: var(--serif); font-size: 1.7rem; font-weight: 400; }
.empty-state p { margin: 0; color: var(--muted); }
.load-more { display: block; min-width: 12rem; height: 3rem; margin: 2rem auto 0; border: 1px solid var(--line); border-radius: 0.7rem; background: transparent; color: var(--gold); cursor: pointer; }
.load-more:hover { background: rgba(216,181,112,0.06); }

footer { padding: 0 1rem 3.5rem; text-align: center; color: #635a52; font-size: 0.72rem; }
footer img { width: 4rem; height: 4rem; object-fit: contain; opacity: 0.58; }

.reader-dialog { width: 100vw; max-width: none; height: 100vh; max-height: none; margin: 0; padding: 0; border: 0; background: #080706; color: var(--text); }
.reader-dialog::backdrop { background: rgba(0,0,0,0.85); }
.reader-header { min-height: 4.8rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.65rem 1rem 0.65rem 1.3rem; border-bottom: 1px solid rgba(255,255,255,0.08); background: #0e0c0a; }
.reader-header .eyebrow { margin-bottom: 0.2rem; }
.reader-header h2 { max-width: 70vw; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--serif); font-size: 1.15rem; font-weight: 400; }
.reader-actions { display: flex; align-items: center; gap: 0.6rem; }
.reader-close { width: 2.5rem; height: 2.5rem; border: 1px solid rgba(255,255,255,0.1); border-radius: 50%; background: transparent; color: white; cursor: pointer; font-size: 1.5rem; line-height: 1; }
.reader-frame-wrap { position: relative; height: calc(100vh - 4.8rem); background: #24211f; }
.reader-frame-wrap iframe { width: 100%; height: 100%; border: 0; }
.reader-loader { position: absolute; inset: 0; z-index: 0; display: grid; place-items: center; color: var(--gold); font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase; }

@media (max-width: 1050px) {
  .book-grid, .loading-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .member-pill { display: none; }
  main { width: min(100% - 1rem, 88rem); }
  .hero { padding-top: 3.4rem; }
  .stats span { font-size: 0.55rem; }
  .library-panel { padding: 1rem; border-radius: 1rem; }
  .panel-heading { align-items: start; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .book-grid, .loading-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
  .book-card-body { min-height: 14rem; padding: 0.8rem; }
  .book-card h3 { font-size: 0.94rem; }
  .category-tag { font-size: 0.53rem; }
  .book-meta { flex-direction: column; }
  .reader-header { padding-left: 0.8rem; }
  .reader-header h2 { max-width: 47vw; font-size: 0.92rem; }
  .reader-actions .ghost-button { font-size: 0.7rem; padding-inline: 0.65rem; }
}
@media (max-width: 390px) {
  .brand span { display: none; }
  .stats { grid-template-columns: 1fr; }
  .stats div + div { border-left: 0; border-top: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
