/* ============================================================
   Arcana Praxis · theme variables, mystical chrome, card magic
   ============================================================ */

:root,
html[data-theme="dark"] {
  --bg: #0d0a1a;
  --bg-panel: rgba(30, 22, 54, 0.62);
  --bg-field: rgba(13, 10, 26, 0.65);
  --border: rgba(212, 175, 55, 0.28);
  --border-soft: rgba(212, 175, 55, 0.14);
  --text: #e8e2f5;
  --text-dim: #a99cc7;
  --gold: #d4af37;
  --gold-bright: #f3d47a;
  --card-back-a: #2a1b4d;
  --card-back-b: #170f30;
  --shadow-glow: 0 0 24px rgba(212, 175, 55, 0.22);
  --nebula-opacity: 1;
}

html[data-theme="light"] {
  --bg: #f4eee2;
  --bg-panel: rgba(255, 252, 244, 0.82);
  --bg-field: rgba(255, 255, 255, 0.85);
  --border: rgba(122, 90, 12, 0.35);
  --border-soft: rgba(122, 90, 12, 0.16);
  --text: #2c2138;
  --text-dim: #6f6284;
  --gold: #9a7414;
  --gold-bright: #7a5a0c;
  --card-back-a: #4b3a7d;
  --card-back-b: #2e2354;
  --shadow-glow: 0 0 18px rgba(154, 116, 20, 0.18);
  --nebula-opacity: 0.25;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  transition: background 0.6s ease, color 0.6s ease;
}

/* ---------- background layers ---------- */
#starfield {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.nebula {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: var(--nebula-opacity);
  transition: opacity 0.6s ease;
  background:
    radial-gradient(ellipse 60% 40% at 20% 15%, rgba(88, 44, 160, 0.28), transparent 65%),
    radial-gradient(ellipse 50% 45% at 85% 30%, rgba(46, 30, 110, 0.32), transparent 65%),
    radial-gradient(ellipse 70% 50% at 50% 95%, rgba(140, 60, 120, 0.16), transparent 70%);
}

/* light theme swaps the nebula for the Canva parchment texture (fixed layer,
   safer than background-attachment: fixed on iOS) */
html[data-theme="light"] .nebula {
  background: url('../img/parchment.jpg') center / cover no-repeat;
  opacity: 1;
}

/* ---------- typography helpers ---------- */
.gold-text {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.glow { text-shadow: 0 0 30px rgba(212, 175, 55, 0.35); }
.text-dim { color: var(--text-dim); }

/* ---------- chrome ---------- */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: 1rem;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25);
}

.field {
  background: var(--bg-field);
  border: 1px solid var(--border-soft);
  border-radius: 0.6rem;
  padding: 0.7rem 1rem;
  color: var(--text);
  font-size: 1.05rem;
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.field:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.15); }
.field::placeholder { color: var(--text-dim); opacity: 0.7; font-style: italic; }

.field-mini {
  background: var(--bg-field);
  border: 1px solid var(--border-soft);
  border-radius: 0.4rem;
  width: 3.2rem;
  padding: 0.1rem 0.3rem;
  text-align: center;
  color: var(--text);
}

