:root {
  color-scheme: dark;
  --ink: #fff6e8;
  --muted: #f0c9a0;
  --gold: #ffd56a;
  --pop: #ff5fa2;
  --line: #ff8a4c;
  --font: "Nunito", "Trebuchet MS", sans-serif;
  --display: "Mystery Quest", "Nunito", cursive;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 18px/1.4 var(--font);
  background:
    radial-gradient(circle at 50% -8%, rgb(255 95 162 / 45%), transparent 38%),
    radial-gradient(circle at 100% 80%, rgb(62 224 197 / 28%), transparent 34%),
    radial-gradient(circle at 0% 90%, rgb(139 108 255 / 35%), transparent 36%),
    #160a28;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle, transparent 38%, rgb(8 6 16 / 55%) 100%),
    repeating-conic-gradient(from 0deg, rgb(255 213 106 / 7%) 0 1deg, transparent 1deg 18deg);
  mask-image: radial-gradient(circle at 50% 42%, black, transparent 72%);
}

main {
  position: relative;
  width: min(960px, calc(100% - 32px));
  margin: 0 auto;
}

.gate, .result {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 0;
}

h1, .rite-copy h2 {
  font-family: var(--display);
  font-weight: 400;
}

.rite {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.rite-copy {
  position: absolute;
  top: 56px;
  left: 24px;
  right: 24px;
  text-align: center;
  pointer-events: none;
}

h1 {
  margin: 0 0 28px;
  font-size: 64px;
  letter-spacing: 0.02em;
  text-align: center;
  color: var(--gold);
}

.rite-copy h2 {
  margin: 0;
  font-size: clamp(40px, 8vw, 68px);
  line-height: 1.05;
  color: var(--pop);
}

.rite-copy p {
  margin: 10px 0 0;
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
}

.spin-hint {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% + min(230px, 39vw) + 36px);
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
}

.card {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #100c18;
  box-shadow: 0 18px 50px rgb(0 0 0 / 35%);
}

.result-photo {
  flex: 1 1 auto;
  min-width: 0;
}

.next-life {
  margin: 0 0 14px;
  text-align: center;
  font-family: var(--display);
  font-weight: 400;
  font-size: 40px;
  line-height: 1.15;
  color: var(--gold);
}

.stage {
  position: relative;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border-radius: 22px;
  background: #000;
}

.stage img { display: block; }

#scene {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#being {
  position: absolute;
  left: 46%;
  bottom: 8%;
  height: 46%;
  width: auto;
  transform: translateX(-50%);
  filter: drop-shadow(0 8px 10px rgb(0 0 0 / 35%));
}

.stamp {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  max-width: 94%;
  background: none;
}

.cloud {
  grid-area: 1 / 1;
  overflow: visible;
  pointer-events: none;
}

.stamp-copy {
  grid-area: 1 / 1;
  z-index: 1;
  padding: 6px 8px 2px;
  text-align: center;
}

.identity {
  margin: 0;
  color: var(--ink);
  font-family: var(--display);
  font-size: 58px;
  line-height: 1.05;
}

.place, .age {
  margin: 4px 0 0;
  color: var(--muted);
}

.wheel {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(460px, 78vw);
  transform: translate(-50%, -50%);
  aspect-ratio: 1;
  touch-action: none;
  cursor: grab;
  filter: drop-shadow(0 16px 28px rgb(255 95 162 / 35%));
}

.wheel.is-spinning { cursor: default; }
.wheel:active { cursor: grabbing; }

.wheel-rotor {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.wheel svg {
  display: block;
  width: 100%;
  height: 100%;
}

.pointer {
  position: absolute;
  z-index: 2;
  top: -6px;
  left: 50%;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 22px solid var(--gold);
  filter: drop-shadow(0 2px 2px rgb(0 0 0 / 45%));
}

button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  border: 2px solid var(--gold);
  border-radius: 999px;
  background: #2a1244;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  font-size: 18px;
  padding: 14px 28px;
  cursor: pointer;
}

