:root {
  --paper: #f3eadb;
  --ink: #2b2520;
  --ink-soft: #6b5f52;
  --cobalt: #3a6ea8;
  --cobalt-deep: #23466f;
  --terra: #b4553d;
  --gold: #d9ad55;
  --radius: 14px;
  --fan-w: 60px;
  --display: "Cormorant Garamond", "Times New Roman", serif;
  --body: "Golos Text", system-ui, sans-serif;
  --card-ratio: 420 / 717;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { overflow-x: hidden; }

body {
  min-height: 100vh;
  background:
    radial-gradient(90% 60% at 100% 100%, rgba(180, 85, 61, .08), transparent 70%),
    var(--paper);
  color: var(--ink);
  font: 400 16px/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* paper grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .35;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45  0 0 0 0 .38  0 0 0 0 .3  0 0 0 .35 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* candlelight that breathes */
.candle {
  position: fixed;
  inset: -20vh 0 auto 0;
  height: 85vh;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(ellipse 70% 50% at 50% 45%, rgba(255, 236, 196, .95), rgba(255, 222, 170, .35) 55%, transparent 80%);
}
.dust { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

.page {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 20px calc(48px + env(safe-area-inset-bottom));
}

.masthead { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.eyebrow { font: 600 11px/1 var(--body); letter-spacing: .18em; text-transform: uppercase; color: var(--cobalt); }
.rule { flex: 1; height: 1px; background: linear-gradient(90deg, var(--cobalt), transparent); opacity: .5; }
.sound {
  border: 0; background: none; padding: 4px 0;
  font: 500 12px/1 var(--body); color: var(--ink-soft); cursor: pointer;
}
.sound[aria-pressed="true"] { color: var(--terra); }

.screen { display: none; }
.screen.is-active { display: block; }

.title { font: 500 44px/1.02 var(--display); letter-spacing: -.01em; margin: 0 0 14px; }
.title em { font-style: italic; color: var(--terra); }
.title.small { font-size: 32px; line-height: 1.08; }
.lead { color: var(--ink-soft); margin: 0 0 22px; }
.fine { color: var(--ink-soft); font-size: 13px; margin-top: 22px; }

textarea {
  width: 100%;
  border: 1px solid rgba(43, 37, 32, .18);
  border-radius: var(--radius);
  background: rgba(255, 252, 246, .8);
  padding: 14px 16px;
  font: 400 17px/1.45 var(--body);
  color: var(--ink);
  resize: none;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
textarea:focus { border-color: var(--cobalt); box-shadow: 0 0 0 4px rgba(58, 110, 168, .12); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 16px; }
.chip {
  border: 1px solid rgba(58, 110, 168, .35);
  background: rgba(255, 252, 246, .4);
  color: var(--cobalt-deep);
  border-radius: 999px;
  padding: 7px 13px;
  font: 500 14px/1.2 var(--body);
  cursor: pointer;
  transition: background .2s, color .2s;
}
.chip:hover, .chip:focus-visible { background: var(--cobalt); color: #fff; }
.gender { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 14px; margin-bottom: 20px; }
.gender input { accent-color: var(--cobalt); }

button { font-family: var(--body); }
.primary, .ghost {
  display: inline-flex; justify-content: center; align-items: center;
  width: 100%; min-height: 52px; padding: 0 26px;
  border-radius: 999px;
  font: 600 16px/1 var(--body);
  cursor: pointer;
  transition: transform .15s, background .2s;
}
.primary { border: 0; background: var(--ink); color: var(--paper); box-shadow: 0 10px 24px -12px rgba(43, 37, 32, .6); }
.ghost { border: 1px solid var(--ink); background: rgba(255, 252, 246, .4); color: var(--ink); }
.primary:active, .ghost:active { transform: scale(.98); }
.actions { display: grid; gap: 10px; margin-top: 18px; }
.actions:empty { display: none; }

.question-echo { font: italic 500 21px/1.3 var(--display); color: var(--ink-soft); margin: 0 0 6px; text-align: center; }
.question-echo:empty { display: none; }

.whisper {
  min-height: 4.2em;
  margin: 4px auto 0;
  max-width: 30em;
  text-align: center;
  font: italic 500 20px/1.35 var(--display);
  color: var(--ink);
}
.whisper .w { opacity: 0; }

/* ---------- stage: deck + fan ---------- */
.stage {
  position: relative;
  height: 300px;
  margin: 0 -20px;
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.stage.is-collapsed { height: 0; overflow: hidden; }
.deck {
  position: absolute;
  left: 50%;
  top: 40px;
  width: 112px;
  aspect-ratio: var(--card-ratio);
  margin-left: -56px;
  cursor: grab;
  outline: none;
  touch-action: none;
}
.deck:active { cursor: grabbing; }
.deck-card, .fan-card, .face {
  background: url("/static/cards/back.jpg") center / cover;
  border-radius: 7px;
}
.deck-card {
  position: absolute;
  inset: 0;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .5) inset, 0 6px 14px -8px rgba(35, 70, 111, .8);
  will-change: transform;
}
.stage-hint {
  position: absolute;
  left: 0; right: 0; bottom: 6px;
  margin: 0;
  text-align: center;
  font: 500 13px/1.3 var(--body);
  letter-spacing: .04em;
  color: var(--cobalt-deep);
}

.fan { position: absolute; inset: 0; pointer-events: none; }
.fan.is-live { pointer-events: auto; touch-action: none; }
.fan-card {
  position: absolute;
  left: 50%;
  bottom: 128px;
  width: var(--fan-w);
  aspect-ratio: var(--card-ratio);
  margin-left: calc(var(--fan-w) / -2);
  box-shadow: -2px 2px 7px -3px rgba(35, 70, 111, .7);
  will-change: transform;
}
.fan-card.is-hover { filter: brightness(1.06) drop-shadow(0 0 6px rgba(217, 173, 85, .8)); }

/* ---------- spread on the table ---------- */
.spread {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px 12px;
  margin: 8px 0 6px;
}
.spread:empty { display: none; }
.spread.is-sticky {
  position: sticky;
  top: 0;
  z-index: 4;
  margin: 0 -20px;
  padding: calc(10px + env(safe-area-inset-top)) 20px 18px;
  transition: background .3s;
}
.spread.is-sticky.is-stuck { background: linear-gradient(to bottom, var(--paper) 78%, rgba(243, 234, 219, 0)); }
.slot { width: var(--slot-w, 92px); text-align: center; }
.slot-label {
  margin-top: 6px;
  font: 500 11px/1.25 var(--body);
  color: var(--ink-soft);
  min-height: 2.5em;
}
.slot-frame {
  position: relative;
  width: 100%;
  aspect-ratio: var(--card-ratio);
  border-radius: 8px;
  border: 1px dashed rgba(43, 37, 32, .25);
  perspective: 800px;
}
.tcard {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  cursor: pointer;
  will-change: transform;
}
.tcard.is-next { animation: beckon 1.6s ease-in-out infinite; }
@keyframes beckon {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(217, 173, 85, 0)); }
  50% { filter: drop-shadow(0 0 9px rgba(217, 173, 85, .95)); }
}
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  box-shadow: 0 10px 20px -12px rgba(43, 37, 32, .8);
}
.face.front { transform: rotateY(180deg); background: #efe3cc; }
.face.front img { width: 100%; height: 100%; object-fit: cover; display: block; }
.face.front.is-reversed img { transform: rotate(180deg); }
.glint {
  position: absolute;
  inset: -40% -60%;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 246, 220, .85) 50%, transparent 60%);
  transform: translateX(-60%);
  pointer-events: none;
}

/* ---------- the reader talks ---------- */
.chat { display: grid; gap: 12px; margin-top: 18px; }
.msg {
  position: relative;
  max-width: 92%;
  padding: 13px 16px 14px;
  border-radius: 4px 18px 18px 18px;
  background: rgba(255, 252, 246, .88);
  box-shadow: 0 10px 24px -18px rgba(43, 37, 32, .55);
  border: 1px solid rgba(43, 37, 32, .06);
}
.msg.is-card { border-left: 3px solid var(--terra); }
.msg.is-summary { background: rgba(255, 249, 236, .95); border-left: 3px solid var(--gold); }
.msg-head { font: 600 11px/1.2 var(--body); letter-spacing: .14em; text-transform: uppercase; color: var(--cobalt); margin-bottom: 4px; }
.msg-title { font: 600 23px/1.1 var(--display); margin: 0 0 6px; }
.msg-text { margin: 0; font-size: 15.5px; }
.msg-text .w { opacity: 0; }
.typing { display: inline-flex; gap: 5px; padding: 15px 16px; border-radius: 4px 18px 18px 18px; background: rgba(255, 252, 246, .88); width: max-content; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-soft); opacity: .4; animation: dot 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 30% { opacity: 1; transform: translateY(-3px); } }

.answer { margin: 22px 0 0; padding: 12px 18px; border-left: 3px solid var(--terra); font: 600 26px/1.15 var(--display); }
.bridge {
  margin-top: 22px; padding: 20px; border-radius: var(--radius);
  background: linear-gradient(160deg, var(--cobalt) 0%, var(--cobalt-deep) 100%);
  color: #f6efe2;
}
.bridge p { margin: 0 0 14px; }
.bridge-link {
  display: inline-block; color: var(--cobalt-deep); background: var(--paper);
  padding: 11px 18px; border-radius: 999px; text-decoration: none; font-weight: 600;
}
.footer-note { color: var(--ink-soft); font: italic 500 18px/1.3 var(--display); text-align: center; margin: 26px 0 0; }
.error { color: var(--terra); text-align: center; }

@media (min-width: 540px) {
  :root { --fan-w: 70px; }
  .title { font-size: 54px; }
  .stage { height: 330px; margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .tcard.is-next, .typing i { animation: none; }
  .msg-text .w, .whisper .w { opacity: 1; }
}

/* =========================================================
   Vintage engraving layer: frame, crest with 1909 sun & moon,
   stars, dividers, lilies, banner button
   ========================================================= */
.page { padding-left: 26px; padding-right: 26px; }
.spread.is-sticky { margin: 0 -26px; padding-left: 26px; padding-right: 26px; }
.stage { margin: 0 -26px; }
.frame { position: absolute; inset: 8px 8px 8px 8px; pointer-events: none; color: var(--ink); z-index: 0; }
.frame::before {
  content: "";
  position: absolute;
  inset: 34px 3px;
  border-left: 1px solid rgba(43, 37, 32, .55);
  border-right: 1px solid rgba(43, 37, 32, .55);
}
.frame::after {
  content: "";
  position: absolute;
  inset: 3px 34px;
  border-top: 1px solid rgba(43, 37, 32, .55);
  border-bottom: 1px solid rgba(43, 37, 32, .55);
}
.corner { position: absolute; width: 74px; height: 74px; color: var(--ink); }
.corner.tl { left: 0; top: 0; }
.corner.tr { right: 0; top: 0; transform: scaleX(-1); }
.corner.bl { left: 0; bottom: 0; transform: scaleY(-1); }
.corner.br { right: 0; bottom: 0; transform: scale(-1, -1); }
.lily { position: absolute; width: 30px; height: 64px; bottom: 60px; color: var(--ink); opacity: .85; }
.lily.l { left: 4px; transform: rotate(-8deg); }
.lily.r { right: 4px; transform: scaleX(-1) rotate(-8deg); }

.masthead { display: none; }
.crest {
  position: relative;
  display: grid;
  grid-template-columns: 74px 1fr 74px;
  align-items: center;
  gap: 6px;
  margin: 6px 0 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(43, 37, 32, .35);
}
.crest::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -5px;
  border-bottom: 1px solid rgba(43, 37, 32, .2);
}
.emblem { position: relative; width: 74px; height: 74px; display: grid; place-items: center; }
.emblem img {
  position: relative;
  width: 62px; height: 62px;
  border-radius: 50%;
  object-fit: cover;
  filter: sepia(.35) saturate(.85) contrast(1.05);
  box-shadow: 0 0 0 1px rgba(43, 37, 32, .45), 0 0 0 4px var(--paper), 0 0 0 5px rgba(43, 37, 32, .3);
}
.emblem.moon img { animation: bob 7s ease-in-out infinite; }
.sun-rays { position: absolute; inset: -6px; width: 86px; height: 86px; animation: spin 90s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bob { 50% { transform: translateY(-3px) rotate(-3deg); } }
.crest-title { text-align: center; }
.crest-star { width: 16px; height: 16px; fill: var(--terra); display: block; margin: 0 auto 2px; }
.word { font: 700 46px/0.95 var(--display); letter-spacing: .16em; margin-right: -.16em; }
.year { font: italic 500 15px/1.2 var(--display); color: var(--ink-soft); margin-top: 4px; }
.twinkle { position: absolute; fill: var(--terra); animation: twinkle 3.6s ease-in-out infinite; }
.twinkle.s1 { width: 9px; height: 9px; left: 78px; top: 4px; }
.twinkle.s2 { width: 7px; height: 7px; right: 80px; top: 52px; animation-delay: 1.1s; fill: var(--ink); }
.twinkle.s3 { width: 12px; height: 12px; right: 88px; top: 0; animation-delay: .6s; }
.twinkle.s4 { width: 7px; height: 7px; left: 84px; top: 58px; animation-delay: 2s; fill: var(--ink); }
@keyframes twinkle { 0%, 100% { opacity: .25; transform: scale(.7); } 50% { opacity: 1; transform: scale(1.1); } }

.title { font: 600 40px/1.05 var(--display); text-align: center; letter-spacing: 0; margin: 4px 0 8px; }
.divider { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 auto 18px; max-width: 220px; }
.divider span { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--ink) 30%, var(--ink) 70%, transparent); opacity: .6; }
.divider svg { width: 14px; height: 14px; fill: var(--terra); }

