/* ═══════════════════════════════════════════════════════════════════
   MANGASHELF – Design System
═══════════════════════════════════════════════════════════════════ */

:root {
  --bg:            #0d0d14;
  --surface:       #16161f;
  --surface-2:     #1e1e2e;
  --surface-3:     #252538;
  --accent:        #8b5cf6;
  --accent-alt:    #ec4899;
  --accent-glow:   rgba(139,92,246,0.35);
  --accent-grad:   linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --text:          #f1f5f9;
  --text-2:        #94a3b8;
  --text-3:        #64748b;
  --border:        rgba(255,255,255,0.07);
  --border-hover:  rgba(139,92,246,0.45);
  --radius-sm:     8px;
  --radius:        12px;
  --radius-lg:     18px;
  --radius-xl:     24px;
  --shadow-card:   0 4px 24px rgba(0,0,0,0.45);
  --shadow-glow:   0 8px 32px rgba(139,92,246,0.25);
  --t:             0.2s ease;
  --header-h:      62px;
  --sort-h:        44px;
  --reader-bar-h:  60px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { cursor: pointer; font-family: inherit; }
input  { font-family: inherit; }
a      { color: inherit; text-decoration: none; }

/* ─── Views ─────────────────────────────────────────────────────────── */
.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.view.active   { opacity: 1; pointer-events: all; transform: translateX(0); transition: opacity .3s, transform .35s cubic-bezier(.4,0,.2,1); }
.view.slide-out{ opacity: 0; pointer-events: none; transform: translateX(100%); transition: opacity .3s, transform .35s cubic-bezier(.4,0,.2,1); }
.view.hidden   { display: none; }

/* ═══════════════════════════════════════════════════════════════════
   LIBRARY VIEW
═══════════════════════════════════════════════════════════════════ */

/* ─── Header ─────────────────────────────────────────────────────── */
.library-header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 14px;
  background: rgba(13,13,20,0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: relative;
  z-index: 20;
}

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

.logo-icon {
  font-size: 26px;
  filter: drop-shadow(0 0 10px rgba(139,92,246,.7));
  animation: breathe 3s ease-in-out infinite;
}

@keyframes breathe {
  0%,100% { filter: drop-shadow(0 0 8px rgba(139,92,246,.5)); }
  50%      { filter: drop-shadow(0 0 16px rgba(236,72,153,.7)); }
}

.brand-name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

/* Search */
.search-wrapper {
  position: relative;
  flex: 1;
  max-width: 380px;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-3);
  pointer-events: none;
}

#search-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 36px 9px 36px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}

#search-input:focus {
  border-color: var(--accent);
  background: var(--surface-3);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#search-input::placeholder { color: var(--text-3); }

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color var(--t);
}
.search-clear:hover { color: var(--text); }

/* Icon buttons */
.icon-btn {
  width: 38px;
  height: 38px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--t), border-color var(--t), color var(--t), box-shadow var(--t);
}

.icon-btn:hover {
  background: var(--surface-3);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.icon-btn.active {
  background: rgba(139,92,246,.2);
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── Sort bar ───────────────────────────────────────────────────── */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  height: var(--sort-h);
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.sort-bar::-webkit-scrollbar { display: none; }

.sort-chip {
  padding: 5px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all var(--t);
}

.sort-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.sort-chip.active {
  background: var(--accent-grad);
  border-color: transparent;
  color: white;
  font-weight: 600;
}

/* ─── Library Grid ───────────────────────────────────────────────── */
.library-grid {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 18px;
  align-content: start;
  overscroll-behavior: contain;
}

.library-grid::-webkit-scrollbar { width: 5px; }
.library-grid::-webkit-scrollbar-track { background: transparent; }
.library-grid::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }

/* ─── Manga Card ─────────────────────────────────────────────────── */
.manga-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  aspect-ratio: 2/3;
  display: flex;
  flex-direction: column;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .25s ease, border-color .2s ease;
  -webkit-tap-highlight-color: transparent;
}

.manga-card:hover {
  transform: translateY(-5px) scale(1.02);
  box-shadow: var(--shadow-glow);
  border-color: var(--border-hover);
}

.manga-card:active {
  transform: scale(0.97);
  transition-duration: .1s;
}

/* Cover area */
.card-cover {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  min-height: 0;
}

.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .45s ease, opacity .3s ease;
  opacity: 0;
}