button:hover { background: #3a1860; }

.retry {
  width: 18px;
  height: 18px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 28px;
}

.actions button { margin-top: 0; }

.result-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  width: 100%;
}

.card { width: 100%; }

.end-ad {
  display: flex;
  flex: 0 0 300px;
  justify-content: center;
  width: 300px;
  min-height: 250px;
}

@media (max-width: 820px) {
  .end-ad {
    position: fixed;
    top: 50%;
    right: 12px;
    z-index: 3;
    transform: translateY(-50%);
  }
}

.end-ad[hidden] { display: none !important; }

@media (max-width: 640px) {
  main { width: min(960px, calc(100% - 20px)); }

  .rite-copy {
    top: max(12px, env(safe-area-inset-top));
  }

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

  .rite-copy p { font-size: 16px; }

  .wheel {
    width: min(78vw, 46vh);
    top: 52%;
  }

  .spin-hint {
    top: auto;
    bottom: max(52px, calc(env(safe-area-inset-bottom) + 40px));
    padding: 0 16px;
    font-size: 11px;
  }

  .result {
    height: 100dvh;
    min-height: 0;
    justify-content: flex-start;
    padding: max(8px, env(safe-area-inset-top)) 0 max(8px, env(safe-area-inset-bottom));
    overflow: hidden;
  }

  .result-row {
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }

  .result-photo {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .next-life {
    flex: none;
    margin: 0 0 8px;
    font-size: clamp(22px, 6vw, 32px);
  }

  .card {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
  }

  .stage {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    aspect-ratio: auto;
  }

  #scene { object-position: center bottom; }

  .stamp {
    top: 6px;
    max-width: 78%;
  }

  .identity { font-size: clamp(28px, 7.4vw, 40px); }

  .place, .age { font-size: 15px; }

  #being {
    height: 42%;
    bottom: 4%;
  }

  .actions {
    flex: none;
    width: 100%;
    margin-top: 10px;
  }

  .actions button {
    flex: 1 1 140px;
    justify-content: center;
    padding: 12px 14px;
    font-size: 16px;
  }

  .end-ad {
    position: static;
    width: 100%;
    flex: none;
    min-height: 0;
    transform: none;
  }

  .legal { bottom: max(10px, env(safe-area-inset-bottom)); }

  #share-dialog { padding: 18px 14px; }

  .share-title { font-size: 26px; }
}

.legal {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 14px;
  z-index: 4;
  display: flex;
  justify-content: center;
  gap: 18px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.legal a {
  color: inherit;
  text-decoration: none;
}

.legal a:hover { color: var(--ink); }

html.loading-life .rite,
html.loading-life .result { visibility: hidden; }

body:has(#result:not([hidden])) .legal { visibility: hidden; }

#share-dialog {
  position: relative;
  width: min(520px, calc(100% - 32px));
  padding: 22px;
  border: 1px solid var(--gold);
  border-radius: 18px;
  background: #241038;
  color: var(--ink);
}

#share-dialog::backdrop { background: rgb(8 4 16 / 72%); }

.share-x {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
}

.share-x svg { width: 18px; height: 18px; }

.share-title {
  margin: 0 36px 16px 0;
  font-family: var(--display);
  font-size: 32px;
  color: var(--gold);
}

.share-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.share-field {
  display: flex;
  flex: 1;
  align-items: center;
  min-width: 0;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #160a28;
}

#share-link {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  border-radius: 999px 0 0 999px;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  padding: 0 8px 0 16px;
}

#share-link::selection { background: transparent; }

#copy-link {
  width: 40px;
  height: 40px;
  margin: 0 4px 0 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
}

#copy-link svg { width: 18px; height: 18px; }

#copy-link .icon-check { display: none; }

#copy-link.is-copied { color: var(--gold); }

#copy-link.is-copied .icon-copy { display: none; }

#copy-link.is-copied .icon-check { display: block; }

#download-jpg {
  width: 48px;
  height: 48px;
  margin: 0;
  padding: 0;
  justify-content: center;
}

#download-jpg svg { width: 22px; height: 22px; }
