:root {
  /* Night sky rather than black: indigo ground, warm cream text, bright gold. */
  --bg: #1a1538;
  --panel: #2a2354;
  --line: #554b88;
  --text: #f7f2e8;
  --muted: #cfc8e2;      /* labels, secondary text */
  --soft: #a9a1c8;       /* footnotes */
  --gold: #efcd85;
  --gold-dim: #b89a5e;
  --danger: #ffa494;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "PT Serif", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --card-ratio: 3 / 5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1.6px 1.6px at 9% 14%, rgba(255, 255, 255, .7) 50%, transparent 52%),
    radial-gradient(1.2px 1.2px at 23% 31%, rgba(255, 255, 255, .45) 50%, transparent 52%),
    radial-gradient(1.8px 1.8px at 78% 9%, rgba(255, 240, 200, .75) 50%, transparent 52%),
    radial-gradient(1.2px 1.2px at 91% 27%, rgba(255, 255, 255, .5) 50%, transparent 52%),
    radial-gradient(1.4px 1.4px at 64% 38%, rgba(255, 255, 255, .35) 50%, transparent 52%),
    radial-gradient(1.3px 1.3px at 36% 6%, rgba(255, 255, 255, .5) 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 5% 58%, rgba(255, 240, 200, .4) 50%, transparent 52%),
    radial-gradient(1.2px 1.2px at 95% 66%, rgba(255, 255, 255, .35) 50%, transparent 52%),
    radial-gradient(900px 560px at 50% -6%, #5340a0 0%, rgba(83, 64, 160, 0) 68%),
    linear-gradient(180deg, #211a48 0%, #171230 100%) fixed;
  background-attachment: fixed;
  color: var(--text);
  font: 17px/1.55 var(--sans);
}

main { max-width: 720px; margin: 0 auto; padding: 48px 16px 64px; }

header { text-align: center; margin-bottom: 36px; }
.emblem { display: block; width: 104px; height: 104px; margin: 0 auto 6px; filter: drop-shadow(0 0 22px rgba(239, 205, 133, .45)); }
body.reading .emblem, body.tg .emblem { width: 56px; height: 56px; margin-bottom: 2px; }
.eyebrow { margin: 0; color: var(--gold); font-size: 13px; letter-spacing: .18em; text-transform: uppercase; }
h1 {
  margin: 6px 0 16px; font: 500 56px/1.1 var(--serif); letter-spacing: .01em;
  background: linear-gradient(180deg, #fffaf0 20%, #f0cf8c 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lede { margin: 0 auto; max-width: 590px; color: #e4def1; font-size: 18px; text-wrap: pretty; }

.field { display: block; margin-bottom: 18px; }
.field > span, summary, .label { display: block; margin: 0 0 7px; color: var(--muted); font-size: 15px; font-weight: 500; }
/* The cards sit in the middle of the page, so their caption does too. */
.label { margin-top: 28px; text-align: center; }
summary { cursor: pointer; }
small { color: var(--gold-dim); font-size: inherit; font-weight: 400; }

textarea, input[type="search"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .07);
  color: var(--text);
  font: inherit;
  transition: border-color .15s, background .15s;
}
textarea:focus, input[type="search"]:focus { border-color: var(--gold-dim); background: rgba(255, 255, 255, .1); }
textarea { resize: vertical; }
::placeholder { color: #a39bc0; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button { font: inherit; color: inherit; cursor: pointer; }

/* The three places of the spread */
.spread { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 10px auto 22px; max-width: 540px; }
.slot { display: grid; gap: 8px; justify-items: center; min-width: 0; }
.place {
  position: relative; display: block; width: 100%; aspect-ratio: var(--card-ratio);
  padding: 0; border-radius: 10px; overflow: hidden;
}
.place.empty {
  display: grid; place-content: center; gap: 6px;
  /* An empty place looks like a card lying face down, waiting to be turned. */
  border: 1px solid var(--gold-dim);
  background: radial-gradient(circle at 50% 42%, rgba(239, 205, 133, .16), transparent 62%), linear-gradient(160deg, #3a3170, #251e4c);
  box-shadow: inset 0 0 0 5px #251e4c, inset 0 0 0 6px rgba(239, 205, 133, .4), 0 8px 22px rgba(8, 5, 25, .45);
  color: var(--gold); font-size: 14px; text-align: center;
  transition: transform .15s, box-shadow .15s;
}
.place.empty:hover { transform: translateY(-3px); box-shadow: inset 0 0 0 5px #251e4c, inset 0 0 0 6px rgba(239, 205, 133, .7), 0 12px 26px rgba(8, 5, 25, .5); }
.place.empty b { font: 300 40px/1 var(--serif); }
.place.filled { border: 0; background: none; box-shadow: 0 10px 26px rgba(8, 5, 25, .55), 0 0 0 1px rgba(239, 205, 133, .35); animation: land .45s cubic-bezier(.2, .7, .2, 1); }
.place img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 10px; transition: transform .45s cubic-bezier(.2, .7, .2, 1); }
.place.rev img { transform: rotate(180deg); }
@keyframes land { from { transform: translateY(-10px) scale(.96); opacity: 0; } }

.slot .name { font: 500 15px/1.25 var(--serif); text-align: center; text-wrap: balance; }
.slot .name em { display: block; color: var(--danger); font: 12px/1.3 var(--sans); }
.flip {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: none;
  color: var(--muted); font-size: 13px;
}
.flip:hover { border-color: var(--gold-dim); color: var(--text); }
.flip[aria-pressed="true"] { border-color: var(--gold-dim); color: var(--gold); }

/* The one action on the page: a gold seal rather than a full-width slab. */
.primary {
  display: block; margin: 14px auto 0; padding: 15px 34px; min-width: min(320px, 100%);
  border: 1px solid #fbe7b4; border-radius: 999px;
  background: linear-gradient(180deg, #f8dd9c 0%, #e2b866 55%, #cf9f4c 100%); color: #2a1e06;
  font: 600 19px/1.2 var(--serif); letter-spacing: .03em; white-space: nowrap;
  box-shadow: 0 0 0 4px rgba(239, 205, 133, .14), 0 10px 26px rgba(8, 5, 25, .5), inset 0 1px 0 rgba(255, 255, 255, .6);
  transition: transform .15s, box-shadow .15s;
}
.primary span { font-size: 13px; opacity: .6; vertical-align: 2px; margin: 0 6px; }
.primary:hover { transform: translateY(-2px); box-shadow: 0 0 0 6px rgba(239, 205, 133, .2), 0 14px 30px rgba(8, 5, 25, .55), inset 0 1px 0 rgba(255, 255, 255, .6); }
.primary:active { transform: translateY(0); }
.primary:disabled { opacity: .55; cursor: progress; transform: none; }
.ghost { margin-top: 20px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 10px; background: none; font-size: 15px; }
.ghost:hover { border-color: var(--gold-dim); }
.aside { margin: 14px 0 0; color: var(--soft); font-size: 14px; text-align: center; text-wrap: pretty; }
.link { padding: 0; border: 0; background: none; color: var(--muted); font-size: inherit; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--gold); }

.error { margin: 0 0 12px; color: var(--danger); font-size: 15px; }

/* While a reading is on screen it replaces the form, so nothing has to be scrolled to. */
body.reading header { margin-bottom: 20px; }
body.reading .lede, body.reading form { display: none; }
body.reading h1 { font-size: 34px; margin-bottom: 0; }
.asked { margin: 0 0 16px; font: italic 19px/1.4 var(--serif); text-align: center; text-wrap: balance; overflow-wrap: anywhere; }
.mini { display: flex; justify-content: center; gap: 14px; margin-bottom: 24px; }
/* Three cards share the row: as large as fits, up to 150px each. */
.mini figure { flex: 1 1 0; max-width: 150px; min-width: 0; margin: 0; text-align: center; }
.mini img { display: block; width: 100%; aspect-ratio: var(--card-ratio); object-fit: cover; border-radius: 8px; box-shadow: 0 6px 14px rgba(0, 0, 0, .45); }
.mini .rev img { transform: rotate(180deg); }
.mini figcaption { margin-top: 8px; color: var(--muted); font: 14px/1.25 var(--serif); text-wrap: balance; }
.mini figcaption em { display: block; color: var(--danger); font: 11px/1.3 var(--sans); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

#reading {
  margin-top: 0; padding: 26px 26px 28px; border: 1px solid var(--line); border-top: 2px solid var(--gold-dim); border-radius: 14px;
  background: linear-gradient(180deg, #30285e, #272050); box-shadow: 0 14px 40px rgba(8, 5, 25, .4);
}
#reading h2 { margin: 0 0 12px; color: var(--gold); font: 500 13px/1 var(--sans); letter-spacing: .18em; text-transform: uppercase; }
#reading-text { font: 20px/1.62 var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; }
#reading-text.waiting::after { content: "Смотрю на карты…"; color: var(--muted); font-style: italic; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
#reading-text.streaming::after { content: "▍"; color: var(--gold); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

footer { margin-top: 48px; color: var(--soft); font-size: 13px; text-align: center; }

/* Card picker */
dialog {
  width: min(880px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 18px; border: 1px solid var(--line); border-radius: 16px;
  background: #241d4b; color: var(--text);
}
dialog[open] { display: flex; flex-direction: column; gap: 12px; }
dialog::backdrop { background: rgba(14, 10, 34, .7); backdrop-filter: blur(4px); }
.picker-head { display: flex; align-items: center; justify-content: space-between; }
.picker-head h2 { margin: 0; font: 500 24px/1.2 var(--serif); }
.close { width: 36px; height: 36px; border: 0; border-radius: 50%; background: none; color: var(--muted); font-size: 26px; line-height: 1; }
.close:hover { background: var(--panel); color: var(--text); }
.suits { display: flex; flex: none; gap: 6px; overflow-x: auto; scrollbar-width: none; }
dialog > input, .picker-head { flex: none; }
.suits button { flex: none; padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; background: none; color: var(--muted); font-size: 14px; }
.suits button[aria-selected="true"] { border-color: var(--gold-dim); background: rgba(216, 179, 106, .1); color: var(--gold); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px 10px; overflow-y: auto; padding: 4px 4px 8px; min-height: 240px; scrollbar-color: var(--line) transparent; }
.pick { display: grid; gap: 6px; padding: 0; border: 0; background: none; color: var(--muted); font: 13px/1.25 var(--serif); text-align: center; }
.pick img { width: 100%; aspect-ratio: var(--card-ratio); object-fit: cover; border-radius: 7px; background: var(--panel); transition: transform .15s, box-shadow .15s; }
.pick:hover img, .pick:focus-visible img { transform: translateY(-4px); box-shadow: 0 8px 18px rgba(0, 0, 0, .5), 0 0 0 2px var(--gold); }
.pick:hover { color: var(--text); }
.pick:disabled { opacity: .3; cursor: not-allowed; }
.pick:disabled img { transform: none; box-shadow: none; }
.grid .none { grid-column: 1 / -1; margin: 40px 0; color: var(--muted); text-align: center; }

[hidden] { display: none !important; }

@media (max-width: 520px) {
  main { padding-top: 32px; }
  h1 { font-size: 40px; }
  .spread { gap: 10px; }
  .slot .name { font-size: 13px; }
  .flip { padding: 5px 8px; font-size: 11.5px; white-space: nowrap; }
  #reading { padding: 18px 16px 20px; }
  .primary { padding: 14px 18px; font-size: 18px; min-width: 0; width: 100%; }
  .primary span { margin: 0 3px; }
  .mini { gap: 10px; margin-bottom: 18px; }
  .mini figcaption { font-size: 13px; }
  .asked { font-size: 17px; margin-bottom: 12px; }
  dialog { padding: 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  .place.filled, #reading-text.streaming::after { animation: none; }
  .place img, .pick img { transition: none; }
}
#reading + .error { margin: 12px 0 0; }

/* Telegram Mini App: Telegram draws its own header, so ours shrinks. */
body.tg main { padding-top: 20px; }
body.tg .eyebrow { display: none; }
body.tg h1 { font-size: 34px; }

/* Balance and packs (Telegram Mini App) */
.wallet { margin-top: 14px; padding: 6px 14px; border: 1px solid var(--gold-dim); border-radius: 999px; background: rgba(216, 179, 106, .08); color: var(--gold); font-size: 14px; }
.wallet:hover { background: rgba(216, 179, 106, .16); }
body.reading .wallet { display: none; }
#shop { width: min(440px, calc(100vw - 24px)); }
.shop-note { margin: 0; color: var(--muted); font-size: 14px; text-wrap: pretty; }
.packs { display: grid; gap: 10px; }
.pack { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); text-align: left; }
.pack:hover { border-color: var(--gold-dim); }
.pack:disabled { opacity: .5; cursor: progress; }
.pack b { font: 500 19px/1.2 var(--serif); }
.pack small { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; }
.pack span { color: var(--gold); font-weight: 600; white-space: nowrap; }
.error a { color: inherit; }

/* Deck choice at the foot of the picker */
.styles { display: flex; flex: none; flex-wrap: wrap; align-items: center; gap: 6px 8px; color: var(--soft); font-size: 13px; }
.styles button { padding: 4px 11px; margin: 0 6px 4px 0; border: 1px solid var(--line); border-radius: 999px; background: none; color: var(--muted); font-size: 13px; }
.styles button[aria-pressed="true"] { border-color: var(--gold-dim); color: var(--gold); }
footer p { margin: 0 0 6px; }
footer a { color: inherit; }

/* The way from the open site into the Telegram bot; hidden when already inside Telegram. */
body.tg .web-only { display: none; }
.telegram {
  display: flex; align-items: center; gap: 14px; margin-top: 26px; padding: 14px 18px;
  border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, .05);
  color: var(--text); text-decoration: none; transition: border-color .15s, background .15s;
}
.telegram:hover { border-color: #6fb8ea; background: rgba(111, 184, 234, .1); }
.telegram svg { flex: none; width: 34px; height: 34px; padding: 6px; border-radius: 50%; background: #2aa3e6; fill: #fff; }
.telegram span { color: var(--muted); font-size: 14px; line-height: 1.4; }
.telegram b { display: block; color: var(--text); font-size: 16px; font-weight: 600; }
a.ghost { display: inline-block; text-decoration: none; color: var(--text); }
