/* ── Splash screen ────────────────────────────────────────── */
.splash-screen {
  position: fixed;
  inset: 0;
  background: #060d1a;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .6s ease;
}
.splash-screen.fade-out { opacity: 0; pointer-events: none; }
.splash-screen.hidden   { display: none; }

.splash-video {
  /* Fill the whole screen. The video is portrait, so on a wide (desktop)
     screen 'contain' grows it to full height with navy bars on the sides
     that blend into the splash background — no logo/text gets cropped. */
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ── Sidebar layout ───────────────────────────────────────── */
.app-layout {
  display: flex;
  align-items: flex-start;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: 250px;
  flex-shrink: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid rgba(var(--accent-rgb), .12);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 22px;
  z-index: 20;
}

.sidebar-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  gap: 2px;
  padding: 6px 0;
}
.sidebar-logo-img {
  width: 168px;
  height: auto;
  object-fit: contain;
  display: block;
}
.sidebar-logo-text {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--rooftop);
  letter-spacing: 0.12em;
  line-height: 1;
  margin-top: -6px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-nav .tab {
  width: 100%;
  justify-content: flex-start;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: .95rem;
}
.sidebar-nav .tab.active {
  background: rgba(var(--accent-rgb), .14);
  color: var(--text);
}
.sidebar-nav .tab--stats {
  margin-left: 0;
  margin-top: 0;
}

/* Divider separating the reading shelves from Owned / For You / Stats */
.sidebar-nav-divider {
  height: 1px;
  background: rgba(var(--accent-rgb), .15);
  margin: 8px 6px;
}

/* Live "Currently Reading" preview under the nav tab (desktop sidebar only) */
.reading-mini {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px 6px 6px;
}
.reading-mini:empty { display: none; }
.reading-mini-item {
  display: flex;
  gap: 8px;
  align-items: center;
  cursor: pointer;
  border-radius: 8px;
  padding: 4px;
  transition: background .15s;
}
.reading-mini-item:hover { background: var(--surface2); }
.reading-mini-cover {
  width: 26px;
  height: 39px;
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
}
.reading-mini-cover img { width: 100%; height: 100%; object-fit: cover; }
.reading-mini-info { flex: 1; min-width: 0; }
.reading-mini-title {
  font-size: .72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.reading-mini-bar { height: 4px; background: var(--surface2); border-radius: 999px; overflow: hidden; }
.reading-mini-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 999px; }

.app-main {
  flex: 1;
  min-width: 0;
}

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Ocean — default theme. Overridden per [data-theme] in themes.css */
  --bg:          #060d1a;
  --surface:     #0d1929;
  --surface2:    #162236;
  --accent:      #38bdf8;
  --accent2:     #67e8f9;
  --accent3:     #818cf8;
  --text:        #e0f2fe;
  --muted:       #4e7a9b;
  --radius:      12px;
  --shadow:      0 8px 40px rgba(0,0,0,.7);
  --glow:        0 0 24px rgba(56,189,248,.15);
  --font-body:    'Inter', system-ui, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
  --accent-rgb:  56, 189, 248;
  --accent3-rgb: 129, 140, 248;
  --rooftop:     #9b5c48;
}

/* Make the whole page feel like an app, not a webpage, on touch devices */
html {
  overflow-x: clip;                 /* no sideways scrolling at the root */
  overscroll-behavior: none;        /* no rubber-band bounce past the edges */
  -webkit-text-size-adjust: 100%;   /* stop iOS auto-enlarging text */
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .4s, color .4s;
  background-image: radial-gradient(ellipse at 50% 0%, rgba(56,189,248,.06) 0%, transparent 60%);
  /* Guard against any element forcing sideways scroll on mobile.
     'clip' (not 'hidden') is used so it doesn't break the sticky sidebar. */
  overflow-x: clip;
  overscroll-behavior: none;
  touch-action: manipulation;       /* removes double-tap-to-zoom + tap delay */
  -webkit-tap-highlight-color: transparent;  /* no grey flash when tapping */
}

h1, h2, h3 {
  font-family: var(--font-display);
}

