:root {
  --lapis: #0B1A4A;
  --cobalt: #1F4BB8;
  --turquoise: #2BB5C4;
  --gold: #E2B254;
  --gold-deep: #B8862E;
  --ivory: #F3EBD8;
  --violet: #7B6CF6;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --card-w: clamp(288px, 76vw, 392px);
  --arch-base: clamp(64px, 20vw, 96px);
  --arch-h: var(--arch-base);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--lapis);
  color: var(--ivory);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
  isolation: isolate;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top) + clamp(150px, 22vh, 210px)) 0 calc(env(safe-area-inset-bottom) + clamp(110px, 16vh, 170px));
}

/* Background: Registan at night */
.bg {
  position: absolute;
  inset: 0;
  z-index: -3;
  background:
    linear-gradient(180deg, rgba(11, 26, 74, 0.82) 0%, rgba(11, 26, 74, 0.35) 38%, rgba(11, 26, 74, 0.2) 62%, rgba(11, 26, 74, 0.75) 100%),
    url("assets/registan.webp") center 62% / cover no-repeat;
  animation: bg-in 1200ms var(--ease-out) both;
}

.sky { position: absolute; inset: 0 0 55% 0; z-index: -2; pointer-events: none; }
.sky i {
  position: absolute;
  width: 2px; height: 2px;
  border-radius: 50%;
  background: var(--ivory);
  opacity: 0.7;
  animation: twinkle var(--t, 4s) ease-in-out var(--d, 0s) infinite;
}

.deco { position: absolute; pointer-events: none; user-select: none; }
.deco img { display: block; width: 100%; height: auto; }

/* Top-left: golden sun */
.sun {
  top: calc(env(safe-area-inset-top) + 10px);
  left: 8px;
  width: clamp(112px, 26vw, 260px);
  height: auto;
  filter: drop-shadow(0 6px 24px rgba(226, 178, 84, 0.35));
  animation: sun-in 900ms var(--ease-out) 200ms both, float 7s ease-in-out 1100ms infinite;
}

/* Top-right: walkers on a snowy slope */
.climb {
  top: calc(env(safe-area-inset-top) + 6px);
  right: 0;
  width: clamp(100px, 26vw, 220px);
  aspect-ratio: 832 / 579;
  container-type: inline-size;
  animation: climb-in 1000ms var(--ease-out) 300ms both;
}
.slope { position: absolute; inset: 0; width: 100%; height: 100%; }
.walkers {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  filter: drop-shadow(0 3px 2px rgba(11, 26, 74, 0.25));
  animation: step 900ms ease-in-out infinite;
}
.flag-text {
  position: absolute;
  left: 85.6%;
  top: 10.2%;
  transform: translate(-50%, -50%) rotate(-25deg) skewX(-4deg);
  font-weight: 700;
  font-size: var(--flag-fs, 1.95cqw);
  letter-spacing: -0.01em;
  color: #1c2b5a;
  white-space: nowrap;
  animation: step 900ms ease-in-out infinite;
}
.fir {
  animation: fir-walk 16s linear var(--d) infinite;
}
.snow { position: absolute; inset: -10% -4% 0 -10%; overflow: hidden; }
.snow i {
  position: absolute;
  top: -8px;
  width: var(--s, 4px); height: var(--s, 4px);
  border-radius: 50%;
  background: #fff;
  opacity: 0.85;
  animation: snow-fall var(--t, 7s) linear var(--d, 0s) infinite;
}

