:root {
  --emerald-950: #09271d;
  --emerald-900: #103b2c;
  --emerald-800: #154a36;
  --emerald-700: #1f694b;
  --gold-500: #c99732;
  --gold-400: #e0b553;
  --gold-200: #f6df9c;
  --ivory: #fffdf4;
  --ink: #1c3528;
  --ease-premium: cubic-bezier(.22, .8, .24, 1);
  color: var(--ink);
  font-family: "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--emerald-950);
}

body {
  min-width: 320px;
  min-height: 100svh;
  margin: 0;
  background: var(--emerald-950);
  color: var(--ink);
  overflow-x: hidden;
}

button {
  border: 0;
  font: inherit;
}

button:focus-visible {
  outline: .2rem solid var(--gold-400);
  outline-offset: .25rem;
}

img {
  display: block;
  max-width: 100%;
  object-fit: contain;
}

.fortune-app {
  position: relative;
  width: 100%;
  min-height: 100svh;
  overflow: hidden;
  background: var(--emerald-950);
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 0;
  min-height: 100svh;
  overflow-x: hidden;
  overflow-y: auto;
  isolation: isolate;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(.985);
  transition: opacity .55s var(--ease-premium), transform .75s var(--ease-premium), visibility .55s;
}

.screen::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, rgb(4 28 19 / 4%), rgb(4 28 19 / 10%));
  content: "";
  pointer-events: none;
}

.screen--active {
  z-index: 1;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1);
}

.screen--home,
.screen--loading,
.screen--result {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.screen--home {
  background-color: #dceac8;
}

.screen--home.screen--active,
.screen--home.screen--visited {
  background-image: url("../assets/backgrounds/home-bg.webp");
}

.screen--home::before {
  background: linear-gradient(180deg, rgb(255 255 243 / 2%), rgb(9 51 33 / 15%));
}

.screen--loading {
  background-color: #384e2c;
  color: var(--ivory);
}

.screen--loading.screen--active,
.screen--loading.screen--visited {
  background-image: url("../assets/backgrounds/loading-bg.webp");
}

.screen--loading::before {
  background: radial-gradient(circle at 50% 43%, rgb(249 214 113 / 14%), transparent 38%), linear-gradient(180deg, rgb(2 25 16 / 10%), rgb(2 25 16 / 22%));
}

.screen--result {
  background-color: #eff5d9;
}

.screen--result.screen--active,
.screen--result.screen--visited {
  background-image: url("../assets/backgrounds/result-bg.webp");
}

.screen--result::before {
  background: linear-gradient(180deg, rgb(255 255 245 / 20%), rgb(213 232 180 / 7%));
}

.screen__inner {
  position: relative;
  z-index: 1;
  width: min(100%, 96rem);
  min-height: 100svh;
  margin: 0 auto;
}

.home-layout {
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: center;
  justify-items: center;
  padding: .45rem .9rem 1.1rem;
}

.home-brand {
  display: grid;
  place-items: center;
  align-self: start;
}

.title-board {
  position: relative;
  width: auto;
  height: clamp(270px, 43svh, 500px);
  aspect-ratio: 2 / 3;
  isolation: isolate;
}

.title-board::before {
  position: absolute;
  inset: 27% 8% 36%;
  z-index: 0;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgb(250 218 114 / 22%), transparent 68%);
  box-shadow: 0 0 1.15rem rgb(249 218 120 / 34%);
  content: "";
  pointer-events: none;
}

.title-board__image {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  transform: translateY(0);
}

.birthday-message span {
  display: block;
}

.birthday-message {
  position: absolute;
  z-index: 2;
  top: 66%;
  left: 50%;
  width: 94%;
  margin: 0;
  color: #184f34;
  font-family: "Leelawadee UI", "Noto Sans Thai", Tahoma, sans-serif;
  font-size: clamp(.7rem, 2vw, .86rem);
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  text-shadow: 0 .04rem .12rem rgb(255 255 238 / 75%);
  transform: translateX(-50%);
}

.birthday-message span:first-child {
  color: #176a36;
  font-size: 1.08em;
  font-weight: 800;
  text-shadow: 0 .04rem .12rem rgb(255 255 238 / 82%), 0 0 .65rem rgb(210 163 49 / 26%);
}

