/* ============================================================
   CBZ-Viewer — CSS
   Dark theme by default, modern card grid, full-screen reader
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  --bg:           #111118;
  --bg-surface:   #1a1a26;
  --bg-elevated:  #22222f;
  --bg-card:      #1e1e2e;
  --border:       #2d2d42;
  --text:         #e8e8f0;
  --text-muted:   #8888aa;
  --accent:       #7c6ff7;
  --accent-hover: #9b8fff;
  --accent-green: #4caf7d;
  --danger:       #e05c5c;
  --toolbar-h:    52px;
  --bottombar-h:  56px;
  --radius:       10px;
  --shadow:       0 4px 20px rgba(0,0,0,.5);
  --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
  --transition:   .18s ease;
}

/* Light theme */
body.light-theme {
  --bg:          #f0f0f5;
  --bg-surface:  #ffffff;
  --bg-elevated: #e8e8f0;
  --bg-card:     #fafaff;
  --border:      #d0d0e0;
  --text:        #1a1a2e;
  --text-muted:  #6060a0;
  --shadow:      0 4px 20px rgba(0,0,0,.15);
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

img { display: block; max-width: 100%; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ============================================================
   SITE HEADER (library / series pages)
   ============================================================ */
.site-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.site-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}
.site-icon { font-size: 1.5rem; }

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  font-size: .95rem;
}
.breadcrumb-link {
  display: flex;
  align-items: center;
  gap: .3rem;
  color: var(--accent);
  font-weight: 600;
}
.breadcrumb-sep { color: var(--text-muted); }
.breadcrumb-current { color: var(--text); font-weight: 600; }

/* ============================================================
   LIBRARY / SERIES PAGES
   ============================================================ */
.library-page { display: flex; flex-direction: column; }

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem;
  flex: 1;
}

.grid-header {
  margin-bottom: 1.25rem;
}
.grid-title {
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: .5rem;
  letter-spacing: -.02em;
}
.badge {
  font-size: .8rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  padding: .15em .55em;
  border-radius: 20px;
  vertical-align: middle;
}

/* Card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.25rem;
}
@media (min-width: 600px)  { .card-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }
@media (min-width: 900px)  { .card-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }
@media (min-width: 1200px) { .card-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); } }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  color: inherit;
  display: flex;
  flex-direction: column;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
  text-decoration: none;
}
.card-cover {
  position: relative;
  aspect-ratio: 2/3;
  overflow: hidden;
  background: var(--bg-elevated);
}
.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .3s ease;
}
.card:hover .card-cover img { transform: scale(1.04); }

.card-badge {
  position: absolute;
  bottom: .4rem;
  right: .4rem;
  background: rgba(0,0,0,.72);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  padding: .15em .45em;
  border-radius: 4px;
  letter-spacing: .04em;
}
.card-body {
  padding: .65rem .75rem .75rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.card-title {
  font-size: .88rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta {
  font-size: .78rem;
  color: var(--text-muted);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 5rem 2rem;
}
.empty-icon { font-size: 4rem; margin-bottom: 1rem; }
.empty-state h2 { margin-bottom: .5rem; font-size: 1.4rem; }
.empty-state p  { color: var(--text-muted); }
.empty-state code {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: .1em .4em;
  border-radius: 4px;
  font-family: monospace;
  font-size: .9em;
}

/* Footer */
.site-footer {
  text-align: center;
  padding: 1rem;
  font-size: .8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ============================================================
   READER PAGE
   ============================================================ */
.reader-page {
  overflow: hidden;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #000;
  color: var(--text);
}

/* ---- Toolbar ---- */
.reader-toolbar {
  height: var(--toolbar-h);
  background: rgba(17,17,24,.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 .75rem;
  flex-shrink: 0;
  z-index: 100;
  transition: opacity var(--transition), transform var(--transition);
}
.reader-toolbar.hidden-chrome,
.reader-bottombar.hidden-chrome {
  opacity: 0;
  pointer-events: none;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: .25rem;
  flex-shrink: 0;
}
.toolbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-width: 0;
  overflow: hidden;
}
.volume-title {
  font-size: .88rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: .3rem .55rem;
  border-radius: 6px;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.toolbar-btn:hover { background: var(--bg-elevated); color: var(--text); }
.toolbar-btn:disabled { opacity: .35; cursor: default; }
.toolbar-btn:disabled:hover { background: none; color: var(--text-muted); }
.icon-btn { font-size: 1.1rem; padding: .3rem .45rem; }
.toolbar-label { display: none; }
@media (min-width: 600px) { .toolbar-label { display: inline; } }

/* ---- Viewport ---- */
.reader-viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  touch-action: none; /* handled in JS */
}

/* ---- Page stage (single / double page) ---- */
.page-stage {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.page-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  transform-origin: center center;
  will-change: transform;
  cursor: grab;
}
.page-container.is-panning { cursor: grabbing; }

.page-img {
  max-height: calc(100dvh - var(--toolbar-h) - var(--bottombar-h));
  max-width: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}
/* Tap zones */
.tap-zone {
  position: absolute;
  top: 10%;
  height: 80%;
  width: 22%;
  z-index: 10;
  cursor: pointer;
  opacity: 0;
}
.tap-zone-left  { left: 0; }
.tap-zone-right { right: 0; }

/* ---- Webtoon stage ---- */
.webtoon-stage {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  padding: 0;
  touch-action: pan-y;
  background: #000;
}
.webtoon-stage img {
  width: 100%;
  max-width: 900px;
  display: block;
  margin: 0 auto;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ---- Bottom bar ---- */
.reader-bottombar {
  height: var(--bottombar-h);
  background: rgba(17,17,24,.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 .75rem;
  flex-shrink: 0;
  z-index: 100;
  transition: opacity var(--transition);
}

.nav-btn {
  font-size: 1.3rem;
  padding: .25rem .5rem;
  flex-shrink: 0;
}

/* Progress / slider */
.progress-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  min-width: 0;
}

/* Custom range slider */
.page-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 4px;
  background: var(--border);
  outline: none;
  cursor: pointer;
  display: none; /* hidden — we use the progress bar visually */
}

.progress-bar-track {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  width: 0%;
  transition: width .15s ease;
  pointer-events: none;
}

.page-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  font-size: .82rem;
  color: var(--text-muted);
}
.page-input {
  width: 3.5ch;
  min-width: 38px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: .82rem;
  text-align: center;
  padding: .1rem .2rem;
  -moz-appearance: textfield;
  appearance: textfield;
}
.page-input::-webkit-inner-spin-button,
.page-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.page-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.page-sep, .page-total { color: var(--text-muted); }

