:root {
  color-scheme: light;
  --paper: #f2eee6;
  --surface: #fffdf8;
  --ink: #171716;
  --muted: #68655f;
  --line: #c8c1b5;
  --red: #c92d2d;
  --yellow: #e8bd31;
  --green: #225f4b;
  --shadow: 0 16px 36px rgba(34, 29, 20, .12);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button, select, input { font: inherit; }
button, a, label { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 72px;
  padding: 0 clamp(18px, 4vw, 64px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 12px; width: fit-content; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; background: var(--red); color: white; font-size: 13px; font-weight: 900; transform: rotate(-3deg); }
.brand-copy { display: grid; line-height: 1; gap: 5px; }
.brand-copy strong { font-size: 14px; }
.brand-copy small { font-size: 9px; color: var(--muted); }

nav { display: flex; height: 100%; }
.nav-button { position: relative; min-width: 84px; border: 0; background: transparent; cursor: pointer; font-weight: 700; }
.nav-button::after { content: ""; position: absolute; left: 22px; right: 22px; bottom: -1px; height: 3px; background: var(--red); transform: scaleX(0); transition: transform .2s ease; }
.nav-button.is-active::after { transform: scaleX(1); }
.theme-toggle { justify-self: end; }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.icon-button:hover, .text-button:hover, .nav-button:hover { color: var(--red); }

main { min-height: calc(100vh - 72px); }
.view { display: none; }
.view.is-active { display: block; }

.library-view { max-width: 1500px; margin: 0 auto; padding: clamp(42px, 7vw, 96px) clamp(18px, 4vw, 64px) 80px; }
.library-heading { display: flex; align-items: end; justify-content: space-between; gap: 32px; }
.eyebrow { margin: 0 0 12px; color: var(--red); font-size: 12px; font-weight: 800; }
.library-heading h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(48px, 7vw, 104px); font-style: italic; line-height: .86; font-weight: 900; }
.subtitle { margin: 18px 0 0; color: var(--muted); font-size: 16px; }
.library-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: end; }

.primary-button, .file-button {
  min-height: 44px;
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-weight: 750;
  cursor: pointer;
  text-decoration: none;
}
.file-button { background: transparent; color: var(--ink); }
.primary-button:hover { background: var(--red); border-color: var(--red); }
.file-button:hover { border-color: var(--red); color: var(--red); }