.home-object {
  position: relative;
  display: grid;
  place-items: center;
  align-self: center;
  width: min(72vw, 28rem);
  min-height: 0;
  transform: translateY(-1rem);
}

.ambient-glow,
.loading-aura {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

.ambient-glow--home {
  width: 78%;
  aspect-ratio: 1;
  background: radial-gradient(circle, rgb(255 222 122 / 38%) 0%, rgb(255 222 122 / 12%) 38%, transparent 70%);
}

.fortune-cylinder--home {
  position: relative;
  z-index: 1;
  width: auto;
  height: clamp(185px, 31svh, 340px);
  animation: gentle-float 5.5s ease-in-out infinite;
}

.home-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(100%, 28rem);
  padding-bottom: .15rem;
  transform: translateY(-1.35rem);
}

.home-instruction {
  margin: 0 0 .7rem;
  color: var(--emerald-900);
  font-size: clamp(.78rem, 2.8vw, 1rem);
  font-weight: 700;
  line-height: 1.55;
  text-align: center;
  text-shadow: 0 .05rem .2rem rgb(255 255 255 / 42%);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .7rem;
  min-width: min(100%, 20rem);
  min-height: 3.3rem;
  padding: .7rem 1.25rem .72rem;
  border: .08rem solid rgb(255 237 165 / 78%);
  border-radius: 999px;
  background: linear-gradient(135deg, #f9e6a7 0%, #d29d34 52%, #f3d57e 100%);
  box-shadow: 0 .75rem 1.35rem rgb(40 54 16 / 25%), inset 0 .08rem .12rem rgb(255 255 255 / 75%);
  color: var(--emerald-950);
  cursor: pointer;
  font-size: clamp(.9rem, 3.5vw, 1.08rem);
  font-weight: 800;
  letter-spacing: .02em;
  transition: transform .25s var(--ease-premium), box-shadow .25s var(--ease-premium), opacity .25s ease;
}

.primary-button:hover:not(:disabled) {
  box-shadow: 0 1rem 1.55rem rgb(40 54 16 / 30%), inset 0 .08rem .12rem rgb(255 255 255 / 75%);
  transform: translateY(-.18rem);
}

.primary-button:active:not(:disabled) {
  box-shadow: 0 .45rem .8rem rgb(40 54 16 / 24%), inset 0 .08rem .12rem rgb(255 255 255 / 75%);
  transform: translateY(.05rem) scale(.985);
}

.primary-button:disabled {
  cursor: wait;
  opacity: .58;
}

.button-arrow {
  display: inline-grid;
  width: 1.35rem;
  height: 1.35rem;
  place-items: center;
  border-radius: 50%;
  background: rgb(9 39 29 / 12%);
  font-size: 1rem;
  line-height: 1;
}

.error-panel {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .35rem .7rem;
  max-width: 20rem;
  margin-top: .8rem;
  padding: .55rem .8rem;
  border: .05rem solid rgb(143 61 41 / 30%);
  border-radius: .75rem;
  background: rgb(255 247 229 / 76%);
  color: #6e3d2d;
  font-size: .78rem;
  line-height: 1.45;
  text-align: center;
}

.error-panel p {
  flex-basis: 100%;
  margin: 0;
}

.text-button {
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: .2rem .45rem;
  border-radius: .4rem;
  background: transparent;
  color: #794929;
  cursor: pointer;
  font-size: .78rem;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: .15rem;
}

.loading-layout {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: .35rem;
  padding: 1.5rem 1rem;
  text-align: center;
}

.loading-visual {
  position: relative;
  display: grid;
  width: min(78vw, 24rem);
  height: min(61svh, 33rem);
  place-items: center;
}

.loading-aura {
  width: 92%;
  aspect-ratio: 1;
  background: radial-gradient(circle, rgb(251 213 108 / 30%) 0%, rgb(251 213 108 / 11%) 42%, transparent 70%);
}

.fortune-cylinder--loading {
  position: relative;
  z-index: 1;
  width: auto;
  height: min(58svh, 31rem);
}

.fortune-stick {
  position: absolute;
  z-index: 2;
  top: 12%;
  left: 68%;
  width: clamp(4rem, 16vw, 6.5rem);
  height: clamp(7rem, 28vw, 10.5rem);
  opacity: 0;
  transform: translate(-50%, 1rem) rotate(-8deg);
}

.loading-copy h1 {
  margin: 0;
  color: var(--gold-200);
  font-size: clamp(1.15rem, 4.8vw, 2rem);
  font-weight: 800;
  letter-spacing: .04em;
  text-shadow: 0 .12rem .3rem rgb(2 22 14 / 65%);
}

.loading-copy p {
  margin: .3rem 0 0;
  color: rgb(255 253 233 / 88%);
  font-size: clamp(.82rem, 3vw, 1.05rem);
  line-height: 1.5;
}

.loading-dots {
  display: inline-flex;
  gap: .35rem;
  margin-top: .8rem;
}

.loading-dots i {
  width: .38rem;
  height: .38rem;
  border-radius: 50%;
  background: var(--gold-400);
  box-shadow: 0 0 .65rem rgb(246 210 105 / 70%);
}

.result-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .65rem;
  padding: 1rem .55rem 1.4rem;
}

