/* ─── Variables ──────────────────────────────────────────────────────────── */
:root {
  --bg: #0d0d0d;
  --surface: #141414;
  --surface-2: #1e1e1e;
  --surface-3: #262626;
  --border: #2a2a2a;
  --text: #ebebeb;
  --text-2: #888;
  --text-3: #4a4a4a;
  --accent: #d4a843;
  --accent-bg: rgba(212, 168, 67, 0.12);
  --danger: #e05454;
  --danger-bg: rgba(224, 84, 84, 0.12);
  --success: #4caf7d;
  --success-bg: rgba(76, 175, 125, 0.12);
  --radius: 8px;
  --radius-lg: 12px;
  --nav-h: 52px;
  --reader-top-h: 52px;
  --reader-bottom-h: 44px;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; }
img { display: block; max-width: 100%; }

/* ─── Nav ────────────────────────────────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: rgba(13, 13, 13, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  gap: 16px;
}
.nav-brand {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  flex: 1;
}
.nav-right { display: flex; align-items: center; gap: 8px; }
.nav-link {
  font-size: 14px;
  color: var(--text-2);
  padding: 6px 10px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link--btn { background: none; border: none; }

/* ─── Main layout ────────────────────────────────────────────────────────── */
.main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  border: none;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
  cursor: pointer;
}
.btn--primary { background: var(--accent); color: #0d0d0d; }
.btn--primary:hover { background: #e6ba58; }
.btn--ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn--ghost:hover { background: var(--surface-3); }
.btn--danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--sm { padding: 6px 12px; font-size: 13px; }
.btn--lg { padding: 13px 24px; font-size: 16px; }
.btn--full { width: 100%; justify-content: center; }

/* ─── Flash messages ─────────────────────────────────────────────────────── */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 14px;
}
.flash--success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(76,175,125,0.3); }
.flash--error { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(224,84,84,0.3); }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.form-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 9px 12px;
  transition: border-color 0.15s;
  width: 100%;
}
.form-input:focus { outline: none; border-color: var(--accent); }
.form-input--sm { font-size: 13px; padding: 7px 10px; }
.form-input--file { padding: 8px 12px; }
.form-hint { color: var(--text-3); font-size: 12px; }
.form-hint--block { display: block; margin-bottom: 12px; font-size: 13px; color: var(--text-2); }
.form-hint--block code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}
.check-label { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check-label input { width: 16px; height: 16px; accent-color: var(--accent); }
select.form-input option { background: var(--surface-2); }

/* ─── Login page ─────────────────────────────────────────────────────────── */
.body--login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: var(--bg);
}
.login-wrap { width: 100%; max-width: 380px; padding: 20px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
}
.login-title {
  font-family: 'Playfair Display', serif;
  font-size: 32px;
  text-align: center;
  margin-bottom: 4px;
}
.login-sub {
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
  margin-bottom: 28px;
}
.login-form { display: flex; flex-direction: column; gap: 16px; }

/* ─── Library home ───────────────────────────────────────────────────────── */
.library-header { margin-bottom: 20px; }
.library-heading { font-family: 'Playfair Display', serif; font-size: 28px; }

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.tab {
  background: none;
  border: none;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  padding: 8px 16px;
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
}
.tab::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0; right: 0;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 0.2s;
}
.tab--active { color: var(--text); }
.tab--active::after { transform: scaleX(1); }

.tab-panel { display: none; }
.tab-panel--active { display: block; }

/* ─── Series grid ────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}
@media (min-width: 480px) { .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }
@media (min-width: 768px) { .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; } }
@media (min-width: 1024px) { .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); } }

.card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform 0.2s, border-color 0.2s;
}
.card:hover { transform: translateY(-3px); border-color: var(--surface-3); }
.card-link { display: block; }
.card-cover {
  aspect-ratio: 5/7;
  overflow: hidden;
  background: var(--surface-2);
}
.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}
.card:hover .card-cover img { transform: scale(1.03); }
.card-body { padding: 10px 12px 12px; }
.card-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta { font-size: 12px; color: var(--text-2); margin-top: 3px; }

.card-bookmark {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  background: rgba(13, 13, 13, 0.75);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.card-bookmark:hover { background: rgba(30,30,30,0.9); color: var(--text); }
.card-bookmark--active { color: var(--accent); }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
}
.empty-state a { color: var(--accent); }

/* ─── Series page ────────────────────────────────────────────────────────── */
.series-header { margin-bottom: 28px; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 12px;
  transition: color 0.15s;
}
.back-link:hover { color: var(--text); }
.series-title { font-family: 'Playfair Display', serif; font-size: 32px; margin-bottom: 4px; }
.series-meta { font-size: 14px; color: var(--text-2); }

.chapter-list { display: flex; flex-direction: column; gap: 2px; }