.card-cover img.loaded { opacity: 1; }

.manga-card:hover .card-cover img { transform: scale(1.07); }

.card-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 52px;
  background: linear-gradient(135deg, var(--surface-2), var(--surface-3));
}

/* Hover overlay */
.card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.88) 0%, rgba(0,0,0,.1) 55%, transparent 100%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 12px;
  opacity: 0;
  transition: opacity .22s ease;
}

.manga-card:hover .card-overlay { opacity: 1; }

.open-btn {
  background: var(--accent-grad);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 22px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .3px;
  box-shadow: 0 4px 16px rgba(139,92,246,.5);
  transform: translateY(6px);
  transition: transform .2s ease;
}

.manga-card:hover .open-btn { transform: translateY(0); }

/* NEW / Completed badge */
.card-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 20px;
  z-index: 2;
}

.card-badge.new      { background: var(--accent-grad); color: white; }
.card-badge.done     { background: rgba(16,185,129,.85); color: white; }
.card-badge.reading  { background: rgba(245,158,11,.85); color: white; }

/* Info area */
.card-info {
  padding: 10px 12px 10px;
  flex-shrink: 0;
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
  line-height: 1.3;
}

.progress-bar {
  height: 3px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 5px;
}

.progress-fill {
  height: 100%;
  background: var(--accent-grad);
  border-radius: 2px;
  transition: width .4s ease;
  min-width: 3px;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-3);
}

/* ─── Empty / Error / Loading states ────────────────────────────── */
.empty-state, .loading-state {
  position: absolute;
  inset: var(--header-h) 0 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px 24px;
  text-align: center;
  pointer-events: all;
}

.empty-state.hidden, .loading-state.hidden { display: none; }

.empty-icon { font-size: 72px; line-height: 1; }

.empty-state h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.empty-state p {
  color: var(--text-2);
  max-width: 320px;
  line-height: 1.7;
  font-size: 14px;
}

.empty-state code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 5px;
  font-family: 'Courier New', monospace;
  color: var(--accent);
  font-size: 13px;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
.spinner.large { width: 52px; height: 52px; border-width: 4px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Buttons */
.btn-primary {
  background: var(--accent-grad);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 28px;
  font-size: 14px;
  font-weight: 700;
  transition: opacity var(--t), transform .1s;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-primary:hover { opacity: .85; }
.btn-primary:active { transform: scale(.97); }

.btn-danger {
  background: rgba(239,68,68,.15);
  border: 1px solid rgba(239,68,68,.35);
  color: #f87171;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  transition: background var(--t);
  width: 100%;
}
.btn-danger:hover { background: rgba(239,68,68,.25); }

.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════════════
   READER VIEW
═══════════════════════════════════════════════════════════════════ */

#reader-view {
  background: #000;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

/* ─── Top bar ────────────────────────────────────────────────────── */
.reader-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: var(--reader-bar-h);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 10px;
  background: linear-gradient(to bottom, rgba(0,0,0,.88) 0%, rgba(0,0,0,.3) 70%, transparent 100%);
  backdrop-filter: blur(2px);
  transition: opacity .3s ease, transform .3s ease;
  will-change: transform, opacity;
}

.reader-topbar.bar-hidden {
  opacity: 0;
  transform: translateY(-100%);
  pointer-events: none;
}

/* ─── Bottom bar ─────────────────────────────────────────────────── */
.reader-bottombar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  min-height: var(--reader-bar-h);
  display: flex;
  align-items: center;
  padding: 8px 14px max(8px, env(safe-area-inset-bottom));
  gap: 10px;
  background: linear-gradient(to top, rgba(0,0,0,.88) 0%, rgba(0,0,0,.3) 70%, transparent 100%);
  backdrop-filter: blur(2px);
  transition: opacity .3s ease, transform .3s ease;
  will-change: transform, opacity;
}

.reader-bottombar.bar-hidden {
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
}

/* Reader icon buttons */
.reader-icon-btn {
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: var(--radius-sm);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--t), border-color var(--t);
  -webkit-tap-highlight-color: transparent;
}

.reader-icon-btn:hover { background: rgba(255,255,255,.2); }
.reader-icon-btn:active { background: rgba(255,255,255,.3); transition-duration: .05s; }

.reader-icon-btn.active {
  background: rgba(139,92,246,.35);
  border-color: rgba(139,92,246,.6);
}

.reader-icon-btn--sm { width: 36px; height: 36px; }

