:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #2a2438;
  --muted: #6f6a7d;
  --border: #e5e0d8;
  --primary: #7c5cbf;
  --primary-contrast: #ffffff;
  --accent: #b08968;
  --star-fill: #e8a33d;
  --star-empty: #d8d3ca;
  --error-bg: #fdecec;
  --error-text: #a03030;
  --notice-bg: #e9f5ec;
  --notice-text: #256b3a;
  --shadow: 0 1px 3px rgba(42, 36, 56, .08), 0 4px 16px rgba(42, 36, 56, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17141f;
    --surface: #211d2c;
    --text: #ece8f4;
    --muted: #a49dbb;
    --border: #352f45;
    --primary: #a68be0;
    --primary-contrast: #17141f;
    --star-fill: #f0b45a;
    --star-empty: #453e58;
    --error-bg: #3a2226;
    --error-text: #f1a5a5;
    --notice-bg: #1f3327;
    --notice-text: #9fd8b0;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; }
.container { max-width: 1060px; margin: 0 auto; padding: 0 1.25rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* top bar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.nav { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav-search { flex: 1; max-width: 420px; }
.nav-search input, .big-search input {
  width: 100%; padding: .5rem .8rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: .95rem;
}
.nav-links { display: flex; align-items: center; gap: .9rem; margin-left: auto; white-space: nowrap; }
.nav-links a { color: var(--text); font-weight: 500; }
.inline { display: inline; }

/* buttons */
.btn {
  display: inline-block; padding: .45rem .9rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font-size: .9rem; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--primary); border-color: transparent; }
.btn-lg { padding: .7rem 1.4rem; font-size: 1.05rem; }
.btn-status.active { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }

/* loading states */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.is-loading::after {
  content: "";
  position: absolute; inset: 0; margin: auto;
  width: 14px; height: 14px;
  border: 2px solid var(--muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin .6s linear infinite;
}
.btn-primary.is-loading { background: var(--primary); }
.btn-primary.is-loading::after { border-color: var(--primary-contrast); border-top-color: transparent; }
@keyframes btn-spin { to { transform: rotate(360deg); } }
.stars-input.is-loading { opacity: .45; pointer-events: none; }
.dates-form.is-loading input { opacity: .6; pointer-events: none; }

/* art */
.logo-mark { width: 27px; height: 27px; }
.brand { display: inline-flex; align-items: center; gap: .5rem; }
.hero-art { max-width: 640px; margin: 0 auto 1rem; }
.hero-art svg { width: 100%; height: auto; display: block; }
.brand-icon { width: 30px; height: 30px; display: block; }
.hero-cat-img { width: 100%; max-width: 540px; height: auto; display: block; margin: 0 auto; }
@media (prefers-color-scheme: dark) {
  /* dark line art on transparency — invert so it reads on the dark theme */
  .hero-cat-img, .brand-icon { filter: invert(.92) hue-rotate(180deg); }
}
.empty-cat { width: 140px; height: auto; display: block; margin: 0 auto .4rem; }
.empty-with-art { text-align: center; padding: 1.6rem 1.2rem; }
.error-card .empty-cat { margin-bottom: .6rem; }

/* hero */
.hero { text-align: center; padding: 3rem 1rem 4rem; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); margin-bottom: 1rem; }
.hero-sub { max-width: 620px; margin: 0 auto 2rem; color: var(--muted); font-size: 1.1rem; }
.hero-actions { display: flex; gap: 1rem; justify-content: center; }

/* layout bits */
.page-title { margin: 1.5rem 0 1rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 2rem 0 .8rem; }
.section-head h2 { margin: 0; font-size: 1.2rem; }
.empty { color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: 10px; padding: 1.2rem; }
.error { background: var(--error-bg); color: var(--error-text); padding: .6rem .9rem; border-radius: 8px; }
.notice { background: var(--notice-bg); color: var(--notice-text); padding: .6rem .9rem; border-radius: 8px; }
.footer { padding: 3rem 1.25rem 2rem; color: var(--muted); font-size: .85rem; }

/* stat tiles */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .8rem; }
.stat-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 1rem; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.stat-num { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .85rem; }

/* covers + book grid */
.cover { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 6px; background: var(--border); display: block; }
.cover-placeholder {
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: .5rem; font-size: .8rem; color: var(--muted);
  background: linear-gradient(160deg, var(--surface), var(--border));
  border: 1px solid var(--border);
}
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 1.1rem; }
.book-card { display: flex; flex-direction: column; gap: .45rem; color: var(--text); }
.book-card:hover { text-decoration: none; }
.book-card:hover .cover { box-shadow: var(--shadow); transform: translateY(-2px); }
.book-card .cover { transition: transform .15s ease, box-shadow .15s ease; }
.book-card-title { font-weight: 600; font-size: .92rem; display: block; }
.book-card-author { color: var(--muted); font-size: .82rem; display: block; }
.because { color: var(--accent); font-size: .78rem; font-style: italic; }

