@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700&family=Noto+Serif+TC:wght@500;600;700&display=swap");

:root {
  --poem-red: #da4e36;
  --poem-gold: #c49149;
  --poem-ink: #302725;
  --paper: #faf8f1;
}

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

html {
  min-width: 320px;
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
}

button,
select {
  font: inherit;
}

button {
  border: 0;
}

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

.poem-bg {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  color: var(--poem-ink);
  background: var(--paper) url("./assets/poem-bg.jpg") center / cover no-repeat;
  font-family: "Noto Sans TC", sans-serif;
}

.brand-logo {
  position: fixed;
  z-index: 40;
  top: 26px;
  left: 60px;
  width: 210px;
}

.brand-logo a,
.brand-logo picture {
  display: block;
}

.brand-logo a:focus-visible {
  outline: 2px solid #00262b;
  outline-offset: 6px;
}

.brand-logo img {
  width: 100%;
  height: auto;
}

.mingyue-menu {
  position: fixed;
  z-index: 60;
  top: 32px;
  right: 56px;
  width: 75px;
  height: 75px;
  border-radius: 999px;
  background: #fff;
  transition: width .5s ease, height .5s ease, border-radius .5s ease;
}

.mingyue-menu::before {
  position: absolute;
  z-index: 0;
  inset: 0;
  border-radius: inherit;
  background: #00262b;
  content: "";
  pointer-events: none;
  transform: translateX(5px);
  transition: inherit;
}

.mingyue-menu-toggle {
  position: absolute;
  z-index: 2;
  top: 0;
  right: -5px;
  display: flex;
  width: 75px;
  height: 75px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 0;
  padding: 0;
  color: #00262b;
  background: #fff;
  border-radius: 50%;
  cursor: pointer;
  transition: color .5s ease, background-color .5s ease;
}

.mingyue-menu-toggle:focus-visible {
  outline: 2px solid #d7a642;
  outline-offset: 4px;
}

.mingyue-menu-line {
  display: block;
  width: 28px;
  height: 3px;
  border-radius: 5px;
  background: currentColor;
  transition: opacity .5s ease, transform .5s ease;
}

.mingyue-menu-list {
  position: relative;
  z-index: 1;
  display: flex;
  margin: 0;
  padding: 57px 16px 17px 21px;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  list-style: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity .5s ease;
}

.mingyue-menu-list li {
  margin: 0;
  padding: 0;
}

.mingyue-menu-list a {
  position: relative;
  display: block;
  color: rgba(255, 255, 255, .62);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 3px;
  text-decoration: none;
  white-space: nowrap;
  transition: color .5s ease;
}

.mingyue-menu-list a img {
  position: absolute;
  top: 50%;
  left: -19px;
  width: 10px;
  height: 15px;
  opacity: 0;
  transform: translateY(-50%);
  transition: opacity .5s ease;
}

.mingyue-menu-list a:hover,
.mingyue-menu-list a:focus-visible {
  color: #fff;
  outline: none;
}

.mingyue-menu-list a:hover img,
.mingyue-menu-list a:focus-visible img {
  opacity: 1;
}

.mingyue-menu.is-open {
  width: 150px;
  height: 310px;
  border-radius: 85px;
}

.mingyue-menu.is-open .mingyue-menu-toggle {
  color: #fff;
  background: transparent;
}

.mingyue-menu.is-open .mingyue-menu-line:nth-child(1) {
  transform: translateY(10px) rotate(23deg);
}

.mingyue-menu.is-open .mingyue-menu-line:nth-child(2) {
  transform: rotate(-23deg);
}

.mingyue-menu.is-open .mingyue-menu-line:nth-child(3) {
  opacity: 0;
}

.mingyue-menu.is-open .mingyue-menu-list {
  opacity: 1;
  pointer-events: auto;
}

.poem-wrap {
  position: fixed;
  z-index: 20;
  inset: 0;
  padding-top: 190px;
}