/* ── Header ───────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid rgba(var(--accent-rgb), .12);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.5px; white-space: nowrap; }

/* Storage status badge */
.storage-badge {
  font-size: .72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  border: none;
  cursor: default;
  white-space: nowrap;
  transition: background .3s, color .3s;
  background: transparent;
  color: transparent; /* hidden until JS sets a status */
}
.storage-badge.badge-ok   { background: rgba(46,213,115,.15); color: #2ed573;  border: 1px solid rgba(46,213,115,.3); }
.storage-badge.badge-warn { background: rgba(255,179,71,.15);  color: var(--accent2); border: 1px solid rgba(255,179,71,.3); }
.storage-badge.badge-err  { background: rgba(255,71,87,.15);   color: #ff4757; border: 1px solid rgba(255,71,87,.3); }

/* Ghost / outline buttons */
.btn-ghost {
  background: none;
  border: 1px solid var(--surface2);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .2s, color .2s, background .2s;
  white-space: nowrap;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--text); background: rgba(232,99,58,.08); }

.btn-add {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
  white-space: nowrap;
}
.btn-add:hover { background: #0ea5e9; transform: translateY(-1px); }

/* Setup banner */
.setup-banner {
  max-width: 1200px;
  margin: 10px auto 0;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(255,179,71,.1);
  border: 1px solid rgba(255,179,71,.25);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: .85rem;
  color: var(--text);
  flex-wrap: wrap;
}
.setup-banner.hidden { display: none; }

.setup-banner-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.setup-banner-actions button {
  padding: 6px 14px;
  border-radius: 7px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, color .2s;
  border: none;
}

#setupFileBtn {
  background: var(--accent2);
  color: #1a1200;
}
#setupFileBtn:hover { background: #e8a030; }

.btn-dismiss {
  background: none;
  color: var(--muted);
  border: 1px solid var(--surface2) !important;
}
.btn-dismiss:hover { color: var(--text); }

/* ── Shelf tabs ───────────────────────────────────────────── */
.shelf-tabs {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 4px;
  margin-top: 14px;
}

.tab {
  background: none;
  border: none;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
  transition: color .2s, background .2s;
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Short tab labels are only used in the mobile bottom bar (see responsive section) */
.tab-short { display: none; }
.tab:hover { color: var(--text); background: var(--surface2); }
.tab.active { color: var(--text); background: var(--bg); font-weight: 700; }
.tab.drag-over { background: rgba(var(--accent-rgb), .15); color: var(--text); }

.count {
  background: var(--surface2);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}
.tab.active .count { background: var(--accent); color: #fff; }

/* ── Main / shelf grid ────────────────────────────────────── */
main { max-width: 1200px; margin: 0 auto; padding: 32px 24px; }

/* The shelf is a vertical stack of rows; each row sits on a wooden plank.
   Rows are built (and balanced) by shelfRowsHtml() in app.js. */
.shelf {
  display: flex;
  flex-direction: column;
}
.shelf.hidden { display: none; }
.shelf.drag-over { outline: 2px dashed rgba(var(--accent-rgb), .45); outline-offset: -4px; border-radius: var(--radius); }

/* A single row of books resting on a shelf */
.book-row {
  display: flex;
  justify-content: center;
  align-items: stretch;        /* all cards match height so covers line up at the top */
  gap: 22px;
  padding: 0 12px 16px;
  margin-bottom: 30px;
  position: relative;
}
/* The wooden shelf plank under each row */
.book-row::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14px;
  border-radius: 2px 2px 5px 5px;
  background: linear-gradient(180deg, #8a5a36 0%, #6f4527 38%, #5a3720 72%, #4a2d1a 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .15),   /* subtle top highlight */
    0 2px 0 #3a2415,                           /* front lip of the plank */
    0 12px 16px -6px rgba(0, 0, 0, .55);       /* shadow cast below the shelf */
}

/* Empty state */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 4rem; margin-bottom: 12px; }
.empty-state p { font-size: 1rem; }

/* ── Book card ────────────────────────────────────────────── */
.book-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: grab;
  transition: transform .2s, box-shadow .2s, opacity .2s;
  position: relative;
  display: flex;
  flex-direction: column;
  /* Fixed size so books look consistent on the shelf (no more giant single book) */
  width: 160px;
  flex: 0 0 auto;
}
.book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.book-card.dragging { opacity: .35; cursor: grabbing; transform: scale(.96); }

.book-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  color: var(--muted);
  flex-shrink: 0;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }

/* Small page-count badge tucked into the bottom-left of the cover */
.cover-pages {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(6, 13, 26, .72);
  color: #fff;
  font-size: .62rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: .02em;
  pointer-events: none;
}