/* Saxophones, mirrored, at mid-height */
.sax {
  --sax-w: clamp(80px, 18vw, 240px);
  top: 50%;
  width: var(--sax-w);
  margin-top: calc(var(--sax-w) * -0.545);
  z-index: 0;
}
.sax img {
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 14px rgba(226, 178, 84, 0.25));
}
.sax-right { right: clamp(-34px, -4vw, 2vw); transform-origin: 20% 15%; animation: sax-in-r 1000ms var(--ease-out) 450ms both, sway-r 3.4s ease-in-out 1500ms infinite; }
.sax-left { left: clamp(-34px, -4vw, 2vw); transform-origin: 80% 15%; animation: sax-in-l 1000ms var(--ease-out) 450ms both, sway-l 3.4s ease-in-out 1500ms infinite; }
.sax-left img { transform: scaleX(-1); }
.notes { position: absolute; bottom: 8%; }
.sax-right .notes { right: 12%; }
.sax-left .notes { left: 12%; }
.notes i {
  position: absolute;
  bottom: 0;
  font-style: normal;
  font-size: clamp(16px, 2.2vw, 28px);
  color: var(--gold);
  text-shadow: 0 0 10px rgba(226, 178, 84, 0.6);
  opacity: 0;
  animation: note 3.6s var(--ease-out) infinite;
}
.notes i:nth-child(2) { animation-delay: 1.2s; }
.notes i:nth-child(3) { animation-delay: 2.4s; }
.sax-left .notes i { --dx: -26px; }
.sax-right .notes i { --dx: 26px; }

/* Bottom-left: glowing lily */
.lily {
  left: -6px;
  bottom: calc(env(safe-area-inset-bottom) - 4px);
  width: clamp(104px, 24vw, 240px);
  height: auto;
  mix-blend-mode: screen;
  transform-origin: 50% 100%;
  animation: lily-in 1200ms var(--ease-out) 550ms both, lily-sway 6s ease-in-out 1800ms infinite;
}

/* Scattered Snoopy */
.snoopies { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.snoopy {
  position: absolute;
  width: var(--w);
  pointer-events: auto;
  border: 0; padding: 0; background: none; cursor: pointer;
  rotate: var(--r);
  animation: pop-in 500ms var(--ease-out) var(--in) both;
}
.snoopy img {
  display: block; width: 100%; height: auto;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
  animation: float var(--f) ease-in-out var(--fd) infinite;
}
.snoopy.wiggle img { animation: wiggle 600ms var(--ease-out); }

/* Kiki flying across the whole page */
.kiki {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1;
  width: clamp(96px, 26vw, 200px);
  pointer-events: none;
  opacity: 0;
  will-change: transform;
}
.kiki img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.35));
  animation: kiki-bob 2.6s ease-in-out infinite;
}
.kiki.to-right img { transform: scaleX(-1); }
@keyframes kiki-bob {
  0%, 100% { translate: 0 0; rotate: -2deg; }
  50% { translate: 0 -7px; rotate: 2deg; }
}

