:root {
  color-scheme: dark;
  --espresso: #0b0705;
  --umber: #24150e;
  --cream: #f1e7d8;
  --muted: rgba(241, 231, 216, 0.58);
  --gold: #b89662;
  --ease-film: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--espresso);
}

body,
button {
  color: var(--cream);
  font-family: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
}

.cinema {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  isolation: isolate;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(91, 54, 31, 0.42), transparent 58%),
    linear-gradient(145deg, #21130d 0%, #0e0906 55%, #070403 100%);
}

.cinema.is-playing {
  cursor: none;
}

.stage,
.scene,
.scene__ambient,
.scene__tone,
.cinema-vignette {
  position: absolute;
  inset: 0;
}

.stage {
  position: fixed;
  inset: 0;
  z-index: 1;
}

.scene {
  overflow: hidden;
  opacity: 0;
  transform: scale(1.01);
  transition:
    opacity 820ms var(--ease-film),
    transform 1100ms var(--ease-film);
  will-change: opacity, transform;
}

.scene--active {
  z-index: 2;
  opacity: 1;
  transform: scale(1);
}

.scene__ambient {
  z-index: 0;
  display: flex;
  overflow: hidden;
  opacity: 0.68;
  filter: blur(72px) saturate(0.92) brightness(0.44);
  transform: scale(1.18);
}

.scene__ambient img {
  min-width: 0;
  height: 100%;
  flex: 1 1 0;
  object-fit: cover;
}

.scene__tone {
  z-index: 1;
  background:
    radial-gradient(ellipse at 50% 48%, color-mix(in srgb, var(--ambient) 42%, transparent), transparent 58%),
    linear-gradient(135deg, rgba(45, 25, 15, 0.36), rgba(8, 5, 4, 0.72));
  mix-blend-mode: screen;
}

.layout {
  position: absolute;
  z-index: 2;
  inset: 0;
}

.photo-frame {
  position: absolute;
  overflow: hidden;
  background: transparent;
  transform: translate3d(0, 0, 0);
}

.photo-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: 50% 42%;
  filter: saturate(0.94) contrast(1.025) brightness(0.94);
  animation: breathe var(--scene-duration, 3.2s) linear both;
  will-change: transform;
}

.layout--landscape .photo-frame {
  inset: 0;
}

.layout--landscape .photo-frame img {
  object-position: 50% 50%;
}

.layout--landscape .photo-frame--contain img {
  object-fit: contain;
}

.layout--portrait-2 .photo-frame:nth-child(1) {
  top: 3vh;
  bottom: 9vh;
  left: 7vw;
  width: 44vw;
  z-index: 2;
}

.layout--portrait-2 .photo-frame:nth-child(2) {
  top: 17vh;
  right: 6vw;
  bottom: 5vh;
  width: 43vw;
  z-index: 3;
}

.layout--portrait-3 .photo-frame:nth-child(1) {
  top: 15vh;
  bottom: 6vh;
  left: 0;
  width: 34vw;
  z-index: 2;
}

.layout--portrait-3 .photo-frame:nth-child(2) {
  top: 2vh;
  bottom: 2vh;
  left: 50%;
  width: 38vw;
  z-index: 4;
  transform: translateX(-50%);
}

.layout--portrait-3 .photo-frame:nth-child(3) {
  top: 9vh;
  right: 0;
  bottom: 13vh;
  width: 34vw;
  z-index: 3;
}

.layout--portrait-3 .photo-frame:nth-child(2) img {
  animation-name: breathe-reverse;
}

.scene--highlight {
  transition-duration: 560ms, 720ms;
}

.film-grain {
  position: absolute;
  z-index: 7;
  inset: -50%;
  width: 200%;
  height: 200%;
  pointer-events: none;
  opacity: 0.043;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.88' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.82'/%3E%3C/svg%3E");
  animation: grain 0.23s steps(2) infinite;
}

.cinema-vignette {
  z-index: 6;
  pointer-events: none;
  box-shadow:
    inset 0 0 12vw rgba(0, 0, 0, 0.42),
    inset 0 0 2vw rgba(0, 0, 0, 0.2);
  background: linear-gradient(180deg, rgba(9, 5, 3, 0.22), transparent 20%, transparent 78%, rgba(9, 5, 3, 0.28));
}

.start-gate {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 7vh 8vw;
  text-align: center;
  background:
    radial-gradient(circle at 50% 43%, rgba(97, 59, 34, 0.22), transparent 38%),
    rgba(9, 5, 3, 0.5);
  backdrop-filter: blur(8px);
  transition: opacity 900ms ease, visibility 900ms;
}

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

.start-gate__content {
  transform: translateY(-1vh);
}

.start-gate__eyebrow {
  margin: 0 0 clamp(1.2rem, 2.6vh, 2.4rem);
  color: var(--gold);
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(0.58rem, 0.72vw, 0.85rem);
  font-weight: 600;
  letter-spacing: 0.48em;
}

