:root {
  --bg: #0f1012;
  --text-muted: rgba(255, 255, 255, 0.74);
  --text-soft: rgba(255, 255, 255, 0.44);
  --line-soft: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --reader-top-offset: 24px;
  --reader-bottom-offset: 14px;
  --reader-side-offset: 4px;
  --locked-width: 100vw;
  --locked-height: 100dvh;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: #fff;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.07), transparent 34%),
    linear-gradient(180deg, #131418 0%, #0f1012 45%, #0d0e10 100%);
  font-family:
    "SF Pro Display",
    "PingFang SC",
    "Hiragino Sans GB",
    "Microsoft YaHei",
    sans-serif;
  overflow: hidden;
  touch-action: pan-y;
}

body.is-loading {
  overflow: hidden;
}

.app-shell {
  position: fixed;
  top: 50%;
  left: 50%;
  width: var(--locked-width);
  height: var(--locked-height);
  overflow: hidden;
  transform: translate(-50%, -50%);
  overscroll-behavior: none;
}

.progress-track {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  width: 100%;
  height: 1px;
  padding-top: var(--safe-top);
  pointer-events: none;
}

.progress-bar {
  height: 1px;
  width: 0;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.1);
  transition: width 220ms ease-out;
  will-change: width;
}

.chapter-nav {
  position: fixed;
  top: calc(6px + var(--safe-top));
  left: 50%;
  z-index: 60;
  display: flex;
  flex-direction: row-reverse;
  gap: 8px;
  transform: translateX(-50%);
  opacity: 0.28;
  pointer-events: auto;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.chapter-nav__button {
  appearance: none;
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  padding: 8px 11px 7px;
  background: rgba(0, 0, 0, 0.06);
  color: rgba(255, 255, 255, 0.4);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  pointer-events: auto;
  touch-action: manipulation;
  transition:
    color 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease,
    transform 180ms ease;
}

.chapter-nav__button.is-active {
  border-top-color: rgba(223, 0, 55, 0.82);
  background: rgba(223, 0, 55, 0.08);
  color: rgba(255, 255, 255, 0.78);
}

.chapter-nav__button:active {
  transform: translateY(1px);
}

.chapter-nav:hover,
.chapter-nav:focus-within {
  opacity: 0.58;
}

.chapter-nav__button:focus-visible,
.chapter-nav__button:hover {
  outline: none;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.68);
}

.page-indicator {
  position: fixed;
  left: calc(12px + var(--safe-left));
  bottom: calc(12px + var(--safe-bottom));
  z-index: 25;
  padding: 5px 9px;
  border: 1px solid var(--line-soft);
  background: rgba(10, 10, 12, 0.18);
  color: var(--text-soft);
  font-size: 10px;
  letter-spacing: 0.08em;
  line-height: 1;
  transform: rotate(90deg);
  transform-origin: left bottom;
  pointer-events: none;
}

.scroll-hint span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line-soft);
  background: rgba(10, 10, 12, 0.18);
  color: rgba(255, 255, 255, 0.58);
  font-size: 10px;
  letter-spacing: 0.14em;
}

.scroll-hint.is-hidden {
  opacity: 0;
  transform: translateY(8px);
}

.scroll-hint {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  z-index: 24;
  transform: translateX(-50%);
  opacity: 0.66;
  transition:
    opacity 200ms ease,
    transform 200ms ease;
  pointer-events: none;
}

.scroll-hint span::after {
  content: "";
  width: 8px;
  height: 8px;
  border-left: 1px solid rgba(255, 255, 255, 0.5);
  border-bottom: 1px solid rgba(255, 255, 255, 0.5);
  transform: rotate(-45deg) translateY(-1px);
}

.loading-overlay,
.message {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding:
    calc(24px + var(--safe-top))
    calc(24px + var(--safe-right))
    calc(24px + var(--safe-bottom))
    calc(24px + var(--safe-left));
  background:
    linear-gradient(180deg, rgba(15, 16, 18, 0.98), rgba(15, 16, 18, 0.96)),
    radial-gradient(circle at top, rgba(255, 255, 255, 0.05), transparent 34%);
  text-align: center;
}

.loading-overlay {
  gap: 12px;
  transition:
    opacity 220ms ease,
    visibility 220ms ease;
}

.loading-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.loading-mark {
  width: min(48px, 12vw);
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.75), transparent);
}

.loading-overlay p,
.message {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 0.08em;
}

.message.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.noscript-message {
  position: static;
  min-height: 100dvh;
}

.presentation {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
  scroll-snap-type: y mandatory;
  scroll-behavior: auto;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
  scrollbar-width: none;
  touch-action: none;
}

.presentation::-webkit-scrollbar {
  display: none;
}