.result-card {
  position: relative;
  width: min(94vw, calc((100svh - 7.25rem) * 2 / 3), 39rem);
  aspect-ratio: 2 / 3;
  isolation: isolate;
}

.result-card::after {
  position: absolute;
  inset: 8% 12%;
  z-index: -1;
  border-radius: 14%;
  background: rgb(255 238 153 / 34%);
  box-shadow: 0 1.2rem 2.2rem rgb(71 97 42 / 22%);
  content: "";
}

.result-card__frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.result-card__content {
  position: absolute;
  inset: 10.5% 13.5% 10.5%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  color: var(--ink);
}

.fortune-number {
  flex: 0 0 auto;
  margin: 0 0 clamp(.45rem, 1.5vw, .9rem);
  color: var(--emerald-800);
  font-size: clamp(1.15rem, 4.5vw, 2rem);
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 .05rem .12rem rgb(255 255 255 / 70%);
}

.fortune-number__label {
  color: var(--gold-500);
  font-size: .72em;
  font-weight: 800;
}

.fortune-details {
  display: grid;
  gap: clamp(.32rem, .9vw, .65rem);
  min-height: 0;
  margin: 0;
  overflow: hidden;
}

.fortune-detail {
  min-width: 0;
}

.fortune-detail dt {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin: 0;
  color: var(--emerald-700);
  font-size: clamp(.78rem, 2.2vw, 1rem);
  font-weight: 800;
  line-height: 1.3;
}

.fortune-detail dt::before {
  flex: 0 0 auto;
  width: .42rem;
  height: .42rem;
  border-radius: 50%;
  background: var(--gold-500);
  box-shadow: 0 0 .3rem rgb(201 151 50 / 42%);
  content: "";
}