/* Center: portal card in the shape of a madrasa iwan */
.portal {
  position: relative;
  z-index: 2;
  width: var(--card-w);
  animation: portal-in 700ms var(--ease-out) 900ms both;
}
.portal-frame, .portal-inner, .tympanum, .portal-inner::before {
  clip-path: inset(0 round calc(var(--card-w) / 2) calc(var(--card-w) / 2) 18px 18px);
}
@supports (clip-path: shape(from 0 0, line to 10px 10px)) {
  .portal-frame, .portal-inner, .tympanum, .portal-inner::before {
    clip-path: shape(
      from 0 100%,
      line to 0 var(--arch-h),
      curve to 50% 0 with 0 calc(var(--arch-h) * 0.42) / 36% calc(var(--arch-h) * 0.12),
      curve to 100% var(--arch-h) with 64% calc(var(--arch-h) * 0.12) / 100% calc(var(--arch-h) * 0.42),
      line to 100% 100%,
      close
    );
  }
}
.portal-frame {
  padding: 3px;
  background: linear-gradient(180deg, var(--turquoise), #1d8fa0);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
}
.portal-inner {
  position: relative;
  padding: 3px;
  background: var(--gold);
  --arch-h: calc(var(--arch-base) - 3px);
}
.portal-inner::before {
  content: "";
  position: absolute;
  inset: 3px;
  background: linear-gradient(180deg, #17378c 0%, var(--cobalt) 35%, #173e9c 100%);
  --arch-h: calc(var(--arch-base) - 6px);
}
.tympanum {
  position: absolute;
  inset: 3px 3px auto 3px;
  --arch-h: calc(var(--arch-base) - 6px);
  height: calc(var(--arch-h) + 34px);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 44 44'%3E%3Cg fill='none' stroke='%23E2B254' stroke-width='1.2'%3E%3Crect x='12' y='12' width='20' height='20'/%3E%3Crect x='12' y='12' width='20' height='20' transform='rotate(45 22 22)'/%3E%3Cpath d='M0 22h3.9M40.1 22H44M22 0v3.9M22 40.1V44'/%3E%3Ccircle cx='22' cy='22' r='3'/%3E%3C/g%3E%3C/svg%3E") center top / 30px 30px repeat;
  opacity: 0.55;
  -webkit-mask-image: linear-gradient(180deg, #000 35%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 35%, transparent 100%);
  pointer-events: none;
}
.portal-body {
  position: relative;
  padding: calc(var(--arch-h) * 0.82) clamp(18px, 5vw, 34px) clamp(22px, 4vw, 32px);
  text-align: center;
}

/* Steps */
.step { animation: step-in 260ms var(--ease-out) both; }
.step.leaving { animation: step-out 160ms ease-in both; }

h1:focus, h2:focus { outline: none; }
h1, h2 {
  margin: 0 0 8px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  text-wrap: balance;
}
h1 { font-size: clamp(30px, 8.4vw, 46px); margin: 6px 0 24px; }
h2 { font-size: clamp(24px, 6.6vw, 34px); }
.lead { margin: 0 auto 22px; font-size: 17px; line-height: 1.4; max-width: 30ch; color: rgba(243, 235, 216, 0.9); }
.hint { margin: 0 0 14px; font-size: 14px; color: rgba(243, 235, 216, 0.7); }

.btn {
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  border: 0;
  border-radius: 999px;
  min-height: 48px;
  padding: 0 26px;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 200ms ease, opacity 200ms ease;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:focus-visible, .chip:focus-visible, .app:focus-visible, .snoopy:focus-visible {
  outline: 2px solid var(--turquoise);
  outline-offset: 3px;
}
.btn-gold { background: var(--gold); color: var(--lapis); box-shadow: 0 6px 18px rgba(226, 178, 84, 0.35); }
.btn-gold:disabled { opacity: 0.45; cursor: default; box-shadow: none; }
.btn-ghost { background: rgba(243, 235, 216, 0.12); color: var(--ivory); box-shadow: inset 0 0 0 1.5px rgba(243, 235, 216, 0.4); }
.btn-link { background: none; color: rgba(243, 235, 216, 0.8); padding: 0 12px; font-weight: 500; }

.ask-actions { display: flex; justify-content: center; gap: 12px; min-height: 64px; align-items: center; }
.btn-yes-grow { transform: scale(var(--grow, 1)); transition: transform 300ms var(--ease-out); }
.btn-no.runaway {
  position: fixed;
  z-index: 20;
  left: 0; top: 0;
  transition: transform 340ms var(--ease-out), opacity 300ms ease;
}
.btn-no.gone { opacity: 0; pointer-events: none; }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 14px; }
.days {
  flex-wrap: nowrap;
  justify-content: flex-start;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: clamp(18px, 5vw, 34px);
  margin-inline: calc(clamp(18px, 5vw, 34px) * -1);
  padding: 2px clamp(18px, 5vw, 34px) 6px;
  scrollbar-width: none;
}
.days::-webkit-scrollbar { display: none; }
.chip {
  font: inherit;
  flex: none;
  scroll-snap-align: start;
  border: 0;
  border-radius: 14px;
  min-height: 44px;
  padding: 8px 14px;
  background: rgba(11, 26, 74, 0.55);
  color: var(--ivory);
  box-shadow: inset 0 0 0 1.5px rgba(43, 181, 196, 0.35);
  cursor: pointer;
  transition: background-color 180ms ease, box-shadow 180ms ease, transform 160ms var(--ease-out), color 180ms ease;
  touch-action: manipulation;
}
.chip:active:not(:disabled) { transform: scale(0.96); }
.chip[aria-checked="true"] { background: var(--turquoise); color: var(--lapis); box-shadow: none; font-weight: 700; }
.chip:disabled { opacity: 0.35; cursor: default; }
.day { display: grid; gap: 2px; text-align: center; min-width: 76px; }
.day b { font-size: 15px; }
.day small { font-size: 12px; opacity: 0.8; }
.times .chip { min-width: 70px; font-size: 16px; font-variant-numeric: tabular-nums; }

.step-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
.step-actions:has(> :only-child) { justify-content: center; }

.apps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0 12px; }
.app {
  font: inherit;
  display: grid; justify-items: center; gap: 10px;
  padding: 20px 8px 16px;
  border: 0; border-radius: 20px;
  background: rgba(11, 26, 74, 0.55);
  color: var(--ivory);
  box-shadow: inset 0 0 0 1.5px rgba(43, 181, 196, 0.35);
  cursor: pointer;
  font-size: 16px; font-weight: 700;
  transition: background-color 180ms ease, transform 160ms var(--ease-out), color 180ms ease;
  touch-action: manipulation;
}
.app svg { width: 40px; height: 40px; }
.app:active { transform: scale(0.97); }
.app[aria-checked="true"] { background: var(--turquoise); color: var(--lapis); }

.summary { margin: 18px 0 16px; display: grid; gap: 8px; text-align: left; }
.summary div {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(11, 26, 74, 0.5);
}
.summary dt { color: rgba(243, 235, 216, 0.7); }
.summary dd { margin: 0; font-weight: 700; text-align: right; }
.summary dd small { display: block; font-weight: 400; font-size: 13px; color: rgba(243, 235, 216, 0.7); }
.error { color: #FFD9A0; font-size: 14px; margin: 0 0 10px; }

.done h2 { font-size: clamp(32px, 9vw, 46px); }

.dock {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: fade 600ms ease 1200ms both;
}
.lang {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(11, 26, 74, 0.7);
  box-shadow: inset 0 0 0 1px rgba(43, 181, 196, 0.4);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.lang button {
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  min-width: 44px;
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: rgba(243, 235, 216, 0.75);
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease;
  touch-action: manipulation;
}
.lang button[aria-pressed="true"] { background: var(--gold); color: var(--lapis); }
.lang button:focus-visible { outline: 2px solid var(--turquoise); outline-offset: 2px; }
.sound {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(11, 26, 74, 0.7);
  box-shadow: inset 0 0 0 1px rgba(43, 181, 196, 0.4);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--ivory);
  cursor: pointer;
  transition: transform 160ms var(--ease-out), color 180ms ease;
  touch-action: manipulation;
}
.sound-wrap { position: relative; }
.sound-hint {
  position: absolute;
  right: -6px;
  bottom: calc(100% + 12px);
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--gold);
  color: var(--lapis);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  transform-origin: calc(100% - 26px) 100%;
  animation: hint-in 420ms var(--ease-out) 1600ms both, hint-bob 2.4s ease-in-out 2100ms infinite;
  transition: opacity 200ms ease, scale 200ms ease;
}
.sound-hint::after {
  content: "";
  position: absolute;
  right: 20px;
  top: 100%;
  border: 7px solid transparent;
  border-top-color: var(--gold);
}
.sound::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--gold);
  opacity: 0;
  animation: ring 1.8s var(--ease-out) 1600ms infinite;
  pointer-events: none;
}
.sound { position: relative; }
.music-on .sound-hint, .music-muted .sound-hint { opacity: 0; scale: 0.92; }
.music-on .sound::after, .music-muted .sound::after { animation: none; opacity: 0; }
@keyframes hint-in { from { opacity: 0; transform: translateY(6px) scale(0.95); } }
@keyframes hint-bob { 50% { translate: 0 -3px; } }
@keyframes ring { 0% { opacity: 0.9; transform: scale(1); } 100% { opacity: 0; transform: scale(1.6); } }
.sound:active { transform: scale(0.94); }
.sound:focus-visible { outline: 2px solid var(--turquoise); outline-offset: 2px; }
.sound svg { width: 22px; height: 22px; }
.sound .sound-on { display: none; }
.sound[aria-pressed="true"] { color: var(--gold); }
.sound[aria-pressed="true"] .sound-on { display: block; }
.sound[aria-pressed="true"] .sound-off { display: none; }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 30; pointer-events: none; }