.page {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding:
    calc(var(--reader-top-offset) + var(--safe-top))
    calc(var(--reader-side-offset) + var(--safe-right))
    calc(var(--reader-bottom-offset) + var(--safe-bottom))
    calc(var(--reader-side-offset) + var(--safe-left));
  scroll-snap-align: start;
  scroll-snap-stop: normal;
  opacity: 0;
  transform: translate3d(0, 18px, 0);
  transition:
    opacity 360ms ease,
    transform 360ms ease;
  will-change: opacity, transform;
}

.page.is-visible {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.page-frame {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: visible;
}

.page-rotator {
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(var(--locked-height) - var(--safe-top) - var(--safe-bottom) - var(--reader-top-offset) - var(--reader-bottom-offset));
  height: calc(var(--locked-width) - var(--safe-left) - var(--safe-right) - (var(--reader-side-offset) * 2));
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center;
}

.page-image {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  box-shadow: var(--shadow);
  background: rgba(255, 255, 255, 0.03);
}

.page-status {
  width: min(100%, 320px);
  display: none;
  place-items: center;
  padding: 20px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  color: rgba(255, 255, 255, 0.66);
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
  transform: translate(-50%, -50%) rotate(90deg);
  position: absolute;
  top: 50%;
  left: 50%;
}

.page-status.is-visible {
  display: grid;
}

.page.is-error .page-image {
  display: none;
}

.mai-layer {
  position: fixed;
  top: 50%;
  left: 50%;
  width: var(--locked-height);
  height: var(--locked-width);
  z-index: 41;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center;
  pointer-events: none;
}

.mai-trigger,
.mai-backdrop,
.mai-panel {
  pointer-events: auto;
}

.mai-trigger {
  position: absolute;
  right: calc(10px + var(--safe-right));
  left: auto;
  top: calc(22px + var(--safe-top));
  bottom: auto;
  z-index: 1;
  appearance: none;
  border: 2px solid rgba(223, 0, 55, 0.7);
  border-radius: 12px;
  background: rgba(12, 12, 15, 0.42);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: rgba(255, 255, 255, 0.84);
  padding: 8px 12px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
  opacity: 0.36;
  transition:
    opacity 180ms ease,
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease;
}

.mai-trigger:active,
.mai-trigger:focus-visible {
  outline: none;
  border-color: rgba(223, 0, 55, 0.78);
  background: rgba(223, 0, 55, 0.16);
  opacity: 0.92;
}

.mai-backdrop {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: rgba(5, 6, 8, 0.42);
}

.mai-panel {
  position: absolute;
  right: 0;
  top: calc(54px + var(--safe-top));
  bottom: calc(10px + var(--safe-bottom));
  z-index: 3;
  width: min(440px, calc(100% - 24px));
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px 0 0 16px;
  background: linear-gradient(180deg, rgba(16, 17, 20, 0.78), rgba(11, 12, 15, 0.82));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding:
    12px
    calc(12px + var(--safe-right))
    calc(12px + var(--safe-bottom))
    12px;
}

.mai-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  position: sticky;
  top: 0;
  padding-bottom: 8px;
  background: inherit;
  z-index: 1;
}

.mai-panel__header h3 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.88);
}

.mai-panel__close {
  appearance: none;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  width: 24px;
  height: 24px;
  padding: 0;
  background: rgba(255, 255, 255, 0.03);
  color: rgba(255, 255, 255, 0.78);
  font-size: 16px;
  line-height: 1;
}

.mai-state {
  display: grid;
  gap: 8px;
}

.mai-state p {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.78);
}

.mai-skeleton {
  height: 14px;
  border-radius: 2px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.06),
    rgba(255, 255, 255, 0.14),
    rgba(255, 255, 255, 0.06)
  );
  background-size: 220% 100%;
  animation: maiShimmer 1.25s linear infinite;
}

@keyframes maiShimmer {
  from {
    background-position: 220% 0;
  }
  to {
    background-position: -220% 0;
  }
}

.mai-block {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.05);
}

.mai-block h4 {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.66);
}

.mai-block p {
  margin: 0;
}

@media (max-width: 540px) {
  :root {
    --reader-top-offset: 20px;
    --reader-bottom-offset: 12px;
    --reader-side-offset: 2px;
  }

  .chapter-nav {
    gap: 6px;
  }

  .chapter-nav__button {
    padding: 7px 10px 6px;
    font-size: 11px;
  }

  .mai-trigger {
    right: calc(8px + var(--safe-right));
    left: auto;
    top: calc(18px + var(--safe-top));
    padding: 6px 8px;
    font-size: 10px;
  }

  .mai-panel {
    top: calc(46px + var(--safe-top));
    bottom: calc(8px + var(--safe-bottom));
    width: min(380px, calc(100% - 18px));
    max-height: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress-bar,
  .scroll-hint,
  .loading-overlay,
  .page,
  .chapter-nav,
  .chapter-nav__button,
  .mai-trigger {
    transition: none;
  }

  .presentation {
    scroll-behavior: auto;
  }

  .page {
    opacity: 1;
    transform: none;
  }

  .mai-skeleton {
    animation: none;
  }
}
