:root {
  color-scheme: dark;
  --brown-950: #160a05;
  --brown-900: #241108;
  --brown-800: #3b1d0c;
  --gold-100: #fff1c9;
  --gold-200: #f4d89c;
  --gold-300: #e5bd68;
  --gold-400: #c9943b;
  --ink: #3b210f;
  --cream: #fff4d8;
  --ease-out: cubic-bezier(0.2, 0.75, 0.2, 1);
  --safe-top: max(20px, env(safe-area-inset-top));
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
}

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

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
}

html {
  background: var(--brown-950);
  font-family: "Noto Sans Thai", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow: hidden;
  color: var(--cream);
  background:
    radial-gradient(circle at 50% 24%, rgba(191, 119, 34, 0.24), transparent 36rem),
    linear-gradient(135deg, #100704, #2d1609 48%, #110704);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.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;
}

.app {
  position: relative;
  isolation: isolate;
  width: 100%;
  max-width: 560px;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  min-height: 560px;
  margin: 0 auto;
  overflow: hidden;
  background: var(--brown-900);
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.62);
}

.screen {
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px) scale(1.016);
  transition:
    opacity 360ms ease,
    transform 480ms var(--ease-out),
    visibility 0s linear 480ms;
}

.screen.is-entering,
.screen.is-leaving {
  visibility: visible;
  transition-delay: 0s;
}

