:root {
  --bg: #07060f;
  --bg-2: #120f24;
  --ink: #ece4d2;
  --ink-dim: #a99f8c;
  --gold: #d9b45a;
  --gold-hi: #f4dc96;
  --panel: rgba(18, 14, 34, 0.94);
  --line: rgba(217, 180, 90, 0.35);
  --cw: 150px;            /* table card width */
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(ellipse at 20% 0%, #2a1748 0%, transparent 55%),
    radial-gradient(ellipse at 90% 100%, #0f2a3d 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 18px;
  overflow-x: hidden;
}

.stars {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .7;
  background-image:
    radial-gradient(1px 1px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 72% 34%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 38% 72%, #ffe9b0 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 82%, #bfe3ff 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 9%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 22% 55%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 64% 61%, #ffd2f0 50%, transparent 51%);
  background-size: 420px 420px;
}

header.top, main { position: relative; z-index: 1; }

/* ── header ─────────────────────────────────────────────────────────────── */

header.top {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  flex-wrap: wrap;
  padding: 24px 32px 12px;
  border-bottom: 1px solid var(--line);
}
h1, h2, h3, .tab, .pill, .draw, .plate, .tip-kicker, .pos-label {
  font-family: "Cinzel", Georgia, serif;
}
h1 {
  margin: 0; font-size: clamp(22px, 3.4vw, 36px); letter-spacing: .06em;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 60%, #9a7428);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand p { margin: 2px 0 0; color: var(--ink-dim); font-style: italic; }

.tabs { display: flex; gap: 4px; }
.tab {
  background: none; border: 1px solid transparent; color: var(--ink-dim);
  padding: 8px 16px; border-radius: 999px; cursor: pointer; font-size: 14px; letter-spacing: .08em;
}
.tab.active { color: var(--gold-hi); border-color: var(--line); background: rgba(217,180,90,.08); }

main { padding: 20px 32px 64px; }
.view { display: none; }
.view.active { display: block; }

/* ── controls ───────────────────────────────────────────────────────────── */

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: center; }
.spread-picker { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pill {
  background: rgba(255,255,255,.03); color: var(--ink); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: 13px; letter-spacing: .05em;
}
.pill small { color: var(--ink-dim); margin-left: 4px; }
.pill.active { background: rgba(217,180,90,.18); border-color: var(--gold); color: var(--gold-hi); }
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-dim); cursor: pointer; }
.toggle input { accent-color: var(--gold); }
.draw {
  background: linear-gradient(180deg, #e7c46d, #a57d2c); color: #1b1203; border: 0;
  padding: 10px 22px; border-radius: 999px; font-weight: 700; letter-spacing: .08em;
  cursor: pointer; box-shadow: 0 0 24px rgba(217,180,90,.35);
}
.draw:hover { filter: brightness(1.1); }
.question-hint { text-align: center; color: var(--ink-dim); font-style: italic; min-height: 1.4em; }

/* ── table + layouts ────────────────────────────────────────────────────── */

.table {
  display: flex; justify-content: center; align-items: center; gap: 40px;
  flex-wrap: wrap; margin-top: 12px; min-height: 420px;
}
.table.spread-three { --cw: clamp(110px, 18vw, 200px); }
.table .row { display: flex; gap: clamp(16px, 4vw, 48px); flex-wrap: wrap; justify-content: center; }

.table.spread-cross { --cw: clamp(64px, min(8.4vw, calc((100vh - 260px) / 6.4)), 128px); gap: clamp(20px, 3vw, 48px); }
.cross {
  display: grid;
  grid-template-columns: repeat(3, auto);
  grid-template-areas: ". crown ." "wake heart horizon" ". keel .";
  gap: 14px 22px; align-items: center; justify-items: center;
}
.cross .pos-heart, .cross .pos-crossing { grid-area: heart; }
.cross .pos-crown { grid-area: crown; }
.cross .pos-wake { grid-area: wake; }
.cross .pos-horizon { grid-area: horizon; }
.cross .pos-keel { grid-area: keel; }
.cross .pos-crossing { z-index: 2; }
.cross .pos-crossing .card { transform: rotate(90deg) translateX(18%); }
.cross .pos-crossing .pos-label { visibility: hidden; }
.cross .pos-heart .pos-label::after { content: " · 2 crosses"; color: var(--ink-dim); }
.staff { display: flex; flex-direction: column; gap: 10px; }
.staff .slot { flex-direction: row; gap: 10px; }
.staff .pos-label { width: 7.5em; text-align: left; }
.guide { align-self: center; }

.slot { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pos-label { font-size: 11px; letter-spacing: .08em; color: var(--gold); text-align: center; max-width: calc(var(--cw) + 40px); }
.pos-label .rev { color: #ff8f8f; font-family: "Cormorant Garamond", serif; font-style: italic; letter-spacing: 0; font-size: 13px; }
.missing { width: var(--cw); aspect-ratio: 2 / 3; border: 1px dashed #ff8f8f; border-radius: var(--radius);
  display: grid; place-items: center; text-align: center; font-size: 12px; color: #ff8f8f; padding: 8px; }

/* ── the card ───────────────────────────────────────────────────────────── */

.card { width: var(--cw); aspect-ratio: 2 / 3; perspective: 900px; cursor: pointer; outline: none; }
.card-inner { position: relative; width: 100%; height: 100%; transition: transform .6s cubic-bezier(.3,.7,.3,1); transform-style: preserve-3d; }
.card.flipped .card-inner { transform: rotateY(180deg); }
/* glow via box-shadow: a filter on the 3D wrapper would flatten the flip and show the back */
.card:hover .card-face, .card:focus-visible .card-face { box-shadow: 0 0 22px rgba(217,180,90,.6), inset 0 0 0 3px #0b0816, inset 0 0 0 4px rgba(217,180,90,.4); }
.card-face {
  position: absolute; inset: 0; border-radius: var(--radius); overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border: 2px solid var(--gold);
  box-shadow: 0 10px 30px rgba(0,0,0,.6), inset 0 0 0 3px #0b0816, inset 0 0 0 4px rgba(217,180,90,.4);
}
.card-face.front { transform: rotateY(180deg); background: #0b0816; display: flex; flex-direction: column; }

.card-face.back {
  background:
    radial-gradient(circle at 50% 50%, rgba(217,180,90,.25) 0 18%, transparent 19%),
    repeating-conic-gradient(from 0deg, #1d1438 0 10deg, #140e29 10deg 20deg),
    #140e29;
  display: grid; place-items: center;
}
.back-sigil {
  font-size: calc(var(--cw) * .38); color: var(--gold-hi);
  text-shadow: 0 0 18px rgba(244,220,150,.8);
}

.art { position: relative; flex: 1; overflow: hidden; background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--suit) 45%, #120c26), #07050f 75%); }
.art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.art-fallback, .tip-art .art-fallback {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: calc(var(--cw) * .45); color: var(--suit); opacity: .8;
  text-shadow: 0 0 24px var(--suit);
}
.is-reversed .art img, .is-reversed .art .art-fallback,
.tip-art.is-reversed img, .tip-art.is-reversed .art-fallback { transform: rotate(180deg); }

.plate {
  display: flex; align-items: center; gap: 6px; justify-content: center;
  padding: 6px 6px 7px; min-height: 2.6em;
  background: linear-gradient(180deg, #1a1330, #0b0816);
  border-top: 1px solid var(--line);
  font-size: clamp(9px, calc(var(--cw) * .078), 14px); line-height: 1.1; letter-spacing: .03em; text-align: center;
}
.plate .numeral { color: var(--suit); font-weight: 700; }
.plate .name { color: var(--ink); }

.deck-stack { width: 170px; height: 255px; position: relative; cursor: pointer; --cw: 170px; }
.deck-stack .card-face { box-shadow: 4px 4px 0 #0b0816, 6px 6px 0 var(--gold), 10px 10px 0 #0b0816, 12px 12px 0 rgba(217,180,90,.6), 0 20px 40px rgba(0,0,0,.6); }
.deck-stack:hover .card-face { filter: brightness(1.15); }

/* ── story ──────────────────────────────────────────────────────────────── */

.story {
  max-width: 760px; margin: 36px auto 0; padding: 22px 28px;
  background: rgba(18, 14, 34, .72); border: 1px solid var(--line); border-radius: 14px;
  font-size: 19px; line-height: 1.6;
  animation: rise .6s ease-out;
}
.story h2 { margin: 0 0 10px; font-size: 20px; letter-spacing: .08em; color: var(--gold-hi); text-align: center; }
.story p { margin: 0 0 14px; }
.story-intro { color: var(--ink-dim); font-style: italic; text-align: center; }
.story-card { color: var(--suit); border-bottom: 1px dotted color-mix(in srgb, var(--suit) 60%, transparent); cursor: help; outline: none; }
.story-card:hover, .story-card:focus-visible { background: color-mix(in srgb, var(--suit) 14%, transparent); }
.story-name { color: var(--ink-dim); font-size: 15px; white-space: nowrap; }
.story-closing { border-top: 1px solid var(--line); padding-top: 14px; margin-bottom: 0 !important; font-style: italic; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (max-width: 720px) { .story { padding: 16px; font-size: 17px; } }

/* ── grimoire ───────────────────────────────────────────────────────────── */

#grimoire { --cw: 128px; }
.suit-group { margin: 12px 0 40px; }
.suit-group header { border-bottom: 1px solid color-mix(in srgb, var(--suit) 50%, transparent); margin-bottom: 18px; padding-bottom: 6px; }
.suit-group h2 { display: inline; margin: 0; color: var(--suit); font-size: 22px; letter-spacing: .06em; }
.suit-sub { margin-left: 10px; color: var(--ink-dim); font-size: 14px; }
.suit-group p { margin: 4px 0 0; color: var(--ink-dim); font-style: italic; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--cw), 1fr)); gap: 18px; justify-items: center; }

.errors { background: #2a0f16; border: 1px solid #ff8f8f; padding: 12px 16px; border-radius: 8px; margin-bottom: 20px; }
.errors pre { white-space: pre-wrap; font-size: 13px; }

/* ── tooltip ────────────────────────────────────────────────────────────── */

.tooltip {
  position: fixed; z-index: 50; left: 0; top: 0;
  display: flex; gap: 0; width: min(760px, calc(100vw - 28px)); max-height: calc(100vh - 28px);
  background: var(--panel); border: 1px solid var(--gold); border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0,0,0,.75), 0 0 40px rgba(217,180,90,.15);
  opacity: 0; pointer-events: none; transform: scale(.97); transition: opacity .15s, transform .15s;
  backdrop-filter: blur(6px); overflow: hidden;
}
.tooltip.open { opacity: 1; pointer-events: auto; transform: none; }
.tip-art {
  --cw: 340px; position: relative; flex: 0 0 340px; aspect-ratio: 2 / 3; align-self: flex-start;
  max-height: calc(100vh - 30px);
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--suit) 45%, #120c26), #07050f 75%);
}
.tip-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.tip-body { padding: 18px 22px; overflow-y: auto; }
.tip-kicker { font-size: 11px; letter-spacing: .14em; color: var(--suit); text-transform: uppercase; }
.tip-body h3 { margin: 4px 0 2px; font-size: 26px; color: var(--gold-hi); letter-spacing: .03em; }
.tip-title { font-style: italic; font-size: 20px; }
.tip-trad { color: var(--ink-dim); font-size: 15px; margin-bottom: 10px; }
.tip-pos { border-left: 3px solid var(--gold); padding: 4px 10px; margin: 8px 0 12px; background: rgba(217,180,90,.07); font-size: 16px; }
.tip-pos strong { font-family: "Cinzel", serif; font-size: 13px; color: var(--gold); letter-spacing: .05em; }
.tip-orient { font-family: "Cinzel", serif; font-size: 13px; letter-spacing: .1em; margin: 8px 0 6px; }
.tip-orient.upright { color: #9fe3b0; }
.tip-orient.reversed { color: #ff9f9f; }
.kws { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.kw { border: 1px solid color-mix(in srgb, var(--suit) 60%, transparent); color: var(--ink); padding: 1px 9px; border-radius: 999px; font-size: 14px; }
.tip-meaning { font-size: 18px; margin: 6px 0 10px; }
.tip-desc { color: var(--ink-dim); font-style: italic; font-size: 16px; margin: 0 0 10px; }
.tip-other summary { cursor: pointer; color: var(--ink-dim); font-size: 14px; }
.tip-other p { font-size: 15px; color: var(--ink-dim); margin: 6px 0 0; }

.live-badge {
  position: fixed; right: 14px; bottom: 12px; z-index: 40;
  font: 12px "Cinzel", serif; letter-spacing: .1em; color: #9fe3b0;
  background: rgba(10,20,14,.8); border: 1px solid #3b7a4f; padding: 4px 10px; border-radius: 999px;
}
.live-badge.pulse { animation: pulse 1s ease-out; }
@keyframes pulse { from { box-shadow: 0 0 0 0 rgba(159,227,176,.8); } to { box-shadow: 0 0 0 14px rgba(159,227,176,0); } }

/* ── small screens ──────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  header.top { padding: 16px; }
  main { padding: 16px 16px 48px; }
  .table.spread-three { --cw: calc((100vw - 32px - 32px) / 3); }
  .table.spread-three .row { flex-wrap: nowrap; gap: 16px; }
  .table.spread-cross { --cw: 64px; flex-direction: column; }
  .cross { gap: 10px 14px; }
  .staff { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .staff .slot { flex-direction: column; }
  .staff .pos-label { width: auto; text-align: center; }
  #grimoire { --cw: calc((100vw - 32px - 36px) / 3); }
  .tooltip { flex-direction: column; overflow-y: auto; }
  .tip-art { flex: none; width: min(60vw, 260px); --cw: 260px; align-self: center; margin-top: 14px; border-radius: 8px; overflow: hidden; }
  .tip-body { overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner, .tooltip { transition: none; }
}