.poem-animation {
  position: absolute;
  z-index: 29;
  bottom: -260px;
  left: 20.6%;
  width: 363px;
  height: 692px;
  opacity: 0;
  transform: translateY(100px);
}

.stack-animation-started .poem-animation {
  animation: bottle-enter 2s 2s ease forwards;
}

.poem-bottle {
  position: relative;
  z-index: 1;
  width: 363px;
  height: 692px;
}

.fortune-stick {
  position: absolute;
  top: 20px;
  left: 87px;
  width: 223px;
  height: 900px;
  opacity: 0;
  transform: scale(.4);
  transform-origin: top center;
}

.poem-container {
  position: relative;
  width: 572px;
  height: 563px;
  margin: 0 auto;
}

.poem-card,
.poem-stack-repeat {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stack-animation-finished .poem-stack-repeat {
  opacity: 0 !important;
  transform: translate(0, 0) !important;
  animation: none !important;
}

.poem-card {
  z-index: 19;
  opacity: 0;
}

.stack-animation-started .poem-card {
  animation: front-card-in .8s 2.15s ease-out forwards;
}

.poem-card-frame,
.poem-stack-repeat img {
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.poem-stack-repeats {
  position: absolute;
  inset: 0;
}

.poem-stack-repeat {
  opacity: 0;
  transform: translate(0, 0);
}

.stack-animation-started .poem-stack-repeat {
  animation:
    stack-card-in .65s var(--stack-show-delay) ease-in-out forwards,
    stack-card-out .65s var(--stack-hide-delay) ease-in-out forwards;
}

.number-picker {
  position: absolute;
  top: 133px;
  left: 50%;
  display: flex;
  height: 248px;
  align-items: center;
  overflow: hidden;
  color: #000;
  font-family: "Noto Serif TC", serif;
  font-weight: 600;
  transform: translateX(-50%);
}

.number-picker-text {
  flex: 0 0 auto;
  font-size: 39px;
  line-height: 1;
}

.number-reel {
  position: relative;
  width: 166px;
  height: 248px;
  outline: 0;
  touch-action: none;
  cursor: grab;
}

.number-reel:active {
  cursor: grabbing;
}

.number-reel:focus-visible {
  outline: 2px solid var(--poem-red);
  outline-offset: 5px;
}

.number-reel-track {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  transition: transform .5s ease;
  will-change: transform;
}

.number-option {
  display: flex;
  width: 100%;
  height: 45px;
  align-items: center;
  justify-content: center;
  border: 0;
  padding: 0;
  color: #000;
  background: transparent;
  font-family: inherit;
  font-size: 36px;
  line-height: 40px;
  opacity: .28;
  transform: scale(.7);
  transition: opacity .3s, transform .3s;
  cursor: pointer;
}

.number-option.is-active {
  opacity: 1;
  transform: scale(1);
}

.number-reel-gradient {
  position: absolute;
  z-index: 3;
  left: 0;
  width: 100%;
  height: 100px;
  pointer-events: none;
  background: linear-gradient(to bottom, #fff 0%, #fff 20%, rgb(255 255 255 / .8) 50%, rgb(255 255 255 / .7) 80%, transparent);
}

.number-reel-gradient-top {
  top: 0;
}

.number-reel-gradient-bottom {
  bottom: 0;
  transform: rotateX(180deg);
}

.number-reel-line {
  position: absolute;
  z-index: 4;
  bottom: 100px;
  left: 50%;
  width: 131px;
  max-width: none;
  transform: translateX(-50%);
  pointer-events: none;
}

.number-select {
  display: none;
}

.draw-button {
  position: absolute;
  bottom: 99px;
  left: 223px;
  width: 134px;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transition: opacity .3s, transform .15s;
}

.draw-button:hover:not(:disabled) {
  opacity: .6;
}

.draw-button:active:not(:disabled) {
  transform: scale(.97);
}

.draw-button:focus-visible,
.detail-back:focus-visible {
  outline: 2px solid var(--poem-red);
  outline-offset: 5px;
}

.draw-button:disabled {
  cursor: wait;
  opacity: .45;
}

.poem-detail-backdrop,
.poem-detail-curtain,
.poem-detail {
  position: fixed;
  inset: 0;
}

.poem-detail-backdrop {
  z-index: 97;
  opacity: 0;
  pointer-events: none;
  background: rgb(255 255 255 / 0);
  backdrop-filter: blur(7px);
}

.poem-detail-curtain {
  z-index: 98;
  background: var(--paper) url("./assets/poem-bg.jpg") center / cover no-repeat;
  box-shadow: 20px 0 50px 20px rgb(0 0 0 / .2);
  transform: translateX(-120%);
  pointer-events: none;
}

.poem-detail {
  z-index: 99;
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
  background: var(--paper) url("./assets/poem-bg.jpg") center / cover no-repeat;
  pointer-events: none;
  transition: opacity .5s, visibility .5s;
}

.poem-detail.is-show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.poem-detail-inner {
  position: relative;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 130px 100px 180px;
  writing-mode: vertical-lr;
  scrollbar-color: rgb(218 78 54 / .55) transparent;
  scrollbar-width: thin;
}

.poem-number {
  margin: 0;
  font-size: 0;
}

.poem-number span {
  position: relative;
  display: inline-block;
  width: 74px;
  height: 74px;
  margin-bottom: 5px;
  border: 3px solid var(--poem-red);
  border-radius: 50%;
  padding: 0px 0 0 7px;
  color: var(--poem-red);
  font-size: 54px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}

.poem-number span::after {
  content: "";
  position: absolute;
  inset: -6px;
  background: url("./assets/poem-title-deco.svg") center / 100% 100% no-repeat;
}

.poem-result {
  margin-left: 100px;
}

.poem-result-heading {
  position: relative;
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.poem-result-heading h2 {
  margin: 0;
  color: #000;
  font-family: "Noto Serif TC", serif;
  font-size: 60px;
  font-weight: 700;
  letter-spacing: 6px;
  line-height: 1;
}

.title-deco {
  position: absolute;
  right: -9px;
  width: 32px;
  height: 32px;
}

.title-deco-start {
  top: 36px;
}

.title-deco-end {
  top: 100px;
}

.poem-verse {
  margin: 0 0 0 60px;
  color: var(--poem-ink);
  font-family: "Noto Serif TC", serif;
  font-size: 35px;
  font-weight: 500;
  letter-spacing: 6px;
  line-height: 2;
  white-space: pre-line;
}

.poem-explanations {
  margin: 0 0 0 120px;
  padding: 0;
  list-style: none;
}

.poem-explanations li {
  margin-right: 78px;
}

.poem-explanations li:last-child {
  margin-right: 0;
}

.explanation-title {
  display: inline-block;
  border-right: 2px solid var(--poem-red);
  padding-right: 10px;
  color: var(--poem-red);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 2px;
}

.explanation-content {
  margin-left: 20px;
  color: #000;
  font-size: 16px;
  letter-spacing: 2px;
  line-height: 2;
  white-space: pre-line;
}

.detail-ink {
  position: absolute;
  bottom: 60px;
  left: 100px;
  width: 73px;
  height: 122px;
}

.detail-back {
  z-index: 4;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transition: opacity .3s, transform .15s;
}

.detail-back:hover {
  opacity: .6;
}

.detail-back:active {
  scale: .97;
}

.detail-back-desktop {
  position: absolute;
  bottom: -80px;
  left: 50%;
  transform: translateX(-50%);
}

.detail-back-mobile {
  display: none;
}

.poem-status {
  position: fixed;
  z-index: 120;
  bottom: 22px;
  left: 50%;
  margin: 0;
  color: var(--poem-red);
  font-size: 14px;
  letter-spacing: .08em;
  transform: translateX(-50%);
}

.poem-status:empty {
  display: none;
}

.poem-bg.is-drawing .poem-animation {
  animation: none;
  opacity: 1;
  transform: translateY(0);
}

.poem-bg.is-drawing .fortune-stick {
  animation: stick-draw-desktop 1.67s ease forwards;
}

.poem-bg.is-drawing .poem-detail-backdrop {
  animation: backdrop-in .55s 1.67s ease forwards;
}

.poem-bg.is-drawing .poem-detail-curtain {
  animation: curtain-in-desktop 1.12s 1.67s cubic-bezier(.22, 1, .36, 1) forwards;
}

.poem-bg.is-drawing .poem-bottle,
.poem-bg.is-drawing .poem-container {
  animation: scene-out-desktop 1.12s 1.67s cubic-bezier(.22, 1, .36, 1) forwards;
}

@keyframes bottle-enter {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes stack-card-in {
  from {
    opacity: 0;
    transform: translate(0, 0);
  }

  to {
    opacity: 1;
    transform: translate(
      calc(-12px * var(--stack-index)),
      calc(16px * var(--stack-index))
    );
  }
}

@keyframes stack-card-out {
  from {
    opacity: 1;
    transform: translate(
      calc(-12px * var(--stack-index)),
      calc(16px * var(--stack-index))
    );
  }

  to {
    opacity: 0;
    transform: translate(0, 0);
  }
}

@keyframes front-card-in {
  from {
    opacity: 0;
    transform: translate(22px, -16px);
  }

  to {
    opacity: 1;
    transform: translate(0, 0);
  }
}

@keyframes stick-draw-desktop {
  0% {
    top: 20px;
    left: 87px;
    opacity: 0;
    transform: scale(.4);
  }
  33% {
    top: -140px;
    left: 63px;
    opacity: 1;
    transform: scale(.4);
  }
  100% {
    top: -439px;
    left: -434px;
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes backdrop-in {
  to {
    opacity: 1;
  }
}

@keyframes curtain-in-desktop {
  to {
    transform: translateX(0);
  }
}

@keyframes scene-out-desktop {
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

@media (max-width: 1599px) and (min-width: 1025px) {
  .poem-animation {
    left: 5.4%;
  }
}

@media (max-width: 1200px) {
  .mingyue-menu,
  .mingyue-menu.is-open {
    top: 24px;
    right: 32px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
  }

  .mingyue-menu::before {
    transform: translateX(4px);
  }

  .mingyue-menu-toggle {
    position: fixed;
    z-index: 2;
    top: 24px;
    right: 28px;
    width: 30px;
    height: 30px;
    gap: 3px;
  }

  .mingyue-menu-line {
    width: 11px;
    height: 2px;
  }

  .mingyue-menu-list {
    position: fixed;
    z-index: 1;
    inset: 0;
    min-width: 320px;
    height: 100vh;
    height: 100dvh;
    padding: 64px 24px 30px;
    justify-content: center;
    gap: 29px;
    overflow-y: auto;
    background: #00262b;
  }

  .mingyue-menu-list a {
    font-size: 24px;
  }

  .mingyue-menu.is-open .mingyue-menu-toggle {
    color: #00262b;
    background: #fff;
  }

  .mingyue-menu.is-open .mingyue-menu-line:nth-child(1) {
    transform: translateY(5px) rotate(44deg);
  }

  .mingyue-menu.is-open .mingyue-menu-line:nth-child(2) {
    transform: rotate(-44deg);
  }
}

@media (max-width: 1024px) {
  .brand-logo {
    top: 17px;
    left: 20px;
    width: 105px;
  }

  .poem-wrap {
    height: 100vh;
    height: 100dvh;
    padding-top: 230px;
  }

  .poem-animation {
    bottom: 0;
    left: -10.6%;
    width: 225px;
    height: 280px;
  }

  .poem-bottle {
    width: 147px;
    height: 280px;
  }

  .fortune-stick {
    top: 20px;
    left: 35px;
    width: 90px;
    height: 363px;
  }

  .poem-container {
    width: 315px;
    height: 310px;
  }

  .number-picker {
    top: 120px;
    width: 100%;
    height: auto;
    justify-content: center;
  }

  .number-picker-text {
    font-size: 21px;
  }

  .number-reel {
    display: none;
  }

  .number-select {
    display: block;
    width: 120px;
    height: 38px;
    margin: 0;
    border: 1px solid var(--poem-gold);
    border-radius: 999px;
    padding: 0 15px 0 12px;
    color: #000;
    background: #fff;
    font-family: "Noto Serif TC", serif;
    font-size: 21px;
    font-weight: 600;
    line-height: 1;
    text-align: center;
    text-align-last: center;
    appearance: auto;
    cursor: pointer;
  }

  .draw-button {
    bottom: 50px;
    left: 92px;
  }

  .poem-detail-curtain {
    transform: translateY(-120%);
  }

  .poem-detail-inner {
    overflow-x: hidden;
    overflow-y: auto;
    padding: 130px 30px 160px;
    writing-mode: horizontal-tb;
  }

  .poem-number {
    display: table;
    margin: 0 auto 60px;
    writing-mode: horizontal-tb;
  }

  .poem-number span {
    width: 50px;
    height: 50px;
    margin: 0 2px;
    padding: 4px 0 0 0px;
    font-size: 32px;
  }

  .poem-result {
    margin: 0 0 60px;
  }

  .poem-result-heading {
    display: block;
    margin-bottom: 35px;
    text-align: center;
  }

  .poem-result-heading h2 {
    display: inline-block;
    margin-bottom: 20px;
    font-size: 38px;
    line-height: 1.2;
  }

  .title-deco {
    top: 25px;
    z-index: -1;
  }

  .title-deco-start {
    right: calc(50% + 20px);
  }

  .title-deco-end {
    right: calc(50% - 45px);
  }

  .poem-verse {
    margin: 0;
    font-size: 20px;
    line-height: 2;
    text-align: center;
  }

  .poem-explanations {
    margin-left: 0;
  }

  .poem-explanations li {
    margin: 0 0 53px;
  }

  .explanation-title {
    position: relative;
    margin-bottom: 19px;
    border: 0;
    padding: 0;
    font-size: 18px;
  }

  .explanation-content {
    margin-left: 0;
    font-size: 14px;
    line-height: 2;
  }

  .detail-ink,
  .detail-back-desktop {
    display: none;
  }

  .detail-back-mobile {
    display: block;
    margin: 40px auto 0;
  }

  .poem-bg.is-drawing .fortune-stick {
    animation-name: stick-draw-mobile;
  }

  .poem-bg.is-drawing .poem-detail-curtain {
    animation-name: curtain-in-mobile;
  }

  .poem-bg.is-drawing .poem-bottle,
  .poem-bg.is-drawing .poem-container {
    animation-name: scene-out-mobile;
  }

  @keyframes stick-draw-mobile {
    0% {
      top: 20px;
      left: 35px;
      opacity: 0;
      transform: scale(.4);
    }
    33% {
      top: -140px;
      left: 63px;
      opacity: 1;
      transform: scale(.4);
    }
    100% {
      top: -280px;
      left: calc(50vw - 31px);
      opacity: 1;
      transform: scale(.7);
    }
  }

  @keyframes curtain-in-mobile {
    to {
      transform: translateY(0);
    }
  }

  @keyframes scene-out-mobile {
    to {
      opacity: 0;
      transform: translateY(100%);
    }
  }
}

@media (max-width: 639px) {
  .mingyue-menu,
  .mingyue-menu.is-open {
    right: 20px;
  }

  .mingyue-menu-toggle {
    right: 16px;
  }

  .mingyue-menu-list {
    gap: clamp(16px, 3.5vh, 29px);
  }

  .mingyue-menu-list a {
    font-size: 20px;
  }

  .poem-animation {
    left: -15.6%;
  }

  .poem-status {
    bottom: 14px;
    width: calc(100% - 32px);
    text-align: center;
  }

  .poem-detail-inner {
    padding: 93px 30px 180px;
  }
}

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