.screen.is-active {
  z-index: 2;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

.screen.is-leaving {
  z-index: 3;
  transform: translateY(-5px) scale(0.992);
  transition:
    opacity 240ms ease,
    transform 280ms ease,
    visibility 0s;
}

.screen__art {
  position: absolute;
  z-index: -3;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 0%;
  user-select: none;
  -webkit-user-drag: none;
}

.screen__veil {
  position: absolute;
  z-index: -2;
  inset: 0;
  pointer-events: none;
}

.screen__veil--home {
  background:
    linear-gradient(180deg, rgba(22, 9, 3, 0.02) 24%, rgba(22, 9, 3, 0.12) 45%, rgba(18, 7, 2, 0.78) 76%, rgba(14, 5, 2, 0.96) 100%),
    radial-gradient(ellipse at 50% 71%, rgba(211, 141, 46, 0.14), transparent 52%);
}

.screen__veil--loading {
  background:
    linear-gradient(180deg, rgba(10, 4, 1, 0.02) 22%, rgba(13, 6, 2, 0.1) 48%, rgba(11, 4, 1, 0.72) 87%, rgba(9, 3, 1, 0.94) 100%),
    radial-gradient(circle at 50% 58%, rgba(235, 161, 53, 0.12), transparent 38%);
}

.screen__veil--result {
  background:
    linear-gradient(180deg, rgba(14, 6, 2, 0.04), transparent 38%, rgba(14, 6, 2, 0.18) 76%, rgba(10, 4, 1, 0.62) 100%),
    radial-gradient(circle at 50% 57%, rgba(255, 206, 117, 0.12), transparent 48%);
}

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

.particles {
  position: absolute;
  z-index: 1;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.particles i {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 3px;
  height: 3px;
  border-radius: 50%;
  opacity: 0;
  background: #ffd879;
  box-shadow:
    0 0 7px 2px rgba(255, 183, 64, 0.7),
    0 0 18px rgba(255, 160, 35, 0.5);
  animation: particleFloat var(--d) var(--delay) linear infinite;
}

.particles i:nth-child(2n) {
  width: 2px;
  height: 2px;
}

.home-content {
  top: auto;
  bottom: calc(var(--safe-bottom) + 8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: auto;
  padding: 0 24px;
  text-align: center;
  animation: homeReveal 900ms 100ms var(--ease-out) both;
}

.ritual-label,
.loading-kicker,
.result-heading > p {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
  color: rgba(255, 226, 170, 0.9);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.085em;
}

.ritual-label span {
  width: 30px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(244, 216, 156, 0.86));
}

.ritual-label span:last-child {
  transform: scaleX(-1);
}

.home-title {
  margin: 8px 0 5px;
  color: var(--cream);
  font-family: "Noto Serif Thai", serif;
  font-size: clamp(2.15rem, 10.6vw, 3.35rem);
  font-weight: 500;
  line-height: 0.98;
  letter-spacing: -0.012em;
  text-shadow:
    0 2px 18px rgba(0, 0, 0, 0.78),
    0 0 34px rgba(218, 147, 50, 0.3);
}

.home-title span,
.home-title strong {
  display: block;
}

.home-title strong {
  margin-top: 8px;
  color: var(--gold-200);
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.015em;
}

.home-lead {
  margin: 10px 0 19px;
  color: rgba(255, 246, 226, 0.88);
  font-size: clamp(0.91rem, 3.8vw, 1.04rem);
  line-height: 1.68;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}

.primary-button {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  width: min(100%, 340px);
  min-height: 58px;
  padding: 7px 8px 7px 25px;
  overflow: hidden;
  color: #371c09;
  border: 1px solid rgba(255, 242, 207, 0.76);
  border-radius: 999px;
  background:
    linear-gradient(100deg, rgba(255, 255, 255, 0.22), transparent 35%),
    linear-gradient(135deg, #f6dd9c 0%, #dcb35f 42%, #b97e27 100%);
  box-shadow:
    0 14px 32px rgba(0, 0, 0, 0.46),
    0 0 30px rgba(219, 157, 56, 0.22),
    0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition:
    transform 180ms ease,
    filter 180ms ease,
    box-shadow 180ms ease;
}

.primary-button::before {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(105deg, transparent 20%, rgba(255, 255, 255, 0.46) 48%, transparent 72%);
  transform: translateX(-120%);
  transition: transform 640ms ease;
}

.primary-button:hover::before {
  transform: translateX(120%);
}

.primary-button:hover {
  filter: saturate(1.08) brightness(1.04);
  box-shadow:
    0 15px 34px rgba(0, 0, 0, 0.44),
    0 0 36px rgba(222, 161, 60, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.56);
}

.primary-button:active {
  transform: scale(0.985);
}

.primary-button:focus-visible {
  outline: 3px solid #fff4cf;
  outline-offset: 4px;
}

.primary-button:disabled {
  cursor: wait;
  filter: saturate(0.75) brightness(0.8);
}

.primary-button__label {
  position: relative;
  z-index: 1;
  justify-self: center;
  padding-left: 31px;
  font-size: 1rem;
  font-weight: 700;
}

.primary-button__symbol {
  position: relative;
  z-index: 1;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #ffeab5;
  border: 1px solid rgba(255, 238, 191, 0.24);
  border-radius: 50%;
  background: rgba(68, 32, 8, 0.78);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.duration-note {
  margin: 9px 0 0;
  color: rgba(255, 240, 205, 0.74);
  font-size: 0.72rem;
  letter-spacing: 0.025em;
}

.load-error {
  margin: 8px 0 0;
  color: #ffe0cf;
  font-size: 0.75rem;
}

.drawing-stage {
  position: absolute;
  top: 27%;
  left: 50%;
  width: min(82vw, 390px);
  aspect-ratio: 2 / 3;
  transform: translateX(-50%);
  transform-origin: 50% 66%;
}

.drawing-stage::after {
  position: absolute;
  z-index: 0;
  top: 88%;
  left: 50%;
  width: 31%;
  height: 4.5%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(9, 3, 1, 0.68), transparent 70%);
  filter: blur(5px);
  content: "";
  transform: translateX(-50%);
}

.fortune-object {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}

.drawing-glow {
  position: absolute;
  z-index: 0;
  top: 25%;
  left: 50%;
  width: 48%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 207, 110, 0.78), rgba(224, 135, 31, 0.24) 44%, transparent 72%);
  filter: blur(14px);
  transform: translateX(-50%) scale(0.8);
}

.loading-ring {
  position: absolute;
  z-index: 0;
  top: 44%;
  left: 50%;
  border: 1px solid rgba(244, 198, 111, 0.24);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.loading-ring::after {
  position: absolute;
  top: -3px;
  left: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffd67b;
  box-shadow: 0 0 12px #f5a83b;
  content: "";
}

.loading-ring--outer {
  width: 68%;
  aspect-ratio: 1;
}

.loading-ring--inner {
  width: 52%;
  aspect-ratio: 1;
  border-style: dashed;
}

.screen--loading.is-active .fortune-object--cylinder {
  animation: cylinderShake 760ms 180ms cubic-bezier(0.36, 0.04, 0.24, 1) 3;
}

.screen--loading.is-active .drawing-glow {
  animation: glowPulse 1.55s 980ms ease-in-out infinite;
}

.screen--loading.is-active .loading-ring--outer {
  animation: ringSpin 10s linear infinite;
}

.screen--loading.is-active .loading-ring--inner {
  animation: ringSpinReverse 8s linear infinite;
}

.loading-copy {
  position: absolute;
  right: 24px;
  bottom: calc(var(--safe-bottom) + 16px);
  left: 24px;
  text-align: center;
  text-shadow: 0 2px 15px rgba(0, 0, 0, 0.78);
}

.loading-kicker {
  color: rgba(255, 224, 165, 0.82);
  font-size: 0.68rem;
}

.loading-copy h2 {
  margin: 6px 0 2px;
  font-family: "Noto Serif Thai", serif;
  font-size: clamp(1.8rem, 8vw, 2.5rem);
  font-weight: 600;
  line-height: 1.25;
}

.loading-copy > p:last-of-type {
  margin: 5px 0 13px;
  color: rgba(255, 243, 217, 0.82);
  font-size: 0.82rem;
}

.loading-dots {
  display: flex;
  justify-content: center;
  gap: 7px;
  height: 8px;
}

.loading-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gold-200);
  animation: dotPulse 1s ease-in-out infinite;
}

