:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Center when it fits; when content is taller than the viewport, "safe" aligns
     to the top instead of clipping the top off-screen, and the page scrolls. */
  justify-content: safe center;
  padding: 1rem 1rem 3rem;
  background: radial-gradient(circle at 50% 20%, #2b1a4a 0%, #0f0a1e 70%);
  color: #f3ecff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: center;
}

main {
  width: 100%;
  max-width: 46rem;
}

h1 {
  font-size: clamp(1.5rem, 6vw, 2.5rem);
  margin: 0 0 0.4rem;
}

.subtitle {
  font-size: clamp(1rem, 3.5vw, 1.25rem);
  opacity: 0.85;
  margin: 0.4rem 0;
}

.status {
  font-size: 0.95rem;
  opacity: 0.6;
}

.build {
  font-size: 0.8rem;
  opacity: 0.4;
  margin-top: 1.25rem;
}

#lang-switch {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.35rem;
}

.lang {
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

/* The switcher is a link per language (the active one is a plain span), so the
   anchors need the browser's link styling removed. */
a.lang {
  text-decoration: none;
  color: inherit;
}

span.lang {
  cursor: default;
}

.lang:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.lang.active {
  opacity: 1;
  border-color: #b48bf0;
  background: rgba(180, 139, 240, 0.18);
}

button#draw {
  margin: 1rem 0 0.5rem;
  padding: 0.75rem 2rem;
  font-size: 1.1rem;
  font-family: inherit;
  color: #f3ecff;
  background: linear-gradient(135deg, #6d4bd6, #a06be0);
  border: 1px solid #b48bf0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  box-shadow: 0 0 18px rgba(160, 107, 224, 0.4);
}

button#draw:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 0 28px rgba(160, 107, 224, 0.7);
}

button#draw:disabled {
  cursor: progress;
  opacity: 0.65;
}

#result {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.reading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.card-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Interpretation panel — appears to the right of the card on wide screens,
   below it on narrow ones. Hidden until a reading exists. */
.interpretation {
  text-align: left;
  max-width: 24rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(180, 139, 240, 0.25);
  border-radius: 12px;
  padding: 1rem 1.15rem;
}

#result:not(.has-reading) .interpretation {
  display: none;
}

.interp-heading {
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.7;
  margin: 0 0 0.5rem;
}

.interp-text {
  margin: 0;
  line-height: 1.55;
  font-size: clamp(0.95rem, 2.6vw, 1.05rem);
}

.interp-text.loading {
  opacity: 0.6;
  font-style: italic;
}

.listen {
  margin-top: 0.85rem;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: #f3ecff;
  background: rgba(180, 139, 240, 0.16);
  border: 1px solid rgba(180, 139, 240, 0.5);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.listen:hover:not(:disabled) {
  background: rgba(180, 139, 240, 0.3);
}

.listen:disabled {
  cursor: progress;
  opacity: 0.6;
}

.listen.playing {
  background: rgba(180, 139, 240, 0.4);
  border-color: #b48bf0;
}

@media (min-width: 620px) {
  .reading {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
  }
  .card-col {
    flex: 0 0 auto;
  }
  .interpretation {
    flex: 0 1 20rem;
  }
}

.card-frame {
  /* Sized by the SMALLER of a height budget and a width budget, so the whole
     card always fits: never taller than 52% of the viewport, never wider than
     74vw (the third term bounds the derived width), never past its natural size.
     The vh line is a fallback for engines without dvh. */
  aspect-ratio: 300 / 524;
  /* Height budget = viewport minus the fixed chrome (title, button, the three
     description lines, marker, paddings ≈ 22rem), also bounded by a width budget
     (third term) and a natural max — so the card + description fit together on
     screen. A 150px floor keeps the card usable on very short viewports; below
     that the page scrolls gracefully (safe-center) rather than clipping. */
  height: max(150px, min(420px, 100vh - 22rem, 74vw * 524 / 300));
  height: max(150px, min(420px, 100dvh - 22rem, 74vw * 524 / 300));
  width: auto;
  max-width: 74vw;
  margin: 0 auto 0.75rem;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, #2a1c48, #3d2a63);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

.card-img {
  width: 100%;
  height: 100%;
  object-fit: contain; /* show the full card face — never crop the art */
  display: block;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.4s ease;
}

.card-name {
  font-size: clamp(1.4rem, 6vw, 2.4rem);
  font-weight: 700;
  line-height: 1.05;
  margin: 0;
  color: #e9d8ff;
  text-shadow: 0 0 20px rgba(180, 139, 240, 0.6);
  overflow-wrap: break-word;
}

.card-number {
  font-size: 1rem;
  letter-spacing: 0.08em;
  opacity: 0.6;
  margin: 0.4rem 0 0;
  text-transform: uppercase;
}

.card-orientation {
  font-size: clamp(1rem, 4vw, 1.35rem);
  letter-spacing: 0.04em;
  margin: 0.5rem 0 0;
  opacity: 0.9;
  text-transform: uppercase;
}

/* Anticipation: dim and pulse while the cards are "consulted".
   The image hides (falls back to its base opacity:0), leaving the frame's
   placeholder gradient pulsing. */
#result.suspense .card-frame {
  animation: pulse 0.9s ease-in-out infinite alternate;
}

#result.suspense .card-name {
  opacity: 0.55;
  animation: pulse 0.6s ease-in-out infinite alternate;
}

