:root {
  --paper: #f7f2e9;
  --paper-2: #efe7d8;
  --card: #fffdf8;
  --ink: #1f1b16;
  --ink-2: #5a5148;
  --line: #e0d6c4;
  --green: #2f5d50;
  --green-dark: #234840;
  --rust: #b8553a;
  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --shadow: 0 1px 2px rgba(31, 27, 22, 0.06), 0 6px 20px rgba(31, 27, 22, 0.08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0 0 0.5rem; }
h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); letter-spacing: -0.01em; }
h2 { font-size: clamp(1.6rem, 3vw, 2.1rem); }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1rem; }
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
.container { width: min(1120px, 100% - 2.5rem); margin-inline: auto; }
.container.narrow { width: min(720px, 100% - 2.5rem); }
.muted { color: var(--ink-2); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.75rem; font-weight: 600; color: var(--rust); margin-bottom: 0.6rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.75rem 1.3rem; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; text-decoration: none; transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { background: #9aa9a3; cursor: not-allowed; }
.btn-ghost { border-color: var(--ink); background: transparent; }
.btn-ghost:hover { background: var(--ink); color: var(--paper); }
.btn.full { width: 100%; }
:focus-visible { outline: 3px solid var(--rust); outline-offset: 2px; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(247, 242, 233, 0.9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; gap: 2rem; height: 64px; }
.logo { display: inline-flex; align-items: center; gap: 0.55rem; font: 700 1.35rem var(--serif); text-decoration: none; white-space: nowrap; }
.logo.small { font-size: 1.1rem; }
.logo-mark {
  width: 22px; height: 26px; background: var(--green); border-radius: 2px 3px 3px 2px; position: relative;
  clip-path: polygon(0 0, 65% 0, 100% 30%, 100% 100%, 0 100%);
}
.logo-mark::after {
  content: ""; position: absolute; top: 0; right: 0; width: 35%; height: 30%;
  background: var(--rust); clip-path: polygon(0 0, 0 100%, 100% 100%);
}
.nav { display: flex; gap: 1.5rem; margin-left: auto; }
.nav a { text-decoration: none; color: var(--ink-2); font-weight: 500; }
.nav a:hover { color: var(--ink); }
.bag-btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  border: 1px solid var(--ink); background: transparent; border-radius: 999px; padding: 0.45rem 0.9rem; font-weight: 600;
}
.bag-btn:hover { background: var(--ink); color: var(--paper); }
.header-actions { display: flex; align-items: center; gap: 0.5rem; }
.account-btn { border-color: var(--line); }
.bag-count {
  min-width: 1.4rem; height: 1.4rem; border-radius: 999px; background: var(--rust); color: #fff;
  font-size: 0.8rem; display: inline-grid; place-items: center; padding: 0 0.35rem;
}
.bag-count.bump { animation: bump 0.35s ease; }
@keyframes bump { 50% { transform: scale(1.35); } }

/* Hero */
.hero { padding: 4.5rem 0 3.5rem; }
.hero-inner { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 3rem; align-items: center; }
.lede { font-size: 1.15rem; color: var(--ink-2); max-width: 34rem; }
.hero-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.5rem; }
.hero-art { display: flex; justify-content: center; }
.stack { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stack-book {
  height: 46px; border-radius: 4px; display: flex; align-items: center; justify-content: center;
  color: rgba(255, 255, 255, 0.92); font: 600 0.95rem var(--serif); letter-spacing: 0.02em; box-shadow: var(--shadow);
}
.stack-book span { border-top: 1px solid rgba(255,255,255,.35); border-bottom: 1px solid rgba(255,255,255,.35); padding: 2px 10px; }
.b1 { width: 300px; background: #2f4a6d; transform: rotate(-2deg) translateX(-10px); }
.b2 { width: 260px; background: #8a3b32; transform: rotate(1deg) translateX(14px); }
.b3 { width: 320px; background: #2b2b2b; height: 54px; }
.b4 { width: 280px; background: var(--green); transform: rotate(-1deg) translateX(-6px); }

/* Sections */
.section { padding: 4.5rem 0; scroll-margin-top: 64px; }
.section.alt { background: var(--paper-2); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.section-head p { margin: 0; }

/* Toolbar */
.toolbar { display: flex; gap: 0.75rem; margin-bottom: 0.9rem; }
.search { flex: 1; }
.search input, .sort select {
  width: 100%; padding: 0.75rem 1rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); font: inherit; color: var(--ink);
}
.search input:focus, .sort select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(47, 93, 80, 0.18); }
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 2rem; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 0.4rem 0.9rem; font-size: 0.9rem; font-weight: 500;
}
.chip:hover { border-color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* Book grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 2rem 1.5rem; }
.book { display: flex; flex-direction: column; text-align: left; background: none; border: 0; padding: 0; }
.book:hover .cover { transform: translateY(-4px) rotate(-0.5deg); box-shadow: 0 10px 28px rgba(31, 27, 22, 0.2); }
.book-title { font: 600 1.02rem/1.25 var(--serif); margin-top: 0.85rem; }
.book-author { color: var(--ink-2); font-size: 0.9rem; }
.book-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 0.4rem; font-size: 0.85rem; }
.price { font-weight: 600; }
.status { color: var(--green); font-weight: 500; }
.status.out { color: var(--rust); }
.empty { text-align: center; padding: 3rem 0; color: var(--ink-2); }

/* Generated covers */
.cover {
  aspect-ratio: 2 / 3; width: 100%; border-radius: 3px 8px 8px 3px; position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between; padding: 1.1rem 0.9rem 1rem 1.3rem;
  color: var(--fg, #fff); background: var(--bg); box-shadow: var(--shadow); transition: transform 0.2s, box-shadow 0.2s;
}
.cover::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 8px;
  background: linear-gradient(90deg, rgba(0,0,0,.28), rgba(0,0,0,.05) 60%, rgba(255,255,255,.12));
}
.cover::after {
  content: ""; position: absolute; left: 1.3rem; right: 0.9rem; top: 50%; height: 2px; background: var(--accent); opacity: 0.85;
}
.cover-title { font: 600 1.15rem/1.15 var(--serif); text-wrap: balance; }
.cover-author { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em; opacity: 0.85; }
.cover.out { filter: grayscale(0.55) brightness(0.92); }
.cover.big { max-width: 260px; }
.cover.big .cover-title { font-size: 1.6rem; }
.cover.tiny { width: 52px; padding: 0.35rem 0.3rem 0.35rem 0.45rem; border-radius: 2px 4px 4px 2px; }
.cover.tiny::before { width: 4px; }
.cover.tiny::after, .cover.tiny .cover-author { display: none; }
.cover.tiny .cover-title { font-size: 0.48rem; }

/* Steps */
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.steps li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.steps p { color: var(--ink-2); margin: 0; }
.step-num {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--green); color: #fff; font-weight: 700; margin-bottom: 0.9rem;
}

/* Plans */
.plans { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.plan { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.75rem; position: relative; }
.plan.featured { border: 2px solid var(--green); }
.plan .tag {
  position: absolute; top: -0.75rem; left: 1.5rem; background: var(--green); color: #fff;
  font-size: 0.75rem; font-weight: 600; padding: 0.15rem 0.6rem; border-radius: 999px;
}
.plan-price { font: 700 2.4rem var(--serif); margin: 0.25rem 0; }
.plan-price small { font: 500 0.95rem var(--sans); color: var(--ink-2); }
.plan p { color: var(--ink-2); margin: 0; }
.fineprint { margin-top: 1.25rem; color: var(--ink-2); font-size: 0.92rem; }

/* FAQ */
details { border-bottom: 1px solid var(--line); padding: 1rem 0; }
details:first-of-type { border-top: 1px solid var(--line); }
summary { font-weight: 600; cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 1rem; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; font-size: 1.3rem; line-height: 1; color: var(--ink-2); }
details[open] summary::after { content: "−"; }
details p { margin: 0.75rem 0 0; color: var(--ink-2); }

/* Footer */
.site-footer { padding: 2rem 0; border-top: 1px solid var(--line); }
.footer-inner { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; font-size: 0.9rem; }

/* Modal */
.modal {
  border: 0; border-radius: 16px; padding: 0; background: var(--paper); color: var(--ink);
  width: min(820px, 100% - 2rem); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.modal.small { width: min(460px, 100% - 2rem); }
.modal::backdrop { background: rgba(31, 27, 22, 0.5); }
.modal-body { padding: 2rem; }
.modal-close {
  position: absolute; top: 0.75rem; right: 0.75rem; width: 2.2rem; height: 2.2rem; border-radius: 50%;
  border: 0; background: transparent; font-size: 1.6rem; line-height: 1; color: var(--ink-2);
}
.modal-close.static { position: static; }
.modal-close:hover { background: var(--paper-2); color: var(--ink); }
.book-detail { display: grid; grid-template-columns: 240px 1fr; gap: 2rem; }
.detail-copy h2 { margin-bottom: 0.2rem; }
.author { font-size: 1.05rem; margin-bottom: 0.25rem; }
.meta { font-size: 0.9rem; }
.durations { border: 0; padding: 0; margin: 1.25rem 0 0.5rem; display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.durations legend { font-weight: 600; margin-bottom: 0.6rem; padding: 0; }
.duration { position: relative; }
.duration input { position: absolute; opacity: 0; }
.duration span {
  display: block; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 0.6rem; text-align: center; cursor: pointer;
}
.duration strong { display: block; }
.duration small { color: var(--ink-2); }
.duration input:checked + span { border: 2px solid var(--green); padding: calc(0.6rem - 1px); background: #eef3f0; }
.duration input:focus-visible + span { outline: 3px solid var(--rust); outline-offset: 2px; }
.due { font-size: 0.9rem; margin-bottom: 1rem; }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgba(31, 27, 22, 0.45); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); z-index: 50; background: var(--paper);
  display: flex; flex-direction: column; transform: translateX(100%); transition: transform 0.25s ease; box-shadow: -10px 0 40px rgba(0,0,0,.15);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 1.4rem; }
.drawer-items { flex: 1; overflow-y: auto; padding: 1rem 1.5rem; }
.drawer-empty { text-align: center; color: var(--ink-2); padding: 3rem 1rem; }
.bag-item { display: grid; grid-template-columns: 52px 1fr auto; gap: 0.9rem; padding: 0.9rem 0; border-bottom: 1px solid var(--line); align-items: start; }
.bag-item h3 { font-size: 0.98rem; margin: 0; }
.bag-item p { margin: 0; font-size: 0.85rem; color: var(--ink-2); }
.bag-item select { margin-top: 0.4rem; padding: 0.3rem 0.4rem; border-radius: 6px; border: 1px solid var(--line); background: var(--card); font: inherit; font-size: 0.85rem; }
.bag-item-right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 0.4rem; }
.remove { border: 0; background: none; color: var(--rust); font-size: 0.82rem; padding: 0; text-decoration: underline; }
.drawer-foot { padding: 1.25rem 1.5rem; border-top: 1px solid var(--line); background: var(--card); }
.row { display: flex; justify-content: space-between; margin-bottom: 0.35rem; }
.row.total { font-weight: 700; font-size: 1.1rem; margin: 0.75rem 0 1rem; padding-top: 0.75rem; border-top: 1px solid var(--line); }
.hint { font-size: 0.82rem; color: var(--green); margin: 0.2rem 0 0; }

/* Checkout */
.summary { list-style: none; padding: 0; margin: 1rem 0 0; }
.summary li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); font-size: 0.93rem; }
.summary li span:first-child small { display: block; color: var(--ink-2); }
.notice { background: #fbeee6; border: 1px solid #efcdbd; border-radius: 10px; padding: 0.75rem 0.9rem; font-size: 0.9rem; }

/* Forms (sign in, create account) */
.form { display: grid; gap: 0.9rem; margin-top: 1.25rem; }
.field { display: grid; gap: 0.3rem; font-size: 0.9rem; font-weight: 600; }
.field input {
  width: 100%; padding: 0.7rem 0.9rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); font: inherit; font-size: 1rem; font-weight: 400; color: var(--ink);
}
.field input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(47, 93, 80, 0.18); }
.form-error { margin: 0; color: var(--rust); font-size: 0.9rem; }
.auth-links { display: flex; flex-direction: column; align-items: flex-start; gap: 0.4rem; margin-top: 1.1rem; }
.link-btn { border: 0; background: none; padding: 0; color: var(--green); font-size: 0.92rem; font-weight: 600; text-decoration: underline; }
.link-btn:hover { color: var(--green-dark); }

