@font-face {
  font-family: "FuturaBook";
  src: url("/media/fonts/futurabkbtrusbyme_book.otf") format("opentype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Kom-post";
  src: url("/media/fonts/kom-post.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  --paper: #fff8df;
  --ink: #241a18;
  --wine: #5d1313;
  --red: #b13e3e;
  --card: #944242;
  --cream: #fff9e7;
  --muted: #716460;
  --font-accent: "Kom-post", "Segoe Print", "Bradley Hand", cursive;
  --font-body: "FuturaBook", Futura, "Century Gothic", Arial, sans-serif;
  --page-gutter: clamp(1.25rem, 3.5vw, 4rem);
  --section-space: clamp(4rem, 8vw, 8.5rem);
  --radius-card: clamp(0.75rem, 1.2vw, 1.25rem);
  --card-aspect-ratio: 7 / 12;
  --shadow: 0 1.25rem 3.5rem rgb(63 18 18 / 18%);
}

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

html {
  scroll-behavior: smooth;
  background: var(--paper);
}

body {
  margin: 0;
  min-width: 18rem;
  color: var(--ink);
  background-color: var(--paper);
  background-image: url("/media/ui/paper.webp");
  font-family: var(--font-body);
  font-size: clamp(1rem, 0.32vw + 0.92rem, 1.22rem);
  line-height: 1.45;
}

button,
a {
  font: inherit;
}

button {
  color: inherit;
}

a {
  color: var(--wine);
}

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

h1,
h2 {
  margin: 0;
  color: var(--wine);
  font-family: var(--font-accent);
  font-weight: 400;
  letter-spacing: 0.08em;
  line-height: 1.08;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(2.35rem, 4.2vw, 4.8rem);
}

h2 {
  font-size: clamp(2rem, 3.6vw, 4.1rem);
}

:focus-visible {
  outline: 0.2rem solid var(--wine);
  outline-offset: 0.3rem;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  background: var(--cream);
  transform: translateY(-180%);
}

.skip-link:focus {
  transform: translateY(0);
}

.utility-nav {
  position: relative;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  max-width: 90rem;
  margin: 0 auto;
  padding: clamp(1rem, 2vw, 2rem) var(--page-gutter) 0;
}

.utility-nav a {
  min-height: 2.75rem;
  padding: 0.6rem 0.85rem;
  border-radius: 999px;
  text-underline-offset: 0.2em;
}

.utility-nav a:hover {
  text-decoration-thickness: 0.12rem;
}

/* Start page */

.home-page {
  display: grid;
  min-height: 100svh;
  padding: clamp(1rem, 3.2vw, 2rem);
  overflow-x: hidden;
}

.home-frame {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: calc(100svh - clamp(2rem, 6.4vw, 4rem));
  border: clamp(0.13rem, 0.22vw, 0.2rem) solid var(--red);
  border-radius: clamp(1.4rem, 3vw, 2.7rem);
}

.home-choice {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  padding: clamp(4.5rem, 12vh, 7.75rem) clamp(1rem, 3vw, 3rem) 1rem;
  text-align: center;
  text-decoration: none;
}

.home-choice h1,
.home-choice h2 {
  position: relative;
  z-index: 2;
  min-height: 2.2em;
  font-size: clamp(1.7rem, 2.7vw, 2.75rem);
}

.home-choice img {
  width: min(28vw, 26rem);
  margin-top: clamp(0.5rem, 2vh, 1.5rem);
  mix-blend-mode: multiply;
  transition: transform 180ms ease;
}

.home-choice:nth-child(2) img {
  width: min(29vw, 27rem);
  margin-top: clamp(-0.25rem, -1vh, -0.75rem);
}

.home-choice:hover img,
.home-choice:focus-visible img {
  transform: translateY(-0.4rem) rotate(-1deg);
}

.home-choice:nth-child(2):hover img,
.home-choice:nth-child(2):focus-visible img {
  transform: translateY(-0.4rem) rotate(1deg);
}

.home-choice:focus-visible {
  outline-offset: -0.5rem;
  border-radius: 2rem;
}

/* Library */

.library-shell {
  width: min(100%, 90rem);
  margin: 0 auto;
  padding: clamp(2.5rem, 4vw, 4.5rem) var(--page-gutter) clamp(8rem, 18vw, 18rem);
}

.library-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(19rem, 0.72fr);
  align-items: start;
  gap: clamp(3rem, 8vw, 9rem);
  min-height: clamp(35rem, 47vw, 44rem);
  padding-top: clamp(1rem, 2.5vh, 1.75rem);
}

.intro-copy {
  padding-top: clamp(1.75rem, 4vw, 4.25rem);
}

.intro-copy p {
  max-width: 39rem;
  margin: clamp(2.3rem, 4vw, 4.25rem) 0 0;
  font-size: clamp(1.05rem, 1.35vw, 1.45rem);
}

.intro-copy p + p {
  margin-top: clamp(2rem, 3.5vw, 3.5rem);
}

.deck-stack {
  position: relative;
  width: min(100%, 31.4375rem);
  aspect-ratio: 503 / 803;
  justify-self: center;
  margin-right: 0;
  transform: translateY(clamp(1rem, 3vh, 1.75rem));
}

.deck-art,
.deck-control,
.deck-minor,
.deck-work {
  position: absolute;
}

.deck-art {
  height: auto;
  pointer-events: none;
}

.deck-back-card {
  z-index: 1;
  top: 0;
  left: 16.5%;
  width: 81.31%;
}

.deck-middle-card {
  z-index: 2;
  top: 3.32%;
  left: 7.55%;
  width: 81.31%;
}

.deck-front-card {
  z-index: 3;
  top: 6.65%;
  left: 0;
  width: 80.12%;
}

.deck-illustration {
  z-index: 4;
  top: 70.28%;
  left: 10.14%;
  width: 39.56%;
}

.deck-control {
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 0;
  min-height: 3rem;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.deck-control > img:first-of-type {
  grid-area: 1 / 1;
  width: 100%;
  height: auto;
}

.deck-control-label {
  grid-area: 1 / 1;
  width: 77%;
  height: auto;
  pointer-events: none;
}

.deck-control-major {
  top: 28.14%;
  left: 10.34%;
  width: 56.86%;
}

.deck-control-court {
  top: 38.61%;
  left: 10.34%;
  width: 64.81%;
}

.deck-control-court .deck-control-label {
  width: 81.3%;
}

.deck-control:hover,
.deck-control:focus-visible,
.primary-button:hover {
  transform: translateY(-0.12rem);
}

.deck-work {
  z-index: 6;
  top: 63.8%;
  left: 43.7%;
  width: 31.81%;
  height: 13.08%;
  transform: rotate(-5deg);
  pointer-events: none;
}

.deck-work img {
  position: absolute;
  height: auto;
}

.deck-work-letter {
  top: 0;
  left: 0;
  width: 21.25%;
}

.deck-work-text {
  top: 3%;
  right: 0;
  width: 65.63%;
}

.deck-work-arrow {
  right: 3%;
  bottom: 0;
  width: 16.88%;
}

.deck-minor {
  z-index: 7;
  top: 63.3%;
  left: 12.6%;
  display: grid;
  place-items: center;
  width: 60.44%;
  transform: rotate(0deg);
}

.deck-minor > img:first-of-type {
  grid-area: 1 / 1;
  width: 100%;
  height: auto;
}

.deck-minor-label {
  grid-area: 1 / 1;
  width: 72.37%;
  height: auto;
  pointer-events: none;
}

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

.arcana-section {
  scroll-margin-top: 2rem;
  margin-top: var(--section-space);
}

.arcana-section:first-of-type {
  margin-top: 0;
}

.arcana-section h2 {
  margin-bottom: clamp(2.2rem, 4vw, 4.25rem);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: clamp(1.1rem, 2.7vw, 3rem);
}

.court-primary {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: calc((100% - 5 * clamp(1.1rem, 2.7vw, 3rem)) / 6 * 4 + 3 * clamp(1.1rem, 2.7vw, 3rem));
  margin-bottom: clamp(1.1rem, 2.7vw, 3rem);
}

.tarot-card {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: var(--card-aspect-ratio);
  padding: 0;
  overflow: hidden;
  border: 0.12rem solid transparent;
  border-radius: var(--radius-card);
  background: var(--card);
  box-shadow: none;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.tarot-card:hover,
.tarot-card:focus-visible {
  z-index: 1;
  box-shadow: 0 0.8rem 1.7rem rgb(93 19 19 / 18%);
  transform: translateY(-0.35rem);
}

.card-image,
.major-placeholder {
  width: 100%;
  height: 100%;
}

.card-image {
  object-fit: cover;
}

.major-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 12% 8%;
  color: rgb(255 248 223 / 86%);
  background: var(--card);
  font-family: var(--font-accent);
}

.placeholder-number {
  align-self: flex-start;
  font-size: clamp(0.8rem, 1.4vw, 1.5rem);
  letter-spacing: 0.08em;
}

.placeholder-name {
  font-size: clamp(0.72rem, 1.1vw, 1.2rem);
  letter-spacing: 0.04em;
  text-align: center;
  text-transform: uppercase;
}

.card-label {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 0.6rem 0.35rem;
  color: var(--cream);
  background: linear-gradient(transparent, rgb(55 12 12 / 84%));
  font-size: clamp(0.68rem, 0.85vw, 0.92rem);
  line-height: 1.2;
  text-align: center;
  opacity: 0;
  transform: translateY(20%);
  transition: opacity 160ms ease, transform 160ms ease;
}

.tarot-card:hover .card-label,
.tarot-card:focus-visible .card-label {
  opacity: 1;
  transform: translateY(0);
}

.back-to-top {
  display: grid;
  place-items: center;
  width: clamp(3.8rem, 6vw, 5.5rem);
  aspect-ratio: 1;
  margin-top: clamp(3rem, 6vw, 6rem);
  border-radius: 50%;
  color: var(--cream);
  background: var(--card);
  font-size: clamp(2rem, 3vw, 3rem);
  font-weight: 300;
  line-height: 1;
  text-decoration: none;
}

.modal-open {
  overflow: hidden;
}

.card-dialog {
  width: min(68rem, calc(100% - 2rem));
  max-height: calc(100svh - 2rem);
  padding: 0;
  overflow: auto;
  border: 0.15rem solid var(--red);
  border-radius: 1.5rem;
  color: var(--ink);
  background-color: var(--paper);
  background-image: url("/media/ui/paper.webp");
  box-shadow: var(--shadow);
}

.card-dialog::backdrop {
  background: rgb(35 12 12 / 72%);
  backdrop-filter: blur(0.15rem);
}

.dialog-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(14rem, 0.75fr) minmax(17rem, 1fr);
  align-items: center;
  gap: clamp(1.5rem, 4vw, 4.5rem);
  min-height: 34rem;
  padding: clamp(1.25rem, 4vw, 3.5rem);
}

.dialog-close {
  position: absolute;
  z-index: 2;
  top: 0.75rem;
  right: 0.75rem;
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border: 0.1rem solid var(--wine);
  border-radius: 50%;
  color: var(--wine);
  background: var(--cream);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}

.dialog-visual {
  width: min(100%, 23rem);
  aspect-ratio: var(--card-aspect-ratio);
  overflow: hidden;
  border-radius: 1rem;
  background: var(--card);
  box-shadow: 0 0.8rem 2.5rem rgb(48 15 15 / 20%);
}

.dialog-card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dialog-copy h2 {
  margin: 0.6rem 0 1.5rem;
  font-size: clamp(2rem, 4vw, 3.8rem);
}

.dialog-copy p:last-child {
  max-width: 34rem;
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.eyebrow {
  margin: 0;
  color: var(--red);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.error-message {
  max-width: 38rem;
  padding: 0.9rem 1rem;
  border: 0.1rem solid var(--red);
  border-radius: 0.75rem;
  color: var(--wine);
  background: var(--cream);
}

/* Reading */

.reading-page {
  min-height: 100svh;
  border-top: 0.25rem solid var(--red);
}

.reading-shell {
  display: grid;
  grid-template-columns: minmax(18rem, 0.9fr) minmax(24rem, 1.1fr);
  align-items: center;
  gap: clamp(3rem, 8vw, 9rem);
  width: min(100%, 78rem);
  min-height: calc(100svh - 5rem);
  margin: 0 auto;
  padding: clamp(3rem, 6vw, 6rem) var(--page-gutter);
}

.reading-copy h1 {
  margin: 0.75rem 0 2rem;
}

.reading-copy > p:not(.eyebrow, .error-message) {
  max-width: 34rem;
  margin-bottom: 2.25rem;
}

.primary-button {
  min-width: 13rem;
  padding: 0.8rem 1.5rem;
  border: 0.12rem solid var(--wine);
  color: var(--cream);
  background: var(--card);
}

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

.reading-result {
  display: grid;
  grid-template-columns: minmax(12rem, 18rem) minmax(12rem, 1fr);
  align-items: center;
  gap: clamp(1.5rem, 4vw, 3.5rem);
}

.reading-card {
  width: 100%;
  aspect-ratio: var(--card-aspect-ratio);
  perspective: 75rem;
}

.reading-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 700ms cubic-bezier(0.2, 0.7, 0.25, 1);
  transform-style: preserve-3d;
}

.reading-card.is-flipped .reading-card-inner {
  transform: rotateY(180deg);
}

.reading-card-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 0.16rem solid var(--wine);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  backface-visibility: hidden;
}

.card-back {
  background-color: var(--card);
  background-image: url("/media/ui/card-back.webp");
  background-position: center;
  background-size: cover;
}

.card-front {
  background: var(--card);
  transform: rotateY(180deg);
}

.card-front > img,
.reading-placeholder {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reading-live h2 {
  margin: 0.65rem 0 1.2rem;
  font-size: clamp(1.8rem, 3vw, 3rem);
}

.reading-live p:last-child {
  margin-bottom: 0;
}

.reading-prompt {
  color: var(--muted);
}

@media (max-width: 56rem) {
  .home-choice {
    padding-top: 5rem;
  }

  .library-intro,
  .reading-shell {
    grid-template-columns: 1fr;
  }

  .library-intro {
    min-height: auto;
    padding-top: 0;
  }

  .deck-stack {
    width: min(75vw, 24rem);
    margin-top: 2rem;
    margin-right: 0;
    transform: none;
  }

  .card-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .court-primary {
    width: 100%;
  }

  .reading-shell {
    width: min(100%, 44rem);
  }
}

@media (max-width: 40rem) {
  .home-page {
    padding: 0.75rem;
  }

  .home-frame {
    grid-template-columns: 1fr;
  }

  .home-choice {
    min-height: calc((100svh - 1.5rem) / 2);
    padding: 2.2rem 1rem 0;
  }

  .home-choice h1,
  .home-choice h2 {
    min-height: auto;
    font-size: clamp(1.5rem, 7vw, 2rem);
  }

  .home-choice img,
  .home-choice:nth-child(2) img {
    width: min(58vw, 15rem);
    max-height: 29svh;
    margin-top: 0;
    object-fit: contain;
  }

  .library-shell {
    padding-inline: 1rem;
  }

  .card-grid,
  .court-primary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
  }

  .dialog-panel {
    grid-template-columns: 1fr;
    padding: 3.75rem 1rem 1.5rem;
  }

  .dialog-visual {
    width: min(56vw, 15rem);
    margin: auto;
  }

  .reading-result {
    grid-template-columns: minmax(10rem, 14rem) 1fr;
    gap: 1.25rem;
  }
}

@media (max-width: 31rem) {
  .reading-result {
    grid-template-columns: 1fr;
  }

  .reading-card {
    width: min(64vw, 14rem);
    margin: 0 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
