:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #697386;
  --line: #d9dee8;
  --brand: #c81f36;
  --brand-ink: #ffffff;
  --accent: #0f766e;
  --shadow: 0 22px 60px rgba(23, 32, 51, 0.18);
  --header-h: 72px;
  --footer-h: clamp(84px, 16vh, 198px);
  --ad-h: min(160px, calc(var(--footer-h) - 38px));
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at 20% 0%, rgba(200, 31, 54, 0.09), transparent 30%), var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

body.is-mobile-view {
  --is-mobile-view: 1;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.site-header,
.ad-footer {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
}

.site-header {
  top: 0;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) clamp(14px, 3vw, 32px) 0;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  width: 220px;
  min-width: 0;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: clamp(128px, 18vw, 190px);
  height: auto;
  flex: 0 0 auto;
}

.site-title {
  position: absolute;
  left: 50%;
  max-width: min(48vw, 620px);
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(20px, 2vw, 28px);
  font-weight: 850;
  letter-spacing: 0;
  line-height: 1.1;
  text-align: center;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  white-space: nowrap;
}

.header-actions,
.reader-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.download-button,
.nav-button {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 7px;
  font-size: 18px;
}

.social-button {
  background: #1877f2;
  border-color: #1877f2;
  color: #ffffff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 21px;
  font-weight: 900;
}

.social-button:hover {
  border-color: #0f5fcb;
  background: #0f5fcb;
  color: #ffffff;
}

.download-button {
  display: inline-flex;
  height: 42px;
  align-items: center;
  gap: 7px;
  padding: 0 13px;
  border-radius: 7px;
  font-size: 13px;
}

.download-button span {
  font-size: 17px;
  line-height: 1;
}

.download-button strong {
  font-size: 13px;
}

.nav-button {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  font-size: 32px;
  line-height: 1;
}

.icon-button:hover,
.download-button:hover,
.nav-button:hover {
  border-color: color-mix(in srgb, var(--brand), var(--line) 42%);
  transform: translateY(-1px);
}

.reader-shell {
  display: block;
  width: 100%;
  min-width: 0;
  height: var(--app-height, 100dvh);
  padding-top: calc(var(--header-h) + env(safe-area-inset-top));
  padding-bottom: calc(var(--footer-h) + env(safe-area-inset-bottom));
}

.thumb-panel {
  display: flex;
  width: min(100%, 1120px);
  min-height: 120px;
  margin: 0 auto;
}

.thumb-panel-header {
  display: none;
}

.thumb-rail {
  display: flex;
  width: 100%;
  gap: 10px;
  padding: 10px 4px 2px;
  overflow: auto;
  background: transparent;
  scrollbar-width: thin;
}

.thumb-button {
  display: block;
  width: 70px;
  flex: 0 0 70px;
  margin: 0;
  padding: 5px;
  border: 2px solid transparent;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
}

.thumb-button.is-active {
  border-color: var(--brand);
  background: rgba(200, 31, 54, 0.08);
}

.thumb-button.is-focused {
  animation: thumbPulse 680ms ease;
}

.thumb-button img {
  display: block;
  width: 100%;
  border-radius: 4px;
  box-shadow: 0 5px 18px rgba(23, 32, 51, 0.16);
}

.thumb-button span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.reader-stage {
  position: relative;
  display: grid;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  height: 100%;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: clamp(12px, 2vw, 22px);
  overflow: hidden;
}

.reader-toolbar {
  justify-content: center;
}