.btn-gold {
  font-family: 'Cinzel', serif;
  background: linear-gradient(135deg, #c9a227, #f3d47a 45%, #c9a227);
  color: #221503;
  padding: 0.7rem 1.8rem;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.06em;
  box-shadow: var(--shadow-glow);
  transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
}
.btn-gold:hover { transform: translateY(-2px); filter: brightness(1.08); box-shadow: 0 0 34px rgba(212, 175, 55, 0.4); }
.btn-gold:active { transform: translateY(0); }

.btn-ghost {
  font-family: 'Cinzel', serif;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 1.4rem;
  border-radius: 999px;
  letter-spacing: 0.05em;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.btn-ghost:hover { background: rgba(212, 175, 55, 0.1); border-color: var(--gold); transform: translateY(-1px); }

.icon-btn {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--bg-panel);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: border-color 0.2s, transform 0.2s;
}
.icon-btn:hover { border-color: var(--gold); transform: scale(1.08); }

button:focus-visible, [role="button"]:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---------- spread selector ---------- */
.spread-btn {
  border: 1px solid var(--border-soft);
  background: var(--bg-field);
  border-radius: 0.8rem;
  padding: 0.9rem 0.6rem;
  text-align: center;
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.2s;
}
.spread-btn:hover { border-color: var(--gold); transform: translateY(-2px); }
.spread-btn.selected {
  border-color: var(--gold);
  box-shadow: inset 0 0 20px rgba(212, 175, 55, 0.1), var(--shadow-glow);
}

/* mini spread-layout diagram inside picker buttons */
.spread-mini {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-top: 0.5rem;
}
.spread-mini .r { display: flex; gap: 2px; justify-content: center; }
.spread-mini i {
  display: block;
  width: 7px;
  height: 10px;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.25s;
}
.spread-mini i.sp { visibility: hidden; }
.spread-btn.selected .spread-mini i, .spread-btn:hover .spread-mini i { background: var(--gold); }

/* ornamental divider */
.hr-ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--gold);
  margin-top: 1.25rem;
  font-size: 1.05rem;
}
.hr-ornament::before, .hr-ornament::after {
  content: '';
  height: 1px;
  width: min(130px, 26vw);
  background: linear-gradient(90deg, transparent, var(--gold));
}
.hr-ornament::after { background: linear-gradient(270deg, transparent, var(--gold)); }

/* ---------- deck ---------- */
.deck {
  position: relative;
  width: 118px;
  height: 200px;
  cursor: pointer;
  transition: transform 0.25s;
}
.deck:hover { transform: translateY(-4px); }
.deck.empty { opacity: 0.25; pointer-events: none; }

.deck-card {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  border: 2px solid rgba(212, 175, 55, 0.55);
  /* Canva artwork on top; CSS pattern beneath as fallback if the image is missing */
  background:
    url('../img/card-back.png') center / cover no-repeat,
    radial-gradient(circle at 50% 42%, rgba(212, 175, 55, 0.18) 0 12%, transparent 13%),
    repeating-linear-gradient(45deg, var(--card-back-a) 0 8px, var(--card-back-b) 8px 16px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}
.deck-card:nth-child(1) { transform: translate(-6px, 6px) rotate(-4deg); }
.deck-card:nth-child(2) { transform: translate(-3px, 3px) rotate(-2deg); }
.deck-card:nth-child(3) { transform: translate(3px, -2px) rotate(2deg); }

.deck-top {
  display: flex;
  align-items: center;
  justify-content: center;
}
/* the Canva card back carries its own crescent — hide the glyph, keep a breathing glow */
.deck-moon { display: none; }
.deck-top { animation: deckglow 3.5s ease-in-out infinite; }
@keyframes deckglow {
  0%, 100% { box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5); }
  50% { box-shadow: 0 6px 28px rgba(212, 175, 55, 0.5); }
}

/* shuffle: cards scatter and re-gather */
.deck.shuffling .deck-card:nth-child(1) { animation: riffle1 0.9s ease-in-out; }
.deck.shuffling .deck-card:nth-child(2) { animation: riffle2 0.9s ease-in-out; }
.deck.shuffling .deck-card:nth-child(3) { animation: riffle3 0.9s ease-in-out; }
.deck.shuffling .deck-card:nth-child(4) { animation: riffle4 0.9s ease-in-out; }
@keyframes riffle1 { 30% { transform: translate(-70px, -14px) rotate(-22deg); } 60% { transform: translate(-30px, 8px) rotate(-9deg); } 100% { transform: translate(-6px, 6px) rotate(-4deg); } }
@keyframes riffle2 { 30% { transform: translate(60px, -30px) rotate(18deg); } 60% { transform: translate(24px, -6px) rotate(7deg); } 100% { transform: translate(-3px, 3px) rotate(-2deg); } }
@keyframes riffle3 { 30% { transform: translate(-52px, 26px) rotate(14deg); } 60% { transform: translate(-18px, 10px) rotate(5deg); } 100% { transform: translate(3px, -2px) rotate(2deg); } }
@keyframes riffle4 { 30% { transform: translate(64px, 20px) rotate(-16deg); } 60% { transform: translate(22px, 6px) rotate(-5deg); } 100% { transform: none; } }

