/* ===== 书归一记 v4 ===== */

/* ── Design Tokens (Light — default) ── */
:root {
  --bg: #F2F2F7;
  --surface: #FFFFFF;
  --text: #000000;
  --text-secondary: #8E8E93;
  --text-tertiary: #C7C7CC;
  --separator: #E5E5EA;
  --separator-opaque: #C6C6C8;
  --accent: #007AFF;
  --danger: #FF3B30;
  --success: #34C759;
  --star: #FF9500;
  --radius: 6px;
  --radius-sm: 4px;
  --nav-height: 50px;
  --header-height: 44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --glass-bg: rgba(242, 242, 247, 0.85);
  --glass-blur: blur(20px);
  --tinted-bg: rgba(229, 236, 238, 0.95);

  /* Fonts */
  --font-display: "Georgia", "Noto Serif SC", "Songti SC", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", "Menlo", "Consolas", monospace;
}

/* ── Dark Theme ── */
[data-theme="dark"] {
  --bg: #000000;
  --surface: #1C1C1E;
  --text: #FFFFFF;
  --text-secondary: #8E8E93;
  --text-tertiary: #48484A;
  --separator: #38383A;
  --separator-opaque: #38383A;
  --accent: #0A84FF;
  --danger: #FF453A;
  --success: #30D158;
  --star: #FF9F0A;
  --glass-bg: rgba(0, 0, 0, 0.85);
  --glass-blur: blur(20px);
  --tinted-bg: rgba(28, 31, 33, 0.95);
}

/* ── Reset ── */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── SVG Icon ── */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: visible;
}

/* ── Header ── */
.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--tinted-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 0.5px solid var(--separator);
  flex-shrink: 0;
  z-index: 50;
}

.app-header h1 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.app-slogan {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  opacity: 0.75;
  white-space: nowrap;
  letter-spacing: 0.3px;
}

/* ── Pages ── */
.page {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.page.active { display: flex; }

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px calc(var(--nav-height) + var(--safe-bottom) + 12px) 20px;
  -webkit-overflow-scrolling: touch;
}

/* ── Bottom Navigation — frosted glass ── */
.bottom-nav {
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--tinted-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: 0.5px solid var(--separator);
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 12px;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 10px;
  font-family: var(--font-body);
  font-weight: 500;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
}

.nav-item .nav-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.nav-item.active { color: var(--accent); }

/* ── Book Card (no overlay) ── */
.book-card {
  position: relative;
  cursor: pointer;
  transition: opacity 0.15s;
  min-width: 0;           /* 防止 grid item 被长书名/作者名撑开 */
  overflow: hidden;       /* 配合 min-width: 0 截断超长文本 */
}

.book-card:active { opacity: 0.7; }

.book-card .book-cover {
  position: relative;
  width: 100%;
  padding-bottom: 150%;   /* 2:3 比例，兼容 aspect-ratio 失效的环境 */
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--separator);
}

.book-card .book-cover img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.book-card .book-cover-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--separator);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
}

.book-card .favorite-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  color: var(--star);
}

.book-card .book-meta {
  padding: 6px 2px 0;
}