.race-line { height: 34px; margin: 38px 0 20px; border-bottom: 1px solid var(--ink); position: relative; overflow: hidden; }
.race-line::before { content: "START"; position: absolute; bottom: 5px; font-size: 9px; font-weight: 900; }
.race-line span { position: absolute; right: 0; bottom: -1px; width: 64px; height: 10px; background: repeating-conic-gradient(var(--ink) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px; }

.section-bar { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 20px; }
.section-bar h2 { margin: 0; font-size: 18px; }
.section-bar span { color: var(--muted); font-size: 13px; }

.volume-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: clamp(14px, 2vw, 28px); }
.volume-card { min-width: 0; cursor: pointer; }
.cover-wrap { position: relative; aspect-ratio: 3 / 4.2; overflow: hidden; background: #d9d1c4; box-shadow: var(--shadow); transition: transform .22s ease, box-shadow .22s ease; }
.volume-card:hover .cover-wrap { transform: translateY(-7px) rotate(-.4deg); box-shadow: 0 22px 42px rgba(34, 29, 20, .2); }
.cover-wrap img { position: relative; z-index: 1; width: 100%; height: 100%; display: block; object-fit: cover; }
.cover-placeholder { position: absolute; inset: 0; display: grid; place-items: center; background: var(--green); color: #fff; font: italic 900 clamp(34px, 5vw, 68px)/1 Georgia, serif; }
.cover-placeholder::after { content: "STEEL BALL RUN"; position: absolute; bottom: 9%; font: 800 9px/1 sans-serif; }
.volume-number { position: absolute; z-index: 2; left: 0; bottom: 0; min-width: 44px; padding: 8px 10px; background: var(--red); color: white; font-size: 12px; font-weight: 900; }
.progress-mark { position: absolute; z-index: 3; left: 0; right: 0; bottom: 0; height: 3px; background: var(--yellow); transform-origin: left; }
.volume-meta { padding-top: 13px; display: flex; align-items: start; justify-content: space-between; gap: 8px; }
.volume-meta h3 { margin: 0; font-size: 14px; }
.volume-meta span { color: var(--muted); font-size: 11px; }

.reader-view { height: calc(100vh - 72px); min-height: 580px; background: #1a1a19; color: #f7f3eb; }
.reader-toolbar { height: 64px; padding: 0 clamp(14px, 3vw, 34px); display: grid; grid-template-columns: 40px 1fr auto 40px; gap: 16px; align-items: center; border-bottom: 1px solid #3c3b38; }
.reader-toolbar .icon-button { background: #252523; border-color: #494843; }
.reader-title-wrap { min-width: 0; }
.reader-title-wrap span { display: block; color: #aaa79f; font-size: 9px; }
.reader-title-wrap h1 { margin: 3px 0 0; font-size: 16px; }
#volume-select { height: 38px; min-width: 110px; padding: 0 30px 0 12px; border: 1px solid #494843; background: #252523; color: inherit; }
.reader-stage { height: calc(100% - 116px); display: grid; place-items: center; overflow: hidden; background: #242422; }
#pdf-frame { width: 100%; height: 100%; border: 0; background: white; }
.reader-empty { max-width: 430px; padding: 30px; text-align: center; }
.empty-number { display: block; color: var(--yellow); font: italic 900 96px/.8 Georgia, serif; }
.reader-empty h2 { margin: 24px 0 8px; font-size: 24px; }
.reader-empty p { margin: 0 0 24px; color: #aaa79f; line-height: 1.7; }
.reader-empty code { color: var(--yellow); }
.reader-footer { height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(14px, 3vw, 34px); border-top: 1px solid #3c3b38; }
.text-button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 13px; }
.text-button:disabled { color: #65635e; cursor: default; }
#reader-status { color: #aaa79f; font-size: 11px; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: 24px; max-width: calc(100vw - 32px); padding: 12px 18px; background: var(--ink); color: var(--paper); box-shadow: var(--shadow); opacity: 0; transform: translate(-50%, 16px); pointer-events: none; transition: .2s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

body.dark { --paper: #191918; --surface: #242422; --ink: #f3efe7; --muted: #aaa69d; --line: #484640; --shadow: 0 16px 36px rgba(0,0,0,.35); color-scheme: dark; }
body.dark .file-button { color: var(--ink); }

@media (max-width: 1100px) { .volume-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 720px) {
  .site-header { height: 62px; grid-template-columns: 1fr auto; padding: 0 16px; }
  .brand-copy { display: none; }
  .site-header nav { position: fixed; left: 50%; bottom: 12px; z-index: 30; height: 48px; transform: translateX(-50%); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
  .nav-button { min-width: 92px; }
  .nav-button::after { bottom: 0; }
  .library-view { padding-top: 48px; padding-bottom: 100px; }
  .library-heading { display: block; }
  .library-heading h1 { font-size: 50px; line-height: .92; }
  .library-actions { margin-top: 26px; justify-content: start; }
  .volume-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 14px; }
  .reader-view { height: calc(100vh - 62px); }
  .reader-toolbar { grid-template-columns: 40px 1fr 104px; gap: 10px; }
  .reader-toolbar > #open-pdf { display: none; }
  .reader-stage { height: calc(100% - 116px); }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

[hidden] { display: none !important; }

.page-toolbar {
  height: 48px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-bottom: 1px solid #3c3b38;
  background: #20201e;
  overflow-x: auto;
  scrollbar-width: none;
}
.page-toolbar::-webkit-scrollbar { display: none; }
.reader-control {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid #494843;
  background: #292927;
  color: #f7f3eb;
  cursor: pointer;
  font-weight: 800;
}
.reader-control:hover:not(:disabled) { border-color: var(--yellow); color: var(--yellow); }
.reader-control:disabled { opacity: .35; cursor: default; }
.fit-button { flex-basis: 48px; width: 48px; font-size: 11px; }
.page-jump {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  border: 1px solid #494843;
  background: #292927;
  color: #aaa79f;
  font-size: 11px;
}
.page-jump input {
  width: 38px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #f7f3eb;
  text-align: right;
  appearance: textfield;
}
.page-jump input::-webkit-inner-spin-button { display: none; }
.toolbar-divider { width: 1px; height: 22px; background: #494843; }
.zoom-value { flex: 0 0 48px; color: #aaa79f; text-align: center; font-size: 11px; }

.reader-stage {
  position: relative;
  display: block;
  height: calc(100% - 164px);
  overflow: hidden;
}
.canvas-scroll {
  width: 100%;
  height: 100%;
  overflow: auto;
  cursor: grab;
  touch-action: none;
  overscroll-behavior: contain;
  scrollbar-color: #5c5952 #242422;
}
.canvas-scroll.is-dragging { cursor: grabbing; user-select: none; }
.canvas-shell {
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
#page-image {
  display: block;
  flex: 0 0 auto;
  max-width: none;
  height: auto;
  background: white;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .42);
  user-select: none;
  -webkit-user-drag: none;
}
.pdf-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  color: #aaa79f;
  font-size: 12px;
}
.pdf-loading span {
  width: 34px;
  height: 34px;
  border: 3px solid #4b4944;
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: reader-spin .8s linear infinite;
}
@keyframes reader-spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .page-toolbar { justify-content: flex-start; padding-inline: 10px; }
  .reader-stage { height: calc(100% - 164px); }
  .canvas-shell { padding: 12px; }
}


/* Immersive reading chrome */
body.reader-immersive { overflow: hidden; }
body.reader-immersive .site-header { display: none; }
body.reader-immersive main { min-height: 100vh; }
body.reader-immersive .reader-view { height: 100vh; min-height: 0; }
body.reader-immersive .reader-stage { height: 100%; }

body.reader-immersive .reader-toolbar,
body.reader-immersive .page-toolbar,
body.reader-immersive .reader-footer {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 12;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
body.reader-immersive .reader-toolbar {
  top: 0;
  background: rgba(24, 24, 23, .94);
  transform: translateY(-100%);
}
body.reader-immersive .page-toolbar {
  top: 64px;
  transform: translateY(-112px);
}
body.reader-immersive .reader-footer {
  bottom: 0;
  background: rgba(24, 24, 23, .94);
  transform: translateY(100%);
}
body.reader-immersive .reader-view.controls-visible .reader-toolbar,
body.reader-immersive .reader-view.controls-visible .page-toolbar,
body.reader-immersive .reader-view.controls-visible .reader-footer {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.page-zone {
  position: absolute;
  z-index: 5;
  top: 0;
  bottom: 0;
  width: 18%;
  min-width: 54px;
  max-width: 220px;
  padding: 0;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, .75);
  cursor: pointer;
}
.page-zone::after {
  position: absolute;
  top: 50%;
  font-size: 30px;
  opacity: 0;
  transform: translateY(-50%);
  transition: opacity .16s ease;
}
.page-zone:hover::after { opacity: .72; }
.page-zone:disabled { cursor: default; }
.page-zone:disabled::after { display: none; }
.page-zone-prev { left: 0; }
.page-zone-next { right: 0; }
.page-zone-prev::after { content: "‹"; left: 18px; }
.page-zone-next::after { content: "›"; right: 18px; }
.page-zone-prev:hover { background: linear-gradient(90deg, rgba(0, 0, 0, .22), transparent); }
.page-zone-next:hover { background: linear-gradient(270deg, rgba(0, 0, 0, .22), transparent); }

@media (max-width: 720px) {
  body.reader-immersive .page-toolbar { top: 64px; }
  .page-zone { width: 20%; min-width: 48px; }
}


/* Parent library and series detail */
.parent-library-heading h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(44px, 6vw, 82px);
  font-style: italic;
  line-height: .92;
}
.series-grid { max-width: 820px; }
.series-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(150px, 220px) 1fr 44px;
  align-items: center;
  gap: clamp(20px, 4vw, 46px);
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.series-card:hover,
.series-card:focus-visible {
  transform: translateY(-4px);
  border-color: var(--red);
  box-shadow: var(--shadow);
  outline: none;
}
.series-cover {
  position: relative;
  aspect-ratio: 3 / 4.2;
  overflow: hidden;
  background: #d9d1c4;
}
.series-cover img { width: 100%; height: 100%; display: block; object-fit: cover; }
.series-part {
  position: absolute;
  left: 0;
  bottom: 0;
  padding: 9px 12px;
  background: var(--red);
  color: white;
  font-size: 11px;
  font-weight: 900;
}
.series-info { min-width: 0; }
.series-info p { margin: 0 0 12px; color: var(--red); font-size: 10px; font-weight: 850; }
.series-info h2 { margin: 0; font-size: clamp(22px, 3vw, 36px); line-height: 1.25; }
.series-info strong { display: block; margin-top: 8px; font: italic 800 19px/1.2 Georgia, serif; }
.series-info span { display: block; margin-top: 24px; color: var(--muted); font-size: 13px; }
.series-arrow { color: var(--red); font-size: 30px; }
.series-back {
  margin: 0 0 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}
.series-back:hover { color: var(--red); }

@media (max-width: 600px) {
  .series-card {
    grid-template-columns: minmax(112px, 42%) 1fr;
    gap: 16px;
    padding: 12px;
  }
  .series-info p { display: none; }
  .series-info h2 { font-size: 18px; }
  .series-info strong { font-size: 15px; }
  .series-info span { margin-top: 18px; font-size: 11px; }
  .series-arrow { display: none; }
}


.header-spacer { width: 1px; height: 1px; }
.nav-button { display: grid; place-items: center; }
.nav-shape { display: block; color: currentColor; }
.nav-triangle {
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 16px solid currentColor;
}
.nav-circle {
  width: 17px;
  height: 17px;
  border: 3px solid currentColor;
  border-radius: 50%;
}
.nav-button.is-active { color: var(--red); }


/* Compact expandable work list */
.series-entry { border-top: 1px solid var(--line); }
.series-entry:last-child { border-bottom: 1px solid var(--line); }
.series-row {
  width: 100%;
  min-height: 76px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto 28px;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.series-row:hover { background: color-mix(in srgb, var(--surface) 72%, transparent); }
.series-row:focus-visible { outline: 2px solid var(--red); outline-offset: -2px; }
.series-index { color: var(--muted); font: 700 11px/1 monospace; }
.series-row > img {
  width: 42px;
  height: 58px;
  display: block;
  object-fit: cover;
  border: 1px solid var(--line);
}
.series-row-title { min-width: 0; display: grid; gap: 5px; }
.series-row-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}
.series-row-title small { color: var(--muted); font-size: 11px; }
.series-row-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.series-chevron {
  color: var(--red);
  font-size: 22px;
  text-align: center;
  transition: transform .18s ease;
}
.series-row[aria-expanded="true"] .series-chevron { transform: rotate(180deg); }
.series-row[aria-expanded="true"] { background: var(--surface); }
.series-panel { padding: 14px 0 24px; }
.series-panel .series-card { max-width: 100%; }

@media (max-width: 600px) {
  .series-row {
    grid-template-columns: 28px minmax(0, 1fr) 24px;
    gap: 10px;
    padding-inline: 6px;
  }
  .series-row-meta { display: none; }
  .series-row-title strong { font-size: 13px; }
}