.panel {
  margin: 0;
  padding: 10px 14px 12px;
  border: 1px solid rgba(43, 37, 32, .5);
  outline: 1px solid rgba(43, 37, 32, .25);
  outline-offset: 4px;
  border-radius: 2px;
  background: rgba(255, 250, 240, .35);
}
.panel legend, .label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
  font: 600 19px/1 var(--display);
}
.label { padding: 0; margin: 22px 0 10px; }
.panel legend svg, .label svg { width: 13px; height: 13px; fill: var(--terra); }
.panel textarea {
  border: 1px solid rgba(43, 37, 32, .35);
  border-radius: 3px;
  background:
    repeating-linear-gradient(to bottom, transparent 0 31px, rgba(43, 37, 32, .18) 31px 32px) 0 6px / 100% 32px,
    rgba(255, 252, 246, .7);
  font: 500 19px/32px var(--display);
  padding: 6px 12px;
}
.panel textarea::placeholder { color: rgba(43, 37, 32, .55); font-style: italic; }
.chip {
  border-color: rgba(43, 37, 32, .35);
  color: var(--ink);
  font: 500 16px/1.1 var(--display);
  padding: 6px 12px;
}
.chip:hover, .chip:focus-visible { background: var(--ink); color: var(--paper); }

.spreads { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.spread-opt {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 10px 4px 9px;
  border: 1px solid rgba(43, 37, 32, .4);
  outline: 1px solid rgba(43, 37, 32, .15);
  outline-offset: 3px;
  border-radius: 2px;
  background: rgba(255, 250, 240, .35);
  color: var(--ink);
  font: 600 14px/1.1 var(--display);
  cursor: pointer;
  transition: border-color .2s, color .2s, background .2s;
}
.spread-opt.is-on { border-color: var(--terra); outline-color: rgba(180, 85, 61, .45); color: var(--terra); background: rgba(255, 246, 232, .7); }
.mini { position: relative; height: 46px; width: 54px; display: block; }
.mini i { position: absolute; width: 18px; height: 30px; border-radius: 2px; background: url("/static/cards/back.jpg") center / cover; box-shadow: 0 2px 4px -2px rgba(35, 70, 111, .8); }
.mini-one i { left: 17px; top: 6px; width: 20px; height: 34px; }
.mini-three i:nth-child(1) { left: 4px; top: 10px; transform: rotate(-10deg); }
.mini-three i:nth-child(2) { left: 18px; top: 6px; z-index: 1; }
.mini-three i:nth-child(3) { left: 32px; top: 10px; transform: rotate(10deg); }
.mini-cross i { width: 12px; height: 20px; }
.mini-cross i:nth-child(1) { left: 21px; top: 13px; }
.mini-cross i:nth-child(2) { left: 21px; top: -8px; }
.mini-cross i:nth-child(3) { left: 21px; top: 34px; }
.mini-cross i:nth-child(4) { left: 6px; top: 13px; }
.mini-cross i:nth-child(5) { left: 36px; top: 13px; }
.mini-auto svg { width: 28px; height: 28px; fill: var(--terra); position: absolute; left: 13px; top: 9px; animation: twinkle 3.6s ease-in-out infinite; }

.gender { margin: 16px 0 16px; }
.banner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  min-height: 58px;
  border: 0;
  border-radius: 2px;
  background:
    radial-gradient(120% 140% at 50% 0%, #c4634a 0%, #a5432f 60%, #8f3726 100%);
  color: #fbefdc;
  font: 600 25px/1 var(--display);
  letter-spacing: .02em;
  cursor: pointer;
  box-shadow: inset 0 0 0 3px #a5432f, inset 0 0 0 4px rgba(251, 239, 220, .65), 0 10px 22px -14px rgba(90, 30, 18, .9);
  transition: transform .15s, filter .2s;
}
.banner svg { width: 14px; height: 14px; fill: rgba(251, 239, 220, .85); }
.banner:active { transform: scale(.985); }
.banner:hover { filter: brightness(1.05); }
.fine { text-align: center; font-size: 13px; }
.fine em { display: block; font: italic 500 18px/1.3 var(--display); color: var(--ink); margin-bottom: 4px; }

.question-echo { margin-top: 2px; }
.ghost { border-radius: 2px; font: 600 20px/1 var(--display); outline: 1px solid rgba(43, 37, 32, .2); outline-offset: 3px; }
.msg { border-radius: 2px; outline: 1px solid rgba(43, 37, 32, .12); outline-offset: 3px; }
.msg.is-card { border-left: 1px solid rgba(43, 37, 32, .06); }
.msg.is-card::before {
  content: "";
  position: absolute;
  left: -7px; top: 14px;
  width: 13px; height: 13px;
  background: var(--terra);
  clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%);
}
.slot-frame { border-radius: 3px; }
.bridge { border-radius: 2px; outline: 1px solid rgba(35, 70, 111, .35); outline-offset: 4px; }
.bridge-link { border-radius: 2px; }
.foot { text-align: center; margin-top: 30px; }

@media (max-width: 380px) {
  .word { font-size: 40px; }
  .title { font-size: 34px; }
  .crest { grid-template-columns: 62px 1fr 62px; }
  .emblem, .emblem img { width: 56px; height: 56px; }
  .sun-rays { width: 72px; height: 72px; }
  .twinkle.s1, .twinkle.s4 { left: 64px; }
  .twinkle.s2, .twinkle.s3 { right: 66px; }
}
@media (prefers-reduced-motion: reduce) {
  .sun-rays, .emblem.moon img, .twinkle, .mini-auto svg { animation: none; }
}