.reader-title-wrap {
  flex: 1;
  min-width: 0;
}

.reader-top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.page-counter {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,.7);
  white-space: nowrap;
  min-width: 56px;
  text-align: right;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
}

/* Nav buttons */
.nav-btn {
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: var(--radius-sm);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--t);
  -webkit-tap-highlight-color: transparent;
}
.nav-btn:hover  { background: rgba(255,255,255,.22); }
.nav-btn:active { background: rgba(255,255,255,.35); transition-duration: .05s; }

/* Slider */
.slider-wrap { flex: 1; display: flex; align-items: center; }

.page-slider {
  width: 100%;
  -webkit-appearance: none;
  height: 4px;
  background: rgba(255,255,255,.18);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.page-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.5), 0 0 0 3px rgba(139,92,246,.4);
  transition: box-shadow var(--t);
}

.page-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.5), 0 0 0 5px rgba(139,92,246,.5);
}

.page-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}

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

/* ─── Image container ───────────────────────────────────────────── */
.image-container {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.image-container::-webkit-scrollbar { display: none; }

/* Scroll mode */
.image-container.mode-scroll {
  display: block;
}

.image-container.mode-scroll img {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  padding: 1px 0;
  pointer-events: none;
}

/* Fit modes */
.image-container.mode-scroll.fit-width  img { width: 100%; max-width: 860px; }
.image-container.mode-scroll.fit-height img { height: 100vh; width: auto; max-width: none; }
.image-container.mode-scroll.fit-original img { width: auto; max-width: none; }

/* Page mode */
.image-container.mode-page {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.image-container.mode-page img {
  display: none;
  pointer-events: none;
}

.image-container.mode-page img.active-page {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* ─── Tap zones ─────────────────────────────────────────────────── */
.tap-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 22%;
  z-index: 30;
  display: none;
}

.tap-left  { left: 0; }
.tap-right { right: 0; }

.mode-page-active .tap-zone { display: block; }

/* ─── Reader loading ─────────────────────────────────────────────── */
.reader-loading {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 200;
  transition: opacity .3s ease;
}

.reader-loading.fade-out {
  opacity: 0;
  pointer-events: none;
}

.reader-loading p {
  color: var(--text-2);
  font-size: 14px;
}

.reader-progress-track {
  width: 220px;
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}

.reader-progress-fill {
  height: 100%;
  background: var(--accent-grad);
  border-radius: 2px;
  width: 0%;
  transition: width .3s ease;
}

/* ─── Page toast ─────────────────────────────────────────────────── */
.page-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,.72);
  color: white;
  padding: 10px 22px;
  border-radius: 30px;
  font-size: 16px;
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
  transition: opacity .18s ease;
  white-space: nowrap;
}

.page-toast.show { opacity: 1; }

/* ─── Settings panel ─────────────────────────────────────────────── */
.settings-panel {
  position: absolute;
  top: 68px;
  right: 14px;
  width: 290px;
  background: rgba(18,18,28,.97);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius-lg);
  z-index: 200;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 16px 48px rgba(0,0,0,.7);
  overflow: hidden;
  animation: panelIn .2s cubic-bezier(.34,1.56,.64,1);
}

@keyframes panelIn {
  from { opacity: 0; transform: scale(.95) translateY(-8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}

.settings-header h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-2);
}

.settings-close {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 15px;
  padding: 4px 8px;
  border-radius: 5px;
  transition: color var(--t);
}
.settings-close:hover { color: var(--text); }

