/* «Ночная мистика»: same palette as bot/design.py. The table is always dark, whatever the Telegram theme. */
@property --accent {
  syntax: "<color>";
  inherits: true;
  initial-value: #9B7BFF;
}

:root {
  --night: #0E0B1F;
  --indigo: #1B1640;
  --violet: #2A1F5C;
  --gold: #D8B45A;
  --gold-light: #F2D98A;
  --gold-deep: #C9972F;
  --moon: #E8E4F5;
  --muted: #968CBE;
  --accent: #9B7BFF;            /* persona colour, set from app.js; animates thanks to @property */
  --foil: 50%;
  --back-bg: linear-gradient(160deg, var(--violet), var(--indigo) 60%, #120D2B);   /* backs.css overrides per skin */
  --back-edge: var(--gold-deep);                  /* foil sheen position, set per card from the phone tilt */
  --serif: "Cormorant Garamond", "Cormorant", Georgia, "Times New Roman", serif;
  --gutter: 16px;
  --vh: var(--tg-viewport-stable-height, 100dvh);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --back-art: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 100'%3E%3Cg fill='none' stroke='%23D8B45A' stroke-width='1.2'%3E%3Crect x='5' y='5' width='50' height='90' rx='4' opacity='.55'/%3E%3Ccircle cx='30' cy='50' r='15' opacity='.8'/%3E%3Ccircle cx='30' cy='50' r='20' opacity='.3'/%3E%3C/g%3E%3Cpath d='M34 39a11 11 0 1 0 0 22a13 13 0 1 1 0-22z' fill='%23D8B45A'/%3E%3Cpath d='M30 13l1.6 5.4L37 20l-5.4 1.6L30 27l-1.6-5.4L23 20l5.4-1.6zM30 73l1.6 5.4L37 80l-5.4 1.6L30 87l-1.6-5.4L23 80l5.4-1.6z' fill='%23F2D98A'/%3E%3C/svg%3E");
  transition: --accent .9s ease;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  color: var(--moon);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
html {
  background: var(--night);
}
body {
  min-height: 100vh;
  /* a faint sky: a few fixed stars around the table */
  background:
    radial-gradient(1px 1px at 12% 8%, rgba(242, 217, 138, .7), transparent),
    radial-gradient(1px 1px at 82% 5%, rgba(232, 228, 245, .6), transparent),
    radial-gradient(1.5px 1.5px at 92% 18%, rgba(242, 217, 138, .5), transparent),
    radial-gradient(1px 1px at 6% 30%, rgba(232, 228, 245, .45), transparent),
    radial-gradient(1px 1px at 70% 12%, rgba(232, 228, 245, .4), transparent),
    radial-gradient(120% 60% at 50% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    var(--night);
}
textarea { -webkit-user-select: text; user-select: text; }

button, textarea { font: inherit; color: inherit; }

.app {
  min-height: var(--vh);
  display: flex;
  flex-direction: column;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
}

/* ---- header ---- */
.top { position: relative; padding: 0 var(--gutter); text-align: center; }
.top h1 { margin: 0 44px !important; }
.top h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: .02em;
  background: linear-gradient(100deg, var(--gold-deep) 20%, var(--gold-light) 40%, #FFF6D6 50%, var(--gold-light) 60%, var(--gold-deep) 80%);
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 2.8s ease-in-out 1.2s 1 both;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -150% 0; } }
.hint {
  margin: 2px 0 0;
  min-height: 1.4em;
  color: var(--muted);
  font-style: italic;
  font-weight: 500;
  transition: opacity .25s;
  text-wrap: balance;
}
.hint.fade { opacity: 0; }
.lvl {
  position: absolute; left: var(--gutter); top: 8px;
  padding: 3px 10px;
  border-radius: 14px;
  background: rgba(42, 31, 92, .55);
  box-shadow: inset 0 0 0 1px rgba(216, 180, 90, .3);
  color: var(--gold-light);
  font-size: 15px; font-weight: 700;
}
.lvl[hidden] { display: none; }
.sound {
  position: absolute; right: var(--gutter); top: 4px;
  width: 36px; height: 36px; padding: 7px;
  border: 0; border-radius: 50%;
  background: rgba(42, 31, 92, .55);
  box-shadow: inset 0 0 0 1px rgba(216, 180, 90, .3);
  color: var(--gold-light);
  cursor: pointer;
}
.sound svg { width: 100%; height: 100%; display: block; }
.sound .mute { display: none; }
.sound[aria-pressed="false"] { color: var(--muted); }
.sound[aria-pressed="false"] .wave { display: none; }
.sound[aria-pressed="false"] .mute { display: inline; }
.sound:focus-visible { outline: 2px solid var(--gold-light); outline-offset: 2px; }

/* ---- the table: velvet cloth lit by one candle ---- */
.table {
  position: relative;
  margin: 12px var(--gutter) 0;
  height: 34vh;
  min-height: 220px;
  border-radius: 24px;
  background:
    radial-gradient(90% 70% at 50% 100%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    linear-gradient(180deg, var(--indigo), #140F33 70%, var(--night));
  box-shadow:
    inset 0 0 0 1px rgba(216, 180, 90, .25),
    inset 0 0 0 5px rgba(14, 11, 31, .6),
    inset 0 0 0 6px rgba(216, 180, 90, .12),
    inset 0 0 70px rgba(0, 0, 0, .6),
    0 20px 60px -20px color-mix(in srgb, var(--accent) 45%, transparent);
  overflow: hidden;
  isolation: isolate;
  opacity: 0;
  transform: translateY(14px) scale(.98);
  transition: height .6s var(--ease-out), opacity .9s ease, transform .9s var(--ease-out), box-shadow .9s;
}
.app.lit .table { opacity: 1; transform: none; }
.app:not([data-stage="setup"]) .table { height: calc(var(--vh) - 170px); min-height: 380px; }
.app[data-stage="reveal"] .table, .app[data-stage="sending"] .table { min-height: 0; } /* app.js fits it */

.aura {
  position: absolute; inset: 0;
  background:
    radial-gradient(50% 40% at 20% 70%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
    radial-gradient(45% 35% at 85% 35%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%);
  opacity: .8;
  animation: aura 14s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes aura { from { transform: translate(-4%, 2%) scale(1); } to { transform: translate(4%, -3%) scale(1.12); } }

.candle {
  position: absolute; inset: -34% 8% auto; height: 74%;
  background: radial-gradient(closest-side, rgba(242, 217, 138, .2), rgba(242, 217, 138, .05) 60%, transparent);
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.4s ease .2s;
}
.app.lit .candle { opacity: 1; animation: flicker 5s ease-in-out infinite 1.6s; }
@keyframes flicker { 0%, 100% { opacity: .85; } 35% { opacity: 1; } 52% { opacity: .72; } 70% { opacity: .95; } }

.motes { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sparks { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 20; }

.lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; overflow: visible; }
.lines path {
  fill: none; stroke: var(--gold-light); stroke-width: 1.2; stroke-linecap: round; opacity: .75;
  filter: drop-shadow(0 0 4px rgba(242, 217, 138, .9));
  stroke-dasharray: var(--len); stroke-dashoffset: var(--len);
  animation: draw 1.6s var(--ease-out) forwards;
}
.lines circle { fill: #FFF6D6; filter: drop-shadow(0 0 6px var(--gold-light)); opacity: 0; animation: star .5s ease forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes star { from { opacity: 0; } to { opacity: 1; } }

/* ---- cards ---- */
.card {
  position: absolute;
  width: var(--w, 64px);
  aspect-ratio: 350 / 600;
  perspective: 1000px;
  transition: left .5s var(--ease-out), top .5s var(--ease-out), width .5s var(--ease-out),
              transform .35s var(--ease-out), opacity .35s, filter .35s;
}
.card-inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform .9s cubic-bezier(.3, 1.35, .45, 1);
}
.card.open .card-inner { transform: rotateY(180deg); }
.card.open.settled .card-inner { transition: none; } /* app.js writes the (smoothed) tilt here each frame */
.face {
  position: absolute; inset: 0;
  border-radius: 7% / 4.1%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}
.face.back {
  background: var(--back-art) center / 88% auto no-repeat, var(--back-bg);
  box-shadow: inset 0 0 0 1.5px var(--back-edge), 0 6px 16px rgba(0, 0, 0, .5);
}
.face.back::after { /* a slow sheen over the gold ornament */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(242, 217, 138, .22) 50%, transparent 65%);
  background-size: 300% 100%;
  background-position: 120% 0;
}
.fan .card.hover .face.back::after, .deck .card .face.back::after { animation: sheen 1.2s ease; }
@keyframes sheen { from { background-position: 120% 0; } to { background-position: -40% 0; } }

.face.front {
  transform: rotateY(180deg);
  background: var(--night);
  box-shadow: 0 0 0 1.5px var(--gold), 0 0 24px color-mix(in srgb, var(--accent) 60%, transparent);
}
.face.front img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card.reversed .face.front img { transform: rotate(180deg); }
/* holographic foil: moves with the phone tilt */
.face.front::before {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(115deg,
    transparent 20%, rgba(155, 123, 255, .28) 32%, rgba(242, 217, 138, .35) 42%,
    rgba(255, 255, 255, .45) 48%, rgba(79, 179, 169, .28) 56%, transparent 70%);
  background-size: 260% 260%;
  background-position: var(--foil) 50%;
  opacity: .35;
  pointer-events: none;
}
/* one bright glint across the face while it turns over */
.face.front::after {
  content: ""; position: absolute; inset: -10%; z-index: 2;
  background: linear-gradient(105deg, transparent 38%, rgba(255, 250, 230, .85) 50%, transparent 62%);
  transform: translateX(-120%);
  pointer-events: none;
}
.card.open .face.front::after { animation: glint .9s ease-out .35s; }
@keyframes glint { to { transform: translateX(120%); } }

.card.major .face.front {
  box-shadow: 0 0 0 2px var(--gold-light), 0 0 30px rgba(242, 217, 138, .75), 0 0 60px color-mix(in srgb, var(--accent) 50%, transparent);
}

/* setup: a squared deck in the middle of the table */
.deck { position: absolute; left: 50%; top: 50%; width: 0; height: 0; z-index: 3; transition: opacity .5s; }
.deck .card { --w: 88px; left: -44px; top: -75px; transition: none; will-change: transform; }
.app[data-stage="pick"] .deck, .app[data-stage="reveal"] .deck, .app[data-stage="sending"] .deck { opacity: 0; pointer-events: none; }

/* the fan along the bottom edge of the table: slide a finger along it, release on your card */
.fan { position: absolute; left: 0; right: 0; bottom: 0; height: 160px; z-index: 4; touch-action: none; pointer-events: none; }
.app[data-stage="pick"] .fan { pointer-events: auto; }
.fan .card {
  --w: 64px;
  left: calc(50% - 32px);
  top: 34px;
  transform-origin: 50% 340%;
  cursor: pointer;
  will-change: transform;
}
.fan .card.hover { z-index: 5; filter: drop-shadow(0 0 10px rgba(242, 217, 138, .8)); }
.fan .card:focus-visible { outline: none; }
.fan .card:focus-visible .face.back { box-shadow: inset 0 0 0 1.5px var(--gold-deep), 0 0 0 3px var(--gold-light); }

/* spread positions */
.slots { position: absolute; inset: 0; z-index: 2; }
.slot {
  position: absolute;
  border-radius: 8px;
  border: 1px dashed rgba(216, 180, 90, .3);
  transition: left .5s var(--ease-out), top .5s var(--ease-out), width .5s var(--ease-out), height .5s var(--ease-out),
              border-color .3s, box-shadow .3s, opacity .4s;
}
.app[data-stage="setup"] .slot { opacity: .5; }
.slot.next {
  border-color: var(--gold-light);
  box-shadow: 0 0 18px rgba(242, 217, 138, .3), inset 0 0 18px rgba(242, 217, 138, .12);
  animation: beckon 1.6s ease-in-out infinite;
}
@keyframes beckon { 50% { opacity: .45; } }
.slot.cross { transform: rotate(90deg); }
.slot.filled { opacity: 0; }
.slot-label {
  position: absolute; transform: translateX(-50%);
  white-space: nowrap;
  font-size: 14px; font-weight: 600; color: var(--muted);
  transition: left .5s var(--ease-out), top .5s var(--ease-out), color .4s, opacity .4s;
  pointer-events: none;
}
.app[data-stage="setup"] .slot-label, .app[data-stage="setup"] .slot-num { opacity: 0; }
.slot-label.open { color: var(--gold-light); text-shadow: 0 0 10px rgba(242, 217, 138, .5); }
.slot-num {
  position: absolute; z-index: 4;
  min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px;
  background: var(--night); color: var(--gold-light);
  box-shadow: 0 0 0 1px var(--gold-deep);
  font-size: 13px; font-weight: 700; line-height: 20px; text-align: center;
  pointer-events: none;
  transition: left .5s var(--ease-out), top .5s var(--ease-out), opacity .4s;
}
.slots .card { cursor: pointer; z-index: 2; }
.slots .card.cross { transform: rotate(90deg); z-index: 3; }
.slots .card:focus-visible { outline: 2px solid var(--gold-light); outline-offset: 3px; border-radius: 6px; }
.app[data-stage="sending"] .slots .card { filter: brightness(1.25) drop-shadow(0 0 16px rgba(242, 217, 138, .9)); transform: translateY(-6px); }
.app[data-stage="sending"] .slots .card.cross { transform: rotate(90deg) translateX(-6px); }

/* ---- panels ---- */
.panel { padding: 16px var(--gutter) 8px; }
.app:not([data-stage="setup"]) .setup { display: none; }
.app:not([data-stage="reveal"]):not([data-stage="sending"]) .reading { display: none; }
.setup { opacity: 0; transform: translateY(10px); transition: opacity .8s ease .35s, transform .8s var(--ease-out) .35s; }
.app.lit .setup { opacity: 1; transform: none; }

fieldset { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
legend, .legend {
  display: block;
  padding: 0;
  margin-bottom: 8px;
  font-size: 16px; font-weight: 600;
  color: var(--gold);
}

.spreads-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.opt {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px 8px;
  border-radius: 14px;
  background: rgba(27, 22, 64, .7);
  box-shadow: inset 0 0 0 1px rgba(150, 140, 190, .25);
  text-align: center; line-height: 1.15;
  cursor: pointer;
  transition: box-shadow .25s, background .25s, transform .2s;
}
.opt:active { transform: scale(.97); }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt img { width: 34px; height: 34px; transition: filter .3s, transform .3s; }
.opt .name { font-size: 15px; font-weight: 600; }
.opt .sub { font-size: 13px; color: var(--muted); }
.opt:has(input:checked) {
  background: linear-gradient(180deg, var(--violet), color-mix(in srgb, var(--accent) 22%, var(--indigo)));
  box-shadow: inset 0 0 0 1.5px var(--gold), 0 6px 20px -8px color-mix(in srgb, var(--accent) 80%, transparent);
}
.opt:has(input:checked) img { filter: drop-shadow(0 0 6px rgba(242, 217, 138, .7)); transform: scale(1.06); }
.opt:has(input:focus-visible) { box-shadow: inset 0 0 0 1.5px var(--gold), 0 0 0 3px rgba(242, 217, 138, .45); }
.opt.locked { opacity: .5; cursor: not-allowed; }
.opt.locked .sub { color: var(--gold); }

.personas-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.personas-row .opt { flex-direction: row; justify-content: center; gap: 6px; padding: 8px 6px; }
.personas-row .opt img { width: 24px; height: 24px; flex: none; }
.personas-row .opt .name { font-size: 14px; text-align: left; }

.question { display: block; margin-bottom: 16px; }
textarea {
  width: 100%;
  resize: none;
  padding: 10px 12px;
  border: 0; border-radius: 14px;
  background: rgba(27, 22, 64, .7);
  box-shadow: inset 0 0 0 1px rgba(150, 140, 190, .25);
  font-size: 17px; line-height: 1.35;
  outline: none;
  transition: box-shadow .3s;
}
textarea::placeholder { color: var(--muted); opacity: .8; font-style: italic; }
textarea:focus { box-shadow: inset 0 0 0 1.5px var(--gold), 0 0 22px -6px rgba(242, 217, 138, .5); }

/* revealed cards, in position order */
.drawn { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.drawn li { display: grid; grid-template-columns: 26px 1fr; gap: 0 6px; }
.drawn li.fresh { animation: rise .6s var(--ease-out); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.drawn .n { grid-row: span 2; color: var(--gold); font-weight: 700; text-align: right; }
.drawn .t { font-weight: 600; }
.drawn .t em { color: var(--muted); font-weight: 500; }
.drawn .t .arc { color: var(--gold-light); }
.drawn .k { color: var(--muted); font-size: 16px; }
.drawn li.hidden .t { color: var(--muted); font-style: italic; font-weight: 500; }

.note {
  margin: 12px var(--gutter) 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(42, 31, 92, .6);
  box-shadow: inset 0 0 0 1px rgba(216, 180, 90, .35);
  text-align: center;
}

/* own button — used only when the page is opened outside Telegram */
.bar {
  position: sticky; bottom: 0;
  margin-top: auto;
  padding: 20px var(--gutter) 0;
  background: linear-gradient(transparent, var(--night) 22px);
  z-index: 5;
}
.bar[hidden] { display: none; }
.primary {
  width: 100%;
  padding: 13px 16px;
  border: 0; border-radius: 14px;
  background: linear-gradient(180deg, var(--gold-light), var(--gold-deep));
  color: var(--night);
  font-size: 19px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px -10px rgba(242, 217, 138, .7);
}
.primary:disabled { opacity: .45; cursor: default; }
.primary:focus-visible { outline: 2px solid var(--moon); outline-offset: 3px; }

/* ---- a card up close ---- */
.zoom {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px var(--gutter);
  background: radial-gradient(70% 50% at 50% 40%, color-mix(in srgb, var(--accent) 22%, transparent), transparent), rgba(14, 11, 31, .95);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: fade-in .3s ease;
}
@keyframes fade-in { from { opacity: 0; } }
.zoom[hidden] { display: none; }
.zoom-card {
  position: relative;
  width: min(62vw, 260px); aspect-ratio: 350 / 600;
  animation: zoom-in .5s var(--ease-out);
}
@keyframes zoom-in { from { transform: perspective(900px) scale(.7) rotateY(-25deg); opacity: 0; } }
.zoom-card img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 12px; display: block;
  box-shadow: 0 0 0 1.5px var(--gold), 0 0 50px color-mix(in srgb, var(--accent) 60%, transparent);
}
.zoom-card::after {
  content: ""; position: absolute; inset: 0; border-radius: 12px;
  background: linear-gradient(115deg, transparent 20%, rgba(155, 123, 255, .3) 34%, rgba(255, 255, 255, .45) 48%, rgba(79, 179, 169, .3) 58%, transparent 72%);
  background-size: 260% 260%; background-position: var(--foil) 50%;
  opacity: .35; pointer-events: none;
}
.zoom-card.reversed img { transform: rotate(180deg); }
.zoom-text { text-align: center; max-width: 34ch; }
.zoom-pos { margin: 0; color: var(--gold); font-weight: 600; }
.zoom-text h2 { margin: 0; font-size: 26px; font-weight: 600; color: var(--gold-light); line-height: 1.15; }
.zoom-keys { margin: 6px 0 0; color: var(--moon); }
.zoom-close {
  margin-top: 4px; padding: 8px 18px;
  border: 0; border-radius: 12px;
  background: transparent; box-shadow: inset 0 0 0 1px rgba(216, 180, 90, .5);
  color: var(--gold-light); font-size: 17px; font-weight: 600;
  cursor: pointer;
}

/* Everything that answers a tap stays; the ambient motion (sky, candle, sheen, aura) goes. */
@media (prefers-reduced-motion: reduce) {
  .top h1, .aura, .app.lit .candle, .slot.next { animation: none; }
}

@media (min-width: 560px) {
  .app { max-width: 560px; margin: 0 auto; }
}
