@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400;1,600&family=Lora:ital,wght@0,400;0,500;0,600;1,400;1,500&family=IM+Fell+English:ital@0;1&display=swap');

/* ── TOKENS ─────────────────────────────────────────────────────────────────── */
:root {
  --parchment:      #f5ead8;
  --parchment-dark: #e8d5b7;
  --parchment-deep: #d9c49a;
  --ink:            #1e0e00;
  --ink-light:      #3d2208;
  --ink-faded:      #7a5c3a;
  --leather:        #8b3e0f;
  --leather-dark:   #5c2a09;
  --leather-light:  #b85c2a;
  --gold:           #c9a84c;
  --gold-light:     #e8cc7a;
  --gold-pale:      #f5e9c0;
  --cream:          #fdf8f0;
  --shadow-warm:    rgba(90, 40, 5, 0.18);
  --shadow-deep:    rgba(30, 10, 0, 0.35);
  --border-pale:    rgba(139, 62, 15, 0.2);
  --border-mid:     rgba(139, 62, 15, 0.4);
  --radius-sm:      4px;
  --radius-md:      8px;
  --radius-lg:      14px;
}

/* ── RESET & BASE ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { max-width: 100%; overflow-x: hidden; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Lora', Georgia, serif;
  background-color: var(--parchment);
  color: var(--ink);
  min-height: 100vh;
  background-image: none;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* ── SCROLLBAR ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--parchment-dark); }
::-webkit-scrollbar-thumb { background: var(--leather); border-radius: 4px; }

/* ── LAYOUT ──────────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ── PROFILE TABS ────────────────────────────────────────────────────────────── */
.profile-bar {
  background: var(--leather-dark);
  display: flex;
  align-items: stretch;
  border-bottom: 3px solid var(--gold);
  box-shadow: 0 3px 12px var(--shadow-deep);
  position: relative;
  z-index: 100;
  padding-top: env(safe-area-inset-top);
}

.profile-bar .brand {
  font-family: 'IM Fell English', serif;
  font-size: 1.4rem;
  color: var(--gold-light);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  letter-spacing: 0.03em;
  border-right: 1px solid rgba(201,168,76,0.3);
  white-space: nowrap;
}

.profile-tabs {
  display: flex;
  gap: 0;
}

.profile-tab {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--gold-pale);
  padding: 0.9rem 2.5rem;
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 4px solid transparent;
  transition: all 0.25s ease;
  letter-spacing: 0.05em;
  opacity: 0.7;
}
.profile-tab:hover { opacity: 1; background: rgba(201,168,76,0.08); }
.profile-tab.active {
  color: var(--gold-light);
  border-bottom-color: var(--gold);
  opacity: 1;
  background: rgba(201,168,76,0.12);
}

/* ── STATS BAR ───────────────────────────────────────────────────────────────── */
.stats-bar {
  background: var(--leather);
  color: var(--gold-pale);
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.55rem 2rem;
  font-family: 'Lora', serif;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--gold);
  flex-wrap: wrap;
}
.stats-bar .stat {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  opacity: 0.9;
}
.stats-bar .stat strong {
  font-weight: 600;
  color: var(--gold-light);
}
.stats-bar .stat-divider {
  opacity: 0.35;
  font-size: 1rem;
}

/* ── NAV ─────────────────────────────────────────────────────────────────────── */
.main-nav {
  background: var(--parchment-dark);
  border-bottom: 2px solid var(--border-mid);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 1.5rem;
  box-shadow: 0 2px 8px var(--shadow-warm);
  position: sticky;
  top: 0;
  z-index: 90;
}

.nav-link {
  font-family: 'Playfair Display', serif;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink-faded);
  padding: 0.85rem 1.4rem;
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.8rem;
}
.nav-link:hover { color: var(--leather); background: rgba(139,62,15,0.06); }
.nav-link.active { color: var(--leather); border-bottom-color: var(--leather); }

.nav-actions {
  margin-left: auto;
  display: flex;
  gap: 0.6rem;
  padding: 0.5rem 0;
}

