:root {
  --bg: #030008;
  --ink: #f6f1e8;
  --muted: rgba(246, 241, 232, 0.68);
  --quiet: rgba(246, 241, 232, 0.42);
  --line: rgba(246, 241, 232, 0.28);
  --gold: #e6d3a3;
  --gutter: 1.25rem;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
}

body {
  overflow: hidden;
  color: var(--ink);
  font-family: var(--sans);
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

#scene,
#scene canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

#sky { z-index: 0; }
#cloud { z-index: 1; }
#embers { z-index: 2; }

.shell {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100dvh;
}

.top {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(0.8rem + env(safe-area-inset-top, 0px)) var(--gutter) 0.2rem;
}

.mark {
  margin: 0;
  padding-left: 0.22em;
  font-family: var(--serif);
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.sound {
  position: absolute;
  right: var(--gutter);
  top: calc(0.55rem + env(safe-area-inset-top, 0px));
  flex: 0 0 auto;
  min-height: 2.75rem;
  padding: 0 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 550;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sound[aria-pressed="true"] {
  color: var(--ink);
  border-color: var(--gold);
}

.dialogue {
  position: absolute;
  inset: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.15rem;
  padding: calc(4.4rem + env(safe-area-inset-top, 0px)) var(--gutter) calc(1.25rem + env(safe-area-inset-bottom, 0px));
  text-align: center;
}

.dialogue::-webkit-scrollbar {
  display: none;
}

#voice {
  width: min(100%, 36rem);
}

#voice p {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(1.35rem, 2.6vw, 1.85rem);
  line-height: 1.28;
  letter-spacing: -0.011em;
  text-align: center;
  text-wrap: balance;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.8);
}

#voice p + p {
  margin-top: 0.8rem;
}

#voice p.reflection {
  font-size: 1.32rem;
  color: rgba(246, 241, 232, 0.9);
}

#voice p.fortune {
  font-size: clamp(1.6rem, 3vw, 2.15rem);
  color: #fffaf3;
}

#voice p.closer {
  font-size: 1.18rem;
  color: var(--muted);
}

.word {
  animation: arrive 420ms ease both;
}

@keyframes arrive {
  from { opacity: 0; }
  to { opacity: 1; }
}

#answers,
#actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  width: min(100%, 56rem, 108vh);
}

#actions {
  width: min(100%, 22rem);
}

#answers:empty,
#actions:empty {
  display: none;
}

.choice {
  width: 100%;
  min-height: 3rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 1rem;
  line-height: 1.25;
  text-align: center;
  animation: rise 420ms ease both;
}

.choice.primary {
  border-color: rgba(230, 211, 163, 0.85);
}

.choice.chosen {
  border-color: var(--gold);
  background: rgba(230, 211, 163, 0.1);
}

.choice:disabled {
  cursor: default;
}

.choice:active {
  background: rgba(246, 241, 232, 0.06);
}

#answers .choice:nth-child(2) { animation-delay: 40ms; }
#answers .choice:nth-child(3) { animation-delay: 80ms; }
#answers .choice:nth-child(4) { animation-delay: 120ms; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.stepper {
  display: grid;
  grid-template-columns: 3rem 1fr 3rem;
  align-items: center;
  gap: 0.35rem;
}

.step {
  width: 3rem;
  height: 3rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
}

.step:active {
  background: rgba(246, 241, 232, 0.06);
}

.readout {
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  font-family: var(--serif);
  font-size: 4rem;
  font-weight: 500;
  line-height: 0.9;
  text-align: center;
  -webkit-appearance: none;
  appearance: none;
}

.readout:focus {
  outline: none;
}

.unit {
  margin: -0.2rem 0 0;
  text-align: center;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--quiet);
}

.spread {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(0.45rem, 1.6vw, 1.35rem);
  align-items: end;
  width: 100%;
  padding-top: 0.2rem;
}

