:root {
  color-scheme: dark;
  --bg: #101113;
  --panel: #181b20;
  --panel-2: #20242b;
  --text: #eef1f5;
  --muted: #a9b0bc;
  --line: #303640;
  --accent: #e6b450;
  --accent-2: #70c1b3;
  --danger: #f06d6d;
  --reader-width: 860px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, Segoe UI, sans-serif;
}
body.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}
a { color: inherit; text-decoration: none; }
button, input, select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
button, select { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: rgba(16,17,19,.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
}
.topbar nav { display: flex; gap: 14px; align-items: center; }
.dot {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: var(--danger);
  border-radius: 999px;
  color: white;
  font-size: 12px;
}
main { padding: 22px clamp(14px, 4vw, 40px) 48px; }

.login-shell {
  width: min(100%, 420px);
  padding: 0;
}
.login-box {
  display: grid;
  gap: 14px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(0,0,0,.28);
}
.login-box h1 {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 30px;
}
.login-box label {
  display: grid;
  gap: 6px;
}
.login-box label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.login-box input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
}
.login-box button {
  min-height: 42px;
  background: var(--accent);
  border-color: transparent;
  color: #17110a;
  font-weight: 800;
}
.login-error {
  margin: 0;
  padding: 10px 12px;
  color: #ffe4e4;
  background: rgba(240,109,109,.14);
  border: 1px solid rgba(240,109,109,.38);
  border-radius: 6px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 620px);
  gap: 20px;
  align-items: end;
  margin-bottom: 18px;
}
h1 { margin: 0 0 6px; font-size: clamp(28px, 4vw, 48px); line-height: 1.05; }
h2 { margin: 28px 0 12px; }
.hero p, .summary, .meta, .stats { color: var(--muted); }
.search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px 110px;
  gap: 10px;
}
.index-hero {
  align-items: start;
}
.search-advanced {
  grid-template-columns: minmax(0, 1fr) minmax(140px, 180px) 96px 86px 70px;
  gap: 8px;
}
.search input, .search select, .search button, .reader-nav a, .reader-nav select, .fav {
  min-height: 38px;
  padding: 0 10px;
}
.search button, .reader-nav a, .fav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #17110a;
  border-color: transparent;
  font-weight: 750;
}
.reset-search {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
}
.filter-toggle {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--accent);
  font-weight: 800;
}
.advanced-filters {
  grid-column: 1 / -1;
  display: none;
  gap: 8px;
}
.advanced-filters.open {
  display: grid;
}
.filter-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}
.filter-row label {
  display: grid;
  gap: 3px;
}
.filter-row label span,
.check-filter {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}
.filter-row select,
.filter-row input {
  width: 100%;
}
.quality-row {
  align-items: end;
}
.check-filter {
  display: flex !important;
  min-height: 38px;
  align-items: center;
  gap: 8px !important;
  padding: 0 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.check-filter input {
  width: auto;
  min-height: 0;
}
.view-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.view-toggle button {
  min-height: 38px;
  padding: 0 10px;
  font-weight: 800;
}
.view-toggle button.active {
  border-color: rgba(230,180,80,.5);
  color: var(--accent);
}
.result-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}
.result-overview div {
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.result-overview span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.result-overview strong {
  display: block;
  margin-top: 2px;
  font-size: 20px;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.chip, .tags a {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
}
.tag-pill {
  gap: 6px;
  max-width: 100%;
}
.tag-pill small {
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 10px;
  line-height: 1;
  font-weight: 800;
  text-transform: uppercase;
  color: #0b0c0e;
}
.tag-pill span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag-artist {
  border-color: rgba(95, 186, 255, .45) !important;
  background: rgba(95, 186, 255, .09) !important;
}
.tag-artist small { background: #5fbaff; }
.tag-type {
  border-color: rgba(116, 221, 147, .45) !important;
  background: rgba(116, 221, 147, .09) !important;
}
.tag-type small { background: #74dd93; }
.tag-genre {
  border-color: rgba(232, 176, 83, .45) !important;
  background: rgba(232, 176, 83, .09) !important;
}
.tag-genre small { background: #e8b053; }
.chip.active { color: var(--accent); border-color: rgba(230,180,80,.45); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.comic-results.view-list {
  grid-template-columns: 1fr;
}
.view-list .card {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  align-items: stretch;
}
.view-list .cover-wrap {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
}
.view-list .card-body {
  grid-column: 2;
  grid-row: 1;
}
.view-list .cover {
  height: 100%;
  min-height: 192px;
  aspect-ratio: auto;
}
.view-list .cover img,
.view-list .no-cover {
  min-height: 0;
}
.view-list .card-title {
  min-height: 0;
  font-size: 18px;
}
.view-list .tags {
  min-height: 0;
}
.view-list .card-actions {
  max-width: 360px;
}
.reading-hero {
  grid-template-columns: 1fr;
}
.reading-list {
  display: grid;
  gap: 12px;
  max-width: 1040px;
}
.reading-item {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 16px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.reading-item h2 {
  margin: 0 0 4px;
  font-size: 20px;
}
.reading-item p {
  margin: 0 0 4px;
}
.muted {
  color: var(--muted);
}
.reading-cover {
  overflow: hidden;
  aspect-ratio: 2 / 3;
  background: #0b0c0e;
  border-radius: 6px;
}
.reading-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.reading-progress {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}
.reading-progress strong {
  color: var(--accent-2);
}
.continue-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  margin-top: 12px;
  padding: 0 14px;
  background: var(--accent);
  border-radius: 6px;
  color: #17110a;
  font-weight: 800;
}
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.cover-wrap {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  min-width: 0;
}
.cover {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: #0b0c0e;
}
.quick-fav {
  position: absolute;
  top: 8px;
  right: 8px;
}
.quick-fav button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: rgba(16, 17, 19, .82);
  border-color: rgba(255,255,255,.2);
  border-radius: 999px;
  color: var(--accent);
  font-size: 18px;
}
.cover img, .detail-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.no-cover {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-height: 240px;
  color: var(--muted);
  background: #111419;
}
.card-body {
  position: relative;
  z-index: 2;
  min-width: 0;
  padding: 12px;
  background: var(--panel);
}
.card-title {
  min-height: 44px;
  font-weight: 800;
}
.card-progress {
  display: grid;
  gap: 5px;
  margin: 8px 0;
}
.card-progress div:first-child {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.read-progress .meter i {
  background: linear-gradient(90deg, var(--accent-2), #8ee6a8);
}
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-top: 8px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.source-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-top: 8px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .02em;
}
.source-mw18 {
  color: #ffcc66;
  background: rgba(255, 204, 102, .12);
  border-color: rgba(255, 204, 102, .5);
}
.status-completed {
  color: #8ee6a8;
  background: rgba(116, 221, 147, .1);
  border-color: rgba(116, 221, 147, .45);
}
.status-ongoing {
  color: #5fbaff;
  background: rgba(95, 186, 255, .1);
  border-color: rgba(95, 186, 255, .45);
}
.status-unknown {
  color: var(--muted);
  background: var(--panel-2);
}
.meta, .stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 8px 0;
  font-size: 13px;
}
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 34px;
  margin: 10px 0;
}
.quality-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 8px 0;
}
.quality-flags span {
  padding: 3px 7px;
  background: rgba(240, 109, 109, .1);
  border: 1px solid rgba(240, 109, 109, .32);
  border-radius: 999px;
  color: #ffb3b3;
  font-size: 12px;
}
.card-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}
.card-actions .continue-btn,
.details-btn,
.action-disabled {
  min-height: 36px;
  margin: 0;
  padding: 0 12px;
  border-radius: 6px;
  font-weight: 800;
}
.details-btn,
.action-disabled {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.fav {
  width: 100%;
}
.fav.on {
  background: var(--accent-2);
}

.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
}
.pager a {
  padding: 10px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.detail {
  display: grid;
  grid-template-columns: minmax(180px, 280px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.detail-cover {
  aspect-ratio: 2 / 3;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.detail-progress {
  display: grid;
  gap: 10px;
  max-width: 520px;
  margin: 12px 0 6px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.detail-progress div:first-child {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 14px;
  align-items: baseline;
}
.detail-progress span,
.detail-progress em {
  color: var(--muted);
  font-style: normal;
}
.detail-progress strong {
  font-size: 24px;
  line-height: 1;
  color: var(--text);
}
.detail-progress em {
  grid-column: 1 / -1;
}
.reading-total {
  margin-top: 8px;
}
.reading-total .meter i {
  background: linear-gradient(90deg, var(--accent-2), #8ee6a8);
}
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.detail-actions button,
.chapter-read-form button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #15191f;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}
.wide { margin-top: 18px; }
.chapters {
  max-width: 920px;
}
.chapter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.chapter-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  min-width: 0;
}
.chapter-main.disabled {
  opacity: .45;
  pointer-events: none;
}
.chapter-label {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.chapter-label b {
  font-weight: 750;
}
.chapter-label small {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.read,
.progress-text { color: var(--accent-2); }
.chapter-side {
  display: flex;
  gap: 10px;
  align-items: center;
}
.chapter-state {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px 8px;
}
.chapter-read-status:empty {
  display: none;
}
.chapter-read-form {
  display: flex;
  align-self: stretch;
}
.chapter-read-form.is-pending,
.detail-actions-form.is-pending {
  opacity: .65;
}
.chapter-read-form button {
  height: 100%;
  min-width: 86px;
}

.reader-head, .reader-bottom {
  display: grid;
  justify-items: center;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
  transition: opacity .18s ease, transform .18s ease;
}
.reader-head > div:first-child {
  justify-self: stretch;
}
.reader-head h1 { font-size: clamp(24px, 3vw, 36px); }
.reader-nav {
  display: grid;
  grid-template-columns: minmax(72px, 96px) minmax(132px, 300px) minmax(72px, 96px);
  gap: 10px;
  align-items: center;
  justify-content: center;
  width: min(100%, 520px);
}
.reader-nav a {
  border-radius: 6px;
}
.reader-nav select {
  min-width: 0;
}
.pages {
  display: grid;
  justify-items: center;
  gap: 0;
}
.reader-page {
  display: grid;
  justify-items: center;
  width: 100%;
  margin: 0;
}
.pages img {
  width: min(100%, var(--reader-width));
  height: auto;
  display: block;
  background: #070809;
  margin: 0;
}
.reader-control-stack {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 20;
  display: grid;
  gap: 10px;
  width: 92px;
  transition: opacity .18s ease, transform .18s ease;
}
.reader-progress-box,
.reader-tools {
  background: rgba(24, 27, 32, .94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,.32);
  backdrop-filter: blur(10px);
  width: 100%;
}
.reader-progress-box {
  display: grid;
  gap: 2px;
  padding: 8px 7px;
  text-align: center;
}
.reader-progress-box span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}
.reader-progress-box strong {
  color: var(--accent-2);
  font-size: 16px;
}
.reader-tools {
  display: grid;
  grid-template-rows: auto auto auto 128px auto;
  gap: 7px;
  justify-items: center;
  align-items: center;
  padding: 9px 7px;
}
.reader-scope,
.reader-fit {
  display: grid;
  gap: 4px;
  width: 100%;
}
.reader-scope {
  grid-template-columns: 1fr 1fr;
}
.reader-fit {
  grid-template-columns: repeat(4, 1fr);
}
.reader-scope button,
.reader-fit button {
  min-width: 0;
  min-height: 24px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}
.reader-scope button.active,
.reader-fit button.active {
  border-color: rgba(240, 184, 92, .55);
  background: rgba(240, 184, 92, .16);
  color: var(--accent);
}
.reader-tools label,
.reader-tools output {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}
.reader-tools input {
  align-self: center;
  justify-self: center;
  width: 24px;
  height: 128px;
  accent-color: var(--accent);
  writing-mode: vertical-lr;
  direction: rtl;
  transform: none;
}
.reader-ui-hidden .topbar,
.reader-ui-hidden .reader-head,
.reader-ui-hidden .reader-bottom,
.reader-ui-hidden .reader-control-stack {
  opacity: 0;
  pointer-events: none;
}
.reader-ui-hidden .reader-head {
  transform: translateY(-8px);
}
.reader-ui-hidden .reader-bottom,
.reader-ui-hidden .reader-control-stack {
  transform: translateY(8px);
}
.image-error {
  display: grid;
  gap: 6px;
  width: min(100%, var(--reader-width));
  min-height: 160px;
  place-content: center;
  padding: 20px;
  background: #140d0f;
  border: 1px solid rgba(255, 107, 107, .36);
  color: #ffb3b3;
  text-align: center;
}
.image-error span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.empty {
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.stats-hero {
  grid-template-columns: 1fr;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  min-height: 118px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.stat-card span,
.stat-card em {
  display: block;
  color: var(--muted);
  font-style: normal;
}
.stat-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 28px;
  line-height: 1;
}
.refresh-card {
  display: flex;
  flex-direction: column;
}
.refresh-meter {
  height: 7px;
  overflow: hidden;
  margin-top: auto;
  background: #0b0c0e;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.refresh-meter i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  animation: refresh-fill 5s linear forwards;
}
@keyframes refresh-fill {
  from { width: 0; }
  to { width: 100%; }
}
.progress-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin: 20px 0;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.progress-stat {
  display: grid;
  gap: 8px;
}
.progress-stat div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
}
.meter {
  height: 10px;
  overflow: hidden;
  background: #0b0c0e;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.meter i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.progress-stat small {
  color: var(--muted);
}
.stat-table {
  margin: 18px 0;
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.stat-table h2 {
  margin: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  color: var(--muted);
  font-weight: 700;
}
td:last-child,
th:last-child {
  text-align: right;
}
.stat-table a {
  color: var(--accent);
}

@media (max-width: 820px) {
  .topbar { align-items: flex-start; }
  .hero, .detail { grid-template-columns: 1fr; }
  .search { grid-template-columns: 1fr 1fr; }
  .search input,
  .search select[name="sort"] {
    grid-column: 1 / -1;
  }
  .reset-search {
    grid-column: 1 / -1;
  }
  .filter-row { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .view-list .card {
    grid-template-columns: 92px minmax(0, 1fr);
  }
  .view-list .cover {
    min-height: 138px;
  }
  .view-list .card-actions {
    grid-template-columns: 1fr;
  }
  .reader-nav {
    grid-template-columns: minmax(58px, 72px) minmax(0, 1fr) minmax(58px, 72px);
    gap: 6px;
    width: 100%;
  }
  .reader-nav a,
  .reader-nav select {
    min-height: 38px;
    padding: 0 7px;
    font-size: 13px;
  }
  .reader-control-stack {
    left: 8px;
    bottom: 8px;
    width: 86px;
    gap: 8px;
  }
  .reader-tools {
    grid-template-rows: auto auto auto 128px auto;
    padding: 8px 6px;
  }
  .reader-progress-box {
    padding: 7px 5px;
  }
}