.start-gate h1 {
  margin: 0;
  font-size: clamp(3.5rem, 8.6vw, 9.5rem);
  font-weight: 400;
  letter-spacing: 0.08em;
  line-height: 1.08;
  text-shadow: 0 0.25rem 2rem rgba(0, 0, 0, 0.48);
}

.loading-progress {
  width: min(28rem, 72vw);
  margin: clamp(2.2rem, 4.8vh, 4rem) auto 0;
  --loading-progress: 0;
}

.loading-progress__meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.7rem;
  color: rgba(241, 231, 216, 0.56);
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(0.58rem, 0.64vw, 0.74rem);
  letter-spacing: 0.12em;
  transition: color 300ms ease;
}

.loading-progress__track {
  height: 2px;
  overflow: hidden;
  background: rgba(241, 231, 216, 0.14);
}

.loading-progress__bar {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, rgba(184, 150, 98, 0.55), var(--gold));
  box-shadow: 0 0 1rem rgba(184, 150, 98, 0.5);
  transform: scaleX(var(--loading-progress));
  transform-origin: left center;
  transition: transform 320ms var(--ease-film);
}

.loading-progress.is-complete .loading-progress__meta {
  color: rgba(241, 231, 216, 0.76);
}

.start-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.85rem;
  margin-top: clamp(1.5rem, 3.2vh, 2.6rem);
  padding: 1rem 1.7rem;
  border: 1px solid rgba(241, 231, 216, 0.42);
  border-radius: 999px;
  background: rgba(15, 9, 6, 0.3);
  font-size: clamp(0.76rem, 0.86vw, 1rem);
  letter-spacing: 0.18em;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: border-color 250ms, background 250ms, transform 250ms;
}

.start-button:disabled {
  cursor: wait;
  opacity: 0.56;
}

.start-button:not(:disabled):hover,
.start-button:not(:disabled):focus-visible {
  border-color: var(--gold);
  background: rgba(184, 150, 98, 0.12);
  outline: none;
  transform: translateY(-2px);
}

.start-button__pulse {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 0 rgba(184, 150, 98, 0.55);
  animation: pulse 1.8s infinite;
}

.start-gate__hint {
  margin: 1.25rem 0 0;
  color: rgba(241, 231, 216, 0.46);
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(0.58rem, 0.64vw, 0.74rem);
  letter-spacing: 0.12em;
}

.status-toast {
  position: absolute;
  z-index: 18;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1.15rem;
  border: 1px solid rgba(241, 231, 216, 0.18);
  border-radius: 999px;
  opacity: 0;
  color: rgba(241, 231, 216, 0.82);
  background: rgba(10, 6, 4, 0.68);
  font-size: 0.82rem;
  letter-spacing: 0.12em;
  pointer-events: none;
  backdrop-filter: blur(12px);
  transform: translate(-50%, -42%) scale(0.96);
  transition: opacity 220ms, transform 260ms var(--ease-film);
}

.status-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.status-toast__icon {
  min-width: 1.2rem;
  color: var(--gold);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.72rem;
}

.error-message {
  position: absolute;
  z-index: 30;
  right: 2rem;
  bottom: 2rem;
  left: 2rem;
  display: none;
  padding: 1rem;
  color: #f8d9ce;
  background: rgba(87, 24, 17, 0.88);
  text-align: center;
}

.error-message.is-visible {
  display: block;
}

@keyframes breathe {
  from { transform: scale(1.018) translate3d(-0.25%, 0.18%, 0); }
  to { transform: scale(1.052) translate3d(0.28%, -0.18%, 0); }
}

@keyframes breathe-reverse {
  from { transform: scale(1.052) translate3d(0.24%, -0.14%, 0); }
  to { transform: scale(1.018) translate3d(-0.2%, 0.15%, 0); }
}

@keyframes pulse {
  70% { box-shadow: 0 0 0 0.55rem rgba(184, 150, 98, 0); }
  100% { box-shadow: 0 0 0 0 rgba(184, 150, 98, 0); }
}

@keyframes grain {
  0% { transform: translate3d(0, 0, 0); }
  25% { transform: translate3d(2%, -3%, 0); }
  50% { transform: translate3d(-4%, 2%, 0); }
  75% { transform: translate3d(3%, 4%, 0); }
  100% { transform: translate3d(-2%, -3%, 0); }
}

@media (max-aspect-ratio: 4 / 3) {
  .layout--portrait-2 .photo-frame:nth-child(1) { left: 3vw; width: 49vw; }
  .layout--portrait-2 .photo-frame:nth-child(2) { right: 3vw; width: 48vw; }
  .layout--portrait-3 .photo-frame:nth-child(1),
  .layout--portrait-3 .photo-frame:nth-child(3) { width: 38vw; }
  .layout--portrait-3 .photo-frame:nth-child(2) { width: 44vw; }
}

@media (prefers-reduced-motion: reduce) {
  .film-grain,
  .photo-frame img,
  .start-button__pulse {
    animation: none;
  }
}