/* ---------- spread layout ---------- */
.spread {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.1rem;
  width: 100%;
}

/* row-shaped spreads (pyramid, box, compass, priestess, golden dawn) */
.spread.rows {
  flex-direction: column;
  align-items: center;
  flex-wrap: nowrap;
}
.spread-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.1rem;
}

.slot {
  width: 108px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
}
.slot-label {
  font-family: 'Cinzel', serif;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  text-align: center;
  min-height: 2em;
  line-height: 1.3;
}

.slot-card {
  width: 108px;
  height: 184px;
  perspective: 900px;
}
.slot-card .placeholder {
  width: 100%;
  height: 100%;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--border);
  font-size: 1.6rem;
}

/* Celtic Cross gets a cross-and-staff arrangement on wide screens */
@media (min-width: 920px) {
  .spread.celtic {
    display: grid;
    grid-template-columns: repeat(4, 128px);
    grid-template-rows: repeat(4, auto);
    justify-content: center;
    column-gap: 1.6rem;
    row-gap: 1rem;
    grid-template-areas:
      ".    crown   .      s10"
      "past present future s9"
      ".    cross   .      s8"
      ".    found   .      s7";
  }
  .spread.celtic .slot:nth-child(1)  { grid-area: present; }
  .spread.celtic .slot:nth-child(2)  { grid-area: cross; }
  .spread.celtic .slot:nth-child(3)  { grid-area: found; }
  .spread.celtic .slot:nth-child(4)  { grid-area: past; }
  .spread.celtic .slot:nth-child(5)  { grid-area: crown; }
  .spread.celtic .slot:nth-child(6)  { grid-area: future; }
  .spread.celtic .slot:nth-child(7)  { grid-area: s7; }
  .spread.celtic .slot:nth-child(8)  { grid-area: s8; }
  .spread.celtic .slot:nth-child(9)  { grid-area: s9; }
  .spread.celtic .slot:nth-child(10) { grid-area: s10; }
}

