:root {
  --bg: #ffffff;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: rgba(255, 255, 255, 0.96);
  --line: rgba(8, 9, 11, 0.13);
  --text: #14161a;
  --muted: rgba(20, 22, 26, 0.62);
  --accent: #ffb238;
  --accent-2: #00a7d8;
  --shadow: 0 24px 70px rgba(20, 22, 26, 0.18);
  color-scheme: light;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

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

button {
  font: inherit;
}

.app {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(0, 167, 216, 0.06), transparent 34%),
    linear-gradient(140deg, transparent 38%, rgba(255, 178, 56, 0.08)),
    #fff;
}

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  min-height: calc(66px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 18px 0;
  background: #000;
  color: #fff;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.16);
  pointer-events: none;
}

.brand,
.top-actions,
.download-button,
.icon-button {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 8px 11px 8px 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 34px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(18px);
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  color: #000;
  font-weight: 900;
  font-size: 0.74rem;
  letter-spacing: 0;
}

.brand strong,
.brand span {
  display: block;
  line-height: 1.05;
  white-space: nowrap;
}

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

.brand span {
  color: rgba(255, 255, 255, 0.64);
  font-size: 0.72rem;
}

.site-title {
  position: absolute;
  left: 50%;
  margin: 0;
  max-width: min(58vw, 760px);
  transform: translateX(-50%);
  color: #fff;
  font-family: "FWC 2026", "Arial Black", Impact, ui-sans-serif, sans-serif;
  font-size: clamp(1rem, 2.1vw, 1.8rem);
  font-weight: 950;
  letter-spacing: 0;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.download-button,
.hud-button,
.magic-trigger,
.magic-item {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(18px);
}

.icon-button,
.hud-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  cursor: pointer;
}

.icon-button:hover,
.download-button:hover,
.hud-button:hover,
.magic-trigger:hover,
.magic-item:hover {
  border-color: rgba(20, 22, 26, 0.24);
  background: rgba(20, 22, 26, 0.06);
}

.download-button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  gap: 8px;
  padding: 0 16px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 800;
  font-size: 0.88rem;
}

.download-button span:first-child {
  color: var(--accent);
  font-size: 1.1rem;
}

.reader {
  position: relative;
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 92px 18px 86px;
  touch-action: pan-y;
}

.stage {
  position: relative;
  display: grid;
  width: min(100%, 1220px);
  height: min(76dvh, 900px);
  place-items: center;
  perspective: 1400px;
}

.mobile-scroll {
  display: none;
}

.page-shell {
  position: relative;
  display: grid;
  max-width: min(100%, 1080px);
  max-height: 100%;
  place-items: center;
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: #fff;
  transform-origin: center right;
  transition: transform 360ms cubic-bezier(.2, .8, .2, 1), filter 260ms ease;
}

.page-shell.cover {
  max-width: min(100%, 560px);
}

.page-shell.spread {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 0;
  background: transparent;
}

.page-shell::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 1;
  width: 9%;
  border-radius: 8px 0 0 8px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.08), transparent);
}

.page-shell.turn-next {
  transform: rotateY(-9deg) translateX(-8px);
  filter: brightness(0.92);
}

.page-shell.turn-prev {
  transform: rotateY(9deg) translateX(8px);
  filter: brightness(0.92);
}

.page-shell.zoomed {
  cursor: grab;
  overflow: auto;
  width: min(94vw, 880px);
  height: min(82dvh, 980px);
}

.page-image {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: min(100%, 82dvh);
  border-radius: 8px;
  user-select: none;
}

.page-image-right {
  display: none;
}

.spread .page-image-right {
  display: block;
}

.map-link-hotspot {
  position: absolute;
  left: 44.18%;
  top: 79.17%;
  z-index: 3;
  display: none;
  width: 29.3%;
  height: 6.6%;
  border-radius: 999px;
}

.map-link-hotspot.active {
  display: block;
}

.zoomed .page-image {
  max-width: none;
  max-height: none;
  width: min(1180px, 170vw);
}

.edge {
  position: fixed;
  top: 20dvh;
  bottom: 18dvh;
  z-index: 4;
  width: 22vw;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.edge-left {
  left: 0;
}

.edge-right {
  right: 0;
}

.mobile-hud {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 22;
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translateX(-50%);
}

.page-status {
  display: flex;
  align-items: center;
  min-width: 86px;
  height: 44px;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 800;
  backdrop-filter: blur(18px);
}

#pageNow {
  color: var(--text);
}

.progress-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  height: 3px;
  background: rgba(20, 22, 26, 0.08);
}

.progress {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 260ms ease;
}

.magic-menu {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 32;
  width: 64px;
  height: 64px;
}

.magic-trigger {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border-color: rgba(255, 255, 255, 0.22);
  background: #009b3a;
  color: #fff;
  cursor: pointer;
  font-size: 1.5rem;
}

.magic-trigger:hover {
  border-color: rgba(255, 255, 255, 0.34);
  background: #008331;
  color: #fff;
}

.magic-trigger .trigger-close {
  display: none;
  font-size: 2rem;
}

.magic-menu.open .trigger-open {
  display: none;
}

.magic-menu.open .trigger-close {
  display: block;
}