.tarot {
  --rest: 0deg;
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  padding: 0.72rem 0.62rem 0.7rem;
  border: 1px solid rgba(230, 211, 163, 0.82);
  border-radius: 0.35rem;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(120, 86, 40, 0.16), transparent 46%),
    linear-gradient(180deg, #221a2e 0%, #100c16 38%, #0b0910 100%);
  box-shadow:
    inset 0 0 0 1px rgba(230, 211, 163, 0.28),
    inset 0 0 0 7px #100c16,
    inset 0 0 0 8px rgba(230, 211, 163, 0.38),
    0 14px 28px rgba(0, 0, 0, 0.42);
  color: var(--ink);
  text-align: center;
}

.spread .tarot:nth-child(1) { --rest: -3.5deg; }
.spread .tarot:nth-child(2) { --rest: 0deg; }
.spread .tarot:nth-child(3) { --rest: 3.5deg; }

.spread.pending .tarot {
  opacity: 0;
}

.spread.in .tarot {
  animation: deal 1280ms cubic-bezier(0.16, 0.84, 0.28, 1) both;
}

.spread.in .tarot:nth-child(1) { animation-delay: 40ms; }
.spread.in .tarot:nth-child(2) { animation-delay: 560ms; }
.spread.in .tarot:nth-child(3) { animation-delay: 1080ms; }

@keyframes deal {
  from {
    opacity: 0;
    transform: translateY(78px) rotate(var(--rest)) scale(0.86);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(var(--rest)) scale(1);
  }
}

.spread.leaving .tarot {
  animation: sweep 1600ms cubic-bezier(0.25, 0.1, 0.2, 1) forwards;
  pointer-events: none;
}

.spread.leaving .tarot:nth-child(1) { animation-delay: 0ms; }
.spread.leaving .tarot:nth-child(2) { animation-delay: 180ms; }
.spread.leaving .tarot:nth-child(3) { animation-delay: 360ms; }

.spread.leaving .tarot.chosen {
  animation-name: sweep-chosen;
  animation-delay: 0ms;
}

@keyframes sweep {
  from { opacity: 1; transform: translateY(0) rotate(var(--rest)); }
  to { opacity: 0; transform: translateX(88vw) translateY(-8vh) rotate(26deg) scale(0.92); }
}

@keyframes sweep-chosen {
  from { opacity: 1; transform: translateY(-22px) rotate(var(--rest)) scale(1.04); }
  to { opacity: 0; transform: translateX(92vw) translateY(-14vh) rotate(32deg) scale(0.96); }
}

#voice.leaving {
  animation: question-away 900ms ease forwards;
}

@keyframes question-away {
  to { opacity: 0; transform: translateY(-22px); }
}

.tarot-corner {
  position: absolute;
  width: 0.72rem;
  height: 0.72rem;
  border: 1px solid rgba(230, 211, 163, 0.85);
  pointer-events: none;
}

.tarot-corner::after {
  content: "";
  position: absolute;
  width: 0.28rem;
  height: 0.28rem;
  background: rgba(230, 211, 163, 0.9);
  transform: rotate(45deg);
}

.tarot-corner.tl { top: 0.28rem; left: 0.28rem; border-right: 0; border-bottom: 0; }
.tarot-corner.tr { top: 0.28rem; right: 0.28rem; border-left: 0; border-bottom: 0; }
.tarot-corner.bl { bottom: 0.28rem; left: 0.28rem; border-right: 0; border-top: 0; }
.tarot-corner.br { bottom: 0.28rem; right: 0.28rem; border-left: 0; border-top: 0; }
.tarot-corner.tl::after { top: 0.16rem; left: 0.16rem; }
.tarot-corner.tr::after { top: 0.16rem; right: 0.16rem; }
.tarot-corner.bl::after { bottom: 0.16rem; left: 0.16rem; }
.tarot-corner.br::after { bottom: 0.16rem; right: 0.16rem; }

