@font-face {
  font-family: "Dot Impact";
  src: url("assets/fonts/dotimpact.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #e9e8e4;
  color: #77746d;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
}

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  width: 100%;
  min-height: 100svh;
  padding: 24px;
  place-items: center;
  border: 0;
  color: #fff;
  background: #000;
  cursor: pointer;
  opacity: 1;
  visibility: visible;
  transition: opacity 650ms ease, visibility 0s linear 650ms;
}

.start-screen.is-leaving {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-screen__label {
  font-family: "Dot Impact", Impact, sans-serif;
  font-size: clamp(28px, 4vw, 58px);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.025em;
  text-transform: uppercase;
}

.start-screen:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -10px;
}

.mute-button {
  position: fixed;
  top: clamp(16px, 2.5vw, 30px);
  left: clamp(16px, 2.5vw, 30px);
  z-index: 1100;
  padding: 6px 9px 5px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 2px;
  color: rgba(255, 255, 255, 0.78);
  background: rgba(0, 0, 0, 0.18);
  font-family: "Dot Impact", Impact, sans-serif;
  font-size: 14px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: none;
}

.mute-button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.stage {
  width: 100%;
  min-height: 100svh;
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  gap: 10px;
  padding: clamp(24px, 5vh, 64px) 4vw clamp(18px, 3vh, 36px);
  background-image: linear-gradient(black, white);
  background-image: url("./assets/bg.webp");
  background-repeat: no-repeat;
  background-size: cover;
}

.magazine-shell {
  width: min(98vw, 1200px);
  height: min(85svh, 810px);
  display: grid;
  place-items: center;
  perspective: 2200px;
  opacity: 1;
  transition: opacity 220ms ease;
}

.magazine-shell.music-fade-out {
  opacity: 0;
  pointer-events: none;
}

.magazine {
  --page-width: min(47vw, 53vh, 590px);
  --page-height: calc(var(--page-width) * 647 / 457);
  --turn: 0;
  --turn-angle: 0deg;
  --offset: calc(var(--page-width) * -0.5);
  --curl-opacity: 0;
  --turn-shadow-x: 0px;
  --turn-shadow-width: 0px;
  --turn-shadow-opacity: 0;
  --left-page-opacity: 0;
  --hinge-bleed: 1px;
  --left-page-image: none;
  --right-page-image: none;
  --turn-front-image: none;
  --turn-back-image: none;
  --hinge-shine-left: linear-gradient(
    to left,
    transparent 1.5%,
    rgba(255, 255, 255, 0.08) 4%,
    rgba(255, 255, 255, 0.18) 8%,
    rgba(255, 255, 255, 0.1) 13%,
    transparent 23%
  );
  --hinge-shine-right: linear-gradient(
    to right,
    transparent 1.5%,
    rgba(255, 255, 255, 0.08) 4%,
    rgba(255, 255, 255, 0.18) 8%,
    rgba(255, 255, 255, 0.1) 13%,
    transparent 23%
  );

  position: relative;
  width: calc(var(--page-width) * 2);
  height: var(--page-height);
  transform: translate3d(var(--offset), 0, 0);
  transform-style: preserve-3d;
  transition: transform 620ms cubic-bezier(0.22, 0.72, 0.18, 1);
  filter: drop-shadow(0 24px 24px rgba(50, 47, 40, 0.14));
  outline: none;
}

.magazine.dragging {
  transition: none;
}

.magazine.auto-returning .edge-zone {
  pointer-events: none;
}

.magazine.auto-returning,
.magazine.auto-returning .turning-page {
  transition-duration: 240ms;
}

.page,
.turning-page {
  position: absolute;
  top: 0;
  width: var(--page-width);
  height: var(--page-height);
  background: #fff;
}

.static-page {
  overflow: hidden;
}

.static-page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.left-page {
  left: 0;
  width: calc(var(--page-width) + var(--hinge-bleed));
  opacity: var(--left-page-opacity);
  border-radius: 2px 0 0 2px;
  border-right: 0;
  transform-origin: right center;
  background-color: #fff;
  background-image: linear-gradient(
    to left,
    rgba(15, 15, 14, 0.5) 0,
    rgba(20, 19, 18, 0.34) 1.5%,
    rgba(20, 19, 18, 0.13) 5%,
    rgba(20, 19, 18, 0.035) 10%,
    transparent 16%
  ), var(--hinge-shine-left), linear-gradient(
    to right,
    rgba(25, 24, 22, 0.3),
    rgba(25, 24, 22, 0.13) 1.5%,
    transparent 7%
  ), var(--left-page-image);
  background-position: left top, left top, left top, center;
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%;
  background-repeat: no-repeat;
}