.page-status {
  min-width: 108px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.magazine {
  position: relative;
  display: flex;
  width: 100%;
  height: 100%;
  max-width: 100%;
  min-height: 0;
  min-width: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.spread {
  position: relative;
  display: grid;
  flex: 0 1 auto;
  width: 100%;
  min-width: 0;
  max-width: 1120px;
  aspect-ratio: 595.276 / 419.528;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  justify-content: center;
  filter: drop-shadow(0 22px 48px rgba(23, 32, 51, 0.18));
  transition: opacity 180ms ease, transform 180ms ease;
}

.spread.is-single {
  max-width: 560px;
  aspect-ratio: 297.638 / 419.528;
  grid-template-columns: minmax(0, 1fr);
}

.spread.is-changing-next {
  animation: slideNext 220ms ease both;
}

.spread.is-changing-previous {
  animation: slidePrevious 220ms ease both;
}

.page-card {
  position: relative;
  display: grid;
  width: 100%;
  min-width: 0;
  aspect-ratio: 297.638 / 419.528;
  margin: 0;
  overflow: hidden;
  background: #eef1f5;
  border-radius: 0;
}

.page-card.left-page {
  border-radius: 8px 0 0 8px;
}

.page-card.right-page {
  border-left: 1px solid rgba(23, 32, 51, 0.22);
  border-radius: 0 8px 8px 0;
}

.spread.is-single .page-card {
  border-radius: 8px;
  border-left: 0;
}

.spread.is-single .page-card[hidden] {
  display: none;
}

.page-card img,
.page-loader {
  grid-area: 1 / 1;
}

.page-card img {
  width: 100%;
  min-width: 0;
  height: 100%;
  object-fit: contain;
  background: #ffffff;
}

.page-loader {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
}

.page-card.is-loaded .page-loader {
  display: none;
}

.page-hit-area {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 4;
  width: 42%;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.page-hit-area.left {
  left: 0;
}

.page-hit-area.right {
  right: 0;
}

.ad-footer {
  bottom: 0;
  height: calc(var(--footer-h) + env(safe-area-inset-bottom));
  flex-direction: column;
  gap: 5px;
  padding: 0 clamp(14px, 3vw, 32px) calc(8px + env(safe-area-inset-bottom));
  justify-content: center;
  border-top: 1px solid var(--line);
}

.ad-banner {
  display: block;
  width: min(100%, 980px);
  height: var(--ad-h);
  aspect-ratio: 980 / 160;
  overflow: hidden;
  border-radius: 7px;
  background: #1c1c1a;
  text-decoration: none;
}

.ad-banner img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.footer-credits {
  display: flex;
  width: min(100%, 980px);
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 12px;
}

.footer-credits p {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  line-height: 1.25;
}

.footer-credits a {
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.footer-credits p a {
  white-space: nowrap;
}

.footer-credits a:hover {
  color: var(--brand);
}

.footer-baqi {
  display: inline-flex;
  flex: 0 0 92px;
  width: 92px;
  align-items: center;
  justify-content: flex-end;
}

.footer-baqi img {
  display: block;
  width: 92px;
  height: auto;
}

@keyframes slideNext {
  0% { transform: translateX(18px); opacity: 0.48; }
  100% { transform: translateX(0); opacity: 1; }
}

@keyframes slidePrevious {
  0% { transform: translateX(-18px); opacity: 0.48; }
  100% { transform: translateX(0); opacity: 1; }
}

@keyframes thumbPulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@media (max-width: 760px) {
  :root {
    --header-h: 108px;
    --footer-h: clamp(76px, 12dvh, 108px);
    --ad-h: min(76px, calc(var(--footer-h) - 30px));
  }

  .site-header {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: 42px 46px;
    row-gap: 6px;
    align-items: center;
    padding: calc(env(safe-area-inset-top) + 8px) 14px 8px;
  }

  .site-title {
    position: static;
    grid-column: 1 / -1;
    grid-row: 1;
    max-width: 100%;
    font-size: 19px;
    line-height: 1.12;
    text-align: center;
    transform: none;
    white-space: normal;
  }

  .brand {
    grid-column: 1;
    grid-row: 2;
    width: auto;
  }

  .brand-logo {
    width: 142px;
  }

  .header-actions {
    grid-column: 2;
    grid-row: 2;
    justify-self: end;
    gap: 6px;
  }

  .reader-shell {
    display: block;
  }

  .thumb-panel {
    position: fixed;
    inset: calc(var(--header-h) + env(safe-area-inset-top) + 10px) 10px calc(var(--footer-h) + env(safe-area-inset-bottom) + 10px);
    z-index: 19;
    display: grid;
    width: auto;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 12px;
    border-right: 0;
    border: 1px solid rgba(217, 222, 232, 0.92);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 24px 60px rgba(23, 32, 51, 0.24);
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity 180ms ease, transform 180ms ease;
  }

  body.thumbs-open .thumb-panel {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  .thumb-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 10px;
    color: var(--ink);
  }

  .thumb-panel-header strong {
    font-size: 16px;
  }

  .thumb-panel-header .icon-button {
    width: 36px;
    height: 36px;
    font-size: 22px;
  }

  .thumb-rail {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    padding: 0 2px 8px;
    overflow: auto;
  }

  .thumb-button {
    width: 100%;
    flex: none;
    margin: 0;
    padding: 4px;
  }

  .reader-stage {
    height: 100%;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 5px;
    padding: 8px 10px 8px;
  }

  .magazine {
    align-items: flex-start;
    overflow: hidden;
  }

  .reader-toolbar {
    justify-content: space-between;
  }

  .nav-button {
    width: 44px;
    height: 44px;
  }

  .page-status {
    min-width: 92px;
  }

  .spread,
  .spread.is-single {
    width: 100%;
    height: auto;
    margin-top: 2px;
    max-height: 100%;
    max-width: 100%;
    grid-template-columns: minmax(0, 1fr);
    filter: drop-shadow(0 18px 38px rgba(23, 32, 51, 0.16));
  }

  .page-card {
    height: auto;
    max-height: 100%;
  }

  .page-card.left-page,
  .page-card.right-page {
    border-radius: 8px;
    border-left: 0;
  }

  .page-card[hidden] {
    display: none;
  }

  .ad-banner {
    aspect-ratio: 980 / 160;
  }

  .footer-credits {
    align-items: center;
    gap: 8px;
    font-size: 10px;
  }

  .footer-credits p {
    white-space: nowrap;
  }

  .footer-baqi {
    flex-basis: 70px;
    width: 70px;
    min-width: 70px;
  }

  .footer-baqi img {
    width: 70px;
  }
}

@media (max-width: 430px) {
  .header-actions {
    gap: 4px;
  }

  .brand {
    gap: 9px;
  }

  .brand-logo {
    width: 118px;
  }

  .site-title {
    font-size: 18px;
    line-height: 1.15;
  }

  .icon-button {
    width: 32px;
    height: 36px;
    font-size: 16px;
  }

  .social-button {
    font-size: 19px;
  }

  .download-button {
    height: 36px;
    gap: 4px;
    padding: 0 6px;
  }

  .download-button strong {
    display: none;
  }

  .download-button span {
    font-size: 15px;
  }
}