.book-card .book-title {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-card .book-author {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Book Grid ── */
.book-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

/* ── Secondary View Tabs — frosted glass pills ── */
.view-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  padding: 3px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.view-tab {
  flex: 1;
  min-width: 50px;
  position: relative;
  padding: 9px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: var(--font-body);
  font-weight: 400;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  line-height: 1;
}

.view-tab.active {
  color: var(--text);
  font-weight: 500;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

[data-theme="dark"] .view-tab.active {
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* Remove underline indicator — pills don't need it */
.view-tab::after { display: none; }

/* ── Search Bar ── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--separator);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 14px;
}

.search-bar .search-icon {
  color: var(--text-secondary);
  display: flex;
  align-items: center;
}

.search-bar input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-body);
}

.search-bar input::placeholder { color: var(--text-tertiary); }

/* ── Group Sections ── */
.group-section { margin-bottom: 28px; }

.group-header {
  font-family: var(--font-body);
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  padding: 8px 0 12px 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.group-count {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 400;
}

.group-subsection { margin-bottom: 20px; }

.group-subheader {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding: 6px 0 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.btn:active { opacity: 0.6; }

.btn-primary {
  background: var(--accent);
  color: #FFFFFF;
}

.btn-secondary {
  background: var(--surface);
  color: var(--accent);
}

.btn-danger { background: none; color: var(--danger); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-primary:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Form — iOS Grouped List (for add-book/detail) ── */
.form-section { margin-bottom: 24px; }
.form-section:first-of-type { margin-top: 8px; }

.form-section-header {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 16px 6px 16px;
  font-weight: 500;
}

.form-row {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  background: var(--surface);
  min-height: 44px;
}

.form-row + .form-row { border-top: 0.5px solid var(--separator); }

/* First form-row after a section header gets top rounding */
.form-section-header + .form-row { border-radius: var(--radius) var(--radius) 0 0; }
.form-row:last-of-type { border-radius: 0 0 var(--radius) var(--radius); }
/* Single form-row after header gets full rounding */
.form-section-header + .form-row:last-of-type { border-radius: var(--radius); }
/* When there's no header */
.form-section > .form-row:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.form-section > .form-row:first-child:last-child { border-radius: var(--radius); }

.form-row .row-label {
  font-size: 15px;
  color: var(--text);
  min-width: 72px;
  flex-shrink: 0;
}

.form-row input,
.form-row select,
.form-row textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-body);
  text-align: right;
  padding: 0;
}

.form-row input::placeholder,
.form-row textarea::placeholder { color: var(--text-tertiary); }

.form-row select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.form-row textarea {
  text-align: left;
  resize: vertical;
  min-height: 60px;
  padding: 4px 0;
}

/* ── Modal form input ── */
.modal-form-group {
  margin-bottom: 14px;
}

.modal-form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.modal-form-group input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.2s;
}

.modal-form-group input:focus { border-color: var(--accent); }

.modal-form-inline {
  display: flex;
  gap: 8px;
}

.modal-form-inline input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-body);
  outline: none;
}

.modal-form-inline input:focus { border-color: var(--accent); }

/* Cover upload — Apple style dashed border */
.cover-upload {
  width: 120px;
  height: 160px;
  margin: 16px auto 24px;
  border: 1.5px dashed var(--separator-opaque);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  background: var(--surface);
  transition: border-color 0.2s;
}

.cover-upload:active { border-color: var(--accent); }

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

.cover-upload .upload-placeholder {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

.cover-upload .upload-placeholder .upload-icon {
  display: block;
  margin-bottom: 6px;
  color: var(--text-tertiary);
}

/* Cover section — side by side with scan button */
.cover-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.cover-section .cover-upload { margin: 0; flex-shrink: 0; }

/* Scan ISBN frosted glass button */
.btn-scan-isbn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100px;
  height: 100px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-scan-isbn:active {
  transform: scale(0.95);
  opacity: 0.8;
}

[data-theme="dark"] .btn-scan-isbn {
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.btn-scan-isbn svg {
  opacity: 0.8;
}

.cover-upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  text-align: center;
}

.empty-state .empty-icon {
  color: var(--text-tertiary);
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state .empty-text {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-state .empty-hint {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 22px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-body);
  z-index: 1000;
  animation: toast-in 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Modal — frosted glass ── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  animation: fade-in 0.2s ease;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 360px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.12);
  animation: modal-in 0.25s ease;
}

[data-theme="dark"] .modal {
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal h3 {
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
  text-align: center;
}

/* Modal header row for close button + title */
.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 16px;
}

.modal-header-row h3 {
  margin-bottom: 0;
}

.modal-close-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: opacity 0.15s;
}
.modal-close-btn:active { opacity: 0.5; }

[data-theme="dark"] .modal-close-btn {
  background: rgba(255,255,255,0.1);
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  justify-content: flex-end;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Wishlist Counter ── */
.wishlist-counter {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
}

.wishlist-counter .counter-bar {
  flex: 1;
  height: 4px;
  background: var(--separator);
  border-radius: 2px;
  overflow: hidden;
}

.wishlist-counter .counter-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.wishlist-counter .counter-text {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
  white-space: nowrap;
}

/* ── Context Menu ── */
.context-menu {
  position: fixed;
  background: var(--surface);
  border-radius: var(--radius);
  z-index: 300;
  min-width: 180px;
  overflow: hidden;
  animation: fade-in 0.12s ease;
  box-shadow: 0 2px 24px rgba(0,0,0,0.15);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-family: var(--font-body);
  color: var(--text);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background 0.1s;
}

.context-menu-item:active { background: var(--separator); }
.context-menu-item.danger { color: var(--danger); }

.context-menu-divider {
  height: 0.5px;
  background: var(--separator);
  margin: 4px 0;
}

/* ── Settings — iOS grouped list ── */
.settings-section { margin-bottom: 28px; }

.settings-items {
  border-radius: var(--radius);
  overflow: hidden;
}

.settings-section-header {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 16px 6px 16px;
  font-weight: 500;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  cursor: pointer;
  transition: background 0.1s;
  min-height: 44px;
}

.settings-item + .settings-item { border-top: 0.5px solid var(--separator); }

.settings-item:first-of-type { border-radius: var(--radius) var(--radius) 0 0; }
.settings-item:last-of-type { border-radius: 0 0 var(--radius) var(--radius); }
.settings-item:only-of-type { border-radius: var(--radius); }

.settings-item:active { background: var(--separator); }

.settings-item .item-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-item .item-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  overflow: visible;
}

.settings-item .item-icon .icon { overflow: visible; }

.settings-item .item-label {
  font-size: 15px;
  color: var(--text);
}

.settings-item .item-right {
  display: flex;
  align-items: center;
  gap: 0;
  color: var(--text-secondary);
  font-size: 15px;
  flex-shrink: 0;
  line-height: 1;
}

.settings-item .item-right .chevron {
  margin-left: 2px;
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid var(--text-tertiary);
  line-height: 1;
  vertical-align: middle;
}

/* ── Stats Modal (list style) ── */
.stat-modal-body {
  max-height: 55vh;
  overflow-y: auto;
}
.stat-modal-body::-webkit-scrollbar { width: 0; }

.stat-summary {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.stat-summary-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-summary-val {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.stat-summary-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.stat-section {
  margin-bottom: 16px;
}

.stat-section-header {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-section-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  background: var(--bg-card);
  border-radius: 10px;
  padding: 2px 8px;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
}

.stat-row:nth-child(even) {
  background: var(--bg);
}

.stat-row-count {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}
  margin-top: 4px;
}

/* ── Detail Page ── */
.detail-cover-wrap {
  width: calc((100% - 24px) / 3); /* same as 3-col grid card */
  aspect-ratio: 2/3;
  margin: 0 auto 20px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--separator);
}

.detail-cover {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-cover-placeholder {
  width: calc((100% - 24px) / 3);
  aspect-ratio: 2/3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--separator);
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  margin: 0 auto 20px;
}

.detail-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  margin-bottom: 4px;
}

.detail-author {
  font-size: 15px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 4px;
}

.detail-synopsis {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  padding: 0 4px;
  margin-bottom: 24px;
}

/* ── Detail Back Button — small frosted glass square ── */
.detail-back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: var(--text-secondary);
  cursor: pointer;
  margin-top: -4px;
  margin-bottom: 12px;
  font-size: 13px;
  font-family: var(--font-body);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  transition: opacity 0.15s;
}