.magic-item {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  border-color: rgba(255, 255, 255, 0.2);
  background: #d71920;
  color: #fff;
  text-decoration: none;
  opacity: 0;
  transform: translate3d(0, 0, 0) scale(0.76);
  transition: transform 280ms cubic-bezier(.17, .84, .44, 1), opacity 180ms ease;
  cursor: pointer;
}

.magic-item:hover {
  border-color: rgba(255, 255, 255, 0.32);
  background: #b9141a;
  color: #fff;
}

.magic-item span {
  line-height: 1;
}

.magic-item small {
  position: absolute;
  right: 58px;
  min-width: max-content;
  padding: 6px 9px;
  border-radius: 999px;
  background: #d71920;
  color: #fff;
  font-size: 0.72rem;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

.magic-menu.open .magic-item {
  opacity: 1;
}

.magic-menu.open .magic-item small {
  opacity: 1;
}

.magic-menu.open .item-thumbs {
  transform: translate3d(-14px, -150px, 0) scale(1);
}

.magic-menu.open .item-zoom {
  transform: translate3d(-84px, -126px, 0) scale(1);
}

.magic-menu.open .item-download {
  transform: translate3d(-126px, -68px, 0) scale(1);
}

.magic-menu.open .item-share {
  transform: translate3d(-124px, -8px, 0) scale(1);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  width: min(420px, 92vw);
  padding: max(18px, env(safe-area-inset-top)) 16px 18px;
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: -28px 0 80px rgba(20, 22, 26, 0.18);
  transform: translateX(102%);
  transition: transform 280ms ease;
  backdrop-filter: blur(18px);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
}

.drawer-header strong,
.drawer-header span {
  display: block;
}

.drawer-header span {
  color: var(--muted);
  font-size: 0.86rem;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: 12px;
  row-gap: 34px;
  height: calc(100dvh - 90px);
  overflow: auto;
  padding-bottom: 24px;
}

.thumb {
  position: relative;
  display: block;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  aspect-ratio: 202 / 260;
  height: 156px;
  cursor: pointer;
}

.thumb.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 178, 56, 0.18);
}

.thumb img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: initial;
  background: #fff;
}

.thumb span {
  position: absolute;
  left: 6px;
  bottom: 6px;
  display: grid;
  min-width: 26px;
  height: 22px;
  place-items: center;
  border-radius: 999px;
  background: rgba(20, 22, 26, 0.72);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 86px;
  z-index: 60;
  max-width: min(320px, calc(100vw - 32px));
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--text);
  opacity: 0;
  transform: translate(-50%, 14px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
  font-size: 0.86rem;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 860px) {
  .mobile-hud {
    left: 50%;
    bottom: 24px;
  }

  .reader {
    padding-bottom: 66px;
  }

  .stage {
    height: min(80dvh, 980px);
  }

  .magic-menu {
    display: none;
  }
}

@media (max-width: 859px) {
  html,
  body,
  .app {
    overflow: hidden;
  }

  .topbar {
    inset: 0 0 auto;
    min-height: calc(56px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 10px 0;
  }

  .brand {
    max-width: calc(100vw - 118px);
  }

  .brand span {
    display: none;
  }

  .site-title {
    max-width: 52vw;
    font-size: 0.72rem;
  }

  .top-actions {
    display: none;
  }

  .reader {
    display: block;
    min-height: 100dvh;
    padding: 0;
    touch-action: pan-x pan-y pinch-zoom;
  }

  .stage {
    display: none;
  }

  .mobile-scroll {
    display: block;
    height: 100dvh;
    overflow: auto;
    padding: 72px 10px 132px;
    scroll-behavior: smooth;
    scroll-snap-type: y proximity;
    touch-action: pan-x pan-y pinch-zoom;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-page {
    position: relative;
    display: block;
    width: min(100%, 520px);
    margin: 0 auto 18px;
    border: 1px solid rgba(20, 22, 26, 0.1);
    border-radius: 7px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 20px 54px rgba(0, 0, 0, 0.34);
    scroll-snap-align: start;
  }

  .mobile-page img {
    display: block;
    width: 100%;
    height: auto;
    user-select: none;
  }

  .mobile-page::after {
    content: attr(data-page);
    position: absolute;
    right: 8px;
    bottom: 8px;
    display: grid;
    min-width: 28px;
    height: 24px;
    place-items: center;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.58);
    color: rgba(255, 255, 255, 0.88);
    font-size: 0.72rem;
    font-weight: 800;
  }

  .mobile-scroll.zoomed {
    overflow: auto;
    scroll-snap-type: none;
  }

  .mobile-scroll.zoomed .mobile-page {
    width: min(760px, 156vw);
    margin-left: 10px;
    margin-right: 10px;
  }

  .edge {
    display: none;
  }

  .hud-button {
    display: none;
  }

  .mobile-hud {
    right: auto;
    left: 50%;
    bottom: max(18px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
  }

  .magic-menu {
    bottom: max(76px, calc(env(safe-area-inset-bottom) + 76px));
  }

  .magic-menu.open ~ .drawer {
    pointer-events: auto;
  }

  .drawer {
    width: 100vw;
    border-left: 0;
    padding-left: 12px;
    padding-right: 12px;
  }

  .thumb-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    column-gap: 12px;
    row-gap: 34px;
  }

  .thumb {
    height: min(280px, max(148px, 38vw));
  }
}

@media (max-width: 420px) {
  .hud-button {
    display: none;
  }

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

  .magic-menu {
    right: max(14px, env(safe-area-inset-right));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