.book-info {
  padding: 10px 12px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.book-title {
  font-family: var(--font-display);
  font-size: .9rem;
  font-weight: 700;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-author {
  font-size: .76rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-genres {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.book-rating {
  font-size: .8rem;
  color: var(--accent2);
  margin-top: auto;
  padding-top: 6px;
}

/* Format badges shown on book cards */
.card-formats {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 5px;
}
.fmt-badge {
  font-size: .78rem;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(var(--accent-rgb), .12);
  border: 1px solid rgba(var(--accent-rgb), .25);
  transition: background .3s, border-color .3s;
}

.card-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0;
  transition: opacity .2s;
}
.book-card:hover .card-actions { opacity: 1; }

.card-actions button {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.7);
  color: #fff;
  font-size: .85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.card-actions button:hover { background: var(--accent); }

/* ── Pills ────────────────────────────────────────────────── */
.genre-pill {
  display: inline-block;
  background: rgba(var(--accent-rgb), .13);
  color: var(--accent);
  border: 1px solid rgba(var(--accent-rgb), .28);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 600;
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .3s, border-color .3s, color .3s;
}
.genre-pill.mini { font-size: .62rem; padding: 1px 6px; }

/* Book-length shown as a neutral meta pill among the tags */
.genre-pill.length-pill {
  background: var(--surface2);
  color: var(--muted);
  border-color: var(--surface2);
}

/* Custom (personal) tags shown inline among the genre pills */
.genre-pill.custom-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: none;
  background: rgba(var(--accent3-rgb), .14);
  color: var(--accent3);
  border-color: rgba(var(--accent3-rgb), .3);
}
.tag-remove {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: .95rem;
  line-height: 1;
  padding: 0 0 0 2px;
  opacity: .6;
}
.tag-remove:hover { opacity: 1; }
.tag-add-pill {
  background: none;
  border: 1px dashed var(--surface2);
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 11px;
  font-size: .68rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.tag-add-pill:hover { border-color: var(--accent); color: var(--accent); }
.tag-add-input {
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: .68rem;
  color: var(--text);
  outline: none;
  width: 120px;
}

/* Series pill — distinct from genre, uses the secondary accent */
.series-pill {
  display: inline-block;
  background: var(--surface2);
  color: var(--accent2);
  border: 1px solid var(--accent2);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 700;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .3s, border-color .3s;
}

.tone-pill {
  display: inline-block;
  background: rgba(var(--accent3-rgb), .13);
  color: var(--accent3);
  border: 1px solid rgba(var(--accent3-rgb), .28);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background .3s, border-color .3s, color .3s;
}

/* ── Modals ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: 18px;
  padding: 32px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow);
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal h2 { font-size: 1.3rem; margin-bottom: 18px; }

.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  /* Comfortable tap target instead of just the X glyph */
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  transition: background .2s, color .2s;
}
.modal-close:hover { color: var(--text); background: var(--surface2); }

/* Search */
.search-row { display: flex; gap: 8px; }
.search-row input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: .9rem;
  outline: none;
  transition: border .2s;
}
.search-row input:focus { border-color: var(--accent); }

.btn-search {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
  white-space: nowrap;
}
.btn-search:hover { background: #0ea5e9; }
.btn-search:disabled { opacity: .5; cursor: not-allowed; }

.search-results {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Search now owns the modal, so let results use more of the screen */
  max-height: 55vh;
  overflow-y: auto;
}

.result-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
  background: var(--surface2);
}
.result-item:hover { background: #2e2c52; }

.result-thumb {
  width: 40px;
  height: 60px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}
.result-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 4px; }

.result-info { flex: 1; min-width: 0; }
.result-title  { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-author { font-size: .76rem; color: var(--muted); }
.result-meta   { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.result-subjects {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 5px;
}

.result-add-shelf {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.result-add-shelf select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: .75rem;
  cursor: pointer;
}
.result-add-shelf button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
}
.result-add-shelf button:hover { background: #0ea5e9; }

/* Manual form divider */
/* Add Book modal — two views: search (default) and manual entry */
.add-view-manual { display: none; }
.add-modal.is-manual .add-view-search { display: none; }
.add-modal.is-manual .add-view-manual { display: block; }

/* Button at the bottom of the search view that switches to the manual form */
.manual-toggle {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  background: none;
  border: 1px dashed var(--surface2);
  border-radius: 10px;
  color: var(--muted);
  font-size: .9rem;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.manual-toggle:hover { border-color: var(--accent); color: var(--text); }
.manual-toggle strong { color: var(--accent); }

/* Link at the top of the manual view that returns to search */
.manual-back {
  background: none;
  border: none;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 4px;
}
.manual-back:hover { color: var(--text); }

/* Manual form */
#manualForm { display: flex; flex-direction: column; gap: 10px; }
#manualForm input,
#manualForm select {
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: .9rem;
  outline: none;
  transition: border .2s;
}
#manualForm input:focus,
#manualForm select:focus { border-color: var(--accent); }
#manualForm select option { background: var(--surface); }

/* Format picker in manual add form */
.manual-format-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.format-label {
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.format-picker {
  display: flex;
  gap: 6px;
}
.fmt-toggle {
  flex: 1;
  padding: 8px 4px;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.fmt-toggle:hover { color: var(--text); border-color: rgba(var(--accent-rgb), .3); }
.fmt-toggle.selected {
  background: rgba(var(--accent-rgb), .15);
  border-color: rgba(var(--accent-rgb), .5);
  color: var(--text);
}

/* Format row in search results — compact icon-only version */
.result-fmt-row {
  display: flex;
  gap: 3px;
  margin-bottom: 2px;
}
.result-fmt-row .fmt-toggle {
  flex: 1;
  padding: 4px 2px;
  font-size: .9rem;
  border-radius: 6px;
}

.btn-add-manual {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, color .2s;
  margin-top: 4px;
}
.btn-add-manual:hover { background: var(--accent); color: #fff; }

/* Loading spinner */
.spinner { text-align: center; padding: 20px; color: var(--muted); font-size: .9rem; }

/* ── Detail modal ─────────────────────────────────────────── */
.detail-modal { max-width: 580px; }

.detail-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.detail-top {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.detail-cover {
  width: 110px;
  height: 165px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
}
.detail-cover img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }

.detail-meta h3   { font-size: 1.15rem; font-weight: 700; margin-bottom: 4px; line-height: 1.3; }
.detail-meta .author { color: var(--muted); font-size: .9rem; }
.detail-api-rating { font-size: .9rem; font-weight: 600; color: var(--accent2); margin-top: 8px; }
.detail-added { font-size: .78rem; color: var(--muted); margin-top: 8px; }

/* Meta grid — single row */
.meta-grid {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface2);
  border-radius: 10px;
  padding: 12px 14px;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  color: var(--text);
  white-space: nowrap;
}
.meta-item--highlight {
  background: rgba(var(--accent-rgb), .1);
  border: 1px solid rgba(var(--accent-rgb), .2);
  border-radius: 6px;
  padding: 4px 8px;
  font-weight: 600;
}

.meta-icon { font-size: .95rem; flex-shrink: 0; }

/* Keep the meta grid on one line on phones too */
@media (max-width: 600px) {
  .meta-grid { gap: 6px; padding: 10px; }
  .meta-item { font-size: .72rem; gap: 4px; }
  .meta-item--highlight { padding: 3px 6px; }
  .meta-icon { font-size: .85rem; }
}

/* Detail sections */
.detail-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.tag-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Synopsis */
.description {
  font-size: .85rem;
  color: var(--muted);
  line-height: 1.65;
}
.muted-text { font-style: italic; opacity: .7; }

.btn-more {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: .85rem;
  padding: 0 0 0 4px;
  font-family: inherit;
}
.btn-more:hover { text-decoration: underline; }

/* Shelf row */
.detail-shelf-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.detail-shelf-row label { color: var(--muted); font-size: .85rem; }
.detail-shelf-row select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: .85rem;
  cursor: pointer;
  outline: none;
}
.detail-shelf-row select:focus { border-color: var(--accent); }

/* Star rating */
.star-rating { display: flex; gap: 4px; }
.star {
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--surface2);
  transition: color .15s, transform .1s;
}
.star:hover,
.star.filled { color: var(--accent2); }
.star:hover  { transform: scale(1.2); }

/* Notes textarea */
.detail-notes textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: .88rem;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border .2s;
}
.detail-notes textarea:focus { border-color: var(--accent); }

.detail-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.btn-save {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.btn-save:hover { background: #0ea5e9; }
.btn-delete {
  background: none;
  border: 1px solid #c0392b;
  color: #c0392b;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: .9rem;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.btn-delete:hover { background: #c0392b; color: #fff; }

/* ── Reading progress ─────────────────────────────────────── */
/* On Currently Reading cards */
.card-progress { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.card-progress-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
}
.card-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 999px;
  transition: width .4s ease;
}
.card-progress-text {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  font-size: .68rem;
  color: var(--accent);
  font-weight: 700;
}
.card-progress-pos { color: var(--muted); font-weight: 500; white-space: nowrap; }
.card-progress-btn {
  background: var(--surface2);
  border: none;
  color: var(--text);
  border-radius: 6px;
  padding: 6px;
  font-size: .68rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.card-progress-btn:hover { background: var(--accent); color: #fff; }

/* In the detail panel */
.detail-progress { display: flex; flex-direction: column; gap: 10px; }
.detail-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.detail-progress-text { font-size: .85rem; color: var(--muted); }
.detail-progress-text strong { color: var(--accent); }

/* Update Progress modal */
.progress-modal { max-width: 420px; }
.progress-book-title { font-size: .9rem; color: var(--muted); margin-bottom: 18px; }
.progress-inputs { display: flex; flex-direction: column; gap: 12px; }
.progress-radio {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
}
.progress-radio:has(input:checked) { border-color: var(--accent); }
.progress-radio-label { font-weight: 600; min-width: 60px; }
.progress-num {
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  width: 88px;
  outline: none;
}
.progress-num--sm { width: 64px; }
.progress-num:disabled { opacity: .4; }
.progress-of { color: var(--muted); font-size: .85rem; }
.progress-preview { margin-top: 20px; text-align: center; font-size: 1.05rem; font-weight: 700; color: var(--accent); }
.progress-preview-bar {
  height: 10px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-preview-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 999px;
  transition: width .25s ease;
}
.progress-actions { display: flex; gap: 10px; justify-content: space-between; margin-top: 22px; }
.btn-finished {
  background: none;
  border: 1px solid var(--surface2);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-finished:hover { border-color: #2ed573; color: #2ed573; }

/* ── For You / Recommendations ────────────────────────────── */
.rec-page { display: flex; flex-direction: column; gap: 32px; max-width: 900px; }

.rec-identity {
  background: rgba(var(--accent-rgb), .1);
  border: 1px solid rgba(var(--accent-rgb), .25);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 1rem;
  color: var(--text);
}
.rec-identity strong { color: var(--accent); }

/* Your Next Read hero */
.rec-hero {
  display: flex;
  gap: 20px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color .2s, transform .2s;
}
.rec-hero:hover { border-color: var(--accent); transform: translateY(-2px); }
.rec-hero-cover {
  width: 110px;
  aspect-ratio: 2/3;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
}
.rec-hero-cover img { width: 100%; height: 100%; object-fit: cover; }
.rec-hero-info { display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.rec-hero-eyebrow { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 700; }
.rec-hero-title { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.rec-hero-author { color: var(--muted); font-size: .9rem; }
.rec-why { margin-top: 6px; font-size: .82rem; color: var(--accent2); text-transform: capitalize; }

/* More of what you love — a wrapped row of normal book cards.
   gap 14px matches the mobile .book-card width calc(50% - 7px) so 2 fit per row. */
.rec-row { display: flex; flex-wrap: wrap; gap: 14px; }

/* Discover section */
.rec-discover-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 12px; margin-bottom: 6px; }
.rec-discover-title { font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text); }
.rec-because { font-size: .82rem; color: var(--muted); margin-bottom: 16px; text-transform: capitalize; }
.rec-refresh {
  background: var(--surface2);
  border: none;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s, color .2s;
}
.rec-refresh:hover { background: var(--accent); color: #fff; }

.rec-discover-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
}
/* Discover cards reuse the standard .book-card; just let them fill the grid cell */
.rec-discover-grid .book-card { width: auto; cursor: default; }
.rec-add-btn {
  margin-top: auto;            /* pin to the bottom of the card */
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.rec-add-btn:hover { background: var(--accent2); color: var(--bg); }

@media (max-width: 600px) {
  .rec-page { gap: 24px; }
  .rec-hero { gap: 14px; padding: 14px; }
  .rec-hero-cover { width: 84px; }
  .rec-hero-title { font-size: 1.15rem; }
  .rec-identity { font-size: .9rem; padding: 12px 14px; }
  .rec-discover-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
}

/* ── Stats tab style ──────────────────────────────────────── */
.tab--stats { margin-left: auto; }

/* Stats & Owned panels override the shelf grid (they're full-width pages, not card grids) */
#shelf-stats          { display: block; }
#shelf-stats.hidden   { display: none; }
#shelf-owned          { display: block; }
#shelf-owned.hidden   { display: none; }
#shelf-foryou         { display: block; }
#shelf-foryou.hidden  { display: none; }

/* ── Stats page layout ────────────────────────────────────── */
.stats-page {
  display: flex;
  flex-direction: column;
  gap: 36px;
  max-width: 860px;
}

/* Overview cards */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 22px 16px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.stat-card-icon { font-size: 1.4rem; }

.stat-number {
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  font-size: .75rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Shelf overview pills */
.shelf-overview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.shelf-ovw-pill {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: .82rem;
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: center;
}
.shelf-ovw-pill strong { color: var(--text); }

/* Stat sections */
.stat-section { display: flex; flex-direction: column; gap: 16px; }

.stat-section-title {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.stat-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--surface2);
}

/* Genre/subject bar chart */
.stat-bars { display: flex; flex-direction: column; gap: 8px; }

.stat-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-bar-label {
  width: 180px;
  font-size: .8rem;
  color: var(--muted);
  text-align: right;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-bar-track {
  flex: 1;
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 4px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
}

.stat-bar-count {
  width: 28px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
  text-align: right;
}

/* ── Owned page ───────────────────────────────────────────── */
.owned-page { display: flex; flex-direction: column; gap: 28px; }

/* Format Breakdown + Read Progress sit side by side on desktop */
.owned-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}

/* Read-progress bar */
.owned-progress { display: flex; flex-direction: column; gap: 12px; }
.owned-progress-bar {
  height: 12px;
  background: var(--surface2);
  border-radius: 6px;
  overflow: hidden;
}
.owned-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 6px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.owned-progress-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .82rem;
  color: var(--muted);
}
.owned-progress-labels strong { color: var(--text); }
.owned-progress-pct { font-weight: 700; color: var(--accent); font-size: 1rem; }
.owned-progress-sub { font-size: .8rem; color: var(--muted); }
.owned-progress-sub strong { color: var(--text); }

/* Format filter pills above the owned book grid */
.owned-filter-row { display: flex; flex-wrap: wrap; gap: 8px; }
.fmt-filter {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: .82rem;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background .2s, color .2s, border-color .2s;
}
.fmt-filter:hover { color: var(--text); border-color: var(--accent); }
.fmt-filter.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.fmt-filter-count {
  background: var(--surface2);
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: .72rem;
  font-weight: 700;
}
.fmt-filter.active .fmt-filter-count { background: rgba(255, 255, 255, .25); color: #fff; }

/* Stack the two stat columns on smaller screens */
@media (max-width: 700px) {
  .owned-stats-grid { grid-template-columns: 1fr; gap: 22px; }
}

/* ── Owned: series grouping ───────────────────────────────── */
.owned-grid { display: flex; flex-direction: column; gap: 14px; }

.series-block {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  overflow: hidden;
}
.series-head {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 12px 14px;
  cursor: pointer;
  transition: background .15s;
}
.series-head:hover { background: var(--surface2); }
.series-peek { display: flex; flex-shrink: 0; padding-left: 14px; }
.series-peek-cover {
  width: 34px;
  height: 51px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--surface2);
  margin-left: -14px;                /* fanned/overlapping stack */
  border: 2px solid var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  flex-shrink: 0;
}
.series-peek-cover img { width: 100%; height: 100%; object-fit: cover; }
.series-head-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.series-name { font-family: var(--font-display); font-weight: 700; font-size: 1rem; }
.series-meta { font-size: .76rem; color: var(--muted); }
.series-progress-bar { height: 5px; background: var(--surface2); border-radius: 999px; overflow: hidden; max-width: 220px; }
.series-progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 999px; }
.series-chevron { color: var(--muted); transition: transform .2s; flex-shrink: 0; font-size: 1.1rem; }

/* Books in a series — hidden until hover (desktop) or tapped open (mobile) */
.series-expanded {
  display: none;
  flex-wrap: wrap;
  gap: 14px;
  padding: 4px 14px 16px;
}
.series-block.is-open .series-expanded { display: flex; }
.series-block.is-open .series-chevron { transform: rotate(90deg); }
@media (hover: hover) {
  .series-block:hover .series-expanded { display: flex; }
  .series-block:hover .series-chevron { transform: rotate(90deg); }
}

/* Standalone owned books (no series) */
.owned-standalone { display: flex; flex-wrap: wrap; gap: 14px; }

/* Tone stats */
.tone-stats { display: flex; flex-wrap: wrap; gap: 10px; }

.tone-stat-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(var(--accent3-rgb), .1);
  border: 1px solid rgba(var(--accent3-rgb), .22);
  border-radius: 999px;
  padding: 6px 14px 6px 12px;
  transition: background .3s, border-color .3s;
}

.tone-stat-label {
  font-size: .84rem;
  font-weight: 600;
  color: var(--accent3);
}

.tone-stat-count {
  font-size: .72rem;
  font-weight: 700;
  background: rgba(var(--accent3-rgb), .28);
  color: var(--accent3);
  border-radius: 999px;
  padding: 1px 8px;
  min-width: 20px;
  text-align: center;
}

/* Pace grid */
.pace-grid { display: flex; flex-wrap: wrap; gap: 12px; }

.pace-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 18px 24px;
  min-width: 90px;
  text-align: center;
}

.pace-stat-emoji { font-size: 1.6rem; }
.pace-stat-count { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1; }
.pace-stat-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ── Premium badge on locked theme buttons ────────────────── */
.theme-btn { position: relative; }

.premium-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  color: #1a0e00;
  font-size: .52rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 999px;
  pointer-events: none;
}

.theme-btn[data-premium] {
  opacity: 0.5;
  cursor: default;
}
.theme-btn[data-premium]:hover {
  opacity: 0.72;
  background: var(--surface2);
  border-color: rgba(var(--accent-rgb), .15);
}
.theme-btn[data-premium].active {
  /* Premium themes can't be truly active — reset to un-selected look */
  border-color: transparent;
  background: none;
}

/* ── Toast notification ───────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--surface);
  border: 1px solid rgba(var(--accent-rgb), .25);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: opacity .22s ease, transform .22s ease;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.toast--show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Settings modal ───────────────────────────────────────── */
.settings-modal { max-width: 460px; }

.settings-section {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--surface2);
}

.settings-section-title {
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 6px;
}

.settings-hint {
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: 14px;
}

.settings-theme-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Styled select for settings */
.settings-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .9rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border .2s;
  width: 100%;
}
.settings-select:focus { border-color: var(--accent); }
.settings-select option { background: var(--surface); }

/* Developer / testing tools */
.settings-dev { border-top: 1px dashed var(--surface2); padding-top: 18px; }
.settings-dev-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-dev {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: .85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s;
}
.btn-dev:hover { border-color: var(--accent); color: var(--text); background: rgba(var(--accent-rgb), .1); }
.btn-dev--danger { color: #ff6b6b; }
.btn-dev--danger:hover { border-color: #ff6b6b; background: rgba(255,107,107,.1); color: #ff6b6b; }

/* Styled select for the search result format dropdown */
.fmt-primary-select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: 6px;
  padding: 5px 7px;
  font-size: .78rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  width: 100%;
  transition: border .2s;
}
.fmt-primary-select:focus { border-color: var(--accent); }

/* "Also own as" checkbox rows */
.also-own-checks {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.also-check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .76rem;
  color: var(--muted);
  cursor: pointer;
  padding: 3px 0;
  white-space: nowrap;
  transition: color .15s;
}
.also-check-row:hover { color: var(--text); }
.also-check-row input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}
.also-check-row.hidden { display: none; }

/* Also-own section in the manual form */
#manualAlsoChecks .also-check-row {
  font-size: .82rem;
  padding: 5px 0;
}

/* ── Text size / viewport scaling ────────────────────────── */
/* Base: grows gently with viewport width so large monitors aren't cramped.
   clamp(min, preferred, max) — at 1080p ≈ 17px, at 1440p ≈ 19px, never below 15px. */
html { font-size: clamp(15px, 1.0vw, 21px); }

/* Settings override — each tier shifts the whole scale */
[data-text-size="small"]  { font-size: clamp(13px, 0.85vw, 18px); }
[data-text-size="medium"] { font-size: clamp(15px, 1.00vw, 21px); }
[data-text-size="large"]  { font-size: clamp(18px, 1.20vw, 26px); }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 3px; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 700px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .stat-bar-label { width: 110px; }
  .settings-theme-row { gap: 6px; }
}

