/* Comic & Book Vault - Style Sheet */
:root {
  --bg-primary: #121316;
  --bg-secondary: #1a1b20;
  --bg-card: #22242b;
  --bg-card-hover: #2b2e37;
  --text-main: #f0f2f5;
  --text-muted: #9aa0a6;
  --accent: #4f80e1;
  --accent-hover: #3d6fd4;
  --border-color: #2e323b;
  --hud-bg: rgba(22, 24, 29, 0.92);
  --header-height: 56px;
  --bottom-hud-height: 64px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.45);
  --container-max-width: 1720px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Utilities */
.hidden { display: none !important; }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover { background-color: var(--bg-card-hover); }

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-main);
  border: none;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-icon:hover { background-color: rgba(255, 255, 255, 0.1); }
.btn-icon.active { background-color: var(--accent); color: white; }

.btn-text-badge {
  font-size: 13px;
  font-weight: bold;
}

/* Header */
.header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: relative;
  z-index: 50;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.header.hud-hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.3px;
}

.brand-icon {
  font-size: 20px;
}

.comic-title-badge {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-muted);
}

.reader-center-info {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

/* Library View */
.view-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px max(24px, var(--safe-right)) 40px max(24px, var(--safe-left));
  display: flex;
  flex-direction: column;
  gap: 20px;
  -webkit-overflow-scrolling: touch;
}

.library-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  max-width: var(--container-max-width);
  margin: 0 auto;
  width: 100%;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  flex: 1 1 280px;
  min-width: 220px;
  max-width: 440px;
  height: 40px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 128, 225, 0.25);
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 14px;
  width: 100%;
}

/* Filter chips */
.filter-chips {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.stats-badge {
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
}

/* Fluid responsive grid for all displays */
.comics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 22px;
  max-width: var(--container-max-width);
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 1600px) {
  .comics-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 26px;
  }
}

@media (min-width: 800px) and (max-width: 1199px) {
  .comics-grid {
    grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
    gap: 18px;
  }
}

@media (max-width: 639px) {
  .comics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .view-container {
    padding: 12px max(10px, var(--safe-right)) 30px max(10px, var(--safe-left));
    gap: 12px;
  }
}

.comic-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-color);
  position: relative;
}

.comic-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  border-color: var(--accent);
}

.cover-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: #191b21;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s ease;
}

.comic-card:hover .cover-img {
  transform: scale(1.03);
}

/* Format Badges */
.format-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 6px;
  border-radius: 4px;
}

