/* ============ Theme ============ */
:root {
  --bg: #0e0f14;
  --panel: #171923;
  --panel-2: #1f2230;
  --border: #2a2e40;
  --text: #e9eaf2;
  --muted: #9a9db3;
  --accent: #8b5cf6;
  --accent-2: #ec4899;
  --radius: 14px;
  --gutter: clamp(14px, 4vw, 28px);
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

a { color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; display: block; }
main { flex: 1; }
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 var(--gutter); }

/* ============ Header ============ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(14, 15, 20, 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px var(--gutter);
  min-height: 64px;
}

/* ---- LOGO PLACEHOLDER ----
   To use your own logo, open public/app.js, find the "logo-box" line in mount()
   and replace it with:  h('img', { class: 'logo-img', src: '/logo.png', alt: 'Logo' })
   then put your logo.png inside the public/ folder. */
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; flex-shrink: 0; }
.logo-box {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 2px dashed #4a4f6a;
  border-radius: 10px;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.logo-img { width: 60px; height: 60px; object-fit: contain; }

.nav { display: flex; gap: 4px; }
.nav a {
  padding: 9px 14px;
  border-radius: 10px;
  color: var(--muted);
  white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a.active { color: #fff; background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--accent); }

.search { margin-left: auto; }
.search input {
  width: 260px;
  max-width: 100%;
  height: 42px;
  padding: 0 16px;
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming in on focus */
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.25); }

/* ============ Hero / headings ============ */
.hero { padding: clamp(28px, 6vw, 56px) 0 clamp(12px, 3vw, 24px); }
.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.7rem, 5vw, 2.8rem);
  line-height: 1.15;
  background: linear-gradient(90deg, #fff, #c4b5fd 60%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p { margin: 0; color: var(--muted); max-width: 60ch; }

.section { padding: clamp(14px, 3vw, 26px) 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: clamp(1.15rem, 3vw, 1.5rem); }
.section-head a { color: var(--accent); font-size: 0.95rem; white-space: nowrap; padding: 6px 0; }
.section-head a:hover { text-decoration: underline; }
.result-count { color: var(--muted); font-size: 0.95rem; margin: 0 0 14px; }

/* ============ Cards / grid ============ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: clamp(12px, 2.5vw, 22px);
}
.card {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.card:hover, .card:focus-visible {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 10px 28px rgba(139, 92, 246, 0.2);
  outline: none;
}
.cover { position: relative; aspect-ratio: 2 / 3; background: var(--panel-2); overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.badge, .type-tag {
  position: absolute;
  top: 8px;
  padding: 3px 9px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge { left: 8px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fff; }
.type-tag { top: auto; bottom: 8px; right: 8px; background: rgba(14, 15, 20, 0.8); color: #fff; }
.card-body { padding: 10px 12px 14px; }
.card-body h3 {
  margin: 0 0 2px;
  font-size: 0.98rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.meta { margin: 0; color: var(--muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty, .error-msg {
  grid-column: 1 / -1;
  padding: 36px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.skeleton { aspect-ratio: 2 / 3.5; border-radius: var(--radius); background: linear-gradient(100deg, var(--panel) 30%, var(--panel-2) 50%, var(--panel) 70%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ============ Detail page ============ */
.back { display: inline-block; margin: 18px 0 6px; padding: 8px 0; color: var(--muted); }
.back:hover { color: var(--text); }
.detail { display: grid; grid-template-columns: minmax(220px, 320px) 1fr; gap: clamp(20px, 4vw, 44px); padding: 12px 0 48px; align-items: start; }
.detail-cover { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); aspect-ratio: 2 / 3; background: var(--panel-2); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45); }
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-info h1 { margin: 10px 0 4px; font-size: clamp(1.6rem, 4.5vw, 2.5rem); line-height: 1.15; overflow-wrap: anywhere; }
.byline { margin: 0 0 14px; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag { padding: 4px 12px; font-size: 0.82rem; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
.tag.hot { background: linear-gradient(90deg, var(--accent), var(--accent-2)); border: 0; font-weight: 700; }
.desc { margin: 20px 0 26px; white-space: pre-line; color: #cfd1e2; max-width: 70ch; overflow-wrap: anywhere; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 28px;
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.35);
  transition: transform 0.15s ease, filter 0.15s ease;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.btn.ghost { background: transparent; border: 1px solid var(--border); box-shadow: none; }
.btn.ghost:hover { border-color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; }

/* ---- chapter list (manga pages) ---- */
.chapters { grid-column: 1 / -1; }
.sort-btn {
  min-height: 44px;
  padding: 0 4px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--accent);
  background: none;
  border: 0;
  cursor: pointer;
}
.sort-btn:hover { text-decoration: underline; }
.chapter-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.chapter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.chapter:hover, .chapter:focus-visible { border-color: var(--accent); background: var(--panel-2); outline: none; }
.ch-name { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.ch-name strong { font-size: 1rem; }
.ch-title { color: var(--muted); font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-meta { flex: none; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.88rem; }
.ch-arrow { font-size: 1.4rem; line-height: 1; color: var(--accent); }

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

/* ============ Mobile ============ */
@media (max-width: 760px) {
  .header-inner { flex-wrap: wrap; gap: 10px 12px; padding-top: 10px; padding-bottom: 10px; }
  .logo-text { font-size: 1rem; }
  /* nav + search drop to their own rows; nav scrolls sideways if it ever overflows */
  .nav { order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; margin: 0 calc(var(--gutter) * -1); padding: 0 var(--gutter); }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: 1; text-align: center; min-height: 44px; display: grid; place-items: center; }
  .search { order: 2; margin-left: auto; flex: 1; min-width: 150px; }
  .search input { width: 100%; }

  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .detail { grid-template-columns: 1fr; padding-bottom: 110px; }
  .detail-cover { max-width: 260px; margin: 0 auto; }
  .detail-info { text-align: left; }
  /* the read buttons stick to the bottom of the screen on phones */
  .actions {
    position: fixed;
    left: var(--gutter);
    right: var(--gutter);
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 15;
    flex-wrap: nowrap;
    gap: 10px;
    padding: 10px;
    background: rgba(14, 15, 20, 0.94);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 999px;
  }
  .actions .btn { flex: 1; min-width: 0; padding: 0 14px; white-space: nowrap; }
  .chapter-list { grid-template-columns: 1fr; }
}

@media (min-width: 761px) and (max-width: 1000px) {
  .search input { width: 200px; }
}

@media (hover: none) {
  .card:hover { transform: none; box-shadow: none; border-color: var(--border); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