/* ── BUTTONS ─────────────────────────────────────────────────────────────────── */
.btn {
  font-family: 'Lora', serif;
  font-size: 0.875rem;
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
}
.btn-primary {
  background: var(--leather);
  color: var(--cream);
  box-shadow: 0 2px 6px var(--shadow-warm);
}
.btn-primary:hover { background: var(--leather-dark); box-shadow: 0 3px 10px var(--shadow-warm); transform: translateY(-1px); }
.btn-secondary {
  background: transparent;
  color: var(--leather);
  border: 1.5px solid var(--border-mid);
}
.btn-secondary:hover { background: var(--parchment-dark); }
.btn-gold {
  background: var(--gold);
  color: var(--ink);
  font-weight: 600;
}
.btn-gold:hover { background: var(--gold-light); }
.btn-ghost {
  background: transparent;
  color: var(--ink-faded);
  border: 1px solid var(--border-pale);
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
}
.btn-ghost:hover { background: var(--parchment-dark); color: var(--ink); }
.btn-danger {
  background: transparent;
  color: #9b3a2a;
  border: 1px solid rgba(155,58,42,0.3);
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
}
.btn-danger:hover { background: rgba(155,58,42,0.08); }
.btn-icon {
  padding: 0.45rem 0.6rem;
  font-size: 1rem;
  background: transparent;
  border: 1px solid var(--border-pale);
  color: var(--ink-faded);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-icon:hover { background: var(--parchment-dark); color: var(--ink); }
.btn-sm { font-size: 0.78rem; padding: 0.35rem 0.8rem; }

/* ── MAIN CONTENT ────────────────────────────────────────────────────────────── */
.content {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: 2rem 2rem;
}

/* ── PAGE HEADERS ────────────────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 2rem;
  display: flex;
  align-items: flex-end;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.page-title {
  font-family: 'IM Fell English', serif;
  font-size: 2.2rem;
  color: var(--ink);
  letter-spacing: -0.01em;
  line-height: 1;
}
.page-title em {
  color: var(--leather);
  font-style: italic;
}
.page-subtitle {
  font-family: 'Lora', serif;
  font-style: italic;
  color: var(--ink-faded);
  font-size: 0.9rem;
  margin-top: 0.3rem;
}

/* ── SORT/FILTER BAR ─────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.8rem;
  flex-wrap: wrap;
  background: var(--cream);
  padding: 0.8rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-pale);
  box-shadow: 0 1px 4px var(--shadow-warm);
}

.toolbar-label {
  font-family: 'Lora', serif;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faded);
}

.search-input {
  font-family: 'Lora', serif;
  font-size: 0.9rem;
  padding: 0.5rem 0.9rem;
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius-sm);
  background: var(--parchment);
  color: var(--ink);
  min-width: 220px;
  transition: border-color 0.2s;
}
.search-input:focus { outline: none; border-color: var(--leather); }
.search-input::placeholder { color: var(--ink-faded); font-style: italic; }

.sort-select {
  font-family: 'Lora', serif;
  font-size: 0.85rem;
  padding: 0.5rem 0.8rem;
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius-sm);
  background: var(--parchment);
  color: var(--ink);
  cursor: pointer;
}
.sort-select:focus { outline: none; border-color: var(--leather); }

/* ── BOOK GRID ───────────────────────────────────────────────────────────────── */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.5rem;
}

.book-card {
  cursor: pointer;
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  position: relative;
}
.book-card:hover { transform: translateY(-5px) rotate(-0.5deg); }
.book-card:hover .book-cover-wrap { box-shadow: -6px 8px 24px var(--shadow-deep), 3px 3px 0 var(--gold); }

.book-cover-wrap {
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: -4px 6px 16px var(--shadow-warm), 1px 1px 0 rgba(201,168,76,0.3);
  aspect-ratio: 2/3;
  background: var(--parchment-dark);
  transition: box-shadow 0.22s ease;
  position: relative;
  border-left: 5px solid var(--leather);
}

.book-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 0.75rem;
  text-align: center;
  background: linear-gradient(160deg, var(--leather) 0%, var(--leather-dark) 100%);
  color: var(--gold-pale);
}
.book-cover-placeholder .ph-title {
  font-family: 'Playfair Display', serif;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
  margin-bottom: 0.5rem;
}
.book-cover-placeholder .ph-author {
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: 0.68rem;
  opacity: 0.75;
}