/* stars */
.stars {
  display: inline-block; font-size: 1.15rem; letter-spacing: 1px; line-height: 1;
  background: linear-gradient(90deg,
    var(--star-fill) calc(var(--rating, 0) / 5 * 100%),
    var(--star-empty) calc(var(--rating, 0) / 5 * 100%));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  user-select: none;
}
.stars-input { cursor: pointer; font-size: 1.4rem; }

/* shelf controls */
.shelf-controls { margin: 1rem 0; display: flex; flex-direction: column; gap: .6rem; }
.status-buttons { display: flex; flex-wrap: wrap; gap: .4rem; }
.rate-row { display: flex; align-items: center; gap: .6rem; }
.rate-label { color: var(--muted); font-size: .9rem; }

/* search page */
.big-search { display: flex; gap: .6rem; max-width: 560px; }
.ol-results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.ol-result {
  display: flex; align-items: center; gap: .9rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem;
}
.ol-result .cover { width: 44px; flex-shrink: 0; }
.cover-s { width: 44px; font-size: .55rem; }
.ol-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ol-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* book detail */
.detail-layout { display: grid; grid-template-columns: 220px 1fr; gap: 2rem; margin-top: 1.5rem; }
@media (max-width: 640px) { .detail-layout { grid-template-columns: 1fr; } .detail-cover { max-width: 200px; } }
.book-title { margin: 0 0 .2rem; }
.book-subtitle { color: var(--muted); font-size: 1.1rem; margin: 0 0 .5rem; }
.book-byline { margin: .2rem 0 .8rem; }
.community-rating { display: flex; align-items: center; gap: .5rem; }
.description p { white-space: pre-line; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1rem 0; }
.chip {
  font-size: .78rem; padding: .2rem .6rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
}
.chip:hover { color: var(--primary); border-color: var(--primary); text-decoration: none; }
.review-editor summary { cursor: pointer; color: var(--primary); font-weight: 600; margin: .6rem 0; }
.review-form { display: flex; flex-direction: column; gap: .6rem; align-items: flex-start; }
.review-form textarea {
  width: 100%; padding: .7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; resize: vertical;
}
.dates-form { display: flex; gap: 1rem; align-items: center; margin: 1rem 0; flex-wrap: wrap; }
.dates-form label { display: flex; gap: .4rem; align-items: center; color: var(--muted); font-size: .9rem; }
.dates-form input { padding: .3rem .5rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.save-note { color: var(--notice-text); font-size: .85rem; }

/* reviews */
.review-card {
  display: flex; gap: 1rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-bottom: .8rem;
}
.review-book { width: 60px; flex-shrink: 0; }
.review-body { flex: 1; min-width: 0; }
.review-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .3rem; }
.review-author { font-weight: 600; }
.review-text { margin: .2rem 0; white-space: pre-line; }

/* shelves page */
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--border); margin-bottom: 1.2rem; flex-wrap: wrap; }
.tab { padding: .5rem .9rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.count { font-size: .78rem; background: var(--border); border-radius: 999px; padding: 0 .45rem; }
.shelf-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .7rem; }
.shelf-item {
  display: flex; gap: 1rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .8rem 1rem;
}
.shelf-cover { width: 56px; flex-shrink: 0; }
.shelf-meta { display: flex; flex-direction: column; gap: .15rem; min-width: 0; flex: 1; }
.shelf-title { font-weight: 600; color: var(--text); }
.badge { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; width: fit-content; padding: .1rem .5rem; border-radius: 999px; }
.badge-want_to_read { background: var(--notice-bg); color: var(--notice-text); }
.badge-currently_reading { background: var(--primary); color: var(--primary-contrast); }
.badge-read { background: var(--border); color: var(--muted); }
.badge-dnf { background: var(--error-bg); color: var(--error-text); }

/* profile */
.profile-head { display: flex; gap: 1.2rem; align-items: center; margin-top: 1.5rem; }
.avatar {
  width: 72px; height: 72px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary); color: var(--primary-contrast);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700;
  object-fit: cover;
}
.avatar-sm { width: 26px; height: 26px; font-size: .85rem; }
.nav-user { display: inline-flex; align-items: center; gap: .45rem; }
.review-author-link { display: inline-flex; align-items: center; gap: .45rem; color: var(--text); }
.profile-head .page-title { margin: 0; }

/* settings */
.settings-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 1.5rem; margin-bottom: 1.2rem; max-width: 560px;
}
.settings-card h2 { margin-top: 0; font-size: 1.1rem; }
.avatar-row { display: flex; gap: 1.2rem; align-items: flex-start; }
.avatar-forms { display: flex; flex-direction: column; gap: .6rem; align-items: flex-start; }
.avatar-upload { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.settings-form textarea {
  padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit; resize: vertical;
}
.review-actions { display: flex; gap: .6rem; align-items: center; }

/* auth */
.auth-card {
  max-width: 400px; margin: 3rem auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; padding: 2rem; box-shadow: var(--shadow);
}
.auth-card h1 { margin-top: 0; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; margin: 1rem 0; }
.auth-form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
.auth-form input {
  padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 1rem;
}

@media (max-width: 720px) {
  .nav { flex-wrap: wrap; }
  .nav-search { order: 3; max-width: none; flex-basis: 100%; }
}
