:root {
  --paper: #f3ecdf;
  --paper-2: #faf6ee;
  --ink: #1f2928;
  --muted: #6f746e;
  --line: rgba(31, 41, 40, 0.14);
  --accent: #b55238;
  --accent-dark: #8e3d29;
  --shadow: 0 18px 45px rgba(49, 39, 27, 0.10);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, rgba(181, 82, 56, 0.08), transparent 26rem),
    linear-gradient(180deg, var(--paper-2), var(--paper));
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.topbar {
  width: min(1160px, calc(100% - 40px));
  margin: 0 auto;
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.wordmark {
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 11px;
  font-weight: 760;
  letter-spacing: -0.02em;
}
.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 15px 15px 6px 6px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--paper-2);
  font: 700 25px/1 Georgia, serif;
  box-shadow: inset -5px 0 rgba(255,255,255,0.08);
}
.brand-mark.small { width: 34px; height: 34px; border-radius: 9px 9px 4px 4px; font-size: 17px; }
.top-actions { display: flex; gap: 8px; }

.hero {
  width: min(900px, calc(100% - 40px));
  margin: 86px auto 54px;
  text-align: center;
}
.eyebrow {
  margin: 0 0 9px;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}
.hero h1, .auth-card h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.8rem, 7vw, 5.5rem);
  font-weight: 500;
  letter-spacing: -0.055em;
  line-height: 0.96;
}
.hero > p:not(.eyebrow) {
  width: min(670px, 100%);
  margin: 20px auto 30px;
  color: var(--muted);
  font-size: 1.06rem;
  line-height: 1.6;
}
.search-wrap {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 15px 0 19px;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(31,41,40,0.18);
  border-radius: 17px;
  box-shadow: var(--shadow);
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.search-wrap:focus-within {
  border-color: rgba(181,82,56,0.55);
  box-shadow: 0 21px 52px rgba(49,39,27,.13);
  transform: translateY(-1px);
}
.search-wrap svg { width: 22px; height: 22px; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.search-wrap input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 1.02rem; }
.search-wrap input::placeholder { color: #99998f; }
kbd { background: #eee7da; border: 1px solid rgba(31,41,40,.1); border-radius: 7px; padding: 4px 7px; color: var(--muted); font-size: .72rem; box-shadow: 0 1px 0 white inset; }

.shelf-toolbar {
  width: min(1160px, calc(100% - 40px));
  margin: 0 auto 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.stats { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.stats strong { color: var(--ink); }
.filters { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.filter {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: .86rem;
}
.filter:hover { background: rgba(255,255,255,.6); color: var(--ink); }
.filter.active { background: var(--ink); color: white; }

.book-grid {
  width: min(1160px, calc(100% - 40px));
  margin: 0 auto 100px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 22px;
  align-items: stretch;
}
.book-card {
  --book-hue: 18;
  position: relative;
  min-height: 302px;
  padding: 25px 22px 20px 25px;
  border: 0;
  border-radius: 8px 16px 16px 8px;
  text-align: left;
  cursor: pointer;
  color: #fffaf0;
  background:
    linear-gradient(90deg, rgba(0,0,0,.18), rgba(255,255,255,.04) 12%, transparent 20%),
    hsl(var(--book-hue) 34% 33%);
  box-shadow: 0 12px 22px rgba(39,32,24,.14), inset -4px 0 rgba(255,255,255,.08);
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
}
.book-card::before {
  content: "";
  position: absolute;
  inset: 9px auto 9px 10px;
  width: 1px;
  background: rgba(255,255,255,.2);
}
.book-card:hover { transform: translateY(-5px) rotate(-.25deg); box-shadow: 0 18px 34px rgba(39,32,24,.20); }
.book-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.book-card .status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 999px;
  background: rgba(255,255,255,.09);
  color: rgba(255,255,255,.88);
  font-size: .67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.book-card h2 {
  margin: 23px 0 7px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -.025em;
}
.book-card .author { margin: 0; color: rgba(255,255,255,.74); font-size: .88rem; }
.book-card .thought-preview {
  margin: 27px 0 0;
  color: rgba(255,255,255,.78);
  font-family: Georgia, "Times New Roman", serif;
  font-size: .88rem;
  line-height: 1.48;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-card .card-foot {
  position: absolute;
  left: 25px;
  right: 20px;
  bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: rgba(255,255,255,.82);
  font-size: .78rem;
}
.stars { letter-spacing: 1px; }

.button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 9px 15px;
  background: rgba(255,255,255,.52);
  cursor: pointer;
  font-weight: 700;
  transition: transform .15s, background .15s, border-color .15s;
}
.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--ink); border-color: var(--ink); color: white; }
.button.primary:hover { background: #101918; }
.button.ghost:hover { background: rgba(255,255,255,.85); }
.button.danger { color: #9d372b; border-color: rgba(157,55,43,.25); background: rgba(157,55,43,.05); }
.button.compact { min-height: 38px; padding: 7px 12px; font-size: .86rem; }
.button.wide { width: 100%; }

.empty {
  width: min(650px, calc(100% - 40px));
  margin: 72px auto 110px;
  text-align: center;
  color: var(--muted);
}
.empty h2 { margin: 18px 0 8px; color: var(--ink); font-family: Georgia, serif; font-size: 1.8rem; font-weight: 500; }
.empty p { margin: 0 auto 22px; line-height: 1.55; }
.empty-stack { height: 54px; width: 76px; margin: 0 auto; position: relative; }
.empty-stack span { position: absolute; left: 0; right: 0; height: 14px; border-radius: 3px 7px 7px 3px; background: var(--ink); }
.empty-stack span:nth-child(1) { top: 0; transform: rotate(-5deg); background: #9c5a45; }
.empty-stack span:nth-child(2) { top: 19px; transform: rotate(3deg); background: #526b63; }
.empty-stack span:nth-child(3) { top: 38px; transform: rotate(-2deg); background: #514a63; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 30px; }
.auth-card {
  width: min(470px, 100%);
  padding: 48px;
  background: rgba(255,255,255,.58);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  text-align: center;
  backdrop-filter: blur(14px);
}
.auth-card .brand-mark { margin: 0 auto 25px; }
.auth-card h1 { font-size: clamp(2.6rem, 10vw, 4.2rem); }
.auth-card .lede { margin: 18px auto 28px; color: var(--muted); line-height: 1.55; }
.auth-card form { text-align: left; }
.auth-card form label { display: block; margin-bottom: 7px; font-weight: 700; font-size: .85rem; }
.auth-card form input { width: 100%; margin-bottom: 10px; text-align: center; letter-spacing: .18em; font-size: 1.35rem; }
.auth-card form .button { margin-top: 6px; }

input, textarea, select {
  width: 100%;
  border: 1px solid rgba(31,41,40,.17);
  border-radius: 10px;
  background: rgba(255,255,255,.72);
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { border-color: rgba(181,82,56,.65); box-shadow: 0 0 0 3px rgba(181,82,56,.10); }
textarea { resize: vertical; line-height: 1.5; }

#bookDialog {
  width: min(720px, calc(100% - 24px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid rgba(31,41,40,.18);
  border-radius: 20px;
  background: #f8f2e8;
  box-shadow: 0 30px 90px rgba(25,23,19,.3);
  color: var(--ink);
}
#bookDialog::backdrop { background: rgba(28,28,24,.42); backdrop-filter: blur(4px); }
.book-form { padding: 28px; }
.dialog-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 24px; }
.dialog-head h2 { margin: 0; font: 500 2rem/1 Georgia, serif; letter-spacing: -.025em; }
.icon-button { width: 37px; height: 37px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.5); cursor: pointer; font-size: 1.4rem; line-height: 1; }
.field-grid { display: grid; gap: 15px; }
.field-grid.two { grid-template-columns: 1fr 1fr; }
.field.span-2 { grid-column: span 2; }
.field label { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-size: .82rem; font-weight: 750; }
.field label span { color: var(--muted); font-weight: 500; }
.dialog-actions { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.message { min-height: 1.3em; margin: 12px 0 0; color: var(--muted); font-size: .84rem; }
.message.error { color: #9d372b; }

@media (max-width: 700px) {
  .topbar { width: min(100% - 24px, 1160px); min-height: 68px; }
  .wordmark > span:last-child { display: none; }
  .hero { margin-top: 58px; width: min(100% - 24px, 900px); }
  .hero h1 { font-size: 3.45rem; }
  kbd { display: none; }
  .shelf-toolbar { width: min(100% - 24px, 1160px); align-items: flex-start; flex-direction: column; }
  .filters { justify-content: flex-start; }
  .book-grid { width: min(100% - 24px, 1160px); grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
  .book-card { min-height: 260px; padding: 19px 16px 16px 19px; }
  .book-card h2 { font-size: 1.25rem; margin-top: 18px; }
  .book-card .thought-preview { font-size: .82rem; margin-top: 19px; -webkit-line-clamp: 3; }
  .book-card .card-foot { left: 19px; right: 15px; bottom: 14px; }
  .auth-card { padding: 34px 24px; }
  .book-form { padding: 20px; }
  .field-grid.two { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: span 1; }
  .field label { display: block; }
  .field label span { display: block; margin-top: 2px; }
}

@media (max-width: 420px) {
  .book-grid { grid-template-columns: 1fr; }
  .book-card { min-height: 245px; }
  .top-actions .ghost { display: none; }
}
