:root {
  --paper: #ebe4d8;
  --paper-deep: #ddd3c4;
  --ink: #1c1814;
  --ink-soft: #4a433a;
  --gold: #9a7b4f;
  --gold-dim: rgba(154, 123, 79, 0.35);
  --shadow: rgba(28, 24, 20, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--ink);
}

body {
  font-family: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", serif;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse 120% 80% at 50% 40%, #2a2520 0%, var(--ink) 65%);
}

.page-frame {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(0.5rem, 2vw, 1.25rem);
  background: linear-gradient(165deg, var(--paper) 0%, var(--paper-deep) 100%);
  box-shadow: inset 0 0 120px var(--shadow);
}

.page-frame--text {
  padding: clamp(1rem, 4vw, 3rem);
}

.frame-box {
  position: relative;
  display: inline-block;
  max-width: min(96vw, 180vh);
  max-height: min(88vh, 56vw);
  border: 1px solid rgba(154, 123, 79, 0.3);
  box-shadow:
    0 0 0 1px rgba(154, 123, 79, 0.12),
    0 24px 48px var(--shadow);
  background: transparent;
  line-height: 0;
}

.frame-box img {
  display: block;
  max-width: min(96vw, 180vh);
  max-height: min(88vh, 56vw);
  width: auto;
  height: auto;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.frame-box img.loaded {
  opacity: 1;
}

.frame-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  pointer-events: auto;
  background: rgba(235, 228, 216, 0.72);
}

.frame-box.is-loading .frame-loading {
  display: flex;
}

.frame-box.is-loading {
  width: 100%;
  min-height: clamp(9rem, 32vh, 22rem);
  box-sizing: border-box;
}

.frame-loading-spin {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 2px solid rgba(154, 123, 79, 0.22);
  border-top-color: var(--gold);
  animation: frame-load-spin 0.78s linear infinite;
  flex-shrink: 0;
}

.frame-loading-hint {
  margin: 0;
  padding: 0 1rem;
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0.1em;
  line-height: 1.6;
  color: rgba(74, 67, 58, 0.72);
  text-align: center;
  white-space: nowrap;
}

@keyframes frame-load-spin {
  to {
    transform: rotate(360deg);
  }
}

.slide-label {
  position: absolute;
  bottom: clamp(0.75rem, 2.5vw, 1.5rem);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  letter-spacing: 0.25em;
  color: rgba(74, 67, 58, 0.55);
  white-space: nowrap;
}

@media (max-width: 900px) {
  .slide-label {
    bottom: max(4.85rem, calc(env(safe-area-inset-bottom, 0px) + 3.6rem));
  }

  .page-frame {
    padding-left: 0;
    padding-right: 0;
    padding-top: clamp(0.35rem, 1.2vw, 0.85rem);
    padding-bottom: clamp(0.35rem, 1.2vw, 0.85rem);
  }

  .page-frame .frame-box {
    display: block;
    width: 100%;
    max-width: 100%;
    max-height: none;
  }

  .page-frame .frame-box img {
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: min(
      88vh,
      calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 10.5rem)
    );
    object-fit: contain;
  }
}

.end-inner {
  text-align: center;
  color: var(--ink-soft);
}

.end-inner p {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  letter-spacing: 0.5em;
}

.end-inner span {
  display: block;
  margin-top: 1rem;
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  color: var(--gold);
}

#chrome {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem clamp(1rem, 3vw, 2rem);
  background: transparent;
  pointer-events: none;
}

#chrome .back-link {
  justify-self: start;
  pointer-events: auto;
  font-size: clamp(0.76rem, 2.2vw, 0.88rem);
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--gold);
  text-decoration: none;
  transition: color 0.2s ease;
}

#chrome .back-link:hover {
  color: #c4a574;
}

#chrome .title {
  justify-self: center;
  text-align: center;
  font-size: clamp(0.84rem, 2.6vw, 1.02rem);
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--gold);
}

#chrome .counter {
  justify-self: end;
  font-size: clamp(0.76rem, 2.2vw, 0.88rem);
  font-weight: 600;
  letter-spacing: 0.15em;
  color: rgba(196, 165, 116, 0.92);
  font-variant-numeric: tabular-nums;
}

a.hit {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 22%;
  max-width: 160px;
  z-index: 15;
  cursor: pointer;
  text-decoration: none;
  color: transparent;
  -webkit-tap-highlight-color: transparent;
}

a.hit.prev {
  left: 0;
}

a.hit.next {
  right: 0;
}

body.slide-loading a.hit {
  pointer-events: none;
  cursor: default;
}

body.slide-loading .touch-nav-btn {
  pointer-events: none;
  opacity: 0.42;
}

@media (max-width: 600px) {
  a.hit {
    width: 28%;
  }
}

.touch-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(0.6rem, env(safe-area-inset-bottom, 0px));
  z-index: 18;
  display: none;
  justify-content: center;
  align-items: center;
  gap: clamp(2.5rem, 14vw, 4rem);
  pointer-events: none;
}

@media (max-width: 900px) {
  .touch-nav {
    display: flex;
  }
}

a.touch-nav-btn {
  pointer-events: auto;
  width: 2.85rem;
  height: 2.85rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(154, 123, 79, 0.45);
  background: rgba(28, 24, 20, 0.72);
  color: rgba(235, 228, 216, 0.88);
  font-family: inherit;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

a.touch-nav-btn:active {
  background: rgba(154, 123, 79, 0.22);
  color: var(--gold);
}