@media (max-width: 600px) {
  /* iOS auto-zooms when you focus a field smaller than 16px.
     Forcing 16px on mobile stops that "everything suddenly zoomed" jump. */
  input, select, textarea { font-size: 16px; }

  /* Give all content a bit more width on small screens */
  main { padding: 24px 16px; }

  /* Shelves: two books per row filling the width, with a slimmer plank */
  .book-row { gap: 14px; padding: 0 6px 12px; margin-bottom: 24px; }
  .book-row::after { height: 11px; }
  .book-card { width: calc(50% - 7px); }

  /* Stats page: tighten cards/bars so they don't feel cramped on a phone */
  .stats-page { gap: 28px; }
  .stat-cards { gap: 10px; }
  .stat-card { padding: 16px 10px 14px; gap: 6px; }
  .stat-card-icon { font-size: 1.2rem; }
  .stat-number { font-size: 1.5rem; }
  .stat-bar-row { gap: 8px; }
  .stat-bar-label { width: 88px; font-size: .74rem; }
  .pace-stat { flex: 1; min-width: 70px; }
  .header-inner { flex-wrap: wrap; gap: 8px; }
  .header-right { gap: 6px; }
  .btn-ghost { padding: 7px 10px; font-size: .78rem; }

  /* Modals go full-screen on mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    padding: 20px;
    border-radius: 18px 18px 0 0;
    max-height: 92dvh;
    width: 100%;
    max-width: 100%;
  }
  .detail-modal { max-height: 92dvh; }
  .settings-modal { max-height: 85dvh; }

  /* Detail modal content */
  .detail-top { flex-direction: column; }
  .detail-cover { width: 80px; height: 120px; }

  /* Touch-target sweep: bigger detail-modal controls on phones */
  .star { font-size: 1.85rem; }
  .star-rating { gap: 8px; }
  .fmt-toggle { padding: 12px 6px; }
  .detail-shelf-row select { padding: 10px 12px; }
  .detail-actions { gap: 12px; }
  .btn-save, .btn-delete { padding: 13px 20px; }
  .storage-badge { padding: 6px 12px; }

  /* Search result items stack vertically on mobile */
  .result-item { flex-wrap: wrap; padding: 12px; }
  .result-add-shelf {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }
  .fmt-primary-select { width: auto; flex: 1; min-width: 120px; }
  .also-own-checks { flex-direction: row; flex-wrap: wrap; gap: 8px; width: 100%; }

  /* Bigger, thumb-friendly controls */
  .result-add-shelf select { padding: 10px 12px; border-radius: 8px; }
  .result-add-btn {
    margin-left: auto;
    padding: 10px 18px;
    font-size: .9rem;
    border-radius: 8px;
    min-width: 84px;
  }
  .also-check-row {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    background: var(--bg);
    border-radius: 8px;
    font-size: .85rem;
  }
  .also-check-row input { width: 18px; height: 18px; }

  /* Tabs */
  .tab--stats { margin-left: 0; }
  .shelf-tabs { overflow-x: auto; padding-bottom: 4px; flex-wrap: nowrap; }
  .tab { white-space: nowrap; padding: 10px 12px; }
}

