:root {
  color-scheme: light;
  --yellow-50: #fff9d6;
  --yellow-100: #fff1a8;
  --yellow-300: #ffd84d;
  --yellow-500: #f6c600;
  --yellow-700: #b88700;
  --ink: #1e1e1e;
  --muted: #646464;
  --surface: #ffffff;
  --surface-alt: #f6f7f8;
  --line: #ded7bf;
  --accent: #176b87;
  --danger: #b33636;
  --shadow: 0 18px 48px rgba(51, 43, 14, 0.12);
  --radius: 8px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --yellow-50: #342d12;
  --yellow-100: #4b3f12;
  --yellow-300: #caa72b;
  --yellow-500: #f0c533;
  --yellow-700: #ffe073;
  --ink: #f4f0df;
  --muted: #c5bea3;
  --surface: #191814;
  --surface-alt: #202124;
  --line: #4c432a;
  --accent: #72c7df;
  --danger: #ff8d8d;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--surface-alt);
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(246, 198, 0, 0.12), transparent 280px),
    var(--surface-alt);
  font-family: Inter, Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 10px clamp(16px, 4vw, 48px);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  overflow: hidden;
  background: #fff7d1;
  border-radius: var(--radius);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}

.brand-mark img {
  width: 100%;
  height: 100%;
}

.brand strong,
.brand small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong {
  font-size: 1rem;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.topbar-actions,
.reader-controls,
.button-row,
.tag-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 48px) 56px;
}

.app:focus {
  outline: none;
}

.manga-hero {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  gap: clamp(20px, 5vw, 48px);
  align-items: center;
  padding: clamp(22px, 5vw, 48px) 0 34px;
}

.eyebrow,
.status,
.meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.eyebrow,
.status {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
}

.manga-summary h1,
.reader-info h1,
.not-found h1 {
  margin: 8px 0;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
}

.manga-summary .description {
  max-width: 700px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.65;
}

select {
  appearance: none;
  min-height: 44px;
  width: 100%;
  color: var(--ink);
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23646464' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 14px center;
  background-repeat: no-repeat;
  background-size: 16px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 42px 0 12px;
  outline: none;
}

:root[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23c5bea3' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

select:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--yellow-500) 55%, transparent);
  outline-offset: 2px;
}

.cover-panel {
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.cover-panel img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--yellow-100);
  border-radius: calc(var(--radius) - 2px);
}

.manga-summary {
  display: grid;
  min-width: 0;
  gap: 16px;
}

.chapter-section {
  display: grid;
  gap: 14px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2 {
  margin: 6px 0 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
  line-height: 1.1;
}

.section-heading span {
  color: var(--muted);
  font-weight: 800;
}

.chapter-list {
  display: grid;
  gap: 10px;
}

.chapter-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 72px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(51, 43, 14, 0.06);
}

.chapter-row.current {
  border-color: var(--yellow-500);
  box-shadow: inset 4px 0 0 var(--yellow-500), 0 8px 24px rgba(51, 43, 14, 0.08);
}

.chapter-number {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #1d1a12;
  background: var(--yellow-500);
  border-radius: var(--radius);
  font-weight: 900;
}

.chapter-main {
  min-width: 0;
}

.chapter-main strong,
.chapter-main small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-main small,
.chapter-pages {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

.chapter-pages {
  font-weight: 800;
  white-space: nowrap;
}

.tag-row span {
  min-height: 28px;
  padding: 5px 9px;
  color: color-mix(in srgb, var(--accent) 78%, var(--ink));
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.primary-button,
.text-button,
.icon-button,
.segmented button,
.page-step {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  padding: 0 16px;
  color: #1d1a12;
  background: var(--yellow-500);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.14);
}

.text-button {
  padding: 0 12px;
  color: var(--accent);
  background: transparent;
}

.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  padding: 0;
  color: var(--ink);
  background: var(--surface-alt);
  border: 1px solid var(--line);
  font-size: 1.25rem;
  line-height: 1;
  text-align: center;
}

.icon-button:disabled,
.icon-button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.38;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reader-view {
  width: 100%;
  padding-top: 16px;
  padding-bottom: 112px;
}

.reader-toolbar {
  position: fixed;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 12px;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  width: min(calc(100% - 24px), 1180px);
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.chapter-title {
  min-width: 0;
}

.chapter-title strong,
.chapter-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-title span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.86rem;
}

.reader-controls select {
  width: auto;
  max-width: 220px;
}

.segmented {
  display: flex;
  min-height: 42px;
  padding: 3px;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
}

.segmented svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.segmented button.active {
  color: #1d1a12;
  background: var(--yellow-500);
}

.reader-info {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  max-width: 980px;
  margin: 0 auto 18px;
}

.reader-info h1 {
  font-size: clamp(1.5rem, 4vw, 2.6rem);
}

#page-counter {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.pages {
  display: grid;
  gap: 14px;
  justify-items: center;
  margin: 0 auto;
}

.width-compact .pages,
.width-compact .reader-info {
  max-width: 760px;
}

.width-comfortable .pages,
.width-comfortable .reader-info {
  max-width: 980px;
}

.width-wide .pages,
.width-wide .reader-info {
  max-width: 1220px;
}

.manga-page {
  width: 100%;
  min-height: 320px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.single-page {
  position: relative;
  grid-template-columns: 64px minmax(0, 1fr) 64px;
  align-items: center;
  max-width: 1080px;
}

.single-page .manga-page {
  grid-column: 2;
}

.page-step {
  position: sticky;
  top: 50vh;
  width: 52px;
  height: 72px;
  color: #1d1a12;
  background: var(--yellow-500);
  font-size: 2rem;
}

.page-step.prev {
  grid-column: 1;
}

.page-step.next {
  grid-column: 3;
}

.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  max-width: 980px;
  margin: 24px auto 0;
}

.empty,
.not-found {
  padding: 32px 0;
  color: var(--muted);
}

@media (max-width: 840px) {
  .manga-hero {
    grid-template-columns: 1fr;
  }

  .cover-panel {
    width: min(280px, 100%);
  }

  .reader-toolbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px;
  }

  .reader-toolbar .chapter-title {
    display: none;
  }

  .reader-controls {
    display: grid;
    grid-column: 2;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 8px;
  }

  .reader-controls select {
    min-height: 40px;
    width: 100%;
    max-width: none;
    padding-right: 30px;
    background-position: right 10px center;
    background-size: 14px 14px;
  }

  #width-select {
    display: none;
  }

  .segmented {
    grid-column: 2;
    grid-row: 1;
    min-width: 84px;
    min-height: 40px;
    padding: 2px;
  }

  .segmented button {
    width: 38px;
    min-height: 34px;
    padding: 0;
  }

  .chapter-jump {
    width: 40px;
    height: 40px;
  }

  .mode-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .reader-view {
    padding-bottom: 104px;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding-inline: 12px;
  }

  .app {
    padding-inline: 12px;
  }

  .manga-hero {
    padding-top: 18px;
  }

  .chapter-row {
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: start;
  }

  .chapter-number {
    width: 36px;
    height: 36px;
  }

  .chapter-pages {
    grid-column: 2;
  }

  .reader-info {
    align-items: start;
    flex-direction: column;
  }

  .single-page {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .single-page .manga-page {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .page-step {
    position: static;
    width: 100%;
    height: 48px;
  }

  .page-step.prev,
  .page-step.next {
    grid-column: auto;
    grid-row: 2;
  }
}
