:root {
  --paper: #eadfca;
  --paper-light: #f5eddd;
  --paper-shadow: #cbbca2;
  --ink: #251c17;
  --ink-soft: #6c5c4d;
  --gold: #ad7c2e;
  --gold-light: #e8c86e;
  --wine: #4b1730;
  --green: #294c34;
  --card-ratio: 0.5614;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -20%, #51483f, transparent 38rem),
    #171310;
  font-family: Georgia, "Times New Roman", serif;
}

button {
  font: inherit;
}

.page {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0;
}

.oracle-table {
  position: relative;
  isolation: isolate;
  height: min(760px, calc(100dvh - 36px));
  min-height: 610px;
  overflow: hidden;
  border: 1px solid rgba(255, 247, 222, 0.72);
  border-radius: 34px;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(255, 255, 255, 0.5), transparent 55%),
    repeating-radial-gradient(ellipse at 20% 30%, transparent 0 9px, rgba(75, 51, 32, 0.025) 10px 11px),
    linear-gradient(145deg, var(--paper-light), var(--paper) 65%, #d8c8ad);
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.52),
    inset 0 0 75px rgba(98, 71, 41, 0.17),
    inset 0 0 0 8px rgba(255, 255, 255, 0.23);
}

.table-border {
  position: absolute;
  inset: 16px;
  z-index: -1;
  border: 1px solid rgba(102, 72, 35, 0.25);
  border-radius: 23px;
  pointer-events: none;
}

.table-title {
  position: relative;
  z-index: 5;
  width: min(780px, calc(100% - 60px));
  margin: 0 auto;
  padding: clamp(31px, 5vh, 51px) 0 5px;
  font-size: clamp(1.65rem, 3.3vw, 3rem);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.025em;
  text-align: center;
  text-wrap: balance;
}

.draw-view {
  display: grid;
  grid-template-rows: 1fr auto;
  height: calc(100% - clamp(100px, 14vh, 135px));
  padding: 0 28px 50px;
  text-align: center;
}

.card-stage {
  position: relative;
  min-height: 350px;
  perspective: 1200px;
}

.deck-stack {
  position: absolute;
  top: 47%;
  left: 50%;
  width: clamp(118px, 12vw, 142px);
  aspect-ratio: var(--card-ratio);
  transform: translate(-50%, -50%);
}

.stack-card {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 2px solid rgba(255, 237, 184, 0.75);
  border-radius: 9px;
  background: #24101c;
  box-shadow: 0 13px 28px rgba(37, 25, 18, 0.35);
  transform: translate(var(--sx), var(--sy)) rotate(var(--sr));
  transition: transform 0.4s cubic-bezier(0.3, 0.8, 0.25, 1);
}

.deck-stack.shuffle-one .stack-card:nth-child(1),
.deck-stack.shuffle-one .stack-card:nth-child(4) { transform: translate(-76px, 4px) rotate(-13deg); }
.deck-stack.shuffle-one .stack-card:nth-child(2),
.deck-stack.shuffle-one .stack-card:nth-child(6) { transform: translate(72px, -5px) rotate(12deg); }
.deck-stack.shuffle-one .stack-card:nth-child(3) { transform: translate(-38px, -10px) rotate(-6deg); }
.deck-stack.shuffle-one .stack-card:nth-child(5),
.deck-stack.shuffle-one .stack-card:nth-child(7) { transform: translate(39px, 11px) rotate(7deg); }

.deck-stack.shuffle-two .stack-card:nth-child(odd) { transform: translate(53px, -2px) rotate(9deg); }
.deck-stack.shuffle-two .stack-card:nth-child(even) { transform: translate(-53px, 3px) rotate(-9deg); }

.back-art {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 5px solid #e8dab3;
  border-radius: 7px;
  background:
    radial-gradient(circle at 50% 50%, #edc760 0 2.8%, transparent 3.2%),
    radial-gradient(circle at 50% 50%, transparent 0 20%, rgba(232, 197, 103, 0.88) 20.5% 21.2%, transparent 21.8%),
    conic-gradient(from 45deg at 50% 50%, transparent 0 11%, rgba(222, 177, 75, 0.56) 12% 13%, transparent 14% 36%, rgba(222, 177, 75, 0.56) 37% 38%, transparent 39% 61%, rgba(222, 177, 75, 0.56) 62% 63%, transparent 64% 86%, rgba(222, 177, 75, 0.56) 87% 88%, transparent 89%),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.03) 0 2px, transparent 2px 7px),
    var(--wine);
  background-position: center;
  background-size: cover;
}

