:root {
  --bg: #f4efe7;
  --surface: #fbf8f3;
  --surface-2: #f0e9dd;
  --ink: #2c2620;
  --ink-soft: #6b6258;
  --accent: #b5651d;
  --accent-dark: #97501a;
  --line: #e4dccf;
  --shadow: 0 10px 30px rgba(60, 46, 28, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand-name {
  font-family: 'Fraunces', Georgia, serif;
  color: var(--ink);
  line-height: 1.15;
}

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 28px;
}

/* ---------------- Header ---------------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 70px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: var(--surface-2);
  border-radius: 9px;
  font-size: 18px;
}
.brand-mark.big { width: 52px; height: 52px; font-size: 26px; margin: 0 auto 6px; }
.brand-name { font-size: 22px; font-weight: 600; }

.nav { display: flex; align-items: center; gap: 22px; }
.nav-link {
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 15px;
}
.nav-link.active, .nav-link:hover { color: var(--ink); text-decoration: none; }
.nav-divider { width: 1px; height: 22px; background: var(--line); }
.nav-user {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 14px;
}
.logout-form { margin: 0; display: inline; }
.nav-button {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
}
.nav-button:hover { color: var(--ink); }

/* ---------------- Page head ---------------- */
.page-head { margin: 46px 0 26px; }
.page-head h1 { font-size: 46px; margin: 0 0 6px; font-weight: 600; }
.subtitle { color: var(--ink-soft); font-size: 17px; margin: 0; }

/* ---------------- Filters ---------------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-bottom: 34px;
}
.search {
  position: relative;
  flex: 1 1 360px;
}
.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.5;
  font-size: 14px;
}
.search input {
  width: 100%;
  padding: 14px 16px 14px 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font: inherit;
  color: var(--ink);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.genre-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 9px 16px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
}
.pill:hover { text-decoration: none; border-color: var(--accent); color: var(--ink); }
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------------- Book grid ---------------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 26px;
  padding-bottom: 60px;
}
.book-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.book-card:hover {
  text-decoration: none;
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}
.cover {
  position: relative;
  aspect-ratio: 3 / 4;
  background:
    radial-gradient(120% 100% at 50% 0%, rgba(255,255,255,0.18), transparent 60%),
    linear-gradient(160deg, color-mix(in srgb, var(--cover) 88%, #fff 12%), color-mix(in srgb, var(--cover) 70%, #000 30%));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
}
.cover-title {
  font-family: 'Fraunces', Georgia, serif;
  color: #fbf6ee;
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  letter-spacing: 0.5px;
}
.badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(251, 248, 243, 0.92);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 7px;
}
.cover-progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 5px;
  background: rgba(0,0,0,0.25);
}
.cover-progress span { display: block; height: 100%; background: var(--accent); }

.book-meta { padding: 18px 18px 20px; display: flex; flex-direction: column; flex: 1; }
.genre {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}
.book-title { font-size: 20px; margin: 8px 0 4px; font-weight: 600; }
.book-author { color: var(--ink-soft); margin: 0; font-size: 15px; }
.book-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  margin-top: 16px;
  color: var(--ink-soft);
  font-size: 13px;
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 12px 22px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--accent-dark); text-decoration: none; }
.btn.full { width: 100%; text-align: center; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--surface-2); }

/* ---------------- Empty states ---------------- */
.empty { color: var(--ink-soft); }
.empty-state { text-align: center; padding: 60px 0; }
.empty-state .empty { margin-bottom: 18px; }

/* ---------------- Auth ---------------- */
.auth-wrap { display: flex; justify-content: center; padding: 60px 0; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-card h1 { font-size: 28px; margin: 0 0 6px; }
.auth-form { text-align: left; margin-top: 24px; display: flex; flex-direction: column; gap: 16px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; color: var(--ink-soft); }
.auth-form input {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font: inherit;
  color: var(--ink);
}
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-form small { color: var(--ink-soft); font-weight: 400; }
.auth-alt { margin-top: 20px; font-size: 14px; color: var(--ink-soft); }
.alert {
  background: #fbe9e3;
  border: 1px solid #e7b9a8;
  color: #8a3d23;
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-top: 18px;
}

/* ---------------- Book detail ---------------- */
.back-link { display: inline-block; margin: 30px 0 18px; color: var(--ink-soft); font-size: 15px; }
.book-detail { display: grid; grid-template-columns: 280px 1fr; gap: 44px; padding-bottom: 60px; }
.detail-cover { border-radius: var(--radius); box-shadow: var(--shadow); }
.book-detail-body h1 { font-size: 38px; margin: 10px 0 4px; }
.book-detail-body .book-author { font-size: 17px; margin-bottom: 18px; }
.description { font-size: 17px; color: var(--ink); margin-bottom: 26px; max-width: 60ch; }
.chapters-heading { font-size: 22px; margin: 36px 0 14px; }
.chapter-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.chapter-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.chapter-list a {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 14px 6px;
  color: var(--ink);
}
.chapter-list a:hover { text-decoration: none; color: var(--accent-dark); }
.chapter-num { color: var(--accent); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; min-width: 90px; }
.chapter-title { font-size: 16px; }
.chip {
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 500;
}

/* ---------------- Reader ---------------- */
.reader { max-width: 720px; margin: 0 auto; padding-bottom: 80px; }
.reader-head { text-align: center; margin: 16px 0 36px; }
.reader-head h1 { font-size: 36px; margin: 8px 0; }
.reader-sub { color: var(--ink-soft); }
.reader-body { font-size: 19px; line-height: 1.85; }
.reader-body p { margin: 0 0 1.4em; }
.reader-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 48px; }

/* ---------------- Error ---------------- */
.error-page { text-align: center; padding: 90px 0; }
.error-page h1 { font-size: 72px; margin: 0; color: var(--accent); }

/* ---------------- Footer ---------------- */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 28px 0;
  color: var(--ink-soft);
  font-size: 14px;
  text-align: center;
}

@media (max-width: 760px) {
  .book-detail { grid-template-columns: 1fr; }
  .detail-cover { max-width: 240px; }
  .page-head h1 { font-size: 36px; }
}