.loading-dots i:nth-child(2) {
  animation-delay: 140ms;
}

.loading-dots i:nth-child(3) {
  animation-delay: 280ms;
}

.loading-progress {
  width: min(100%, 270px);
  height: 2px;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 232, 181, 0.16);
}

.loading-progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, #f5d486, #c68d32);
  box-shadow: 0 0 12px rgba(242, 184, 81, 0.75);
  transform: translateX(-100%);
}

.screen--loading.is-active .loading-progress span {
  animation: progressFill 3s 100ms linear both;
}

.result-heading {
  position: absolute;
  z-index: 3;
  top: 24.5%;
  left: 50%;
  width: 100%;
  padding: 0 24px;
  text-align: center;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.74);
  transform: translateX(-50%);
}

.result-heading > p {
  color: rgba(255, 226, 171, 0.86);
  font-size: 0.67rem;
}

.result-heading h2 {
  margin: 1px 0 0;
  color: var(--gold-100);
  font-family: "Noto Serif Thai", serif;
  font-size: clamp(1.38rem, 6.4vw, 1.92rem);
  font-weight: 600;
  line-height: 1.3;
}

.result-heading h2:focus {
  outline: none;
}

.fortune-card {
  position: absolute;
  z-index: 2;
  top: 28.5%;
  left: 50%;
  width: min(110vw, 520px);
  aspect-ratio: 2 / 3;
  margin: 0;
  opacity: 0;
  transform: translate(-50%, 70px) scale(0.96);
  will-change: transform, opacity;
}

.screen--result.is-active .fortune-card {
  animation:
    cardReveal 840ms 80ms var(--ease-out) both,
    cardFloat 7s 1.05s ease-in-out infinite;
}

.fortune-card__art {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  filter:
    drop-shadow(0 24px 22px rgba(0, 0, 0, 0.44))
    drop-shadow(0 0 18px rgba(232, 174, 77, 0.12));
}

.fortune-card__content {
  position: absolute;
  z-index: 1;
  top: 9.2%;
  right: 15.5%;
  bottom: 10.5%;
  left: 15.5%;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  color: var(--ink);
  text-align: center;
}

.fortune-card__eyebrow {
  margin: 0 0 1px;
  color: #8f6026;
  font-size: clamp(0.58rem, 2.55vw, 0.75rem);
  font-weight: 700;
  letter-spacing: 0.16em;
}

.fortune-card__badge {
  margin: 0;
  color: #6e3a12;
  font-family: "Noto Serif Thai", serif;
  font-size: clamp(1.25rem, 5.9vw, 1.75rem);
  font-weight: 700;
  line-height: 1.35;
}

.fortune-card__ornament {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  width: 76%;
  margin: 5px 0 9px;
  color: #a56c22;
  font-size: 0.62rem;
}

.fortune-card__ornament::before,
.fortune-card__ornament::after {
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, rgba(133, 80, 22, 0.7));
}

.fortune-card__ornament::after {
  transform: scaleX(-1);
}

.fortune-card__text {
  display: flex;
  flex: 1;
  align-items: center;
  margin: 0;
  overflow: hidden;
  color: #462713;
  font-family: "Noto Sans Thai", system-ui, sans-serif;
  font-size: clamp(0.88rem, 3.65vw, 1.04rem);
  font-weight: 500;
  line-height: 1.72;
  opacity: 0;
  text-wrap: pretty;
}

.screen--result.is-active .fortune-card__text {
  animation: textReveal 700ms 620ms ease both;
}

.fortune-card__footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 7px;
}

.fortune-card__footer p {
  margin: 0;
  color: #7b4a21;
  font-size: clamp(0.66rem, 2.65vw, 0.74rem);
  font-weight: 600;
  white-space: nowrap;
}

.fortune-card__footer span {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(122, 73, 25, 0.54));
}

.fortune-card__footer span:last-child {
  transform: scaleX(-1);
}

