:root {
  --bg-night: #050b14;
  --bg-deep: #0c1c31;
  --text-main: #f3e8d2;
  --text-soft: rgba(243, 232, 210, 0.72);
  --accent: #f0c36b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 18%, rgba(33, 77, 102, 0.28), transparent 34%),
    radial-gradient(circle at 82% 16%, rgba(240, 195, 107, 0.12), transparent 30%),
    linear-gradient(180deg, var(--bg-deep), var(--bg-night));
  color: var(--text-main);
  font-family: Georgia, "Times New Roman", serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.02), transparent 34%),
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 22px,
      rgba(255, 255, 255, 0.02) 23px
    );
  mix-blend-mode: soft-light;
  pointer-events: none;
}

body.is-transitioning {
  overflow: hidden;
}

body.is-embedded .next-chapter,
body.is-embedded .chapter-transition {
  display: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.overlay {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  padding: 5vh clamp(1.25rem, 3vw, 3rem);
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 2rem;
}

.hero {
  align-self: center;
  max-width: min(40rem, 92vw);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  position: relative;
}

h1 {
  margin: 0;
  font-size: clamp(3rem, 9vw, 7rem);
  line-height: 0.92;
  font-weight: 500;
  white-space: nowrap;
}

.description {
  margin: 2.2rem 0 0;
  max-width: 35rem;
  color: var(--text-soft);
  line-height: 1.8;
  font-size: clamp(1rem, 1.5vw, 1.18rem);
  word-break: keep-all;
  overflow-wrap: normal;
}

.next-chapter {
  position: fixed;
  right: 3rem;
  top: 50%;
  transform: translateY(-50%);
  width: 4.4rem;
  height: 4.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(243, 232, 210, 0.2);
  color: var(--text-main);
  text-decoration: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0.01)),
    rgba(8, 16, 26, 0.44);
  box-shadow:
    inset 0 0 0 1px rgba(240, 195, 107, 0.04),
    0 18px 36px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(6px);
  transition:
    margin 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease,
    box-shadow 180ms ease;
  z-index: 5;
}

.next-chapter span {
  font-size: 1.7rem;
  line-height: 1;
  transform: translateX(0);
  transition: transform 180ms ease, color 180ms ease;
}

.next-chapter:hover {
  margin-top: -2px;
  border-color: rgba(240, 195, 107, 0.38);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.014)),
    rgba(10, 18, 29, 0.52);
  box-shadow:
    inset 0 0 0 1px rgba(240, 195, 107, 0.08),
    0 24px 42px rgba(0, 0, 0, 0.26);
}

.next-chapter:hover span {
  transform: translateX(3px);
  color: var(--accent);
}

.chapter-transition {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transition: opacity 280ms ease;
}

.chapter-transition span {
  position: absolute;
  right: -24vw;
  top: 50%;
  width: 58vw;
  height: 1px;
  transform-origin: right center;
  transform: translateY(-50%) scaleX(0);
  background: linear-gradient(90deg, rgba(0, 0, 0, 0), rgba(240, 195, 107, 0.94), rgba(247, 228, 189, 0.98));
  box-shadow:
    0 0 18px rgba(240, 195, 107, 0.34),
    0 0 56px rgba(114, 186, 204, 0.16);
}

.chapter-transition span:nth-child(1) {
  margin-top: -3.5rem;
}

.chapter-transition span:nth-child(2) {
  width: 72vw;
  margin-top: 0;
}

.chapter-transition span:nth-child(3) {
  width: 46vw;
  margin-top: 3.8rem;
}

body.is-transitioning .chapter-transition {
  opacity: 1;
}

body.is-transitioning .chapter-transition span:nth-child(1) {
  animation: transition-slice-a 1180ms cubic-bezier(0.2, 0.75, 0.14, 1) forwards;
}

body.is-transitioning .chapter-transition span:nth-child(2) {
  animation: transition-slice-b 1320ms cubic-bezier(0.16, 0.82, 0.12, 1) forwards;
}

body.is-transitioning .chapter-transition span:nth-child(3) {
  animation: transition-slice-c 1260ms cubic-bezier(0.18, 0.8, 0.14, 1) forwards;
}

body.is-transitioning .overlay {
  opacity: 0.2;
  filter: blur(9px);
  transform: scale(0.985);
  transition: opacity 820ms ease, filter 820ms ease, transform 820ms ease;
}

body.is-transitioning .next-chapter {
  border-color: rgba(240, 195, 107, 0.52);
  box-shadow:
    inset 0 0 0 1px rgba(240, 195, 107, 0.14),
    0 0 44px rgba(240, 195, 107, 0.24);
}

@keyframes transition-slice-a {
  0% {
    transform: translateY(-50%) scaleX(0);
    opacity: 0;
  }
  18% {
    opacity: 1;
  }
  100% {
    transform: translateY(-50%) scaleX(2.6);
    opacity: 0;
  }
}

@keyframes transition-slice-b {
  0% {
    transform: translateY(-50%) scaleX(0);
    opacity: 0;
  }
  14% {
    opacity: 1;
  }
  100% {
    transform: translateY(-50%) scaleX(2.9);
    opacity: 0;
  }
}

@keyframes transition-slice-c {
  0% {
    transform: translateY(-50%) scaleX(0);
    opacity: 0;
  }
  22% {
    opacity: 1;
  }
  100% {
    transform: translateY(-50%) scaleX(2.4);
    opacity: 0;
  }
}

.ticker {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  align-items: center;
  color: rgba(243, 232, 210, 0.45);
  font-size: 0.82rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.ticker p {
  margin: 0;
}

.ticker p::after {
  content: " /";
  margin-left: 1.25rem;
  color: rgba(240, 195, 107, 0.32);
}

.ticker p:last-child::after {
  content: "";
  margin: 0;
}

@media (max-width: 900px) {
  .overlay {
    padding-top: max(1.25rem, env(safe-area-inset-top));
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  }
}

#scene {
  animation: page-canvas-fade-in 900ms cubic-bezier(0.2, 0.8, 0.18, 1) both;
}

.overlay {
  animation: page-ui-fade-in 780ms cubic-bezier(0.2, 0.8, 0.18, 1) both;
  animation-delay: 90ms;
}

@keyframes page-canvas-fade-in {
  0% {
    opacity: 0;
    transform: scale(1.018);
    filter: blur(8px);
  }
  100% {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
}

@keyframes page-ui-fade-in {
  0% {
    opacity: 0;
    transform: translateY(12px);
    filter: blur(8px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

body:not(.text-ready) .overlay {
  opacity: 0;
  transform: translateY(12px);
  filter: blur(8px);
  pointer-events: none;
  animation: none !important;
}

body.text-ready .overlay {
  animation: page-ui-fade-in 780ms cubic-bezier(0.2, 0.8, 0.18, 1) both;
}

body.is-transitioning.text-ready .overlay {
  animation: page-ui-fade-out 420ms ease forwards;
}

@keyframes page-ui-fade-out {
  0% {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: translateY(10px);
    filter: blur(6px);
  }
}