.book-info {
  padding: 0.6rem 0.2rem 0;
}
.book-info .b-title {
  font-family: 'Playfair Display', serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-info .b-author {
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: 0.75rem;
  color: var(--ink-faded);
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-info .b-rating { margin-top: 0.3rem; }
.book-info .b-date {
  font-size: 0.68rem;
  color: var(--ink-faded);
  margin-top: 0.1rem;
}
.book-info .b-pages {
  font-size: 0.68rem;
  color: var(--ink-faded);
}

.reread-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--gold);
  color: var(--ink);
  font-family: 'Lora', serif;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  letter-spacing: 0.05em;
}

/* ── STAR RATING ─────────────────────────────────────────────────────────────── */
.star-rating {
  display: inline-flex;
  gap: 1px;
  align-items: center;
}
.star {
  font-size: 0.85rem;
  line-height: 1;
  cursor: default;
  color: var(--gold);
}
.star-empty { color: var(--parchment-deep); }
.star-half {
  position: relative;
  display: inline-block;
}
.star-interactive { cursor: pointer; transition: transform 0.1s; }
.star-interactive:hover { transform: scale(1.2); }

/* ── BOOK DETAIL ─────────────────────────────────────────────────────────────── */
.book-detail {
  max-width: 900px;
  margin: 0 auto;
}

.book-detail-header {
  display: flex;
  gap: 2.5rem;
  margin-bottom: 2.5rem;
  align-items: flex-start;
}

.book-detail-cover {
  flex-shrink: 0;
  width: 180px;
}
.book-detail-cover .book-cover-wrap {
  width: 100%;
  aspect-ratio: 2/3;
  border-left-width: 8px;
}

.book-detail-meta { flex: 1; }
.book-detail-meta h1 {
  font-family: 'IM Fell English', serif;
  font-size: 2rem;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: 0.3rem;
}
.book-detail-meta .author {
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: 1.1rem;
  color: var(--leather);
  margin-bottom: 1rem;
}
.book-detail-meta .meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.5rem 1rem;
  margin-bottom: 1.2rem;
}
.meta-item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.meta-item .meta-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faded);
}
.meta-item .meta-value {
  font-family: 'Lora', serif;
  font-size: 0.9rem;
  color: var(--ink);
  font-weight: 500;
}
.detail-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* ── DIVIDER ─────────────────────────────────────────────────────────────────── */
.ornament-divider {
  text-align: center;
  margin: 2rem 0;
  color: var(--gold);
  font-size: 1.2rem;
  letter-spacing: 0.5em;
  opacity: 0.6;
}

/* ── REVIEW CARDS ────────────────────────────────────────────────────────────── */
.review-entry {
  background: var(--cream);
  border: 1px solid var(--border-pale);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-bottom: 1.2rem;
  box-shadow: 0 2px 8px var(--shadow-warm);
  position: relative;
}
.review-entry::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--leather);
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}
.review-entry.reread::before { background: var(--gold); }

.review-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.review-label {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
}
.review-date {
  font-size: 0.78rem;
  font-style: italic;
  color: var(--ink-faded);
}
.review-actions { margin-left: auto; display: flex; gap: 0.5rem; }

.review-section { margin-bottom: 1rem; }
.review-section-title {
  font-family: 'Lora', serif;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--leather);
  margin-bottom: 0.4rem;
}
.review-section p {
  font-family: 'Lora', serif;
  font-size: 0.92rem;
  line-height: 1.75;
  color: var(--ink-light);
  white-space: pre-wrap;
}

/* ── TEXTAREA ────────────────────────────────────────────────────────────────── */
textarea, input[type=text], input[type=date], input[type=number], input[type=search], select.form-select {
  font-family: 'Lora', serif;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--parchment);
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.85rem;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.7; }
textarea:focus, input:focus, select.form-select:focus {
  outline: none;
  border-color: var(--leather);
  box-shadow: 0 0 0 3px rgba(139,62,15,0.12);
}