.back-art::before {
  position: absolute;
  inset: 8px;
  content: "";
  border: 1px solid rgba(242, 207, 122, 0.9);
  border-radius: 2px;
  box-shadow: inset 0 0 0 4px rgba(41, 76, 52, 0.62);
}

.back-art::after {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  width: 41%;
  aspect-ratio: 1;
  content: "✦";
  border: 1px solid var(--gold-light);
  color: var(--gold-light);
  background: rgba(41, 76, 52, 0.96);
  place-items: center;
  transform: translate(-50%, -50%) rotate(45deg);
  box-shadow: 0 0 0 5px rgba(225, 182, 80, 0.14);
}

.back-art.has-image {
  border-width: 0;
  background-repeat: no-repeat;
  background-color: #17100f;
  background-size: contain;
}

.back-art.has-image::before,
.back-art.has-image::after {
  display: none;
}

.card-fan {
  position: absolute;
  inset: 0;
}

.draw-card {
  position: absolute;
  top: 47%;
  left: 50%;
  width: clamp(91px, 9.5vw, 118px);
  aspect-ratio: var(--card-ratio);
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(110, 72, 34, 0.5);
  border-radius: 9px;
  background: #24101c;
  box-shadow: 0 14px 25px rgba(48, 34, 24, 0.33);
  cursor: pointer;
  opacity: 0;
  transform: translate(-50%, -50%) translate(0, 10px) scale(0.8);
  animation: deal-card 0.52s cubic-bezier(0.18, 0.78, 0.28, 1) forwards;
  animation-delay: var(--delay);
  transition: filter 0.2s ease;
}

.draw-card:hover,
.draw-card:focus-visible {
  z-index: 20;
  filter: brightness(1.14);
  outline: 3px solid var(--gold);
  outline-offset: 4px;
}

.draw-card.is-selected {
  z-index: 30;
  opacity: 1;
  transform: translate(-50%, -50%) translate(0, -12px) rotate(0) scale(1.12);
  transition: transform 0.42s ease, opacity 0.35s ease;
}

