@font-face {
  font-family: 'Caveat';
  src: url('../fonts/caveat-var.woff2') format('woff2-variations'), url('../fonts/caveat-var.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --cream: #F4EFE6;
  --font-hand: 'Caveat', cursive;
  --blush: #FAECE7;
  --coral: #D85A30;
  --coral-light: #F0997B;
  --sage: #5DCAA5;
  --amber: #EF9F27;
  --ink-brown: #412402;
  --muted-brown: #854F0B;
  --card-white: #FFFFFF;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--cream);
  color: var(--ink-brown);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--cream);
  position: relative;
  padding-bottom: env(safe-area-inset-bottom);
}

.view { display: none; padding: max(16px, env(safe-area-inset-top)) 16px 32px; }
.view.active { display: block; }

/* ---------- App bar ---------- */
.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  margin-bottom: 8px;
}
.appbar .icon-btn { visibility: visible; }
.appbar .spacer { flex: 1; }
.appbar-actions { display: flex; gap: 4px; }

.icon-btn {
  background: none;
  border: none;
  padding: 8px;
  border-radius: 50%;
  color: var(--ink-brown);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:active { background: rgba(0,0,0,0.06); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.coral { color: var(--coral); }

/* ---------- Library header ---------- */
.library-title { text-align: center; }
.library-title h1 {
  font-family: var(--font-hand);
  font-size: 40px;
  font-weight: 700;
  margin: 0 0 2px;
  color: var(--ink-brown);
  line-height: 1;
}
.library-title p {
  font-family: var(--font-hand);
  font-size: 17px;
  color: var(--muted-brown);
  margin: 0;
}
.library-header-row {
  display: flex;
  align-items: flex-start;
}
.library-header-row .flex1 { flex: 1; }

.search-row { display: flex; gap: 6px; align-items: center; }
.search-row input {
  flex: 1;
  border: none;
  border-radius: 20px;
  background: var(--card-white);
  padding: 10px 14px;
  font-size: 14px;
  color: var(--ink-brown);
}
.search-row input::placeholder { color: var(--muted-brown); }

/* ---------- Filter chips ---------- */
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  border: 1px solid rgba(133,79,11,0.25);
  background: var(--card-white);
  color: var(--muted-brown);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.chip.selected {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
  font-weight: 600;
}
.chip.selected.status-chip { background: var(--coral); border-color: var(--coral); }
.chip.selected.mood-chip { background: var(--sage); border-color: var(--sage); }
.chip.selected.recommend-chip { background: var(--amber); border-color: var(--amber); }
.chip-check { font-size: 11px; }

/* ---------- Book grid ---------- */
.book-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.book-card {
  background: var(--card-white);
  border-radius: 14px;
  padding: 8px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.book-cover {
  aspect-ratio: 0.72;
  border-radius: 8px;
  overflow: hidden;
  background: var(--coral-light);
  display: flex;
  align-items: center;
  justify-content: center;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-cover svg { width: 28px; height: 28px; color: #fff; }

.book-title {
  font-size: 11px;
  font-weight: 500;
  margin: 6px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-author {
  font-size: 9px;
  color: var(--muted-brown);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 3px;
}

.status-badge {
  font-size: 8.5px;
  font-weight: 600;
  color: #fff;
  padding: 3px 7px;
  border-radius: 20px;
  display: inline-block;
}
.status-badge.tbr { background: var(--muted-brown); }
.status-badge.reading { background: var(--amber); }
.status-badge.finished { background: var(--sage); }
.status-badge.dnf { background: var(--coral); }

.stars { display: inline-flex; gap: 1px; }
.stars svg { width: 11px; height: 11px; }
.stars.rating-lg svg { width: 26px; height: 26px; }
.star-filled { color: var(--coral); }
.star-empty { color: var(--coral-light); }

.empty-state {
  text-align: center;
  color: var(--muted-brown);
  padding: 60px 20px;
  font-size: 14px;
}

.fab {
  position: fixed;
  right: max(24px, calc((100vw - 480px) / 2 + 24px));
  bottom: max(24px, env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--coral);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  cursor: pointer;
  z-index: 20;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- Cards / sections ---------- */
.card {
  background: var(--card-white);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}
.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-brown);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

textarea, input[type="text"], input[type="number"], input[type="date"] {
  width: 100%;
  border: none;
  font-size: 13.5px;
  color: var(--ink-brown);
  font-family: inherit;
  background: transparent;
  padding: 0;
  resize: vertical;
}
textarea:focus, input:focus { outline: none; }
textarea::placeholder, input::placeholder { color: #999; }

.field {
  margin-bottom: 12px;
}
.field label {
  display: block;
  font-size: 11px;
  color: var(--muted-brown);
  margin-bottom: 4px;
}
.field input {
  border: 1px solid rgba(133,79,11,0.2);
  border-radius: 8px;
  padding: 10px 12px;
}

.wrap-chips { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Header/cover card in edit + summary ---------- */
.book-header-card { display: flex; gap: 12px; align-items: flex-start; }
.cover-thumb-wrap { position: relative; width: 72px; height: 104px; flex-shrink: 0; }
.cover-thumb-wrap.edit-cover { width: 44px; height: 64px; cursor: pointer; }
.cover-thumb {
  width: 100%; height: 100%; border-radius: 8px; overflow: hidden;
  background: var(--coral-light); display: flex; align-items: center; justify-content: center;
}
.cover-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cover-thumb svg { width: 24px; height: 24px; color: #fff; }
.cover-badge {
  position: absolute; right: -4px; bottom: -4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--ink-brown); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.cover-badge svg { width: 12px; height: 12px; }

.book-header-info { flex: 1; min-width: 0; }
.book-header-info .name { font-weight: 600; font-size: 17px; margin: 0; }
.book-header-info .author { color: var(--muted-brown); font-size: 13px; margin: 2px 0 0; }
.book-header-info .genre { color: #888; font-size: 11px; margin: 8px 0 0; }
.book-header-info input { font-weight: 600; font-size: 15px; margin-bottom: 4px; }

.date-row {
  display: flex; align-items: center; padding: 4px 0; gap: 8px;
}
.date-row .dr-icon { color: var(--muted-brown); width: 15px; height: 15px; flex-shrink: 0; }
.date-row .dr-label { font-size: 13px; }
.date-row .dr-value { margin-left: auto; font-size: 13px; color: var(--muted-brown); }
.date-row input[type="date"] { max-width: 130px; text-align: right; }
.date-row .icon-btn { padding: 4px; }
.date-row .icon-btn svg { width: 15px; height: 15px; }

/* ---------- Quote / dashed card ---------- */
.dashed-card {
  border: 1.4px dashed rgba(133,79,11,0.4);
  border-radius: 12px;
  padding: 14px;
  background: var(--card-white);
  margin-bottom: 12px;
}
.quote-mark { font-size: 34px; line-height: 0.6; color: var(--coral); font-weight: bold; display: block; }
.quote-mark.right { text-align: right; }
.quote-text { font-family: var(--font-hand); font-size: 22px; font-weight: 600; padding: 0 4px; line-height: 1.3; }

.mood-pill {
  padding: 8px 12px;
  border-radius: 20px;
  background: rgba(93,202,165,0.18);
  font-size: 12px;
  display: inline-block;
}

.recommend-badge {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 13px;
}

.character-card {
  width: 92px;
  border: 1.4px dashed rgba(133,79,11,0.35);
  border-radius: 12px;
  padding: 14px 8px;
  text-align: center;
}
.character-card svg { width: 18px; height: 18px; color: var(--coral-light); }
.character-card .cname { font-size: 11px; margin-top: 6px; }

.summary-page-title {
  font-family: var(--font-hand);
  text-align: center;
  font-size: 44px;
  letter-spacing: 1px;
  margin: 0 0 0;
  font-weight: 700;
  line-height: 1;
}
.summary-tagline { font-family: var(--font-hand); text-align: center; font-size: 18px; color: var(--muted-brown); margin: 2px 0 20px; }
.summary-footer { font-family: var(--font-hand); text-align: center; font-size: 18px; color: var(--muted-brown); margin-top: 24px; }

/* ---------- Buttons ---------- */
.btn-primary {
  width: 100%;
  background: var(--ink-brown);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.btn-text { background: none; border: none; color: var(--coral); font-size: 14px; cursor: pointer; padding: 8px; }

/* ---------- Modal sheets / dialogs ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(65,36,2,0.35);
  display: none; align-items: flex-end; justify-content: center; z-index: 50;
}
.overlay.active { display: flex; }
.overlay.center { align-items: center; }

.sheet {
  width: 100%; max-width: 480px;
  background: var(--cream);
  border-radius: 20px 20px 0 0;
  padding: 20px 4px calc(20px + env(safe-area-inset-bottom));
}
.sheet-title { font-weight: 600; padding: 0 20px 8px; }
.sheet-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px; cursor: pointer; font-size: 15px;
}
.sheet-item svg { width: 20px; height: 20px; }
.sheet-item.danger { color: var(--coral); }

.dialog {
  width: min(340px, 90vw);
  background: var(--cream);
  border-radius: 16px;
  padding: 20px;
}
.dialog h3 { margin: 0 0 12px; font-size: 17px; }
.dialog p { font-size: 13px; color: var(--muted-brown); line-height: 1.4; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog-actions button {
  background: none; border: none; padding: 8px 12px; font-size: 14px; cursor: pointer; color: var(--coral);
}
.dialog input {
  width: 100%; border: 1px solid rgba(133,79,11,0.2); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 12px; font-size: 14px;
}

.hidden { display: none !important; }

@media (prefers-color-scheme: dark) {
  /* Kept light-only intentionally to match the mobile app's cozy paper aesthetic. */
}