.badge-epub { background: #d97706; }
.badge-pdf { background: #dc2626; }
.badge-cbr { background: #2563eb; }
.badge-cbz { background: #059669; }

.btn-card-dispatch {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(22, 24, 29, 0.9);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.85;
  transition: all 0.15s ease;
}

.btn-card-dispatch:hover {
  opacity: 1;
  background: var(--accent);
  color: #fff;
  transform: scale(1.1);
}

.comic-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.comic-title-row .comic-title {
  flex: 1;
}

.btn-card-info {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.btn-card-info:hover, .btn-card-info:active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.progress-bar-container {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(0, 0, 0, 0.5);
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
}

.comic-info {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  justify-content: space-between;
  min-width: 0;
}

.comic-title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  color: var(--text-main);
  flex: 1;
  min-width: 0;
  height: 2.7em;
}

.comic-author {
  font-size: 12px;
  color: #a78bfa;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.comic-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
}

/* Empty State */
.empty-state {
  margin: 60px auto;
  text-align: center;
  max-width: 400px;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

/* READER VIEW */
.reader-view {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100vh;
  height: 100dvh;
  background: #000;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.canvas-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.page-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  transition: transform 0.15s ease-out;
  gap: 4px;
}

/* Single mode fit height */
.canvas-container.fit-height .page-wrapper.single-mode .comic-page-img,
.canvas-container.fit-height .single-mode .comic-page-img,
.canvas-container.fit-height .comic-page-img {
  max-height: 100vh;
  max-height: 100dvh;
  max-width: 100vw;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* Double mode spread fit height */
.canvas-container.fit-height .page-wrapper.double-mode .comic-page-img,
.canvas-container.fit-height .double-mode .comic-page-img {
  max-height: 100vh;
  max-height: 100dvh;
  max-width: 49.5vw;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* Fit width (for vertical webtoon/scroll reading) */
.canvas-container.fit-width {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  align-items: flex-start;
}

.canvas-container.fit-width .page-wrapper {
  height: auto;
  min-height: 100%;
  flex-direction: column;
}

.canvas-container.fit-width .comic-page-img {
  width: 100vw;
  max-width: 100%;
  height: auto;
  max-height: none;
  object-fit: contain;
}

.comic-page-img {
  user-select: none;
  -webkit-user-drag: none;
  display: block;
}

/* Touch Zones */
.touch-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 45;
}

.touch-zone.left {
  left: 0;
  width: 25%;
}

.touch-zone.center {
  left: 25%;
  width: 50%;
}

.touch-zone.right {
  right: 0;
  width: 25%;
}

/* Bottom HUD */
.reader-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-hud-height);
  background: var(--hud-bg);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 50;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

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

.slider-container {
  flex: 1;
  max-width: 600px;
  margin: 0 20px;
}

.page-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.page-indicator-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 60px;
  text-align: center;
  padding: 4px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

/* Thumbnails Drawer */
.thumbnails-drawer {
  position: fixed;
  bottom: var(--bottom-hud-height);
  left: 0;
  right: 0;
  height: 140px;
  background: var(--hud-bg);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  z-index: 48;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 10px 16px;
  display: flex;
  align-items: center;
}

.thumbnails-track {
  display: flex;
  gap: 12px;
  height: 100%;
}

.thumb-item {
  height: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 4px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
}

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

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

/* Table of Contents Drawer */
.toc-drawer {
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: var(--bottom-hud-height);
  width: 320px;
  max-width: 85vw;
  background: var(--hud-bg);
  backdrop-filter: blur(16px);
  border-left: 1px solid var(--border-color);
  z-index: 55;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
}

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

.toc-header h3 {
  font-size: 16px;
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.toc-item {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.15s ease;
}

.toc-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.toc-item.active {
  background: rgba(79, 128, 225, 0.2);
  color: var(--accent);
  font-weight: 600;
}

.toc-title {
  font-size: 14px;
}

.toc-page {
  font-size: 12px;
  color: var(--text-muted);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

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

.modal-body {
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-hint {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.4;
}

.qr-box {
  display: flex;
  justify-content: center;
  padding: 16px;
  background: #fff;
  border-radius: var(--radius-md);
  margin: 0 auto;
}

.qr-box img {
  width: 200px;
  height: 200px;
}

.url-badge-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.url-label {
  font-size: 12px;
  color: var(--text-muted);
}

.url-badge {
  display: flex;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.url-badge input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 12px;
  color: var(--text-main);
  font-family: monospace;
  font-size: 13px;
  outline: none;
}

.pwa-tip {
  font-size: 13px;
  color: var(--text-muted);
  background: rgba(79, 128, 225, 0.1);
  border: 1px solid rgba(79, 128, 225, 0.2);
  padding: 12px;
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

/* Upload Modal Styles */
.upload-modal-card {
  max-width: 520px;
}

.upload-target-selector {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.upload-label {
  font-size: 13px;
  color: var(--text-muted);
}

.target-options {
  display: flex;
  gap: 8px;
}

.target-radio {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.target-radio input {
  display: none;
}

.target-radio.active {
  background: rgba(79, 128, 225, 0.2);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.upload-drop-area {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 30px 20px;
  text-align: center;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.02);
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.upload-drop-area:hover, .upload-drop-area.drag-over {
  border-color: var(--accent);
  background: rgba(79, 128, 225, 0.08);
}

.upload-drop-area svg {
  color: var(--text-muted);
}

.upload-formats-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.upload-files-list {
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.upload-file-name {
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-file-size {
  color: var(--text-muted);
  font-size: 12px;
}

.upload-progress-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.upload-progress-bar-bg {
  height: 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
}

.upload-progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease;
}

.upload-actions {
  display: flex;
  justify-content: flex-end;
}

/* Big File Picker Button inside Modal */
.file-picker-action-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.btn-file-select-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background-color: var(--accent);
  color: #fff;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  box-shadow: 0 4px 14px rgba(79, 128, 225, 0.4);
  transition: background-color 0.15s ease, transform 0.1s ease;
  user-select: none;
}

.btn-file-select-label:active {
  transform: scale(0.98);
  background-color: var(--accent-hover);
}

.file-picker-subhint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* Mobile Floating Action Button (FAB) */
.mobile-fab-upload {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: none; /* Shown via media query on mobile */
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  border: none;
  cursor: pointer;
  z-index: 40;
  transition: transform 0.2s ease, background 0.15s ease;
}

.mobile-fab-upload:active {
  transform: scale(0.92);
  background: var(--accent-hover);
}

/* ========================================================
   Mobile & Responsive Layout Optimizations
   ======================================================== */
@media (max-width: 680px) {
  :root {
    --header-height: 52px;
  }

  .header {
    padding: 0 10px;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .header-left {
    flex-shrink: 0;
    gap: 8px;
  }

  .header-right {
    flex-shrink: 0;
    gap: 6px;
    margin-left: auto;
  }

  /* Hide brand name text on mobile so buttons NEVER overflow */
  .brand-name {
    display: none;
  }

  .brand {
    font-size: 16px;
    gap: 0;
  }

  .brand-icon {
    font-size: 22px;
  }

  /* Compact header buttons: show only icons on mobile */
  #library-actions {
    display: flex;
    gap: 6px;
  }

  #library-actions .btn {
    padding: 8px 10px;
    gap: 0;
    min-width: 38px;
    height: 38px;
    justify-content: center;
  }

  #library-actions .btn span {
    display: none;
  }

  #library-actions .btn svg {
    margin: 0;
  }

  /* Comic Title in reader header */
  .comic-title-badge {
    max-width: 140px;
    font-size: 11px;
    padding: 3px 6px;
  }

  /* Center info in reader header */
  .reader-center-info {
    display: none; /* Hidden on phone header; already shown in bottom HUD */
  }

  /* Reader action buttons */
  #reader-actions {
    gap: 3px;
  }

  #reader-actions .btn-icon {
    width: 34px;
    height: 34px;
  }

  /* Floating upload button for mobile */
  .mobile-fab-upload {
    display: flex;
  }

  /* Upload modal card on mobile */
  .upload-modal-card {
    max-height: 90vh;
    overflow-y: auto;
    padding: 0;
    margin: 10px;
  }

  .modal-body {
    padding: 16px;
    gap: 14px;
  }

  .target-options {
    flex-wrap: wrap;
  }

  .upload-drop-area.desktop-only {
    display: none;
  }

  /* Library toolbar responsive */
  .library-toolbar {
    gap: 10px;
  }

  .search-box {
    width: 100%;
  }

  .filter-chips {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .filter-chips .chip {
    white-space: nowrap;
    flex-shrink: 0;
  }
}

@media (max-width: 420px) {
  .comic-title-badge {
    max-width: 110px;
  }

  #btn-fullscreen {
    display: none; /* App is already fullscreen on phone */
  }

  #btn-view-mode {
    display: none; /* Phone screens are portrait single page */
  }
}

/* ========================================================
   Toolbar Controls Row & Dropdowns
   ======================================================== */
.toolbar-controls-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.toolbar-dropdowns-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dropdown-wrapper {
  position: relative;
}

.toolbar-select {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
  height: 38px;
}

.toolbar-select:hover, .toolbar-select:focus {
  border-color: var(--accent);
}

.comic-author.clickable {
  cursor: pointer;
}

.comic-author.clickable:hover {
  text-decoration: underline;
  color: #c4b5fd;
}

/* ========================================================
   EPUB Reader Font Size Controls
   ======================================================== */
.epub-font-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px 4px;
}

.btn-font {
  font-size: 13px;
  font-weight: 700;
  width: 32px;
  height: 32px;
}

.font-size-val {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 20px;
  text-align: center;
}

/* ========================================================
   Item Details & Rich Metadata Modal
   ======================================================== */
.details-modal-card {
  max-width: 720px;
  width: min(720px, 94vw);
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
}

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

.details-header-title h3 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 16px;
  font-weight: 600;
}

.details-modal-body {
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}

.details-layout {
  display: flex;
  gap: 20px;
}

.details-cover-col {
  width: 180px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.details-cover-wrapper {
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
}

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

.details-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.details-info-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.details-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px 12px;
  background: var(--bg-primary);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.meta-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.meta-value {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  word-break: break-word;
}

.author-link {
  color: #a78bfa;
  cursor: pointer;
}

.author-link:hover {
  text-decoration: underline;
}

.details-tags-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tags-chips-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-chip {
  background: rgba(79, 128, 225, 0.15);
  color: var(--accent);
  border: 1px solid rgba(79, 128, 225, 0.3);
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}

.tag-chip:hover {
  background: rgba(79, 128, 225, 0.25);
}

.details-synopsis-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.synopsis-content {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  color: #d1d5db;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* ========================================================
   Kindle Modal & Options
   ======================================================== */
.kindle-modal-card {
  max-width: 520px;
  width: min(520px, 94vw);
}

.kindle-option-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kindle-option-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kindle-badge-free {
  font-size: 10px;
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.kindle-subhint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ========================================================
   High Contrast E-Ink Theme (Kindle / Monochrome displays)
   ======================================================== */
body.theme-eink {
  --bg-primary: #ffffff !important;
  --bg-secondary: #f4f4f4 !important;
  --bg-card: #ffffff !important;
  --bg-card-hover: #e5e5e5 !important;
  --text-main: #000000 !important;
  --text-muted: #444444 !important;
  --accent: #000000 !important;
  --accent-hover: #333333 !important;
  --border-color: #000000 !important;
  --shadow-card: none !important;
  filter: grayscale(100%);
}

body.theme-eink .comic-card {
  border: 2px solid #000 !important;
}

body.theme-eink .chip {
  border: 1px solid #000 !important;
  color: #000 !important;
}

body.theme-eink .chip.active {
  background: #000 !important;
  color: #fff !important;
}

body.theme-eink .format-badge {
  background: #000 !important;
  color: #fff !important;
  border: 1px solid #fff;
}

/* ========================================================
   Responsive Media Queries for Mobile Screens
   ======================================================== */
@media (max-width: 680px) {
  .details-layout {
    flex-direction: column;
    align-items: center;
    gap: 14px;
  }
  .details-cover-col {
    width: 140px;
  }
  .toolbar-controls-row {
    width: 100%;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }
  .toolbar-dropdowns-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .toolbar-select {
    width: 100%;
  }
  .dropdown-wrapper {
    width: 100%;
  }
  .stats-badge {
    text-align: right;
    font-size: 12px;
  }
}