/* Keyframes */
@keyframes bg-in { from { opacity: 0; transform: scale(1.04); } }
@keyframes sun-in { from { opacity: 0; transform: translate(-24px, -18px) rotate(-8deg); } }
@keyframes climb-in { from { opacity: 0; transform: translate(40px, -16px); } }
@keyframes sax-in-l { from { opacity: 0; translate: -40px 0; } }
@keyframes sax-in-r { from { opacity: 0; translate: 40px 0; } }
@keyframes lily-in { from { opacity: 0; transform: translateY(24px) scale(0.94); } }
@keyframes portal-in { from { opacity: 0; transform: translateY(16px); filter: blur(6px); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.9); } }
@keyframes step-in { from { opacity: 0; transform: translateY(8px); filter: blur(3px); } }
@keyframes step-out { to { opacity: 0; transform: translateY(-6px); filter: blur(3px); } }
@keyframes float { 50% { transform: translateY(-8px); } }
@keyframes twinkle { 50% { opacity: 0.15; } }
@keyframes step { 50% { translate: 0 -2.5px; } }
@keyframes sway-l { 0%, 100% { rotate: -3deg; } 50% { rotate: 3deg; } }
@keyframes sway-r { 0%, 100% { rotate: 3deg; } 50% { rotate: -3deg; } }
@keyframes lily-sway { 0%, 100% { rotate: -1.5deg; } 50% { rotate: 1.5deg; } }
@keyframes note {
  0% { opacity: 0; transform: translate(0, 0) scale(0.9); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), -90px) scale(1.1) rotate(12deg); }
}
@keyframes fir-walk {
  0% { transform: translate(1010px, 163px); opacity: 0; }
  8% { opacity: 1; }
  88% { opacity: 1; }
  100% { transform: translate(-160px, 635px); opacity: 0; }
}
@keyframes snow-fall {
  to { transform: translate(var(--x, -30px), 260px); opacity: 0; }
}
@keyframes wiggle {
  0% { transform: rotate(0); }
  25% { transform: rotate(-10deg) scale(1.06); }
  60% { transform: rotate(8deg); }
  100% { transform: rotate(0); }
}