.detail-back-btn:active { opacity: 0.6; }

[data-theme="dark"] .detail-back-btn {
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* ── Reading Progress Section ── */
.reading-progress-section {
  margin-bottom: 20px;
  padding: 0 4px;
}

.reading-progress-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  font-weight: 500;
}

.reading-progress-pills {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.progress-pill {
  padding: 6px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.15s;
  min-width: 38px;
  text-align: center;
}

.progress-pill:active { opacity: 0.7; }

.progress-pill.active {
  background: var(--accent);
  color: #FFFFFF;
  font-weight: 500;
}

/* ── Detail Info Section ── */
.detail-info-section .form-row:first-of-type { border-radius: var(--radius) var(--radius) 0 0; }
.detail-info-section .form-row:last-of-type { border-radius: 0 0 var(--radius) var(--radius); }
.detail-info-section .form-row:only-of-type { border-radius: var(--radius); }

/* ── Detail Actions — frosted glass rows ── */
.detail-actions-glass {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 24px;
}

.detail-glass-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: var(--text-secondary);
  font-size: 15px;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.detail-glass-btn:active { opacity: 0.6; }
.detail-glass-btn.danger { color: var(--danger); }

[data-theme="dark"] .detail-glass-btn {
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* ── Delete Sheet (bottom slide-up) ── */
.delete-sheet-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 400;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in 0.2s ease;
}

.delete-sheet {
  width: 100%;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  padding: 24px 20px calc(var(--safe-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: sheet-up 0.25s ease;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
}

.delete-sheet-title {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  padding: 8px 0 6px;
}

.delete-sheet-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  transition: opacity 0.15s;
}

.delete-sheet-btn:active { opacity: 0.7; }
.delete-sheet-btn.danger { color: var(--danger); }

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ── Book Action Sheet (bottom slide-up, reuses delete-sheet pattern) ── */
.book-action-sheet-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 400;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in 0.2s ease;
}

.book-action-sheet {
  width: 100%;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  padding: 24px 20px calc(var(--safe-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: sheet-up 0.25s ease;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
}

.book-action-sheet-title {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  padding: 8px 0 6px;
}

.book-action-sheet-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  transition: opacity 0.15s;
}

.book-action-sheet-btn:active { opacity: 0.7; }
.book-action-sheet-btn.danger { color: var(--danger); }
.book-action-sheet-btn.cancel {
  background: transparent;
  font-weight: 400;
  color: var(--text-secondary);
}

/* ── Two-Card Selector (Add page) ── */
.add-method-cards {
  display: flex;
  gap: 12px;
  padding: 32px 8px;
}

.add-method-card {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 16px 24px;
  text-align: center;
  cursor: pointer;
  transition: opacity 0.15s;
}

.add-method-card:active { opacity: 0.6; }

.add-method-card .method-icon {
  margin-bottom: 14px;
  color: var(--accent);
}

.add-method-card .method-title {
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.add-method-card .method-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Scan Page ── */
.scan-container {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.scan-viewport {
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-viewport .scan-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.scan-viewport .scan-corners { position: absolute; inset: 32px; }

.scan-corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: rgba(255,255,255,0.6);
  border-style: solid;
}

.scan-corner.tl { top: 0; left: 0; border-width: 2px 0 0 2px; border-radius: 0; }
.scan-corner.tr { top: 0; right: 0; border-width: 2px 2px 0 0; border-radius: 0; }
.scan-corner.bl { bottom: 0; left: 0; border-width: 0 0 2px 2px; border-radius: 0; }
.scan-corner.br { bottom: 0; right: 0; border-width: 0 2px 2px 0; border-radius: 0; }

.scan-viewport .scan-placeholder {
  color: rgba(255,255,255,0.3);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}

.scan-viewport .scan-placeholder .scan-placeholder-icon {
  display: block;
  margin-bottom: 12px;
  color: rgba(255,255,255,0.15);
}

.scan-viewport video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0; left: 0;
}

.scan-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ── Scrollbar ── */
.page-content::-webkit-scrollbar { width: 0; }
.modal::-webkit-scrollbar { width: 0; }

/* ── Modal list items (shelves, categories) ── */
.modal-list {
  max-height: 45vh;
  overflow-y: auto;
}

.modal-list::-webkit-scrollbar { width: 0; }

.modal-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg);
  border-radius: var(--radius);
  margin-bottom: 8px;
  gap: 12px;
}

.modal-list-item-main {
  flex: 1;
  min-width: 0;
}

.modal-list-item-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  display: block;
}

.modal-list-item-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-list-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Theme toggle ── */
.theme-options {
  display: flex;
  gap: 12px;
}

.theme-option {
  flex: 1;
  padding: 16px;
  background: var(--surface);
  border: 2px solid var(--separator);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  font-size: 14px;
}

.theme-option.active { border-color: var(--accent); }

/* ── Responsive ── */
@media (min-width: 768px) {
  .book-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }
}
