:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-hover: #1f2b47;
  --accent: #e94560;
  --accent-light: #ff6b81;
  --accent-glow: rgba(233, 69, 96, 0.3);
  --text: #e8e8e8;
  --text-muted: #8892a4;
  --text-dim: #5a6478;
  --border: #2a2a4a;
  --success: #2ed573;
  --warning: #ffa502;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* === HEADER === */
.header {
  text-align: center;
  padding: 50px 20px 30px;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
}

.logo {
  font-size: 2.6em;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -1px;
}

.logo-icon { font-style: normal; margin-right: 8px; }

.tagline {
  color: var(--text-muted);
  font-size: 1.1em;
  margin-top: 8px;
}

/* === INPUT SECTION === */
.input-section {
  max-width: 700px;
  margin: 30px auto;
  padding: 0 20px;
}

.url-form {
  display: flex;
  gap: 10px;
  background: var(--bg-card);
  padding: 8px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  transition: border-color 0.3s;
}

.url-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}

.url-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1em;
  padding: 14px 16px;
  outline: none;
}

.url-input::placeholder { color: var(--text-dim); }

.btn-grab {
  background: linear-gradient(135deg, var(--accent), #c0392b);
  color: #fff;
  border: none;
  padding: 14px 28px;
  border-radius: 10px;
  font-size: 1em;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-grab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-grab:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-grab .spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.btn-grab.loading .spinner { display: block; }
.btn-grab.loading .btn-text { display: none; }

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

/* === SUPPORTED SITES === */
.supported {
  text-align: center;
  margin-top: 16px;
  color: var(--text-dim);
  font-size: 0.85em;
}

.supported span {
  background: var(--bg-card);
  padding: 4px 10px;
  border-radius: 6px;
  margin: 0 3px;
  color: var(--text-muted);
}

/* === RESULT SECTION === */
.result-section {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px 60px;
  display: none;
}

.result-section.visible { display: block; }

/* Chapter info card */
.chapter-info {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
}

.chapter-title {
  font-size: 1.5em;
  font-weight: 700;
  color: var(--accent-light);
}

.chapter-meta {
  display: flex;
  gap: 20px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.9em;
}

.meta-item .icon { font-size: 1.1em; }

/* === TABS === */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab {
  padding: 10px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 600;
  transition: all 0.25s;
  white-space: nowrap;
}

.tab:hover { background: var(--bg-hover); color: var(--text); }

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

/* === DOWNLOAD PANEL === */
.download-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
}

.download-panel h3 {
  font-size: 1.1em;
  margin-bottom: 16px;
  color: var(--text);
}

.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.export-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 16px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  transition: all 0.25s;
  text-decoration: none;
}

.export-btn:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.export-btn .icon { font-size: 2em; }

.export-btn .label {
  font-weight: 700;
  font-size: 0.95em;
}

.export-btn .desc {
  font-size: 0.75em;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.3;
}

.export-btn.downloading {
  opacity: 0.6;
  pointer-events: none;
}

/* === PREVIEW PANEL === */
.preview-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
  display: none;
}

.preview-panel.visible { display: block; }

/* Preview modes */
.preview-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.view-modes {
  display: flex;
  gap: 6px;
}

.view-mode {
  padding: 8px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85em;
  transition: all 0.2s;
}

.view-mode:hover { color: var(--text); }
.view-mode.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.page-counter {
  color: var(--text-muted);
  font-size: 0.9em;
  font-weight: 600;
}

/* Scroll view (vertical) */
.preview-scroll {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.preview-scroll img {
  max-width: 100%;
  display: block;
  border-radius: 4px;
}

/* Grid view */
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.preview-grid img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.2s;
}

.preview-grid img:hover { transform: scale(1.05); }

/* Single page view */
.preview-single {
  text-align: center;
}

.preview-single img {
  max-width: 100%;
  max-height: 85vh;
  border-radius: 6px;
}

.page-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin-top: 16px;
}

.page-nav button {
  padding: 10px 24px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.page-nav button:hover { background: var(--accent-light); }
.page-nav button:disabled { opacity: 0.3; cursor: not-allowed; }

.page-nav .current {
  font-size: 1.1em;
  color: var(--text-muted);
  font-weight: 600;
}

/* === PROGRESS BAR === */
.progress-wrap {
  display: none;
  margin: 16px 0;
}

.progress-wrap.visible { display: block; }

.progress-bar {
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s;
}

.progress-text {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85em;
  margin-top: 6px;
}

/* === LIGHTBOX === */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.lightbox.visible { display: flex; }

.lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--accent);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.2em;
  cursor: pointer;
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 14px 28px;
  border-radius: var(--radius);
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 999;
}

.toast.visible { transform: translateX(-50%) translateY(0); }