.noscript-message {
  position: fixed;
  z-index: 10;
  right: 16px;
  bottom: 16px;
  left: 16px;
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 16px;
  color: #42210c;
  border-radius: 14px;
  background: #f4d494;
  text-align: center;
}

@keyframes homeReveal {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes particleFloat {
  0% {
    opacity: 0;
    transform: translate3d(0, 18px, 0) scale(0.7);
  }
  18% {
    opacity: 0.82;
  }
  72% {
    opacity: 0.28;
  }
  100% {
    opacity: 0;
    transform: translate3d(15px, -95px, 0) scale(1.25);
  }
}

@keyframes cylinderShake {
  0%,
  100% {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  25% {
    transform: translate3d(-4px, 1px, 0) rotate(-1.8deg);
  }
  50% {
    transform: translate3d(4px, -2px, 0) rotate(1.9deg);
  }
  75% {
    transform: translate3d(-2px, 0, 0) rotate(-1.1deg);
  }
}

@keyframes glowPulse {
  0%,
  100% {
    opacity: 0.42;
    transform: translateX(-50%) scale(0.78);
  }
  50% {
    opacity: 1;
    transform: translateX(-50%) scale(1.13);
  }
}

@keyframes ringSpin {
  from {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

@keyframes ringSpinReverse {
  from {
    transform: translate(-50%, -50%) rotate(360deg);
  }
  to {
    transform: translate(-50%, -50%) rotate(0deg);
  }
}

@keyframes dotPulse {
  0%,
  100% {
    opacity: 0.24;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@keyframes progressFill {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes cardReveal {
  from {
    opacity: 0;
    transform: translate(-50%, 76px) scale(0.965);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

@keyframes cardFloat {
  0%,
  100% {
    transform: translate(-50%, 0);
  }
  50% {
    transform: translate(-50%, -5px);
  }
}

@keyframes textReveal {
  from {
    opacity: 0;
    filter: blur(3px);
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    filter: blur(0);
    transform: translateY(0);
  }
}

@media (max-height: 700px) {
  .home-content {
    bottom: calc(var(--safe-bottom) + 2px);
  }

  .ritual-label {
    font-size: 0.6rem;
  }

  .home-title {
    margin-top: 5px;
    font-size: clamp(1.85rem, 9.8vw, 2.6rem);
  }

  .home-lead {
    margin: 5px 0 12px;
    line-height: 1.55;
  }

  .primary-button {
    min-height: 53px;
  }

  .primary-button__symbol {
    width: 38px;
    height: 38px;
  }

  .drawing-stage {
    top: 20%;
    width: min(80vw, 340px);
  }

  .loading-copy {
    bottom: calc(var(--safe-bottom) + 7px);
  }

  .loading-copy h2 {
    font-size: 1.7rem;
  }

  .loading-copy > p:last-of-type {
    margin-bottom: 8px;
  }

  .result-heading {
    top: 16%;
  }

  .fortune-card {
    top: 23%;
    width: min(96vw, calc((100dvh - 125px) * 0.6667), 430px);
  }

  .fortune-card__text {
    font-size: clamp(0.75rem, 3.65vw, 0.87rem);
    line-height: 1.55;
  }

  .fortune-card__ornament {
    margin-top: 2px;
    margin-bottom: 5px;
  }
}

@media (min-width: 560px) and (max-height: 820px) {
  .app {
    max-width: 52vh;
  }

  .drawing-stage {
    top: 26%;
    width: min(34vh, 300px);
  }

  .result-heading {
    top: 24%;
  }

  .fortune-card {
    top: 28%;
    width: min(44vh, 380px);
  }
}

@media (min-width: 560px) {
  body {
    padding: 0 20px;
  }

  .app {
    border-right: 1px solid rgba(255, 226, 168, 0.12);
    border-left: 1px solid rgba(255, 226, 168, 0.12);
  }

  .home-content,
  .loading-copy {
    padding-right: 46px;
    padding-left: 46px;
  }
}

@media (min-width: 620px) and (min-height: 720px) {
  body {
    display: grid;
    padding: 14px 20px;
    place-items: center;
  }

  .app {
    height: calc(100dvh - 28px);
    min-height: 0;
    border: 1px solid rgba(255, 230, 178, 0.16);
    border-radius: 36px;
    box-shadow:
      0 36px 90px rgba(0, 0, 0, 0.68),
      0 0 0 1px rgba(0, 0, 0, 0.34),
      inset 0 1px 0 rgba(255, 255, 255, 0.06);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }

  .particles {
    display: none;
  }

  .fortune-card__text,
  .fortune-card {
    opacity: 1;
  }
}