.right-page {
  left: var(--page-width);
  width: var(--page-width);
  border-left: 0;
  border-radius: 0 2px 2px 0;
  background-color: #fff;
  background-image: linear-gradient(
    to right,
    rgba(15, 15, 14, 0.5) 0,
    rgba(20, 19, 18, 0.34) 1.5%,
    rgba(20, 19, 18, 0.13) 5%,
    rgba(20, 19, 18, 0.035) 10%,
    transparent 16%
  ), var(--hinge-shine-right), var(--right-page-image);
  background-position: left top, left top, center;
  background-size: 100% 100%, 100% 100%, 100% 100%;
  background-repeat: no-repeat;
}

.magazine.open .right-page {
  left: calc(var(--page-width) - var(--hinge-bleed));
  width: calc(var(--page-width) + var(--hinge-bleed));
}

.magazine.back-cover .right-page,
.magazine.back-cover .outer-shadow-right,
.magazine.turning-to-back-cover .right-page,
.magazine.turning-to-back-cover .outer-shadow-right {
  visibility: hidden;
}

.magazine.turning-to-back-cover .edge-zone-right {
  opacity: 0;
  outline: 0;
}

.turn-shadow-clip {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

.turn-shadow {
  position: absolute;
  top: 1.5%;
  left: var(--turn-shadow-x);
  width: var(--turn-shadow-width);
  height: 97%;
  opacity: var(--turn-shadow-opacity);
  pointer-events: none;
  filter: blur(8px);
  will-change: left, width, opacity;
  transition: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 3%, #000 97%, transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 3%, #000 97%, transparent);
}

.turn-shadow.forward-shadow {
  background: linear-gradient(to right, transparent 0, rgba(18, 17, 16, 0.11) 42%, rgba(18, 17, 16, 0.48) 100%);
}

.turn-shadow.backward-shadow {
  background: linear-gradient(to right, rgba(18, 17, 16, 0.48) 0, rgba(18, 17, 16, 0.11) 58%, transparent 100%);
}

.outer-shadow {
  position: absolute;
  top: 0;
  z-index: 8;
  width: max(6%, 36px);
  height: 100%;
  pointer-events: none;
}

.outer-shadow-right {
  right: 0;
  background: linear-gradient(to left, rgba(25, 24, 22, 0.3), rgba(25, 24, 22, 0.13) 22%, transparent 100%);
}

.turning-page {
  left: var(--page-width);
  z-index: 3;
  transform-origin: left center;
  transform-style: preserve-3d;
  transform: rotateY(var(--turn-angle));
  border: 0;
  background: transparent;
  transition: transform 620ms cubic-bezier(0.22, 0.72, 0.18, 1);
  will-change: transform;
}

.magazine.dragging .turning-page {
  transition: none;
}

.turning-page.backward {
  left: 0;
  z-index: 4;
  transform-origin: right center;
  transform: rotateY(var(--turn-angle));
}

.face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.turning-page.forward .face {
  left: calc(0px - var(--hinge-bleed));
}

.turning-page.backward .face {
  right: calc(0px - var(--hinge-bleed));
}

.face-front {
  border-radius: 0 2px 2px 0;
  box-shadow: 10px 10px 18px rgba(45, 42, 36, 0.06);
}

.turning-page.forward .face-front {
  border-left: 0;
  background-color: #fff;
  background-image: linear-gradient(
    to right,
    rgba(15, 15, 14, 0.5) 0,
    rgba(20, 19, 18, 0.34) 1.5%,
    rgba(20, 19, 18, 0.13) 5%,
    rgba(20, 19, 18, 0.035) 10%,
    transparent 16%
  ), var(--hinge-shine-right), var(--turn-front-image);
  background-position: left top, left top, center;
  background-size: 100% 100%, 100% 100%, 100% 100%;
  background-repeat: no-repeat;
}

.turning-page.backward .face-front {
  border-right: 0;
  background-color: #fff;
  background-image: linear-gradient(
    to left,
    rgba(15, 15, 14, 0.5) 0,
    rgba(20, 19, 18, 0.34) 1.5%,
    rgba(20, 19, 18, 0.13) 5%,
    rgba(20, 19, 18, 0.035) 10%,
    transparent 16%
  ), var(--hinge-shine-left), linear-gradient(
    to right,
    rgba(25, 24, 22, 0.3),
    rgba(25, 24, 22, 0.13) 1.5%,
    transparent 7%
  ), var(--turn-front-image);
  background-position: left top, left top, left top, center;
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%;
  background-repeat: no-repeat;
}

.turning-page.forward .face-front::after {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: 7%;
  opacity: var(--curl-opacity);
  background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(202, 201, 197, 0.7) 62%, rgba(255, 255, 255, 0.96));
  transition: opacity 170ms ease;
}