.toast.error { border-color: #e74c3c; }

/* === FOOTER === */
footer {
  text-align: center;
  padding: 30px;
  color: var(--text-dim);
  font-size: 0.85em;
}

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

footer a:hover { text-decoration: underline; }

/* === MANGA SECTION (multi-chapter) === */
.manga-section {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px 60px;
  display: none;
}

.manga-section.visible { display: block; }

/* Chapter controls */
.chapter-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chapter-controls-left {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chapter-controls-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ch-ctrl-btn {
  padding: 8px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85em;
  transition: all 0.2s;
}

.ch-ctrl-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--bg-hover);
}

.ch-ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.selected-count {
  color: var(--accent-light);
  font-weight: 700;
  font-size: 0.95em;
}

.btn-download-batch {
  padding: 10px 24px;
  background: linear-gradient(135deg, var(--accent), #c0392b);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 0.95em;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-download-batch:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-download-batch:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Chapter list */
.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-height: 500px;
  overflow-y: auto;
}

.chapter-list::-webkit-scrollbar { width: 6px; }
.chapter-list::-webkit-scrollbar-track { background: var(--bg-secondary); border-radius: 3px; }
.chapter-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.tome-group {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tome-header {
  padding: 14px 20px;
  background: var(--bg-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.tome-label {
  font-weight: 700;
  font-size: 1em;
  color: var(--accent-light);
}

.tome-count {
  color: var(--text-dim);
  font-size: 0.85em;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 6px;
  padding: 12px;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  font-size: 0.88em;
}

.chapter-item:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}

.chapter-item input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
}

.ch-checkbox-wrap {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  cursor: pointer;
}

.ch-num {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.ch-name {
  color: var(--text-dim);
  font-size: 0.82em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 80px;
}

.ch-badge {
  margin-left: auto;
  font-size: 0.7em;
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
  font-weight: 700;
}

.ch-badge.locked {
  background: rgba(255, 100, 100, 0.12);
  color: #e74c3c;
  border: 1px solid rgba(255, 100, 100, 0.25);
  font-weight: 600;
  font-size: 0.85em;
}

.chapter-item.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.chapter-item.locked:hover {
  opacity: 0.6;
  background: transparent;
  border-color: transparent;
}

/* Batch progress */
.batch-progress {
  display: none;
  margin-top: 20px;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.batch-progress.visible { display: block; }

.batch-progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  font-weight: 600;
  font-size: 0.95em;
}

.batch-progress-header span:first-child { color: var(--accent-light); }
.batch-progress-header span:last-child { color: var(--text-muted); }

/* === VIEWER PHASE === */
.viewer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.viewer-summary {
  font-weight: 700;
  font-size: 1em;
  color: var(--accent-light);
}

.manga-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 0;
}

.manga-tab {
  padding: 10px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9em;
  color: var(--text-muted);
  transition: all 0.2s;
}

.manga-tab:hover { color: var(--text); background: var(--bg-hover); }

.manga-tab.active {
  background: var(--bg-card);
  color: var(--accent-light);
  border-bottom-color: var(--bg-card);
}

.manga-tab-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 24px;
}

.manga-export-section {
  margin-bottom: 24px;
}

.manga-export-section:last-child { margin-bottom: 0; }

.manga-export-section h3 {
  font-size: 1em;
  margin-bottom: 12px;
  color: var(--text);
}

.chapter-picker-row {
  margin-bottom: 14px;
}

.chapter-picker {
  width: 100%;
  max-width: 400px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9em;
  cursor: pointer;
}

.chapter-picker:focus {
  outline: none;
  border-color: var(--accent);
}

.viewer-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
}

.reader-controls .chapter-picker {
  max-width: 300px;
  text-align: center;
}

.manga-view-mode {
  padding: 8px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85em;
  transition: all 0.2s;
}

.manga-view-mode:hover {
  color: var(--text);
  border-color: var(--accent);
}

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

/* === RESPONSIVE === */
@media (max-width: 600px) {
  .logo { font-size: 1.8em; }
  .url-form { flex-direction: column; }
  .btn-grab { justify-content: center; }
  .export-grid { grid-template-columns: repeat(2, 1fr); }
  .preview-grid { grid-template-columns: repeat(2, 1fr); }
  .chapter-meta { flex-direction: column; gap: 8px; }
  .tabs { gap: 4px; }
  .tab { padding: 8px 14px; font-size: 0.8em; }
  .chapter-controls { flex-direction: column; align-items: stretch; }
  .chapter-controls-right { justify-content: space-between; }
  .chapter-grid { grid-template-columns: 1fr; }
  .ch-ctrl-btn { padding: 7px 10px; font-size: 0.8em; }
  .btn-download-batch { width: 100%; text-align: center; }
  .manga-tabs { flex-wrap: wrap; }
  .manga-tab { padding: 8px 14px; font-size: 0.8em; }
  .viewer-bar { flex-direction: column; gap: 10px; text-align: center; }
  .reader-controls { flex-direction: column; }
  .chapter-picker { max-width: 100%; }
  .viewer-controls { flex-direction: column; align-items: stretch; }
  .manga-tab-content { padding: 16px; }
}
