:root {
  --bg: #121214;
  --bg-2: #1b1b1f;
  --bg-3: #26262c;
  --line: #34343c;
  --text: #f4f4f6;
  --muted: #a7a7b3;
  --accent: #ff4d2e;
  --accent-2: #ff8a3d;
  --ok: #3ddc84;
  --warn: #ffb020;
  --star: #ffc83d;
  --radius: 10px;
  --cover-w: 150px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column; }
a { color: inherit; }
button { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; border-radius: 4px; }

/* ---------- topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 12px clamp(16px, 4vw, 48px);
  background: linear-gradient(180deg, rgba(10,10,12,.96), rgba(10,10,12,.82)); backdrop-filter: blur(8px); border-bottom: 1px solid rgba(255,255,255,.05); }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; white-space: nowrap; }
.logo-mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; font-weight: 900; font-size: 20px; color: #fff; }
.logo-text { font-size: 20px; letter-spacing: .2px; }
.logo-text b { color: var(--accent); }
.mainnav { display: flex; gap: 18px; align-items: center; }
.mainnav a, .linklike { text-decoration: none; color: var(--muted); font-weight: 600; background: none; border: 0; padding: 4px 0; cursor: pointer; }
.mainnav a:hover, .linklike:hover, .mainnav a.active { color: var(--text); }
.mainnav a.active { box-shadow: inset 0 -2px 0 var(--accent); }
.searchbox { margin-left: auto; display: flex; background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; width: min(340px, 40vw); }
.searchbox input { flex: 1; min-width: 0; background: transparent; border: 0; color: var(--text); padding: 9px 14px; font-size: 15px; }
.searchbox input:focus { outline: none; }
.searchbox:focus-within { border-color: var(--accent-2); }
.searchbox button { background: none; border: 0; padding: 0 14px; cursor: pointer; }

main { flex: 1; outline: none; }
.loading { display: grid; place-items: center; padding: 120px 0; color: var(--muted); }
.spinner { width: 42px; height: 42px; border: 4px solid var(--bg-3); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- hero ---------- */
.hero { position: relative; min-height: 420px; display: flex; align-items: flex-end; padding: 40px clamp(16px, 4vw, 48px) 56px; overflow: hidden; }
.hero-bg { position: absolute; inset: 0; background: radial-gradient(1200px 500px at 75% 30%, var(--hero-color, #ff4d2e) 0%, transparent 60%), linear-gradient(90deg, var(--bg) 25%, transparent 80%); opacity: .55; }
.hero::after { content: ""; position: absolute; inset: auto 0 0 0; height: 120px; background: linear-gradient(transparent, var(--bg)); }
.hero-inner { position: relative; z-index: 1; display: flex; gap: 40px; align-items: center; width: 100%; }
.hero-text { max-width: 640px; }
.hero-kicker { display: inline-flex; gap: 8px; align-items: center; text-transform: uppercase; letter-spacing: 1.5px; font-size: 13px; font-weight: 800; color: #fff; background: rgba(0,0,0,.35); padding: 5px 12px; border-radius: 999px; }
.hero h1 { font-size: clamp(30px, 5vw, 56px); line-height: 1.05; margin: 14px 0 8px; }
.hero .hero-book { font-size: 18px; color: #ddd; margin: 0 0 6px; }
.hero p.summary { color: #d8d8de; max-width: 560px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.hero-actions { display: flex; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.hero-cover { margin-left: auto; width: 210px; flex: none; transform: rotate(3deg); box-shadow: var(--shadow); border-radius: 8px; overflow: hidden; }
.btn { display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 8px; padding: 11px 20px; font-weight: 700; cursor: pointer; text-decoration: none; font-size: 15px; }
.btn-primary { background: #fff; color: #111; }
.btn-primary:hover { background: #e6e6e6; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(1.1); }
.btn-ghost { background: rgba(120,120,130,.35); color: #fff; }
.btn-ghost:hover { background: rgba(120,120,130,.5); }
.btn-small { padding: 7px 12px; font-size: 14px; }

.welcome { padding: 0 clamp(16px, 4vw, 48px); margin: -20px 0 10px; color: var(--muted); position: relative; z-index: 2; }

/* ---------- rows ---------- */
.row { margin: 26px 0 8px; }
.row-head { display: flex; align-items: baseline; gap: 12px; padding: 0 clamp(16px, 4vw, 48px); }
.row-head h2 { font-size: 21px; margin: 0; }
.row-head .sub { color: var(--muted); font-size: 14px; }
.row-head a { margin-left: auto; font-size: 14px; color: var(--accent-2); text-decoration: none; font-weight: 700; white-space: nowrap; }
.row-wrap { position: relative; }
.row-track { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x proximity; scroll-padding-inline: clamp(16px, 4vw, 48px); padding: 14px clamp(16px, 4vw, 48px) 18px; scrollbar-width: none; }
.row-track::-webkit-scrollbar { display: none; }
.row-arrow { position: absolute; top: 14px; bottom: 18px; width: 44px; border: 0; background: rgba(10,10,12,.65); color: #fff; font-size: 28px; cursor: pointer; z-index: 3; opacity: 0; transition: opacity .2s; }
.row-wrap:hover .row-arrow { opacity: 1; }
.row-arrow.left { left: 0; border-radius: 0 8px 8px 0; }
.row-arrow.right { right: 0; border-radius: 8px 0 0 8px; }
.row-empty { padding: 10px clamp(16px, 4vw, 48px); color: var(--muted); }

/* ---------- book card ---------- */
.card { flex: none; width: var(--cover-w); scroll-snap-align: start; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; transition: transform .18s ease; position: relative; }
.card:hover, .card:focus-visible { transform: scale(1.07); z-index: 2; }
.card .cover { box-shadow: 0 6px 16px rgba(0,0,0,.4); }
.card-title { font-size: 14px; font-weight: 700; margin-top: 8px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badges { position: absolute; top: 6px; left: 6px; right: 6px; display: flex; justify-content: space-between; pointer-events: none; }
.badge { font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 6px; background: rgba(0,0,0,.72); color: #fff; }
.badge.avi { background: var(--accent); }
.badge.out { background: rgba(0,0,0,.75); color: var(--warn); }
.badge.stars { color: var(--star); }
.rank { position: absolute; left: -10px; bottom: 40px; font-size: 64px; font-weight: 900; color: var(--bg); -webkit-text-stroke: 2px #888; line-height: 1; z-index: -1; }

/* cover */
.cover { position: relative; aspect-ratio: 2 / 3; border-radius: 7px; overflow: hidden; background: var(--bg-3); }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover .fallback { position: absolute; inset: 0; padding: 14px 12px; display: flex; flex-direction: column; justify-content: space-between;
  background: linear-gradient(160deg, hsl(var(--h) 70% 52%), hsl(calc(var(--h) + 40) 65% 28%)); color: #fff; }
.cover .fallback::before { content: ""; position: absolute; left: 7px; top: 0; bottom: 0; width: 3px; background: rgba(255,255,255,.25); }
.cover .fb-title { font-weight: 900; font-size: 17px; line-height: 1.12; text-shadow: 0 2px 6px rgba(0,0,0,.3); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.cover .fb-author { font-size: 12px; opacity: .9; font-weight: 600; }
.cover.loaded .fallback { display: none; }

/* ---------- search page ---------- */
.page { padding: 24px clamp(16px, 4vw, 48px) 40px; }
.page h1 { margin: 6px 0 4px; font-size: 30px; }
.search-layout { display: grid; grid-template-columns: 250px 1fr; gap: 28px; margin-top: 18px; }
.filters { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; align-self: start; position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.filters h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 16px 0 8px; }
.filters h3:first-child { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg-3); color: var(--text); padding: 4px 10px; border-radius: 999px; font-size: 13px; cursor: pointer; text-decoration: none; }
.chip:hover { border-color: var(--muted); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip small { color: var(--muted); }
.chip.on small { color: #ffe0d8; }
.filters select, .filters input[type=number], .field { width: 100%; background: var(--bg-3); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.results-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.results-head .count { color: var(--muted); }
.results-head select { margin-left: auto; background: var(--bg-3); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.active-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 22px 16px; }
.grid .card { width: auto; }
.more { display: flex; justify-content: center; margin: 28px 0 0; }
.big-search { display: flex; gap: 10px; margin-top: 10px; max-width: 720px; }
.big-search input { flex: 1; font-size: 18px; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-3); color: var(--text); }
.big-search input:focus { outline: 2px solid var(--accent-2); }
.filter-toggle { display: none; }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }
.empty .big { font-size: 48px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: start center; overflow-y: auto; padding: 40px 16px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.72); }
.modal-card { position: relative; width: min(920px, 100%); background: var(--bg-2); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; animation: pop .2s ease; }
@keyframes pop { from { transform: translateY(14px) scale(.98); opacity: 0; } }
.modal-close { position: absolute; right: 12px; top: 12px; z-index: 3; width: 38px; height: 38px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); cursor: pointer; font-size: 17px; }
.detail-top { display: grid; grid-template-columns: 230px 1fr; gap: 28px; padding: 30px; background: linear-gradient(135deg, hsl(var(--h) 55% 22%), var(--bg-2) 70%); }
.detail-top h2 { margin: 0 0 4px; font-size: 30px; line-height: 1.15; }
.detail-author { font-size: 17px; color: #ddd; margin-bottom: 10px; }
.detail-author a { color: inherit; }
.facts { display: flex; flex-wrap: wrap; gap: 8px 16px; color: var(--muted); font-size: 14px; margin: 10px 0; }
.facts b { color: var(--text); font-weight: 600; }
.avail { display: inline-flex; gap: 6px; align-items: center; font-weight: 700; font-size: 14px; padding: 5px 10px; border-radius: 8px; background: rgba(61,220,132,.13); color: var(--ok); }
.avail.out { background: rgba(255,176,32,.13); color: var(--warn); }
.detail-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.detail-body { padding: 4px 30px 30px; }
.detail-body h3 { font-size: 18px; margin: 24px 0 10px; }
.rating-line { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.stars { color: var(--star); letter-spacing: 2px; }
.stars .off { color: #4a4a52; }
.review { background: var(--bg-3); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.review-head { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.review-head .who { font-weight: 700; }
.review-head .when { color: var(--muted); margin-left: auto; font-size: 12.5px; }
.review p { margin: 6px 0 0; white-space: pre-line; }
.review-form { background: var(--bg-3); border-radius: 12px; padding: 16px; display: grid; gap: 12px; }
.review-form .two { display: grid; grid-template-columns: 1fr 140px; gap: 10px; }
.review-form textarea { min-height: 90px; resize: vertical; font-family: inherit; }
.star-input { display: flex; gap: 4px; font-size: 32px; }
.star-input button { background: none; border: 0; cursor: pointer; color: #4a4a52; padding: 0 2px; line-height: 1; transition: transform .1s; }
.star-input button.on { color: var(--star); }
.star-input button:hover { transform: scale(1.15); }
.notice { padding: 10px 14px; border-radius: 8px; background: rgba(61,220,132,.13); color: var(--ok); font-weight: 600; }
.notice.err { background: rgba(255,77,46,.15); color: #ff8b76; }
.hp { position: absolute; left: -5000px; }
.detail-row .row-head, .detail-row .row-track { padding-left: 0; padding-right: 0; }

/* ---------- footer ---------- */
.footer { padding: 30px clamp(16px, 4vw, 48px); color: var(--muted); font-size: 14px; border-top: 1px solid var(--line); margin-top: 30px; }
.footer p { margin: 4px 0; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 10px 18px; }
  .searchbox { order: 3; width: 100%; }
  .mainnav { gap: 14px; font-size: 14px; }
  .hero { min-height: 0; padding-top: 22px; padding-bottom: 40px; }
  .hero-inner { flex-direction: column-reverse; align-items: flex-start; gap: 16px; }
  .hero-cover { margin-left: 0; width: 120px; transform: rotate(-2deg); }
  .hero h1 { margin-top: 10px; }
  .row-head .sub { display: none; }
  .row-head h2 { font-size: 18px; }
  .search-layout { grid-template-columns: 1fr; }
  .filters { position: static; max-height: none; display: none; }
  .filters.open { display: block; }
  .filter-toggle { display: inline-flex; }
  .detail-top { grid-template-columns: 130px 1fr; gap: 18px; padding: 22px 18px; }
  .detail-top h2 { font-size: 23px; }
  .detail-body { padding: 4px 18px 22px; }
  :root { --cover-w: 118px; }
}
@media (max-width: 520px) {
  .logo-text { font-size: 17px; }
  .mainnav { gap: 12px; }
  .mainnav #surprise .lbl { display: none; }
  .detail-top { grid-template-columns: 1fr; }
  .detail-top .cover { width: 150px; }
  .review-form .two { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