.setting-section {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.setting-label {
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 10px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.toggle-btn {
  flex: 1;
  padding: 7px 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  transition: all var(--t);
  text-align: center;
}

.toggle-btn:hover { border-color: rgba(139,92,246,.4); color: var(--text-2); }

.toggle-btn.active {
  background: rgba(139,92,246,.25);
  border-color: rgba(139,92,246,.6);
  color: var(--text);
}

.settings-slider {
  width: 100%;
  -webkit-appearance: none;
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.settings-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.settings-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

.settings-footer {
  padding: 14px 18px;
}

/* ─── Reader BG variants ─────────────────────────────────────────── */
#image-container.bg-dark  { background: #111; }
#image-container.bg-sepia { background: #f4e8d0; }
#image-container.bg-white { background: #fff; }

/* ═══════════════════════════════════════════════════════════════════
   VOLUMES SHEET
═══════════════════════════════════════════════════════════════════ */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.sheet.hidden { display: none; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  animation: fadeIn .2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet-panel {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border-top: 1px solid var(--border);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: slideUp .3s cubic-bezier(.32,1,.23,1);
  box-shadow: 0 -8px 40px rgba(0,0,0,.5);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sheet-title-wrap { flex: 1; min-width: 0; }

.sheet-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-subtitle {
  display: block;
  font-size: 13px;
  color: var(--text-3);
  margin-top: 3px;
}

.sheet-close-btn {
  width: 36px;
  height: 36px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--t);
}

.sheet-close-btn:hover { background: var(--surface-3); }

/* Volume list */
.volumes-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px max(16px, env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}

.volumes-list::-webkit-scrollbar { width: 4px; }
.volumes-list::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }

.volume-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--t);
  border-bottom: 1px solid var(--border);
}

.volume-row:last-child { border-bottom: none; }
.volume-row:hover { background: var(--surface-2); }
.volume-row:active { background: var(--surface-3); }

.volume-cover {
  width: 48px;
  height: 68px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.volume-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .3s ease;
}
.volume-cover img.loaded { opacity: 1; }

.volume-info {
  flex: 1;
  min-width: 0;
}

.volume-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 5px;
}

.volume-progress-bar {
  height: 3px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 4px;
}

.volume-progress-fill {
  height: 100%;
  background: var(--accent-grad);
  border-radius: 2px;
}

.volume-meta {
  font-size: 11px;
  color: var(--text-3);
}

.volume-read-btn {
  width: 34px;
  height: 34px;
  background: var(--accent-grad);
  border: none;
  border-radius: 8px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
  transition: opacity var(--t), transform .1s;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.volume-read-btn:hover  { opacity: .85; }
.volume-read-btn:active { transform: scale(.93); }

/* Reader series name (small line above volume title) */
.reader-series-name {
  display: block;
  font-size: 11px;
  color: rgba(255,255,255,.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
}

.reader-title-text {
  display: block;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 6px rgba(0,0,0,.8);
  line-height: 1.3;
}

/* ═══════════════════════════════════════════════════════════════════
   CARD SKELETON (loading placeholders)
═══════════════════════════════════════════════════════════════════ */
.card-skeleton {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  aspect-ratio: 2/3;
  overflow: hidden;
  position: relative;
}

.card-skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,.06) 50%, transparent 100%);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

/* ═══════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
═══════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  :root { --header-h: 56px; }

  .library-header { padding: 0 12px; gap: 10px; }
  .brand-name { font-size: 17px; }
  .logo-icon { font-size: 22px; }
  .search-wrapper { max-width: none; }
  #search-input { font-size: 15px; } /* Prevent iOS zoom on focus */

  .library-grid {
    padding: 14px;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }

  .sort-bar { padding: 8px 14px; }

  .reader-topbar, .reader-bottombar { padding-left: 10px; padding-right: 10px; }
  .reader-title-text { font-size: 13px; }
  .page-counter { min-width: 44px; }

  .settings-panel {
    right: 10px;
    left: 10px;
    width: auto;
  }
}

@media (max-width: 380px) {
  .library-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ─── Landscape phone reader ─────────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --reader-bar-h: 46px; }
  .reader-topbar  { height: var(--reader-bar-h); }
  .reader-bottombar { min-height: var(--reader-bar-h); }
}