.draw-card.is-dismissed {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.draw-controls {
  position: relative;
  z-index: 40;
  display: flex;
  min-height: 88px;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.gold-button {
  min-width: 225px;
  min-height: 49px;
  padding: 13px 21px;
  border: 1px solid #8a5f22;
  border-radius: 999px;
  color: #fff8e8;
  background: linear-gradient(180deg, #9a6d2a, #694514);
  box-shadow: 0 9px 22px rgba(66, 45, 28, 0.26);
  cursor: pointer;
  font-family: "Trebuchet MS", Arial, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.gold-button span {
  margin: 0 7px;
}

.gold-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 13px 27px rgba(66, 45, 28, 0.34);
}

.gold-button:focus-visible,
.text-button:focus-visible {
  outline: 3px solid #694514;
  outline-offset: 4px;
}

.gold-button:disabled {
  cursor: wait;
  opacity: 0.64;
}

.choose-hint {
  margin: 4px 0 0;
  color: #65451d;
  font-size: 0.9rem;
  font-style: italic;
}

.status {
  min-height: 1rem;
  margin: 9px 0 0;
  color: rgba(68, 53, 39, 0.62);
  font-size: 0.7rem;
  line-height: 1.4;
}

.result-view {
  display: grid;
  grid-template-columns: minmax(220px, 310px) minmax(320px, 530px);
  gap: clamp(44px, 7vw, 90px);
  align-items: center;
  justify-content: center;
  height: calc(100% - clamp(100px, 14vh, 135px));
  padding: 15px 70px 43px;
}

.reveal-column {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.stage-label {
  margin: 0;
  color: #7c5b26;
  font-family: "Trebuchet MS", Arial, sans-serif;
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.reveal-wrap {
  width: min(100%, 245px);
  perspective: 1400px;
}

.reveal-card {
  position: relative;
  width: 100%;
  aspect-ratio: var(--card-ratio);
  filter: drop-shadow(0 21px 24px rgba(55, 38, 24, 0.34));
}

.reveal-card.is-flipped {
  animation: reveal-turn 0.8s cubic-bezier(0.2, 0.76, 0.24, 1) forwards;
}

.reveal-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 12px;
  background: #17100f;
  opacity: 1;
}

.reveal-back {
  z-index: 2;
}

.reveal-front {
  z-index: 1;
  display: grid;
  opacity: 0;
  background: #e6cf91;
  place-items: center;
}

.reveal-card.is-flipped .reveal-back {
  animation: hide-card-back 0.8s linear forwards;
}

.reveal-card.is-flipped .reveal-front {
  animation: show-card-front 0.8s linear forwards;
}

.reveal-front img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.reading {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.55s ease, transform 0.55s ease;
}

.reading.is-visible {
  opacity: 1;
  transform: none;
}

.reading-rule {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 145px;
  margin-bottom: 17px;
  color: var(--gold);
}

.reading-rule::before,
.reading-rule::after {
  flex: 1;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, var(--gold));
}

.reading-rule::after {
  background: linear-gradient(90deg, var(--gold), transparent);
}

.reading h2 {
  margin: 0;
  color: #4c3014;
  font-size: clamp(1.9rem, 4vw, 3.5rem);
  font-weight: 400;
  line-height: 1;
  text-wrap: balance;
}

.appears {
  margin: 12px 0 16px;
  color: var(--ink);
  font-style: italic;
}

.meaning {
  max-width: 500px;
  color: var(--ink-soft);
  font-size: 0.96rem;
  line-height: 1.7;
}

.meaning p {
  margin: 0 0 10px;
  text-wrap: pretty;
}

.text-button {
  margin-top: 12px;
  padding: 9px 0;
  border: 0;
  border-bottom: 1px solid rgba(112, 75, 29, 0.55);
  color: #6f4a1b;
  background: transparent;
  cursor: pointer;
  font-family: "Trebuchet MS", Arial, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.noscript {
  margin: 0;
  padding: 14px;
  color: white;
  background: #6e1c34;
  text-align: center;
}

[hidden] {
  display: none !important;
}

@keyframes deal-card {
  to {
    opacity: 1;
    transform: translate(-50%, -50%) translate(var(--x), var(--y)) rotate(var(--rotation));
  }
}

@keyframes reveal-turn {
  0% { transform: rotateY(0deg) scale(1); }
  49% { transform: rotateY(88deg) scale(0.97); }
  50% { transform: rotateY(-88deg) scale(0.97); }
  100% { transform: rotateY(0deg) scale(1); }
}

@keyframes hide-card-back {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes show-card-front {
  0%, 49% { opacity: 0; }
  50%, 100% { opacity: 1; }
}

@media (max-width: 720px) {
  .page {
    width: calc(100% - 18px);
    padding: 9px 0;
  }

  .oracle-table {
    height: calc(100dvh - 18px);
    min-height: 650px;
    border-radius: 23px;
  }

  .table-title {
    width: calc(100% - 40px);
    padding-top: 28px;
    font-size: clamp(1.55rem, 7vw, 2.15rem);
  }

  .draw-view {
    height: calc(100% - 108px);
    padding: 0 8px 48px;
  }

  .deck-stack {
    width: 116px;
  }

  .draw-card {
    width: 82px;
  }

  .draw-controls {
    min-height: 84px;
  }

  .result-view {
    grid-template-columns: 1fr;
    gap: 22px;
    align-content: start;
    height: calc(100% - 120px);
    overflow-y: auto;
    padding: 16px 23px 38px;
    text-align: center;
  }

  .oracle-table.showing-result .table-title {
    display: none;
  }

  .oracle-table.showing-result .result-view {
    height: 100%;
    padding-top: 28px;
    padding-bottom: 58px;
  }

  .reveal-wrap {
    width: min(48vw, 195px);
  }

  .reading-rule {
    margin-right: auto;
    margin-left: auto;
  }

  .meaning {
    margin: 0 auto;
  }

  .text-button {
    display: inline-flex;
    min-height: 46px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin: 22px auto 34px;
    padding: 12px 19px;
    border: 1px solid rgba(111, 74, 27, 0.8);
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(255, 251, 236, 0.94), rgba(225, 204, 160, 0.72));
    box-shadow: 0 7px 18px rgba(78, 48, 17, 0.16);
    font-size: 0.72rem;
  }
}

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