:root {
  color-scheme: dark;
  --ivory: #f7f7f3;
  --muted: #d4d4cc;
  --gold: #dfc180;
  --charcoal: #0c1922;
  --edge: clamp(24px, 5vw, 84px);
  --serif: Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-family: var(--sans);
  background: var(--charcoal);
  color: var(--ivory);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body { margin: 0; }
button { font: inherit; }
button:focus-visible { outline: 2px solid var(--ivory); outline-offset: 5px; }

.scene {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: linear-gradient(115deg, #1d120e, #160e0b 46%, #100c0a);
}

.scene-world {
  position: absolute;
  inset: 0;
  transform: translate(var(--shift-x, 0px), var(--shift-y, 0px));
  transition: transform 950ms cubic-bezier(.18, .7, .22, 1);
}

.scene-image, .scene-light, .scene-dust, .scene-scrim, .ornaments {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scene-image {
  inset: auto;
  left: var(--image-left, 0px);
  top: var(--image-top, 0px);
  width: var(--image-width, 100%);
  height: var(--image-height, 100%);
  object-fit: fill;
  mask-image: linear-gradient(90deg, transparent, #000 var(--image-feather, 0px));
  pointer-events: none;
  opacity: 0;
  transition: opacity 450ms ease;
}
.scene-image.is-ready { opacity: 1; }

.wall-brand {
  position: absolute;
  z-index: 1;
  left: var(--wall-logo-x);
  top: var(--wall-logo-y);
  width: var(--wall-logo-width);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
}
.wall-brand.is-ready { opacity: 1; }
.wall-brand img {
  display: block;
  width: 100%;
  height: auto;
  transform: perspective(calc(var(--wall-logo-width) * 2.6)) rotateY(14deg) rotateZ(2.8deg);
  filter: sepia(.22) saturate(.72) brightness(.9)
    drop-shadow(1px 1px 0 #ecc98f50)
    drop-shadow(2px 4px 1px #000b)
    drop-shadow(6px 9px 5px #0007);
}
.wall-brand[data-composition='tall'] img {
  transform: perspective(calc(var(--wall-logo-width) * 3)) rotateY(4deg) rotateZ(.5deg);
}

.scene-light, .scene-dust, .scene-scrim { pointer-events: none; }
.scene-light {
  background: radial-gradient(ellipse at 23% 64%, #ef882e22, transparent 36%);
  mix-blend-mode: screen;
  animation: fire-breath 9s ease-in-out infinite alternate;
}

.scene-scrim {
  background:
    linear-gradient(180deg, #160c09ad 0%, transparent 23%, transparent 86%, #130b0878 100%),
    radial-gradient(ellipse at 9% 25%, #160f0cb5 0%, #170d0b72 20%, transparent 51%);
}

.scene-header {
  position: absolute;
  z-index: 2;
  top: max(clamp(18px, 3.7vh, 54px), env(safe-area-inset-top));
  left: max(var(--edge), env(safe-area-inset-left));
  right: max(var(--edge), env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.scene-controls { display: flex; align-items: center; gap: 9px; }

.icon-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid #e8c99163;
  border-radius: 50%;
  background: #0c1922cf;
  color: var(--ivory);
  cursor: pointer;
  transition: background-color 180ms ease, border-color 180ms ease;
}
.icon-button:hover, .icon-button[aria-pressed='true'] { background: #23343d; border-color: var(--gold); }
.icon-button:disabled { opacity: .5; cursor: default; }
.sound-button[aria-pressed='false'] .sound-on, .sound-button[aria-pressed='true'] .sound-off { display: none; }

.scene-intro {
  position: absolute;
  z-index: 1;
  top: max(clamp(132px, 20vh, 288px), var(--intro-safe-top, 0px));
  left: max(var(--edge), env(safe-area-inset-left));
  pointer-events: none;
  text-shadow: 0 2px 18px #000b;
}

.scene-intro h1 {
  margin: 0;
  font: 400 clamp(2.9rem, 5.2vw, 5.5rem)/.98 var(--serif);
  letter-spacing: -.055em;
}
.scene-intro h1 span { display: block; }
.scene-intro h1 em { font-weight: 400; color: var(--gold); }
.scene-eyebrow { margin-bottom: 15px; color: var(--gold); font-size: .67rem; font-weight: 650; letter-spacing: .24em; }
.brand-flourish { display: flex; align-items: center; gap: 12px; width: 157px; margin-top: 20px; color: var(--gold); }
.brand-flourish::before, .brand-flourish::after { content: ''; height: 1px; flex: 1; background: linear-gradient(90deg, transparent, #dfc180b0); }
.brand-flourish::after { transform: rotate(180deg); }
.brand-flourish img { object-fit: contain; opacity: .9; }
.scene-intro p { margin: 14px 0 0; font-size: 1rem; line-height: 1.5; color: var(--muted); }

.scene-footer {
  position: absolute;
  z-index: 1;
  bottom: max(clamp(14px, 2.8vh, 42px), env(safe-area-inset-bottom));
  left: max(var(--edge), env(safe-area-inset-left));
  color: var(--muted);
  text-shadow: 0 1px 8px #000;
  font-size: .875rem;
  pointer-events: none;
}
.scene-footer > span { display: block; font-size: .65rem; font-weight: 600; letter-spacing: .18em; color: var(--gold); }
.scene-footer i { font-style: normal; padding: 0 6px; }
.scene-footer small { display: block; margin-top: 7px; font-size: .7rem; color: #c8c9c3a8; }

.ornaments { pointer-events: none; }
.ornament {
  --ornament-zoom: 1.65;
  position: absolute;
  z-index: 0;
  display: grid;
  place-items: center;
  width: max(48px, var(--ornament-size));
  height: max(48px, var(--ornament-size));
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ivory);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  transform: translate(-50%, -50%);
  -webkit-tap-highlight-color: transparent;
}
.ornament::before {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  background: radial-gradient(circle, #f3c77a35 0%, transparent 68%);
  content: '';
  opacity: 0;
  transition: opacity 200ms ease, scale 200ms ease;
}
.ornament:focus-visible, .ornament.is-selected { z-index: 1; }
.ornament:focus-visible::before, .ornament.is-selected::before { opacity: .55; }
.ornament.is-muted { opacity: .55; }
.ornament:focus-visible { outline-color: var(--gold); outline-offset: 0; }

.sprite {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  line-height: 1;
  background-repeat: no-repeat;
  background-size: 300% 200%;
  background-position: var(--sprite-x) var(--sprite-y);
  filter: drop-shadow(1px 4px 3px #140a066e);
}
.sprite::after { content: attr(data-fallback); font-size: 68%; }
.sprites-ready .sprite { background-image: url('assets/ornaments-natural.png'); }
.sprites-ready .sprite::after { content: none; }

.ornament .sprite {
  font-size: calc(var(--ornament-size) * .72);
  transform-origin: 50% 17%;
  scale: calc(var(--ornament-scale, .9) * var(--ornament-zoom));
  filter: brightness(.9) saturate(.88) drop-shadow(1px 3px 2px #07110980) drop-shadow(0 0 1px #ffe3a8a6) drop-shadow(0 0 4px #ffd58a45);
  animation: ornament-sway 8.4s ease-in-out var(--sway-delay) infinite;
  transition: scale 220ms ease, filter 220ms ease;
}
.ornament:focus-visible .sprite, .ornament.is-selected .sprite { scale: calc(var(--ornament-scale, .9) * var(--ornament-zoom) * 1.09); animation-play-state: paused; }

.ornament-name {
  position: absolute;
  top: calc(100% + 3px);
  left: 50%;
  translate: -50% -4px;
  padding: 6px 10px;
  border: 1px solid #d8aa6b7d;
  border-radius: 5px;
  background: #20130ef5;
  font-size: .875rem;
  line-height: 1.2;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, translate 150ms ease;
}
.ornament:focus-visible .ornament-name { opacity: 1; translate: -50% 0; }

@media (hover: hover) {
  .ornament:hover { z-index: 1; }
  .ornament:hover::before { opacity: .55; }
  .ornament:hover .sprite { scale: calc(var(--ornament-scale, .9) * var(--ornament-zoom) * 1.09); animation-play-state: paused; }
  .ornament:hover .ornament-name { opacity: 1; translate: -50% 0; }
}

.scene-dialog {
  position: fixed;
  inset: 0;
  width: min(430px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: clamp(22px, 4vh, 36px) clamp(19px, 5vw, 36px);
  overflow: auto;
  border: 1px solid #c6a867a1;
  border-radius: 19px;
  background: radial-gradient(ellipse at 50% 20%, #243640 0%, #101e27 52%, #0b151d 100%);
  color: var(--ivory);
  box-shadow: 0 18px 65px #080503c9;
  text-align: center;
}
.scene-dialog[open] { animation: dialog-in 240ms ease-out both; }
.scene-dialog::backdrop { background: #080f15d4; animation: backdrop-in 240ms ease-out both; }
.dialog-brand { display: block; width: 140px; height: auto; margin: -8px auto 14px; }
.dialog-eyebrow { margin: 0 0 10px; font-size: .6rem; font-weight: 600; letter-spacing: .16em; color: var(--gold); }
.dialog-close { position: absolute; z-index: 2; top: 12px; right: 12px; width: 44px; height: 44px; }
.scene-dialog h2 {
  margin: 0;
  color: var(--ivory);
  font: 400 clamp(1.95rem, 6vw, 2.65rem)/1.04 var(--serif);
  letter-spacing: -.045em;
}
.scene-dialog h2:focus { outline: none; }
.scene-dialog p { margin: 12px auto 0; max-width: 28ch; color: var(--muted); font-size: 1rem; line-height: 1.57; }

.prize-image {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  width: clamp(112px, 29vh, 170px);
  height: clamp(112px, 29vh, 170px);
  margin: -8px auto 12px;
}
.prize-image::before {
  position: absolute;
  z-index: -1;
  inset: -21%;
  background: radial-gradient(circle, var(--ornament-glow, #e6b67455) 0%, transparent 65%);
  content: '';
  opacity: .7;
}
.prize-image .sprite { width: 100%; font-size: 112px; }
.prize-dialog.is-revealing .sprite { animation: prize-in 540ms cubic-bezier(.17, .75, .25, 1) both; }
.prize-sparks { position: absolute; inset: 0; pointer-events: none; }
.prize-spark {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--spark-size);
  height: var(--spark-size);
  border-radius: 50%;
  background: #ffe1a0;
  box-shadow: 0 0 8px #ffc87b;
  opacity: 0;
}
.prize-dialog.is-revealing .prize-spark { animation: spark-out 770ms ease-out var(--spark-delay) both; }

.dialog-actions {
  display: grid;
  justify-items: center;
  gap: 6px;
  margin-top: 24px;
}
.action-button, .secondary-button {
  min-height: 46px;
  padding: 9px 21px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: .95rem;
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease;
}
.action-button, .secondary-button.is-primary {
  border-color: #e6ce98;
  background: linear-gradient(120deg, #f5e5bd, #d8b66f);
  color: #10212b;
  font-weight: 650;
}
.action-button:hover, .secondary-button.is-primary:hover { background: #f4e5bf; }
.secondary-button { background: transparent; color: var(--muted); }
.secondary-button:hover { background: #ffffff0b; color: var(--ivory); }

.help-dialog { padding-top: 64px; }
.help-dialog .action-button { margin-top: 24px; }
.script-note { position: fixed; right: 18px; bottom: 22px; left: 18px; margin: 0; padding: 12px; background: #231610; text-align: center; }
.visually-hidden { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }

@keyframes fire-breath { from { opacity: .6; } to { opacity: 1; } }
@keyframes ornament-sway { 0%, 100% { rotate: calc(var(--ornament-tilt, 0deg) - .6deg); } 50% { rotate: calc(var(--ornament-tilt, 0deg) + .6deg); } }
@keyframes dialog-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes prize-in {
  from { opacity: .15; transform: translate(var(--origin-x, 0), var(--origin-y, 0)) scale(.35) rotate(-9deg); }
  76% { opacity: 1; transform: translate(0, 0) scale(1.08) rotate(2deg); }
  to { opacity: 1; transform: none; }
}
@keyframes spark-out {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
  22% { opacity: .92; }
  100% { opacity: 0; transform: translate(var(--spark-x), var(--spark-y)) scale(.15); }
}

.motion-paused .scene-light, .motion-paused .ornament .sprite { animation-play-state: paused; }

@media (max-width: 720px) and (orientation: portrait), (max-aspect-ratio: 3/4) {
  :root { --edge: clamp(20px, 6vw, 46px); }
  .scene-scrim {
    background:
      linear-gradient(180deg, #140c09e6 0%, #180e0ba6 12%, transparent 29%, transparent 87%, #150b0894 100%),
      radial-gradient(ellipse at 0% 15%, #140b0987, transparent 48%);
  }
  .scene-intro { top: max(108px, calc(env(safe-area-inset-top) + 82px)); right: var(--edge); }
  .scene-intro h1 { font-size: clamp(1.8rem, 8.6vw, 3.5rem); line-height: 1.05; }
  .scene-intro h1 span { display: inline; }
  .scene-intro p { margin-top: 10px; }
  .scene-eyebrow { font-size: .56rem; letter-spacing: .2em; margin-bottom: 9px; }
  .brand-flourish { width: 112px; margin-top: 10px; gap: 8px; }
  .brand-flourish img { width: 15px; height: 15px; }
  .scene-header { top: max(18px, env(safe-area-inset-top)); }
  .icon-button { width: 44px; height: 44px; }
  .scene-footer { bottom: max(13px, env(safe-area-inset-bottom)); }
}

@media (max-height: 650px) and (orientation: portrait) {
  .scene-intro { top: 90px; }
  .scene-eyebrow, .brand-flourish { display: none; }
  .scene-intro p { font-size: .85rem; margin-top: 8px; }
  .scene-footer > span { font-size: .55rem; }
}

@media (max-height: 530px) and (orientation: landscape) {
  .scene-intro { top: 30%; }
  .scene-intro h1 { font-size: 2.6rem; }
  .scene-intro p { margin-top: 10px; }
  .scene-eyebrow { margin-bottom: 9px; }
  .brand-flourish { display: none; }
  .prize-image { width: 104px; height: 104px; margin-bottom: 4px; }
  .dialog-actions { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .scene-world { transform: none; }
}