.turning-page.backward .face-front::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 7%;
  opacity: var(--curl-opacity);
  background: linear-gradient(to left, rgba(255, 255, 255, 0), rgba(202, 201, 197, 0.7) 62%, rgba(255, 255, 255, 0.96));
  transition: opacity 170ms ease;
}

.face-back {
  transform: rotateY(180deg);
  border-color: transparent;
  border-radius: 2px 0 0 2px;
  background-color: #fff;
  background-image: linear-gradient(
    to left,
    rgba(15, 15, 14, 0.5) 0,
    rgba(20, 19, 18, 0.34) 1.5%,
    rgba(20, 19, 18, 0.13) 5%,
    rgba(20, 19, 18, 0.035) 10%,
    transparent 16%
  ), var(--hinge-shine-left), linear-gradient(
    to right,
    rgba(25, 24, 22, 0.3),
    rgba(25, 24, 22, 0.13) 1.5%,
    transparent 7%
  ), var(--turn-back-image);
  background-position: left top, left top, left top, center;
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%;
  background-repeat: no-repeat;
}

.turning-page.backward .face-front {
  border-radius: 2px 0 0 2px;
}

.turning-page.backward .face-back {
  border-radius: 0 2px 2px 0;
  background-color: #fff;
  background-image: linear-gradient(
    to right,
    rgba(15, 15, 14, 0.5) 0,
    rgba(20, 19, 18, 0.34) 1.5%,
    rgba(20, 19, 18, 0.13) 5%,
    rgba(20, 19, 18, 0.035) 10%,
    transparent 16%
  ), var(--hinge-shine-right), var(--turn-back-image);
  background-position: left top, left top, center;
  background-size: 100% 100%, 100% 100%, 100% 100%;
  background-repeat: no-repeat;
}

.edge-zone {
  position: absolute;
  top: 0;
  z-index: 10;
  width: max(11%, 42px);
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  opacity: 0;
  background: transparent;
  touch-action: none;
  cursor: grab;
}

.edge-zone:active {
  cursor: grabbing;
}

.edge-zone:focus-visible {
  opacity: 1;
  outline: 2px solid rgba(75, 72, 65, 0.42);
  outline-offset: 4px;
}

.edge-zone-left {
  left: 0;
  display: none;
}

.magazine.open .edge-zone-left {
  display: block;
}

.edge-zone-right {
  right: 0;
}

.magazine.at-end .edge-zone-right {
  display: none;
}

.magazine-controls {
  position: relative;
}

.reading-hint {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  width: max-content;
  max-width: 92vw;
  margin: 0;
  color: rgba(255, 255, 255, 0.52);
  font-size: clamp(10px, 0.8vw, 12px);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-align: center;
  transform: translateX(-50%);
  transition: opacity 260ms ease, visibility 0s linear 260ms;
}

.reading-hint.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.magazine-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(28px, 5vw, 72px);
}

.magazine-action {
  appearance: none;
  padding: 0;
  border: 0;
  color: #fff;
  background: transparent;
  font-family: "Dot Impact", Impact, sans-serif;
  font-size: clamp(28px, 3.25vw, 48px);
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: 0.015em;
  text-transform: uppercase;
  text-shadow: 0 2px 12px rgba(20, 14, 38, 0.26);
  cursor: pointer;
  transition: none;
}

.magazine-action:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 5px;
}

.instructions {
  margin: 0;
  font-size: 11px;
  font-weight: 620;
  line-height: 1;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.instructions {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #8c8982;
}

.instructions i {
  width: 18px;
  height: 1px;
  background: #aaa79f;
}

@media (max-width: 680px) {
  .magazine-shell {
    height: min(74svh, 650px);
  }

  .magazine {
    --page-width: min(48vw, 46vh, 360px);
  }

  .stage {
    padding-inline: 2vw;
  }
}

@media (prefers-reduced-motion: reduce) {
  .start-screen,
  .reading-hint,
  .magazine-shell,
  .magazine,
  .turning-page,
  .turn-shadow,
  .turning-page.forward .face-front::after {
    transition-duration: 1ms;
  }
}