@media (max-width: 599px) {
  .sax { --sax-w: 90px; z-index: 3; }
  .sax-left { left: calc((100vw - var(--card-w)) / 2 - 66px); }
  .sax-right { right: calc((100vw - var(--card-w)) / 2 - 66px); }
  .sax-left img { transform: scaleX(-1) rotate(20deg); }
  .sax-right img { transform: rotate(20deg); }
}

@media (min-width: 900px) {
  :root { --card-w: clamp(392px, 30vw, 440px); }
  .sax { --sax-w: clamp(130px, 12vw, 220px); }
  .sax-left { left: calc(50% - var(--card-w) / 2 - clamp(165px, 15vw, 270px)); }
  .sax-right { right: calc(50% - var(--card-w) / 2 - clamp(165px, 15vw, 270px)); }
  .climb { width: clamp(135px, 13.5vw, 225px); }
  .sun { width: clamp(180px, 17vw, 280px); }
  .lily { width: clamp(150px, 14vw, 240px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
  }
  .step, .portal, .bg { animation: fade 240ms ease both !important; }
  .fir, .snow i, .notes i { display: none; }
}
@keyframes fade { from { opacity: 0; } }

@media (max-height: 700px) and (max-width: 599px) {
  .stage { padding-top: calc(env(safe-area-inset-top) + 112px); padding-bottom: calc(env(safe-area-inset-bottom) + 72px); }
  .portal-body { padding-bottom: 16px; }
  .chip { min-height: 40px; padding-block: 6px; }
  .chips { gap: 6px; margin-bottom: 10px; }
  .lily { width: 84px; }
}