/* Checkout and account */
.checkout-error { margin: 0 0 0.75rem; }
.account-sub { font-size: 1.1rem; margin: 1.5rem 0 0; }
#account-rentals { margin-bottom: 1.25rem; }
#account-rentals > p { margin: 0.6rem 0 0; }
.rental-due { color: var(--ink-2); white-space: nowrap; }
.extend-btn { display: block; margin-top: 0.3rem; font-size: 0.85rem; text-align: left; }
.extend-btn:disabled { color: var(--ink-2); text-decoration: none; cursor: default; }

/* Admin page */
.admin-tag {
  font: 700 0.65rem var(--sans); text-transform: uppercase; letter-spacing: 0.1em;
  background: var(--rust); color: #fff; padding: 0.2rem 0.5rem; border-radius: 999px;
}
.admin-main { padding: 2rem 0 4rem; }
.admin-tabs { margin-bottom: 1.25rem; }
.tab-count:not(:empty) {
  display: inline-grid; place-items: center; min-width: 1.3rem; height: 1.3rem; padding: 0 0.3rem; margin-left: 0.25rem;
  border-radius: 999px; background: var(--rust); color: #fff; font-size: 0.75rem;
}
.admin-intro { max-width: 46rem; margin-bottom: 1.25rem; }
.admin-empty { color: var(--ink-2); padding: 1.5rem 0; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.admin-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem;
  display: flex; flex-direction: column; gap: 0.75rem;
}
.admin-card h3 { margin: 0; }
.admin-card p { margin: 0; }
.text-small { font-size: 0.85rem; }
.address { font-size: 0.93rem; }
.admin-books { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.admin-books li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0; border-bottom: 1px solid var(--line); font-size: 0.93rem; }
.review-reason { background: #fbeee6; border: 1px solid #efcdbd; border-radius: 10px; padding: 0.6rem 0.8rem; font-size: 0.9rem; }
.admin-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.btn.small { padding: 0.4rem 0.85rem; font-size: 0.85rem; }
.btn-danger { border-color: var(--rust); color: var(--rust); background: transparent; }
.btn-danger:hover, .btn-danger.confirming { background: var(--rust); color: #fff; }
.admin-table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.admin-table th, .admin-table td { text-align: left; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.admin-table th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); white-space: nowrap; }
.admin-table tr:last-child td { border-bottom: 0; }
.overdue { color: var(--rust); font-weight: 600; }
.num-input { width: 4rem; padding: 0.35rem 0.5rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); font: inherit; }
.admin-form {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.9rem; margin-top: 1.5rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem;
}
.admin-form h3 { margin: 0; }
.admin-form .wide { grid-column: 1 / -1; }
.field textarea {
  width: 100%; padding: 0.7rem 0.9rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper); font: inherit; font-size: 1rem; font-weight: 400; color: var(--ink); resize: vertical;
}
.admin-link { margin-bottom: 0.6rem; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 150%); background: var(--ink); color: var(--paper);
  padding: 0.7rem 1.1rem; border-radius: 999px; font-size: 0.92rem; z-index: 60; pointer-events: none;
  opacity: 0; visibility: hidden; transition: transform 0.25s ease, opacity 0.25s ease, visibility 0.25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

/* Responsive */
@media (max-width: 860px) {
  .nav { display: none; }
  .header-inner { justify-content: space-between; }
  .hero { padding-top: 3rem; }
  .hero-inner { grid-template-columns: 1fr; }
  .hero-art { display: none; }
  .steps, .plans { grid-template-columns: 1fr; }
  .book-detail { grid-template-columns: 1fr; }
  .cover.big { max-width: 180px; }
}
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 1.5rem 1rem; }
  .toolbar { flex-direction: column; }
  .modal-body { padding: 1.5rem; }
  .durations { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