#result.suspense .card-orientation {
  opacity: 0.6;
  font-style: italic;
  text-transform: none;
}

@keyframes pulse {
  from { opacity: 0.35; transform: scale(0.97); }
  to   { opacity: 0.75; transform: scale(1.03); }
}

/* Reveal: settle in with a soft pop. */
#result.revealed .card-img {
  opacity: 1;
}

#result.revealed .card-frame {
  animation: reveal 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

#result.revealed .card-name {
  animation: reveal 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes reveal {
  from { opacity: 0; transform: scale(0.6) rotate(-6deg); }
  to   { opacity: 1; transform: scale(1) rotate(0); }
}

/* The "direction": an upside-down draw flips the card image 180°. */
#result.revealed.reversed .card-img {
  transform: rotate(180deg);
}

/* Very short viewports (e.g. landscape phones): trim non-essential chrome so the
   card and its description still fit together on one screen. */
@media (max-height: 480px) {
  h1 { font-size: 1.4rem; margin-bottom: 0.15rem; }
  .subtitle { display: none; }
  button#draw { margin: 0.5rem 0; padding: 0.5rem 1.5rem; }
  .card-name { font-size: 1.3rem; }
  .card-number { margin-top: 0.2rem; }
  .card-orientation { font-size: 0.95rem; margin-top: 0.25rem; }
  .build { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #result.suspense .card-frame,
  #result.suspense .card-name,
  #result.revealed .card-frame,
  #result.revealed .card-name,
  button#draw {
    animation: none;
    transition: none;
  }
  /* Keep the reversal readable without the spin transition. */
  .card-img {
    transition: opacity 0.3s ease;
  }
}

/* Collapsed about/FAQ block. Closed by default so it stays out of the way, but
   it is real content in the DOM — accordion text is indexed at full weight,
   unlike CSS-hidden copy, which is a spam-policy violation. */
.about {
  margin: 2.5rem auto 0;
  max-width: 42rem;
  text-align: left;
  border-top: 1px solid rgba(180, 139, 240, 0.25);
  padding-top: 1rem;
}

.about > summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.95rem;
  opacity: 0.7;
  text-align: center;
  padding: 0.4rem;
  border-radius: 8px;
}

.about > summary::-webkit-details-marker {
  display: none;
}

.about > summary::after {
  content: " ▾";
  opacity: 0.7;
}

.about[open] > summary::after {
  content: " ▴";
}

.about > summary:hover {
  opacity: 1;
}

.about-body {
  font-size: 0.95rem;
  line-height: 1.65;
  opacity: 0.82;
}

.about-body p {
  margin: 0.8rem 0;
}

.faq-heading {
  font-size: 1.05rem;
  margin: 1.6rem 0 0.6rem;
  opacity: 0.95;
}

.faq-q {
  font-size: 0.95rem;
  margin: 1.1rem 0 0.2rem;
  color: #c4a5ff;
}

.faq-a {
  margin: 0.2rem 0 0;
}

/* Link from the draw page into the card reference. Without a real internal
   link the 234 card pages would be orphans, reachable only via the sitemap. */
.cta--index {
  margin-top: 2rem;
}

.cta--index a {
  color: #c4a5ff;
  text-decoration: none;
  font-size: 0.95rem;
  border-bottom: 1px solid rgba(196, 165, 255, 0.4);
  padding-bottom: 2px;
}

.cta--index a:hover {
  color: #f3ecff;
  border-bottom-color: #f3ecff;
}