.chapter-row {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
  overflow: hidden;
}
.chapter-row:hover { background: var(--surface-2); border-color: var(--surface-3); }
.chapter-row--done .chapter-row__title { color: var(--text-2); }
.chapter-row__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
  padding: 14px 16px;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.chapter-row__check {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  align-self: stretch;
  background: none;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--text-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.chapter-row__check:hover { background: var(--surface-3); color: var(--text-1); }
.chapter-row__check--done { color: var(--accent, #7c6af7); }
.chapter-row--missing {
  background: var(--bg);
  border-style: dashed;
  border-color: var(--surface-3);
  cursor: default;
  justify-content: flex-start;
  gap: 10px;
}

.chapter-row__info { display: flex; align-items: center; gap: 10px; flex: 1; flex-wrap: wrap; }
.chapter-row__title { font-size: 14px; font-weight: 500; }
.chapter-row__arrow { flex-shrink: 0; color: var(--text-3); }

.missing-icon { color: var(--text-3); font-size: 14px; }
.missing-label { font-size: 13px; color: var(--text-3); font-style: italic; }

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 20px;
}
.badge--done { background: var(--success-bg); color: var(--success); }
.badge--progress { background: var(--accent-bg); color: var(--accent); }
.badge--new { background: var(--surface-2); color: var(--text-3); }
.badge--admin { background: var(--accent-bg); color: var(--accent); }
.badge--user { background: var(--surface-2); color: var(--text-2); }

/* ─── Reader ─────────────────────────────────────────────────────────────── */
.body--reader {
  overflow: hidden;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #111;
}

.reader-top {
  flex-shrink: 0;
  height: var(--reader-top-h);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  background: rgba(10, 10, 10, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 50;
  transition: transform 0.25s ease;
}
.reader-top.hidden { transform: translateY(-100%); }

.reader-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--text-2);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.reader-back:hover { background: var(--surface-2); color: var(--text); }

.reader-top__center {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}
.reader-series {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-chapter-btn {
  background: none;
  border: none;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  padding: 0;
  max-width: 100%;
  text-align: left;
}
.reader-chapter-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-chapter-btn svg { flex-shrink: 0; color: var(--text-2); }

.reader-top__nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.reader-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.reader-nav-btn:hover { background: var(--surface-2); color: var(--text); }
.reader-nav-btn--disabled { cursor: default; }

/* Pages container — the scrollable area */
.pages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.pages-container::-webkit-scrollbar { width: 4px; }
.pages-container::-webkit-scrollbar-track { background: transparent; }
.pages-container::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }

.page-wrapper {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  line-height: 0;
  display: block;
}
.page-wrapper + .page-wrapper { border-top: 1px solid #1a1a1a; }
.page-canvas {
  width: 100%;
  height: auto;
  display: block;
}
.page-placeholder {
  width: 100%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
}
.page-placeholder::after {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Chapter end CTA */
.chapter-end {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 20px 36px;
  text-align: center;
}
.chapter-end__inner { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.chapter-end__text { color: var(--text-2); font-size: 13px; }

/* Bottom progress bar */
.reader-bottom {
  flex-shrink: 0;
  height: var(--reader-bottom-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: rgba(10, 10, 10, 0.95);
  border-top: 1px solid var(--border);
  z-index: 50;
}
.progress-bar {
  flex: 1;
  height: 3px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
  width: 0%;
}
.page-info { font-size: 13px; color: var(--text-2); white-space: nowrap; flex-shrink: 0; }

/* Chapter picker */
.chapter-picker {
  position: fixed;
  top: var(--reader-top-h);
  left: 0;
  right: 0;
  bottom: var(--reader-bottom-h);
  z-index: 200;
  overflow-y: auto;
  background: rgba(13, 13, 13, 0.97);
  backdrop-filter: blur(8px);
}
.picker-inner {
  max-width: 600px;
  margin: 0 auto;
  padding: 12px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.picker-item {
  display: block;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.picker-item:hover { background: var(--surface-2); color: var(--text); }
.picker-item--active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.picker-backdrop {
  position: fixed;
  inset: 0;
  z-index: 199;
}

/* ─── Admin ──────────────────────────────────────────────────────────────── */
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.admin-title { font-family: 'Playfair Display', serif; font-size: 28px; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.stat-row {
  display: flex;
  gap: 12px;
  margin-bottom: 32px;
}
.stat-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 80px;
}
.stat-value { font-size: 28px; font-weight: 700; font-family: 'Playfair Display', serif; }
.stat-label { font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.5px; }

.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 20px;
}
.admin-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.admin-section__title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}
.admin-section__header .admin-section__title { margin-bottom: 0; }

.inline-form { margin-bottom: 16px; }
.inline-form__inner { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form__inner .form-input { max-width: 300px; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.admin-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}
.admin-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.table-link { color: var(--text); }
.table-link:hover { color: var(--accent); }
.table-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.table-series-name { display: flex; align-items: center; gap: 10px; }
.table-cover-thumb { width: 28px; height: 40px; object-fit: cover; border-radius: 3px; flex-shrink: 0; }
.text-muted { color: var(--text-3); font-size: 13px; }

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.form-row .form-group { min-width: 180px; }
.form-group--check { justify-content: flex-end; padding-bottom: 9px; }

.zip-progress-bar-track {
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 12px;
}
.zip-progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent, #7c6af7);
  border-radius: 3px;
  transition: width 0.3s ease;
}
@keyframes pulse-opacity { 0%,100% { opacity:1; } 50% { opacity:0.5; } }
.zip-progress-bar-fill--pulse { animation: pulse-opacity 1.2s ease-in-out infinite; }
.zip-progress-text { font-size: 13px; color: var(--text-2); margin-top: 6px; }

.upload-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}
@media (min-width: 768px) {
  .upload-grid { grid-template-columns: 1fr 1fr; }
}
.upload-form { display: flex; flex-direction: column; gap: 16px; }
