:root {
  --navy: #062a42;
  --navy-deep: #041b2b;
  --cyan: #0fd8e0;
  --cyan-soft: #8ff4f7;
  --paper: #fff;
  --muted: rgba(255,255,255,.62);
  --danger: #ff6b6b;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", SimSun, serif;
  --font-hud: "Chakra Petch", "Segoe UI", "Microsoft YaHei", sans-serif;
  color-scheme: dark;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #1d78c4; }
body { min-height: 100vh; margin: 0; overflow-x: hidden; color: var(--paper); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }

.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -4;
  background:
    radial-gradient(circle at 78% 18%, rgba(143,244,247,.2), transparent 22%),
    linear-gradient(145deg, #2a8bd1 0%, #1d78c4 46%, #105486 100%);
}
.bg-overlay {
  position: fixed;
  inset: 0;
  z-index: -3;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(6,42,66,.42), rgba(6,42,66,.09) 48%, transparent 78%);
}
.bg-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -2;
  height: 22vh;
  pointer-events: none;
  background: linear-gradient(to top, rgba(5,24,40,.5), transparent);
}

.site-header, main { width: min(1380px, calc(100% - 64px)); margin-inline: auto; }
.site-header { padding: 30px 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { margin: 0; }
.brand a {
  position: relative;
  display: inline-block;
  padding: 4px 0 10px;
  color: #fff;
  font-family: var(--font-serif);
  font-size: clamp(1.65rem,2.7vw,2.35rem);
  font-weight: 650;
  letter-spacing: .11em;
  text-decoration: none;
  text-shadow: 0 2px 6px rgba(3,16,24,.35);
}
.brand a::after { content: ""; position: absolute; left: 0; bottom: 0; width: 38px; height: 3px; background: var(--cyan); box-shadow: 0 0 8px rgba(15,216,224,.35); }
.home-link { color: rgba(255,255,255,.72); font: 600 .7rem var(--font-hud); letter-spacing: .12em; text-decoration: none; text-shadow: 0 1px 3px rgba(3,16,24,.55); }
.home-link::before { content: "← "; color: var(--cyan); }
.home-link:hover { color: #fff; }

main { padding: clamp(42px,7vh,82px) 0 78px; }
.library { min-height: 70vh; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 28px;
  margin-bottom: 22px;
  padding: 12px;
  border: 1px solid rgba(143,244,247,.18);
  border-radius: 13px;
  background: rgba(6,42,66,.34);
  box-shadow: 0 12px 35px rgba(3,16,24,.12);
  backdrop-filter: blur(8px);
}
.search {
  flex: 1 1 520px;
  display: grid;
  grid-template-columns: 21px minmax(90px,1fr) auto;
  align-items: center;
  gap: 11px;
  min-width: 0;
  padding: 6px 7px 6px 14px;
  border: 1px solid rgba(143,244,247,.2);
  border-radius: 9px;
  background: rgba(4,27,43,.7);
  transition: border-color .18s,box-shadow .18s;
}
.search:focus-within { border-color: rgba(15,216,224,.75); box-shadow: 0 0 0 3px rgba(15,216,224,.08); }
.search svg { width: 20px; fill: none; stroke: var(--cyan-soft); stroke-width: 1.8; stroke-linecap: round; }
.search input { min-width: 0; border: 0; outline: 0; color: #fff; background: transparent; }
.search input::placeholder { color: rgba(255,255,255,.44); }
.search button, .pagination button, .viewer-actions a, .viewer-actions button {
  border: 0;
  border-radius: 7px;
  padding: 9px 17px;
  color: var(--navy);
  background: var(--cyan);
  font-weight: 750;
  text-decoration: none;
  transition: transform .15s,background .15s;
}
.search button:hover, .pagination button:hover:not(:disabled), .viewer-actions a:hover { transform: translateY(-1px); background: var(--cyan-soft); }
.library-tools { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.result-count { color: #fff; font: 600 .72rem var(--font-hud); letter-spacing: .1em; }
.library-tools select { min-width: 110px; padding: 8px 10px; border: 1px solid rgba(143,244,247,.22); border-radius: 7px; color: rgba(255,255,255,.84); background: rgba(4,27,43,.72); font: .7rem var(--font-hud); }

.library-layout { display: flex; flex-direction: column; gap: 20px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.filter {
  flex: none;
  padding: 6px 12px;
  border: 1px solid rgba(143,244,247,.18);
  border-radius: 999px;
  color: rgba(255,255,255,.72);
  background: rgba(6,42,66,.42);
  font: 600 .7rem var(--font-hud);
  transition: color .15s,border-color .15s,background .15s;
}
.filter:hover { color: #fff; border-color: rgba(15,216,224,.65); }
.filter.active { color: var(--navy); border-color: var(--cyan); background: var(--cyan); }

.results { min-width: 0; }
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill,minmax(min(100%,clamp(168px,17vw,230px)),1fr));
  gap: clamp(14px,1.7vw,23px);
  align-items: start;
  min-height: 300px;
}
.book-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(143,244,247,.12);
  border-radius: 11px;
  background: rgba(6,42,66,.64);
  box-shadow: 0 13px 28px rgba(3,16,24,.18);
  transition: transform .18s,border-color .18s,box-shadow .18s;
}
.book-card:hover { transform: translateY(-4px); border-color: rgba(15,216,224,.45); box-shadow: 0 18px 36px rgba(3,16,24,.26); }
.cover-button { display: block; width: 100%; padding: 0; border: 0; color: inherit; background: none; text-align: left; }
.cover-wrap { position: relative; display: block; aspect-ratio: 3/4.15; overflow: hidden; background: linear-gradient(145deg,#15516b,var(--navy)); }
.cover-wrap::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top,rgba(4,27,43,.8),transparent 38%); opacity: .18; }
.cover { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .3s; }
.book-card:hover .cover { transform: scale(1.02); }
.cover-fallback { position: absolute; inset: 0; display: grid; place-items: center; color: rgba(143,244,247,.55); background: linear-gradient(150deg,#15516b,var(--navy) 70%); }
.cover-fallback svg { width: 48px; fill: none; stroke: currentColor; stroke-width: 1.3; }
.read-cue { position: absolute; z-index: 2; left: 50%; bottom: 13px; padding: 6px 15px; border-radius: 999px; color: var(--navy); background: var(--cyan); font-size: .68rem; font-weight: 750; opacity: 0; transform: translate(-50%,6px); transition: opacity .18s,transform .18s; }
.cover-button:hover .read-cue, .cover-button:focus-visible .read-cue { opacity: 1; transform: translate(-50%,0); }
.book-info { padding: 11px 12px 13px; }
.book-tags { display: flex; gap: 5px; min-height: 17px; overflow: hidden; }
.tag { position: relative; max-width: 100px; overflow: hidden; padding: 2px 7px 2px 10px; border-radius: 3px; color: rgba(255,255,255,.68); background: rgba(255,255,255,.07); font: .56rem var(--font-hud); white-space: nowrap; text-overflow: ellipsis; }
.tag::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--tag-color); }
.tag.quiet::before { background: var(--cyan); }
.book-info h2 { margin: 8px 0 5px; overflow: hidden; color: #fff; font: 500 .95rem/1.5 var(--font-serif); text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.book-info h2:hover, .book-info h2:focus { color: var(--cyan-soft); outline: none; }
.book-meta { margin: 0; overflow: hidden; color: rgba(143,244,247,.52); font: .62rem var(--font-hud); text-overflow: ellipsis; white-space: nowrap; }
.book-excerpt { display: -webkit-box; margin: 9px 0 0; overflow: hidden; color: rgba(255,255,255,.66); font-family: var(--font-serif); font-size: .72rem; line-height: 1.6; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }

.skeleton { padding-bottom: 14px; animation: pulse 1.2s ease-in-out infinite alternate; }
.skeleton-cover { aspect-ratio: 3/4.15; background: rgba(143,244,247,.1); }
.skeleton-line { width: 58%; height: 9px; margin: 8px 12px 0; background: rgba(255,255,255,.08); }
.skeleton-line.wide { width: 76%; margin-top: 14px; }
@keyframes pulse { to { opacity: .45; } }

.empty-state { grid-column: 1/-1; min-height: 310px; display: grid; place-items: center; align-content: center; color: rgba(255,255,255,.62); text-align: center; }
.empty-mark { display: grid; place-items: center; width: 54px; height: 54px; margin-bottom: 17px; border: 1px solid rgba(15,216,224,.7); border-radius: 50%; color: var(--cyan); font: 1.3rem var(--font-hud); }
.empty-state h2 { margin: 0 0 7px; color: #fff; font: 500 1.08rem var(--font-serif); }
.empty-state p { margin: 0; font-size: .78rem; }
.notice { margin-bottom: 18px; padding: 11px 14px; border: 1px solid rgba(143,244,247,.18); border-radius: 8px; color: rgba(255,255,255,.75); background: rgba(6,42,66,.72); }
.notice.error { border-color: rgba(255,107,107,.45); color: #ffc8c5; }
.hidden { display: none !important; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 42px; }
.pagination button { padding: 7px 14px; font-size: .7rem; }
.pagination button:disabled { cursor: not-allowed; opacity: .3; }
.pagination span { min-width: 65px; color: #fff; text-align: center; font: .7rem var(--font-hud); }

.viewer { width: 100vw; max-width: none; height: 100vh; max-height: none; margin: 0; padding: 0; border: 0; color: #fff; background: rgba(3,16,24,.88); }
.viewer::backdrop { background: rgba(3,16,24,.86); backdrop-filter: blur(8px); }
.viewer-shell { width: calc(100% - 42px); height: calc(100% - 34px); margin: 17px 21px; display: grid; grid-template-rows: auto 1fr; overflow: hidden; border: 1px solid rgba(143,244,247,.22); border-radius: 12px; background: var(--navy-deep); box-shadow: 0 22px 70px rgba(0,0,0,.4); }
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 13px 16px; border-bottom: 1px solid rgba(15,216,224,.16); background: var(--navy); }
.viewer-head h2 { max-width: 65vw; margin: 0; overflow: hidden; font: 500 1rem var(--font-serif); text-overflow: ellipsis; white-space: nowrap; }
.viewer-actions { display: flex; gap: 8px; }
.viewer-actions a, .viewer-actions button { padding: 7px 12px; font-size: .68rem; }
.viewer-actions button { color: #fff; background: rgba(255,255,255,.1); }
.viewer-loading { grid-row: 2; display: grid; place-items: center; color: var(--cyan-soft); font: .72rem var(--font-hud); }
.viewer iframe { grid-row: 2; width: 100%; height: 100%; border: 0; opacity: 0; background: #252a2e; }
.viewer iframe.ready { opacity: 1; }

.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; }

@media (max-width: 760px) {
  .site-header, main { width: min(100% - 28px,1380px); }
  .site-header { padding: 20px 0; }
  .brand a { font-size: 1.45rem; }
  .home-link { font-size: .6rem; }
  main { padding-top: 36px; }
  .toolbar { align-items: stretch; flex-direction: column; padding: 9px; }
  .search { flex-basis: auto; width: 100%; }
  .library-tools { width: 100%; margin-left: 0; justify-content: space-between; }
  .filters { flex-wrap: nowrap; padding-bottom: 4px; }
  .viewer-shell { width: 100%; height: 100%; margin: 0; border: 0; border-radius: 0; }
  .viewer-head { padding: 12px; }
  .viewer-actions a { display: none; }
  .viewer-head h2 { max-width: 60vw; }
}

@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