/* ---------- flip card ---------- */
.flip {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.4, 0.1, 0.2, 1);
  cursor: pointer;
  animation: dealIn 0.5s ease-out;
}
@keyframes dealIn {
  from { transform: translateY(-160px) scale(0.7) rotate(6deg); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.flip.revealed { transform: rotateY(180deg); cursor: default; }

.flip .face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid rgba(212, 175, 55, 0.55);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
.flip .back {
  background:
    url('../img/card-back.png') center / cover no-repeat,
    radial-gradient(circle at 50% 42%, rgba(212, 175, 55, 0.18) 0 12%, transparent 13%),
    repeating-linear-gradient(45deg, var(--card-back-a) 0 8px, var(--card-back-b) 8px 16px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent; /* artwork replaces the glyph */
  font-size: 2rem;
  text-shadow: none;
}
.flip:hover:not(.revealed) { box-shadow: 0 0 22px rgba(212, 175, 55, 0.35); border-radius: 10px; }

.flip .front {
  transform: rotateY(180deg);
  background: #16102b;
}
.flip .front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.flip .front.reversed img { transform: rotate(180deg); }
.flip.revealed .face.front { animation: revealGlow 1.4s ease-out; }
@keyframes revealGlow {
  0% { box-shadow: 0 0 0 rgba(243, 212, 122, 0); }
  40% { box-shadow: 0 0 42px rgba(243, 212, 122, 0.75); }
  100% { box-shadow: 0 0 0 rgba(243, 212, 122, 0); }
}

/* image fallback tile when artwork can't load */
.img-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem;
  text-align: center;
  background: linear-gradient(160deg, #241640, #120b24);
  color: var(--gold-bright);
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}
.img-fallback .sym { font-size: 1.8rem; }

/* ---------- interpretation cards ---------- */
.interp {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  animation: fadeUp 0.7s ease-out;
}
@media (min-width: 768px) {
  .interp { flex-direction: row; align-items: flex-start; }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: none; }
}
.interp-img {
  flex: 0 0 auto;
  width: 200px;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--border);
  box-shadow: var(--shadow-glow);
  transition: transform 0.15s ease-out;
  will-change: transform;
}
.interp-img img { width: 100%; display: block; }
.interp-img.reversed img { transform: rotate(180deg); }

.kw {
  display: inline-block;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0 0.25rem 0.3rem 0;
}

.badge {
  display: inline-block;
  font-family: 'Cinzel', serif;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.badge.upright { color: #9fd8a8; border-color: rgba(120, 200, 140, 0.4); }
.badge.reversed { color: #e2a1a1; border-color: rgba(220, 130, 130, 0.4); }

.angle-line {
  border-left: 2px solid var(--gold);
  padding-left: 0.9rem;
  font-style: italic;
  color: var(--text-dim);
}

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5, 3, 12, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  width: 100%;
  max-width: 34rem;
  padding: 1.5rem;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
  animation: fadeUp 0.3s ease-out;
}
.modal-box.wide { max-width: 56rem; }

/* ---------- card library ---------- */
.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 0.7rem;
}
.lib-card {
  cursor: pointer;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-field);
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  padding: 0;
  text-align: center;
}
.lib-card img {
  width: 100%;
  display: block;
  aspect-ratio: 32 / 55;
  object-fit: cover;
}
.lib-card p {
  font-family: 'Cinzel', serif;
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  padding: 0.3rem 0.2rem;
  color: var(--text-dim);
  line-height: 1.25;
}
.lib-card:hover {
  border-color: var(--gold);
  transform: translateY(-3px);
  box-shadow: var(--shadow-glow);
}

.history-item {
  border: 1px solid var(--border-soft);
  border-radius: 0.7rem;
  padding: 0.8rem 1rem;
  transition: border-color 0.2s;
}
.history-item:hover { border-color: var(--gold); }

/* ---------- misc ---------- */
.hidden { display: none !important; }

/* ---------- print: a clean reading on paper ---------- */
@media print {
  #starfield, .nebula, header .flex, #setup, #table, #reading-actions,
  #action-toast, .modal, footer, .hr-ornament { display: none !important; }
  body { background: #fff !important; color: #1a1424 !important; }
  .gold-text { background: none !important; color: #7a5a0c !important; }
  .glow { text-shadow: none !important; }
  .text-dim { color: #5c5470 !important; }
  .panel {
    background: #fff !important;
    border: 1px solid #c8c2d4 !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    break-inside: avoid;
  }
  .interp { break-inside: avoid; }
  .interp-img { box-shadow: none !important; border-color: #c8c2d4 !important; }
  .badge.upright { color: #2e7d3e !important; }
  .badge.reversed { color: #a33d3d !important; }
  .angle-line { border-left-color: #7a5a0c !important; }
  .kw { color: #5c5470 !important; border-color: #c8c2d4 !important; }
  textarea.field {
    background: #fff !important;
    color: #1a1424 !important;
    border: 1px solid #c8c2d4 !important;
  }
}

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


/* ---------- Rider-Waite-Smith artwork (2026-11-10) ----------
   The deck is now self-hosted from sharp public-domain scans, so the faces can be
   shown larger and framed like real cards: cream stock, gold edge, soft lift. */
.flip .front { background: #f1e8d4; }
.flip .face.front { border-color: rgba(212, 175, 55, 0.8); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 244, 207, 0.25) inset; }
.flip.revealed:hover { z-index: 5; }
.flip.revealed:hover .face.front { box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), 0 0 28px rgba(212, 175, 55, 0.35); }
.interp-img {
  width: 240px;
  border-radius: 14px;
  border: 2px solid rgba(212, 175, 55, 0.7);
  background: #f1e8d4;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55), 0 0 0 6px rgba(20, 14, 45, 0.55), 0 0 34px rgba(212, 175, 55, 0.22);
}
.interp-img img { aspect-ratio: 32 / 55; object-fit: cover; }
.lib-card { border-radius: 10px; border-color: rgba(212, 175, 55, 0.3); background: #f1e8d4; }
.lib-card p { background: var(--bg-field); }
@media (max-width: 520px) { .interp-img { width: 200px; } }
@media print { .interp-img { box-shadow: none !important; } }
