/* My Comics — dark, clean, cover-focused UI */
:root {
  --bg: #12141a;
  --bg-elevated: #1a1d26;
  --bg-card: #20242f;
  --text: #e8eaf0;
  --text-dim: #9aa0b0;
  --accent: #ffb347;
  --accent-2: #4fa3ff;
  --danger: #ff5c5c;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

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

/* Ensure the hidden attribute always wins over display rules */
[hidden] { display: none !important; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(18, 20, 26, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.topbar h1 {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.iconbtn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.iconbtn:active { background: rgba(255, 255, 255, 0.1); }

.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.badge-offline { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- search */

.searchwrap { padding: 10px 14px 0; }
#search {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
#search:focus { border-color: var(--accent-2); }

/* ---------------------------------------------------------------- views */

.view { padding: 14px; max-width: 1200px; margin: 0 auto; padding-bottom: 40px; }

.section-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 18px 0 10px;
}
.section-title:first-child { margin-top: 4px; }

/* Horizontal "continue reading" strip */
.hstrip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: thin;
}
.hstrip .card { width: 110px; flex: none; }

/* Cover grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
}
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 10px; }
}

.card { cursor: pointer; position: relative; }

.cover {
  position: relative;
  aspect-ratio: 17 / 24;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  box-shadow: var(--shadow);
}
.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.25s;
}
.cover img.loaded { opacity: 1; }

.cover .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-word;
}

.card-title {
  margin-top: 7px;
  font-size: 12.5px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* Progress bar on cards */
.progressbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(0, 0, 0, 0.55);
}
.progressbar > div { height: 100%; background: var(--accent); }
.cover .done-check {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--accent);
  color: #201500;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

/* Download state indicators */
.dl-btn {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dl-btn.downloaded { background: var(--accent-2); }
.dl-btn.downloading {
  background: rgba(0, 0, 0, 0.7);
  font-size: 9px;
  font-weight: 700;
}

/* Series card count bubble */
.count-bubble {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
}

/* Downloads list */
.dl-list { display: flex; flex-direction: column; gap: 10px; }
.dl-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.dl-row img { width: 44px; height: 62px; object-fit: cover; border-radius: 6px; background: var(--bg-card); }
.dl-row .meta { flex: 1; min-width: 0; }
.dl-row .meta .t { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-row .meta .s { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.dl-row .del {
  border: none;
  background: none;
  color: var(--danger);
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 20px;
  font-size: 14px;
}

/* ---------------------------------------------------------------- reader */

.reader {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
}
.reader[hidden] { display: none; }
.reader-stage {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  -webkit-overflow-scrolling: touch;
}
#reader-img {
  display: block;
  user-select: none;
  -webkit-user-select: none;
}
#reader-img.fit-width { width: 100%; height: auto; }
#reader-img.fit-screen { max-width: 100vw; max-height: 100vh; width: auto; height: auto; margin: auto; }
.reader-stage.centered { align-items: center; }

.reader-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.7);
  font-size: 14px;
}
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.reader-ui { position: fixed; inset: 0; pointer-events: none; transition: opacity 0.2s; }
.reader-ui.hidden { opacity: 0; }
.reader-top, .reader-bottom {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(10, 10, 14, 0.85);
  pointer-events: auto;
}
.reader-ui.hidden .reader-top, .reader-ui.hidden .reader-bottom { pointer-events: none; }
.reader-top { top: 0; padding-top: calc(10px + env(safe-area-inset-top)); }
.reader-bottom { bottom: 0; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.reader-title {
  flex: 1;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-pageinfo { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
#reader-slider { flex: 1; accent-color: var(--accent); }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}