/* ---- Spinner ---- */
.page-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.5);
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.page-loader.active { opacity: 1; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Reader error ---- */
.reader-error {
  text-align: center;
  padding: 3rem 2rem;
  max-width: 520px;
}
.error-icon { font-size: 3rem; margin-bottom: 1rem; }
.reader-error h2 { margin-bottom: .75rem; color: var(--danger); }
.reader-error p  { color: var(--text-muted); margin-bottom: 1.25rem; line-height: 1.6; }

/* ============================================================
   SETTINGS PANEL
   ============================================================ */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  transition: opacity var(--transition);
}
.settings-overlay.hidden { display: none; }

@media (min-width: 600px) {
  .settings-overlay { align-items: center; padding: 1.5rem; }
}

.settings-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.25rem 2rem;
  transform: translateY(0);
}
@media (min-width: 600px) {
  .settings-panel {
    border-radius: var(--radius);
  }
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.settings-header h2 { font-size: 1.15rem; font-weight: 700; }
.settings-close {
  font-size: 1.1rem;
  color: var(--text-muted);
  padding: .3rem .4rem;
  border-radius: 6px;
  transition: background var(--transition), color var(--transition);
}
.settings-close:hover { background: var(--bg-elevated); color: var(--text); }

.settings-section {
  margin-bottom: 1.5rem;
}
.settings-label {
  display: block;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: .65rem;
}

/* Radio group */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.radio-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  cursor: pointer;
  font-size: .9rem;
}
.radio-item input { accent-color: var(--accent); width: 16px; height: 16px; }
.radio-item small { color: var(--text-muted); font-size: .8em; }

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .4rem;
  font-size: .9rem;
}
.toggle { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 24px;
  transition: background var(--transition);
  cursor: pointer;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: #fff;
}

/* Zoom controls */
.zoom-controls {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: .5rem;
}
.zoom-preset {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .82rem;
  padding: .3rem .65rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.zoom-preset:hover { border-color: var(--accent); color: var(--text); }
.zoom-preset.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.zoom-custom-row {
  display: flex;
  align-items: center;
  gap: .75rem;
}
#zoomLabel { min-width: 3.5rem; text-align: center; font-size: .9rem; font-weight: 600; }

/* Shortcuts table */
.shortcuts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
.shortcuts-table td {
  padding: .3rem .4rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
.shortcuts-table td:first-child {
  font-family: monospace;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  width: 40%;
}

/* Settings footer */
.settings-footer { margin-bottom: 0; }
.btn-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: .45rem 1rem;
  border-radius: 6px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  width: 100%;
}
.btn-danger:hover { background: rgba(224,92,92,.12); }

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