/* ── MODAL ───────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30,10,0,0.65);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--cream);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px var(--shadow-deep);
  max-width: 680px;
  width: 100%;
  max-height: min(90vh, 90dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  flex: 1;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.6rem 1rem;
  border-bottom: 1px solid var(--border-pale);
  margin-bottom: 1.2rem;
  flex-shrink: 0;
}
.modal-title {
  font-family: 'IM Fell English', serif;
  font-size: 1.4rem;
  color: var(--ink);
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--ink-faded);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}
.modal-close:hover { background: var(--parchment-dark); color: var(--ink); }

.modal-body { padding: 0 1.6rem 1.6rem; }

.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-faded);
  margin-bottom: 0.35rem;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 1rem 0 0;
  border-top: 1px solid var(--border-pale);
  margin-top: 1rem;
  flex-shrink: 0;
}

/* ── GOOGLE BOOKS RESULTS ────────────────────────────────────────────────────── */
.gbooks-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border-pale);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  background: var(--parchment);
}
.gbooks-item {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  overflow: hidden;
}
.gbooks-item:hover { border-color: var(--leather); box-shadow: 0 2px 8px var(--shadow-warm); }
.gbooks-item.selected { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.gbooks-item img { width: 100%; aspect-ratio: 2/3; object-fit: cover; }
.gbooks-item .gb-info { padding: 0.3rem 0.4rem; font-size: 0.68rem; }
.gbooks-item .gb-title { font-weight: 600; line-height: 1.3; }
.gbooks-item .gb-author { color: var(--ink-faded); font-style: italic; }

/* ── TOC VIEW ────────────────────────────────────────────────────────────────── */
.toc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.toc-table thead tr {
  border-bottom: 2px solid var(--leather);
}
.toc-table th {
  text-align: left;
  font-family: 'Playfair Display', serif;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--leather);
  padding: 0.6rem 1rem;
  cursor: pointer;
  user-select: none;
}
.toc-table th:hover { color: var(--leather-dark); }
.toc-table th.sorted { color: var(--leather-dark); }
.toc-table tbody tr {
  border-bottom: 1px solid var(--border-pale);
  cursor: pointer;
  transition: background 0.15s;
}
.toc-table tbody tr:hover { background: var(--cream); }
.toc-table td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
}
.toc-cover {
  width: 36px;
  height: 54px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: -2px 2px 5px var(--shadow-warm);
  border-left: 3px solid var(--leather);
}
.toc-cover-placeholder {
  width: 36px;
  height: 54px;
  background: var(--leather);
  border-radius: 2px;
}
.toc-title { font-family: 'Playfair Display', serif; font-weight: 600; }
.toc-author { font-style: italic; color: var(--ink-faded); font-size: 0.82rem; }
.status-chip {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.chip-read { background: rgba(139,62,15,0.12); color: var(--leather-dark); }
.chip-reading { background: rgba(201,168,76,0.2); color: #7a5000; }
.chip-graveyard { background: rgba(80,80,80,0.12); color: #444; }
.chip-tbr { background: rgba(60,100,160,0.12); color: #2a4a80; }

/* ── GRAVEYARD ───────────────────────────────────────────────────────────────── */
.graveyard-section { margin-bottom: 2.5rem; }
.graveyard-title {
  font-family: 'IM Fell English', serif;
  font-size: 1.4rem;
  color: var(--ink-faded);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-pale);
}

/* ── EMPTY STATES ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--ink-faded);
}
.empty-state .empty-icon { font-size: 3.5rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state h3 {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}
.empty-state p { font-style: italic; font-size: 0.9rem; }

/* ── TOAST ───────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--leather-dark);
  color: var(--cream);
  padding: 0.75rem 1.2rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  box-shadow: 0 4px 16px var(--shadow-deep);
  animation: toastIn 0.3s ease;
  max-width: 320px;
  border-left: 4px solid var(--gold);
}
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.error { border-left-color: #c0392b; }

/* ── LOADING ─────────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-mid);
  border-top-color: var(--leather);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── COVER UPLOAD AREA ───────────────────────────────────────────────────────── */
.cover-upload-area {
  border: 2px dashed var(--border-mid);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--parchment);
  color: var(--ink-faded);
  font-style: italic;
  font-size: 0.85rem;
}
.cover-upload-area:hover { border-color: var(--leather); background: var(--parchment-dark); color: var(--ink); }
.cover-upload-area input { display: none; }

/* ── RESPONSIVE ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* ── PROFILE BAR ── */
  .profile-bar { flex-direction: column; }
  .profile-bar .brand {
    border-right: none;
    border-bottom: 1px solid rgba(201,168,76,0.25);
    width: 100%;
    font-size: 1rem;
    padding: 0.55rem 1rem;
    justify-content: center;
  }
  .profile-tabs { width: 100%; }
  .profile-tab { flex: 1; text-align: center; padding: 0.6rem 0; font-size: 1rem; }

  /* ── STATS BAR ── */
  .stats-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem 0;
    padding: 0.6rem 1rem;
    font-size: 0.8rem;
  }
  .stat-divider { display: none; }
  .stats-bar .stat { padding: 0.15rem 0; }

  /* ── NAV ── */
  .main-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
    padding: 0;
    position: sticky;
    top: 0;
  }
  .main-nav::-webkit-scrollbar { display: none; }
  .nav-link { flex-shrink: 0; padding: 0.8rem 1rem; font-size: 0.72rem; white-space: nowrap; }
  .nav-actions { flex-shrink: 0; padding: 0.45rem 0.75rem; }
  .nav-actions .btn { font-size: 0.72rem; padding: 0.3rem 0.65rem; white-space: nowrap; }

  /* ── CONTENT ── */
  .content { padding: 1rem; }
  .page-title { font-size: 1.5rem; }

  /* ── BOOK GRID ── */
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.85rem; }

  /* ── FORMS ── */
  .form-row, .form-row-3 { grid-template-columns: 1fr; }

  /* ── TOC TABLE ── */
  .toc-scroll-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
  .toc-table { min-width: 560px; }
  .toc-table th, .toc-table td { padding: 0.55rem 0.6rem; }

  /* ── BOOK DETAIL ── */
  .book-detail-header { flex-direction: column; }
  .book-detail-cover { width: 130px; }
  .book-detail-meta h1 { font-size: 1.4rem; }
  .detail-actions { flex-wrap: wrap; gap: 0.4rem; }

  /* ── MODAL: bottom sheet ── */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
    padding-top: env(safe-area-inset-top);
  }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: min(92vh, 92dvh);
    border-radius: 16px 16px 0 0;
  }
  .modal-body {
    padding-bottom: max(1.6rem, env(safe-area-inset-bottom));
  }
  .modal-header { padding: 1rem 1.2rem 0.75rem; }
  .modal-body > *:last-child { padding-bottom: 0; }

  /* ── GOOGLE BOOKS ── */
  .gbooks-results { grid-template-columns: repeat(auto-fill, minmax(85px, 1fr)); }

  /* ── FORM COMPACT ── */
  .form-group { margin-bottom: 0.6rem; }
  .form-label { font-size: 0.72rem; margin-bottom: 0.2rem; }
  textarea, input[type=text], input[type=date], input[type=number], input[type=search], select.form-select {
    font-size: 0.9rem;
    padding: 0.45rem 0.7rem;
  }
  .modal-body { padding: 0 1rem 1rem; }
  .modal-header { padding: 0.9rem 1rem 0.75rem; }
  .modal-footer { padding-top: 0.75rem; margin-top: 0.5rem; }
  .form-row, .form-row-3 { gap: 0.6rem; }
}

@media (max-width: 430px) {
  .book-grid { grid-template-columns: repeat(3, 1fr); gap: 0.65rem; }
  .content { padding: 0.75rem; }
  .page-title { font-size: 1.2rem; }
  .book-info .b-title { font-size: 0.76rem; }
  .book-info .b-author { font-size: 0.68rem; }
}

/* ── READING PROGRESS BAR ────────────────────────────────────────────────────── */
.book-progress {
  height: 4px;
  background: var(--parchment-deep);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 0.3rem;
}
.book-progress-fill {
  height: 100%;
  background: var(--leather);
  border-radius: 99px;
  transition: width 0.3s ease;
}