/* ─── Safe area insets (notched phones) ──────────────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
  .reader-bottombar {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .library-grid {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}

/* ─── Reduced motion ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   STORAGE BAR
═══════════════════════════════════════════════════════════════════ */
.storage-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 20px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--text-3);
}
.storage-icon { flex-shrink: 0; color: var(--text-3); }
.storage-track {
  flex: 1;
  height: 6px;
  background: var(--surface-3);
  border-radius: 99px;
  overflow: hidden;
  max-width: 320px;
}
.storage-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: var(--accent-grad);
  transition: width .5s ease, background .3s ease;
}
.storage-fill.warn { background: linear-gradient(135deg,#f59e0b,#ef4444); }
.storage-text {
  font-size: 11.5px;
  white-space: nowrap;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════════════
   CARD DELETE BUTTON
═══════════════════════════════════════════════════════════════════ */
.card-delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: rgba(0,0,0,.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(.9);
  transition: opacity .18s ease, transform .18s ease, background .18s ease;
  backdrop-filter: blur(4px);
}
.manga-card:hover .card-delete-btn { opacity: 1; transform: scale(1); }
.card-delete-btn:hover { background: rgba(239,68,68,.9); }
/* Touch devices: always show (no hover) */
@media (hover: none) {
  .card-delete-btn { opacity: 1; transform: scale(1); background: rgba(0,0,0,.45); }
}

/* ═══════════════════════════════════════════════════════════════════
   SHEET HEADER ACTIONS + DELETE
═══════════════════════════════════════════════════════════════════ */
.sheet-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.sheet-delete-btn {
  width: 36px;
  height: 36px;
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: var(--radius-sm);
  color: #f87171;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--t);
}
.sheet-delete-btn:hover { background: rgba(239,68,68,.25); }

/* ═══════════════════════════════════════════════════════════════════
   MODALS (download + confirm)
═══════════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: overlayIn .2s ease;
}
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.modal-panel {
  width: 100%;
  max-width: 520px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 70px rgba(0,0,0,.6), var(--shadow-glow);
  animation: panelIn .25s cubic-bezier(.34,1.4,.64,1);
}
.modal-panel--sm { max-width: 400px; padding-bottom: 22px; }
@keyframes panelIn { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 17px; font-weight: 800; color: var(--text); }
.modal-body { padding: 18px 20px 20px; }
.modal-hint { font-size: 13.5px; color: var(--text-2); line-height: 1.6; margin-bottom: 14px; }
.modal-hint strong { color: var(--text); }
.modal-note { font-size: 11.5px; color: var(--text-3); margin-top: 14px; line-height: 1.5; }

.dl-input-row { display: flex; gap: 10px; }
.dl-input {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color var(--t), box-shadow var(--t);
}
.dl-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.dl-input::placeholder { color: var(--text-3); }
.dl-go { flex-shrink: 0; padding: 11px 22px; }

.dl-error {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  color: #f87171;
  font-size: 13px;
}

.dl-list { margin-top: 8px; display: flex; flex-direction: column; gap: 10px; }
.dl-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.dl-item-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.dl-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dl-item-pct { font-size: 12px; color: var(--accent); font-weight: 700; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.dl-item-pct.done  { color: #4ade80; }
.dl-item-pct.error { color: #f87171; }
.dl-track { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.dl-fill { height: 100%; width: 0%; border-radius: 99px; background: var(--accent-grad); transition: width .4s ease; }
.dl-fill.done { background: #22c55e; }
.dl-item-meta { display: flex; justify-content: space-between; margin-top: 7px; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.dl-dismiss {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 5px;
  flex-shrink: 0;
}
.dl-dismiss:hover { color: var(--text); background: var(--surface-3); }

/* Confirm modal */
.confirm-icon {
  margin: 24px auto 4px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(239,68,68,.14);
  color: #f87171;
  display: flex;
  align-items: center;
  justify-content: center;
}
.confirm-title { text-align: center; font-size: 19px; font-weight: 800; color: var(--text); margin: 6px 24px 0; }
.confirm-message { text-align: center; font-size: 14px; color: var(--text-2); line-height: 1.6; margin: 10px 24px 0; }
.confirm-message strong { color: var(--text); }
.confirm-actions { display: flex; gap: 12px; padding: 22px 24px 0; }
.confirm-actions button { flex: 1; }

.btn-ghost {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  transition: background var(--t);
}
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-danger-solid {
  background: linear-gradient(135deg,#ef4444,#dc2626);
  border: none;
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 4px 18px rgba(239,68,68,.4);
  transition: opacity var(--t), transform .1s;
}
.btn-danger-solid:hover { opacity: .9; }
.btn-danger-solid:active { transform: scale(.97); }

/* ═══════════════════════════════════════════════════════════════════
   TOASTS
═══════════════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: max-content;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
  animation: toastIn .25s cubic-bezier(.34,1.4,.64,1);
  font-size: 13.5px;
  color: var(--text);
}
.toast.leaving { animation: toastOut .2s ease forwards; }
@keyframes toastIn  { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(20px); } }
.toast-msg { flex: 1; }
.toast-action {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 13.5px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background var(--t);
}
.toast-action:hover { background: rgba(139,92,246,.18); }

@media (max-width: 540px) {
  .modal-panel { max-width: 100%; }
  .dl-input { font-size: 16px; } /* avoid iOS zoom */
}