.tarot-art {
  position: relative;
  display: block;
  aspect-ratio: 3 / 4;
  border-radius: 0.08rem;
  overflow: hidden;
  background: #07060b;
  box-shadow:
    0 0 0 1px rgba(230, 211, 163, 0.72),
    0 0 0 4px #100c16,
    0 0 0 5px rgba(230, 211, 163, 0.28);
}

.tarot-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tarot-art::after {
  content: "";
  position: absolute;
  inset: 0.22rem;
  border: 1px solid rgba(243, 230, 196, 0.28);
  pointer-events: none;
}

.tarot-rule {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.55rem 0.15rem 0;
}

.tarot-rule::before,
.tarot-rule::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(230, 211, 163, 0.75), transparent);
}

.tarot-rule span {
  width: 0.38rem;
  height: 0.38rem;
  flex: 0 0 auto;
  border: 1px solid var(--gold);
  background: rgba(230, 211, 163, 0.35);
  transform: rotate(45deg);
}

.tarot-name {
  display: block;
  margin-top: 0.42rem;
  padding: 0 0.2rem;
  font-family: var(--serif);
  font-variant: small-caps;
  font-size: clamp(0.78rem, 1.35vw, 1.05rem);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0.08em;
  color: #f3e6c4;
}

.spread.in .tarot.chosen {
  border-color: #f3e6c4;
  box-shadow:
    inset 0 0 0 1px rgba(243, 230, 196, 0.7),
    inset 0 0 0 7px #100c16,
    inset 0 0 0 8px rgba(243, 230, 196, 0.7),
    0 22px 40px rgba(0, 0, 0, 0.55);
  animation: lift-card 560ms ease forwards;
}

@keyframes lift-card {
  from { transform: translateY(0) rotate(var(--rest)); }
  to { transform: translateY(-22px) rotate(var(--rest)) scale(1.04); }
}

.spread.in.leaving .tarot {
  animation: sweep 1600ms cubic-bezier(0.25, 0.1, 0.2, 1) forwards;
}

.spread.in.leaving .tarot:nth-child(1) { animation-delay: 0ms; }
.spread.in.leaving .tarot:nth-child(2) { animation-delay: 180ms; }
.spread.in.leaving .tarot:nth-child(3) { animation-delay: 360ms; }

.spread.in.leaving .tarot.chosen {
  animation-name: sweep-chosen;
  animation-delay: 0ms;
  border-color: #f3e6c4;
}

.tarot:disabled {
  cursor: default;
}

.noscript {
  margin: 0;
  text-align: center;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--quiet);
}

.noscript {
  position: fixed;
  z-index: 4;
  left: var(--gutter);
  right: var(--gutter);
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

@media (hover: hover) and (pointer: fine) {
  .choice:hover,
  .step:hover,
  .sound:hover {
    border-color: rgba(246, 241, 232, 0.72);
  }

  .choice.primary:hover,
  .sound[aria-pressed="true"]:hover {
    border-color: var(--gold);
  }
}

@media (max-width: 720px) {
  .tarot {
    padding: 0.48rem 0.4rem 0.5rem;
  }

  .tarot-name {
    letter-spacing: 0.04em;
    font-size: 0.68rem;
  }

  .tarot-rule {
    margin-top: 0.35rem;
  }
}

@media (max-width: 340px) {
  :root { --gutter: 1rem; }
  #voice p { font-size: 1.35rem; }
  #voice p.fortune { font-size: 1.55rem; }
  .readout { font-size: 3.4rem; }
}

@media (max-height: 700px) {
  .dialogue { gap: 0.75rem; }
  .choice { min-height: 2.75rem; }
  #voice p { font-size: 1.28rem; }
  #voice p.fortune { font-size: 1.45rem; }
  #answers { width: min(100%, 40rem, 92vh); }
  .readout { font-size: 3.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  .word,
  .choice {
    animation: none;
  }
}