.fortune-detail dd {
  margin: .15rem 0 0;
  color: var(--ink);
  font-size: clamp(.68rem, 1.95vw, .92rem);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.result-actions {
  display: flex;
  justify-content: center;
  width: 100%;
}

.primary-button--result {
  min-width: min(78vw, 17rem);
  min-height: 2.9rem;
  font-size: .92rem;
}

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

.noscript-message {
  position: fixed;
  inset: 1rem;
  z-index: 10;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 1.5rem;
  border-radius: 1rem;
  background: var(--ivory);
  color: var(--emerald-950);
  text-align: center;
}

[hidden] {
  display: none !important;
}

@media (max-width: 959px), (orientation: portrait) {
  .home-layout {
    padding-bottom: .7rem;
  }

  .title-board {
    width: min(72vw, 43rem);
    height: auto;
  }

  .title-board::before,
  .title-board__image {
    transform: translateY(-5%);
  }

  .birthday-message {
    top: 61.5%;
    font-size: clamp(.9rem, 4vw, 1.1rem);
    line-height: 1.32;
  }

  .birthday-message span:first-child {
    font-size: 1.7em;
  }

  .home-object {
    align-self: end;
  }

  .fortune-cylinder--home {
    height: clamp(165px, 25svh, 260px);
  }

  .home-action {
    z-index: 3;
    transform: translateY(-1.5rem);
  }

  .home-action .primary-button {
    min-width: min(68vw, 20rem);
    min-height: 3.5rem;
    font-size: clamp(1rem, 4vw, 1.2rem);
  }
}

@media (min-width: 480px) {
  .home-layout {
    padding-inline: 1.5rem;
  }

  .title-board {
    height: clamp(320px, 44svh, 540px);
  }

  .result-layout {
    gap: 1rem;
    padding-inline: 1rem;
  }
}

@media (min-width: 960px) and (min-aspect-ratio: 4 / 3) {
  .home-layout {
    grid-template-columns: minmax(0, 1fr) minmax(13rem, 26rem) minmax(0, 1fr);
    grid-template-rows: 1fr;
    column-gap: clamp(.5rem, 2vw, 2rem);
    max-width: 92rem;
    padding: 1.5rem clamp(1rem, 3vw, 3rem);
  }

  .home-brand {
    grid-column: 1;
    align-self: center;
    width: 100%;
    transform: translateY(-4rem);
  }

  .title-board {
    width: min(100%, 24rem);
    height: auto;
  }

  .home-object {
    grid-column: 2;
    align-self: center;
    width: min(100%, 25rem);
    transform: translateY(-1.5rem);
  }

  .fortune-cylinder--home {
    height: min(55svh, 32rem);
  }

  .home-action {
    grid-column: 3;
    align-self: center;
    padding-bottom: 0;
    transform: translateY(-1.5rem);
  }

  .home-instruction {
    max-width: 17rem;
  }

  .result-card__content {
    inset-inline: 14.5%;
  }

  .fortune-detail dd {
    font-size: clamp(.82rem, 1.2vw, 1rem);
  }
}

@media (min-width: 1024px) and (min-aspect-ratio: 4 / 3) {
  .home-layout {
    grid-template-columns: minmax(18rem, 1fr) minmax(18rem, 27rem) minmax(18rem, 1fr);
  }

  .result-layout {
    padding-block: .75rem 1rem;
  }

  .result-card__content {
    inset: 10.5% 15.5% 10.5%;
  }

  .fortune-details {
    gap: .8rem;
  }
}

@media (max-height: 680px) and (max-width: 767px) {
  .home-layout {
    padding-top: 0;
  }

  .title-board {
    width: auto;
    height: clamp(300px, 51svh, 340px);
  }

  .birthday-message {
    top: 61.5%;
    font-size: clamp(.72rem, 3.4vw, .8rem);
    line-height: 1.24;
  }

  .birthday-message span:first-child {
    font-size: 1.45em;
  }

  .fortune-cylinder--home {
    height: 155px;
  }

  .primary-button {
    min-height: 3rem;
  }
}

@media (min-width: 600px) and (orientation: portrait) {
  .home-layout {
    padding-block: 0;
  }

  .title-board {
    width: min(65vw, 43rem);
    height: auto;
  }

  .birthday-message {
    top: 58.5%;
    font-size: clamp(1.25rem, 4vw, 2.5rem);
  }

  .fortune-cylinder--home {
    height: min(30svh, 28rem);
  }

  .home-action {
    width: min(100%, 40rem);
    transform: translateY(-1.5rem);
  }

  .home-action .primary-button {
    min-width: min(58vw, 36rem);
    min-height: clamp(4rem, 5.4svh, 5rem);
    font-size: clamp(1.15rem, 2.5vw, 1.8rem);
  }
}

@media (min-width: 600px) and (max-width: 899px) and (orientation: portrait) {
  .title-board {
    width: min(60vw, 34rem);
  }

  .birthday-message {
    font-size: clamp(1.15rem, 3.3vw, 1.9rem);
  }

  .fortune-cylinder--home {
    height: min(26svh, 24rem);
  }

  .home-action {
    transform: translateY(-1.5rem);
  }
}

@media (min-width: 768px) and (max-width: 959px) and (orientation: landscape) {
  .screen--home {
    overflow-y: hidden;
  }

  .title-board {
    width: min(55vw, 30rem);
    height: min(55svh, 25.5rem);
  }

  .title-board::before,
  .title-board__image {
    transform: translateY(-18%);
  }

  .birthday-message {
    top: 62%;
    font-size: clamp(.82rem, 1.8vw, 1rem);
    line-height: 1.28;
  }

  .birthday-message span:first-child {
    font-size: 1.45em;
  }

  .ambient-glow--home {
    width: 70%;
    transform: translateY(-.5rem);
  }

  .fortune-cylinder--home {
    height: min(25svh, 12rem);
  }
}