/* ── Sidebar layout overrides ─────────────────────────────── */
/* The horizontal banner art doesn't fit the sidebar layout */
.header-canvas { display: none; }

/* Header becomes a slim top bar inside the main column */
.app-main > header {
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-main .header-inner {
  max-width: none;
  margin: 0;
  padding: 14px 28px;
  justify-content: flex-end;
}
.app-main .header-inner .storage-badge { margin-right: auto; }
.app-main > header > main,
.app-main main { max-width: 1100px; }

/* Mobile: logo becomes a slim top bar, nav becomes a fixed bottom tab bar */
@media (max-width: 820px) {
  .app-layout { flex-direction: column; }

  /* Top bar now holds only the logo */
  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    /* Keep clear of the iPhone status bar / notch */
    padding-top: calc(10px + env(safe-area-inset-top));
    gap: 10px;
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid rgba(var(--accent-rgb), .12);
  }
  .sidebar-logo { flex-direction: row; align-items: center; gap: 8px; padding: 0; }
  .sidebar-logo-img { width: 38px; }
  .sidebar-logo-text { font-size: 1.3rem; margin-top: 0; }

  /* The reading preview + divider are desktop-sidebar only */
  .reading-mini, .sidebar-nav-divider { display: none; }

  /* Nav detaches from the sidebar and pins to the bottom of the screen */
  .sidebar-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    flex-direction: row;
    gap: 0;
    background: var(--surface);
    border-top: 1px solid rgba(var(--accent-rgb), .14);
    padding: 6px 4px;
    /* Lift the bar above the iPhone home indicator */
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 18px rgba(0, 0, 0, .18);
  }
  .sidebar-nav .tab {
    flex: 1;
    width: auto;
    min-height: 58px;          /* comfortable thumb target */
    flex-direction: column;     /* label sits centred */
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 1px;
    font-size: .74rem;          /* sized to fit 6 tabs across a phone */
    font-weight: 600;
    white-space: nowrap;
    border-radius: 10px;
  }
  .sidebar-nav .tab--stats { margin-top: 0; }

  /* Use the short labels and hide the count pills to keep tabs clean */
  .sidebar-nav .tab-long { display: none; }
  .sidebar-nav .tab-short { display: inline; }
  .sidebar-nav .count { display: none; }

  /* Stop book cards hiding behind the fixed bottom bar */
  .app-main { padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
}

