:root {
  color-scheme: dark;
  --background: #111;
  --surface: #1c1c1c;
  --text: #f4f4f4;
  --muted: #aaa;
  --border: #343434;
  --page-width: 1040px;
  --reader-width: 900px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--background);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; }
select { font: inherit; }

.site-header {
  min-height: 4rem;
  padding: 1.25rem max(1rem, calc((100% - var(--page-width)) / 2));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.catalog-main {
  width: min(100% - 2rem, var(--page-width));
  margin: 0 auto;
  padding: clamp(3rem, 8vw, 7rem) 0;
}

.section-title {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 750;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.section-title { margin: 0 0 1rem; }

.comic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 31rem), 1fr));
  gap: 1.5rem;
}

.comic-card {
  display: grid;
  grid-template-columns: minmax(9rem, 38%) 1fr;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: .8rem;
  background: var(--surface);
  text-decoration: none;
  transition: border-color 160ms ease, transform 160ms ease;
}
.comic-card:hover { border-color: #666; transform: translateY(-3px); }
.comic-card:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }

.comic-cover {
  display: grid;
  min-height: 15rem;
  overflow: hidden;
  background: #0b0b0b;
  place-items: center;
}
.comic-cover img { display: block; width: 100%; height: 100%; object-fit: cover; }

.comic-details { align-self: center; padding: clamp(1.25rem, 4vw, 2rem); }
.comic-details h3 { margin: 0; font-size: 1.35rem; }
.comic-details p {
  margin: .65rem 0 1.2rem;
  color: var(--muted);
  line-height: 1.5;
}
.comic-details .comic-author,
.comic-details .comic-subtitle {
  margin: .3rem 0 0;
  color: var(--text);
  font-size: .85rem;
}
.comic-details .comic-subtitle { color: var(--muted); }
.comic-subtitle + p { min-height: 3em; margin-top: .8rem; }
.comic-count { font-size: .85rem; font-weight: 700; }

.reader-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4rem;
  padding:
    .75rem max(1rem, calc((100% - var(--page-width)) / 2), env(safe-area-inset-right))
    .75rem max(1rem, calc((100% - var(--page-width)) / 2), env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.reader-brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-decoration: none;
}
.reader-brand img { display: block; width: 2.125rem; height: 2.125rem; }

.selectors { display: flex; gap: .65rem; }
.selectors label { display: grid; gap: .2rem; }
.selectors span { color: var(--muted); font-size: .7rem; }
.selectors select {
  min-height: 44px;
  max-width: 16rem;
  padding: .4rem 2rem .4rem .55rem;
  border: 1px solid var(--border);
  border-radius: .4rem;
  background: #262626;
  color: var(--text);
}

.episode-header {
  width: min(100% - 2rem, var(--page-width));
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 4.5rem) 0;
  text-align: center;
}

.work-title {
  margin: 0 0 .5rem;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1 { margin: 0; font-size: clamp(1.7rem, 5vw, 3.4rem); line-height: 1.1; }
.episode-summary { max-width: 42rem; margin: 1rem auto 0; color: var(--muted); }

.pages {
  display: flex;
  align-items: center;
  flex-direction: column;
  width: min(100%, var(--reader-width));
  margin: 0 auto;
  background: white;
  overflow: hidden;
}

.pages img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  object-fit: contain;
}

.episode-navigation {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(100% - 2rem, var(--page-width));
  min-height: 5rem;
  margin: 1.5rem auto 0;
  border-top: 1px solid var(--border);
}

.episode-navigation a {
  min-width: 0;
  padding: 1.5rem 0;
  overflow-wrap: anywhere;
  text-decoration: none;
}
.episode-navigation a:last-child { text-align: right; }
.episode-navigation a[href]:hover { text-decoration: underline; }

.credits {
  padding: 1.25rem 1rem 2.5rem;
  color: var(--muted);
  font-size: .82rem;
  text-align: center;
}

@media (max-width: 680px) {
  .reader-header {
    align-items: stretch;
    flex-direction: column;
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-left: max(1rem, env(safe-area-inset-left));
  }
  .selectors { display: grid; grid-template-columns: 1fr 1fr; }
  .selectors select { width: 100%; max-width: none; }
  .episode-header { padding: 2.25rem 0; }
  .episode-navigation { gap: 1rem; }
  .episode-navigation a { display: flex; align-items: center; min-height: 56px; }
  .episode-navigation a:last-child { justify-content: end; }
  .credits {
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: max(2.5rem, env(safe-area-inset-bottom));
    padding-left: max(1rem, env(safe-area-inset-left));
  }
}

@media (max-width: 430px) {
  .comic-card { grid-template-columns: 1fr; }
  .comic-cover { min-height: 0; aspect-ratio: 16 / 9; }
  .selectors { grid-template-columns: 1fr; }
  .episode-header { width: min(100% - 1.5rem, var(--page-width)); }
  h1 { font-size: clamp(1.6rem, 8vw, 2.25rem); }
  .episode-navigation { width: calc(100% - 1.5rem); font-size: .9rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .comic-card { transition: none; }
}