/* ── Auth screen ─────────────────────────────────────────────────── */
.auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg, #0d1b2a);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.auth-logo-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.auth-logo-text {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text, #e8e0d0);
}

.auth-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text, #e8e0d0);
  margin: 0;
}

.auth-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted, #8899aa);
  margin: 0 0 16px;
}

.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form input {
  width: 100%;
  padding: 12px 14px;
  background: var(--card-bg, #1a2e42);
  border: 1px solid var(--border, #2a3f55);
  border-radius: 8px;
  color: var(--text, #e8e0d0);
  font-size: 1rem;
  font-family: 'Inter', sans-serif;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent, #5b9bd5);
}

.auth-form button[type="submit"] {
  width: 100%;
  padding: 13px;
  background: var(--accent, #5b9bd5);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}

.auth-form button[type="submit"]:hover  { opacity: 0.9; }
.auth-form button[type="submit"]:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-error {
  font-size: 0.85rem;
  min-height: 18px;
  margin: 0;
  text-align: center;
}

.auth-toggle {
  font-size: 0.85rem;
  color: var(--text-muted, #8899aa);
  margin-top: 8px;
}

.auth-toggle a {
  color: var(--accent, #5b9bd5);
  text-decoration: none;
}

.auth-toggle a:hover { text-decoration: underline; }
