:root {
  --bg-0: #0b0314;
  --bg-1: #160828;
  --bg-2: #241040;
  --gold: #e3b65a;
  --gold-hi: #fbe3a1;
  --gold-lo: #a8792c;
  --ink: #f3e6c4;
  --muted: rgba(243, 230, 196, .62);
  --line: rgba(227, 182, 90, .38);
  --err: #ff9d8a;

  --f-script: 'Marck Script', 'Bad Script', cursive;
  --f-hand: 'Bad Script', 'Marck Script', cursive;
  --f-num: 'Cormorant Garamond', Georgia, serif;

  --gold-grad: linear-gradient(100deg, var(--gold-lo) 0%, var(--gold) 22%, var(--gold-hi) 42%, var(--gold) 58%, var(--gold-lo) 78%, var(--gold) 100%);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --pad: max(4.2vmin, 22px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--f-hand);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 80% at 50% 0%, var(--bg-2) 0%, var(--bg-1) 45%, var(--bg-0) 100%);
}

button { font: inherit; color: inherit; }

/* ---------- Фон ---------- */
#stars { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }

.nebula {
  position: fixed; inset: -20%; z-index: 0; pointer-events: none;
  background:
    radial-gradient(40% 30% at 22% 28%, rgba(140, 70, 220, .22), transparent 70%),
    radial-gradient(35% 28% at 80% 70%, rgba(90, 40, 170, .25), transparent 70%),
    radial-gradient(30% 22% at 60% 20%, rgba(227, 182, 90, .07), transparent 70%);
  filter: blur(10px);
  animation: drift 38s ease-in-out infinite alternate;
}
@keyframes drift {
  0% { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
  100% { transform: translate3d(3%, -2%, 0) rotate(6deg) scale(1.08); }
}

.frame {
  position: fixed; z-index: 1; pointer-events: none;
  inset: calc(var(--safe-t) + 2.2vmin) 2.2vmin calc(var(--safe-b) + 2.2vmin);
  border: 1px solid var(--line);
  border-radius: 3vmin;
  box-shadow: inset 0 0 0 .7vmin rgba(11, 3, 20, .0), inset 0 0 0 calc(.7vmin + 1px) rgba(227, 182, 90, .14), inset 0 0 12vmin rgba(130, 70, 220, .12);
}
.frame i {
  position: absolute; width: 2.6vmin; height: 2.6vmin;
  background: var(--gold);
  clip-path: path('M13 0 C14 9 17 12 26 13 C17 14 14 17 13 26 C12 17 9 14 0 13 C9 12 12 9 13 0Z');
  opacity: .8;
  filter: drop-shadow(0 0 6px rgba(251, 227, 161, .8));
}
.frame i:nth-child(1) { top: -1.3vmin; left: -1.3vmin; }
.frame i:nth-child(2) { top: -1.3vmin; right: -1.3vmin; }
.frame i:nth-child(3) { bottom: -1.3vmin; left: -1.3vmin; }
.frame i:nth-child(4) { bottom: -1.3vmin; right: -1.3vmin; }

/* ---------- Звёздочки-искры ---------- */
#sparkles { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
.spark {
  position: absolute;
  width: var(--s, 5vmin); height: calc(var(--s, 5vmin) * 1.35);
  margin: calc(var(--s, 5vmin) * -.5) 0 0 calc(var(--s, 5vmin) * -.5);
  transition: left 1.6s var(--ease-out), top 1.6s var(--ease-out), opacity .8s ease, width 1.6s var(--ease-out), height 1.6s var(--ease-out);
}
.spark svg {
  width: 100%; height: 100%; overflow: visible;
  animation: twinkle var(--d, 4s) ease-in-out var(--delay, 0s) infinite;
  filter: drop-shadow(0 0 .9vmin rgba(251, 227, 161, .55));
}
@keyframes twinkle {
  0%, 100% { transform: scale(.78) rotate(-6deg); opacity: .55; }
  50% { transform: scale(1.06) rotate(5deg); opacity: 1; }
}

/* ---------- Сцена и экраны ---------- */
#stage { position: fixed; inset: 0; z-index: 3; }

.screen {
  position: absolute;
  inset: calc(var(--safe-t) + 5vmin) 5vmin calc(var(--safe-b) + 5vmin);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3.2vmin;
  text-align: center;
  padding: var(--pad);
  animation: screenIn .9s var(--ease-out) both;
}
.screen > * { zoom: var(--fit, 1); }
.screen.leaving { animation: screenOut .55s ease-in both; pointer-events: none; }
@keyframes screenIn {
  from { opacity: 0; transform: translateY(3vmin) scale(.985); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: none; }
}
@keyframes screenOut {
  from { opacity: 1; transform: none; filter: none; }
  to { opacity: 0; transform: translateY(-2.5vmin) scale(1.01); filter: blur(8px); }
}

/* Золотой текст */
.gold {
  background: var(--gold-grad);
  background-size: 250% 100%;
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  animation: shimmer 7s linear infinite;
  filter: drop-shadow(0 0 1.6vmin rgba(227, 182, 90, .28));
}
@keyframes shimmer { from { background-position: 0% 0; } to { background-position: -250% 0; } }

/* Рукописное появление строк */
.write {
  display: block;
  padding: .12em .25em .2em;
  clip-path: inset(-20% 100% -30% 0);
  animation: write 1.15s cubic-bezier(.55, .1, .35, 1) forwards, shimmer 7s linear infinite;
  animation-delay: var(--w, 0s), 0s;
}
@keyframes write { to { clip-path: inset(-20% -5% -30% 0); } }

.rise {
  opacity: 0;
  animation: rise .9s var(--ease-out) forwards;
  animation-delay: var(--w, 0s);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(2.4vmin); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}

.title {
  margin: 0;
  font-family: var(--f-script);
  font-weight: 400;
  font-size: clamp(54px, 12.5vmin, 150px);
  line-height: 1.02;
}
.title .write:nth-child(2) { margin-left: 18%; }
.title .write:nth-child(3) { margin-left: -10%; }

.h2 {
  margin: 0;
  font-family: var(--f-script);
  font-weight: 400;
  font-size: clamp(40px, 8.6vmin, 104px);
  line-height: 1.05;
}

.lead {
  margin: 0;
  font-family: var(--f-hand);
  font-size: clamp(24px, 4.6vmin, 56px);
  line-height: 1.45;
  color: var(--ink);
  max-width: 82vmin;
}

.topic {
  font-family: var(--f-script);
  font-size: clamp(44px, 9.5vmin, 116px);
  line-height: 1.1;
  margin: 0;
}

.sub {
  margin: 0;
  font-size: clamp(18px, 3.2vmin, 38px);
  color: var(--muted);
}

.roll-call {
  font-family: var(--f-script);
  font-size: clamp(40px, 9vmin, 110px);
  line-height: 1;
  margin: 0;
  color: var(--ink);
  display: flex; align-items: baseline; gap: .35em;
}
.roll-call b { font-family: var(--f-num); font-weight: 700; letter-spacing: .02em; }

/* Вопрос на экране «Брось кубик» — главный акцент */
.prompt-head {
  margin: 0;
  font-family: var(--f-script);
  font-weight: 400;
  font-size: clamp(36px, 7.4vmin, 92px);
  line-height: 1.12;
}
.write.white {
  color: var(--ink);
  animation: write 1.15s cubic-bezier(.55, .1, .35, 1) forwards;
  animation-delay: var(--w, 0s);
}

/* ---------- Кнопки ---------- */
.btn {
  position: relative;
  border: 0; cursor: pointer;
  font-family: var(--f-script);
  font-size: clamp(24px, 4.6vmin, 54px);
  line-height: 1;
  padding: 2.1vmin 6vmin 2.4vmin;
  border-radius: 999px;
  transition: transform .25s var(--ease-spring), opacity .3s, filter .3s;
}
.btn:active { transform: scale(.95); }
/* Все кнопки — в одной полупрозрачной стилистике */
.btn.primary, .btn.ghost {
  background: rgba(227, 182, 90, .07);
  color: var(--gold-hi);
  box-shadow: 0 0 0 1.5px rgba(227, 182, 90, .55) inset, 0 0 4vmin rgba(227, 182, 90, .08);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.btn.primary:active, .btn.ghost:active { background: rgba(227, 182, 90, .18); }
.btn.primary:disabled { opacity: .38; cursor: default; }
.btn.small { font-size: clamp(18px, 3.2vmin, 36px); padding: 1.6vmin 4.4vmin 1.8vmin; }

.actions { display: flex; gap: 2.4vmin; align-items: center; justify-content: center; flex-wrap: wrap; }

/* ---------- Кубики ---------- */
.die {
  width: var(--size, 34vmin); height: var(--size, 34vmin);
  position: relative;
  filter: drop-shadow(0 0 2.6vmin rgba(227, 182, 90, .35)) drop-shadow(0 2vmin 4vmin rgba(0, 0, 0, .5));
}
.die svg { width: 100%; height: 100%; overflow: visible; }
.die .shape { transform-origin: 50% 50%; }
.die.float .shape { animation: dieFloat 6s ease-in-out infinite; }
@keyframes dieFloat {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-4%) rotate(4deg); }
}
.die .num {
  font-family: var(--f-num); font-weight: 700;
  fill: var(--gold-hi);
  paint-order: stroke; stroke: rgba(20, 6, 36, .9); stroke-width: 6px; stroke-linejoin: round;
}
.die-pair { display: flex; gap: 4vmin; align-items: center; }
.die-pair .plus { font-family: var(--f-script); font-size: 9vmin; color: var(--gold); }

/* Бросок при раскрытии */
.die.rolling { animation: dieRoll 1.9s cubic-bezier(.15, .7, .25, 1) both; }
@keyframes dieRoll {
  0% { transform: perspective(900px) translateY(-30vmin) rotateX(0) rotateY(0) rotateZ(0) scale(.35); opacity: 0; }
  15% { opacity: 1; }
  55% { transform: perspective(900px) translateY(2vmin) rotateX(540deg) rotateY(320deg) rotateZ(260deg) scale(1.08); }
  75% { transform: perspective(900px) translateY(-1.5vmin) rotateX(700deg) rotateY(352deg) rotateZ(350deg) scale(.97); }
  100% { transform: perspective(900px) translateY(0) rotateX(720deg) rotateY(360deg) rotateZ(360deg) scale(1); opacity: 1; }
}
.die .num { opacity: 0; }
.die.show-num .num { animation: numIn .7s var(--ease-spring) forwards; }
.die.idle-num .num { opacity: 1; }
@keyframes numIn { from { opacity: 0; transform: scale(.3); } to { opacity: 1; transform: scale(1); } }
.die .num { transform-box: fill-box; transform-origin: center; }

.die-glow {
  position: absolute; inset: -18%; border-radius: 50%;
  background: radial-gradient(circle, rgba(251, 227, 161, .45), rgba(227, 182, 90, .12) 40%, transparent 68%);
  opacity: 0; pointer-events: none;
}
.die.show-num .die-glow { animation: glowPulse 1.6s ease-out forwards; }
@keyframes glowPulse { 0% { opacity: 0; transform: scale(.5); } 30% { opacity: 1; } 100% { opacity: .35; transform: scale(1.1); } }

/* Мини-кубики на заставке */
.dice-row { display: flex; gap: 2.6vmin; align-items: center; justify-content: center; flex-wrap: wrap; }
.dice-row .die { --size: 10.5vmin; filter: drop-shadow(0 0 1.4vmin rgba(227, 182, 90, .3)); }
.dice-row .die .shape { animation: dieFloat 5s ease-in-out infinite; animation-delay: var(--dd, 0s); }

/* ---------- Ввод ---------- */
.input-layout { display: flex; flex-direction: column; align-items: center; gap: 2.6vmin; }
.input-side { display: flex; flex-direction: column; align-items: center; gap: 2.2vmin; }

.hint { margin: 0; font-size: clamp(18px, 3.1vmin, 36px); color: var(--muted); }
.hint b { font-family: var(--f-num); font-weight: 700; color: var(--gold-hi); font-size: 1.12em; }

.valuebox {
  position: relative;
  width: 38vmin; height: 19vmin;
  display: grid; place-items: center;
  border-radius: 1.6vmin 3.4vmin 1.4vmin 2.8vmin;
  background: linear-gradient(180deg, rgba(40, 16, 72, .75), rgba(20, 7, 38, .85));
  box-shadow: 0 0 0 2px var(--gold) inset, 0 0 0 .8vmin rgba(227, 182, 90, .1), 0 0 5vmin rgba(227, 182, 90, .2);
  transform: rotate(-1.6deg) skewX(-2deg);
  transition: box-shadow .3s;
}
.valuebox .digits {
  font-family: var(--f-num); font-weight: 700;
  font-size: 14vmin; line-height: 1;
  color: var(--gold-hi);
  text-shadow: 0 0 3vmin rgba(251, 227, 161, .45);
  transform: rotate(1.6deg) skewX(2deg);
  min-width: 1ch;
}
.valuebox .caret {
  display: inline-block; width: .5vmin; height: 10vmin; margin-left: .6vmin;
  background: var(--gold-hi); vertical-align: middle; border-radius: 1px;
  animation: blink 1.05s steps(1) infinite;
}
.valuebox .placeholder { color: rgba(251, 227, 161, .22); }
@keyframes blink { 50% { opacity: 0; } }
.valuebox.pop .digits { animation: pop .28s var(--ease-spring); }
@keyframes pop { from { transform: rotate(1.6deg) skewX(2deg) scale(1.25); } }
.valuebox.shake { animation: shake .5s; box-shadow: 0 0 0 2px var(--err) inset, 0 0 5vmin rgba(255, 140, 120, .3); }
@keyframes shake {
  0%, 100% { transform: rotate(-1.6deg) skewX(-2deg) translateX(0); }
  20% { transform: rotate(-1.6deg) skewX(-2deg) translateX(-2vmin); }
  40% { transform: rotate(-1.6deg) skewX(-2deg) translateX(1.8vmin); }
  60% { transform: rotate(-1.6deg) skewX(-2deg) translateX(-1.2vmin); }
  80% { transform: rotate(-1.6deg) skewX(-2deg) translateX(.8vmin); }
}
.err { min-height: 1.4em; margin: 0; color: var(--err); font-size: clamp(18px, 3vmin, 34px); transition: opacity .3s; }

.keypad {
  display: grid; grid-template-columns: repeat(3, 12.5vmin); gap: 2vmin;
}
.key {
  height: 11vmin; border: 0; cursor: pointer;
  border-radius: 2.4vmin;
  font-family: var(--f-num); font-weight: 700; font-size: 6.2vmin; line-height: 1;
  color: var(--gold-hi);
  background: radial-gradient(120% 100% at 50% 0%, rgba(90, 50, 150, .55), rgba(30, 12, 54, .85));
  box-shadow: 0 0 0 1px rgba(227, 182, 90, .45) inset, 0 .8vmin 2.4vmin rgba(0, 0, 0, .35);
  transition: transform .18s var(--ease-spring), background .2s, box-shadow .2s;
  display: grid; place-items: center;
}
.key:active, .key.pressed {
  transform: scale(.92);
  background: radial-gradient(120% 100% at 50% 0%, rgba(227, 182, 90, .55), rgba(80, 40, 120, .85));
  box-shadow: 0 0 0 1px var(--gold-hi) inset, 0 0 4vmin rgba(227, 182, 90, .45);
}
.key svg { width: 5.4vmin; height: 5.4vmin; }
.key.fn { font-family: var(--f-script); font-weight: 400; font-size: 4.2vmin; color: var(--gold); }

/* ---------- Результат ---------- */
.answer {
  margin: 0;
  font-family: var(--f-script);
  font-size: clamp(32px, 6.4vmin, 78px);
  line-height: 1.28;
  max-width: 84vmin;
  color: var(--gold-hi);
  text-shadow: 0 0 2.4vmin rgba(227, 182, 90, .3);
}
.answer.long { font-size: clamp(28px, 5.5vmin, 66px); }
.answer .wd {
  display: inline-block; opacity: 0;
  animation: wordIn .7s var(--ease-out) forwards;
  animation-delay: var(--w, 0s);
}
@keyframes wordIn {
  from { opacity: 0; transform: translateY(1.6vmin) scale(.96); filter: blur(5px); }
  to { opacity: 1; transform: none; filter: none; }
}
.season-word {
  font-family: var(--f-script);
  font-size: clamp(70px, 17vmin, 200px);
  line-height: 1.05; margin: 0;
}
.season-icon { width: 20vmin; height: 20vmin; color: var(--gold-hi); filter: drop-shadow(0 0 2vmin rgba(251, 227, 161, .55)); }
.season-icon svg { width: 100%; height: 100%; animation: spinSlow 30s linear infinite; }
@keyframes spinSlow { to { transform: rotate(360deg); } }

.result-die { --size: 30vmin; }
.result-pair .die { --size: 22vmin; }

/* ---------- Финал ---------- */
.screen.thanks { justify-content: flex-start; padding-top: 7vmin; gap: 2.4vmin; }
.heart { width: 13vmin; height: 13vmin; color: var(--gold); animation: beat 1.6s ease-in-out infinite; filter: drop-shadow(0 0 2vmin rgba(227, 182, 90, .5)); }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.14); } 30% { transform: scale(.98); } 45% { transform: scale(1.08); } }

.summary {
  list-style: none; margin: 1vmin 0 0; padding: 0;
  width: min(86vmin, 100%);
  display: flex; flex-direction: column; gap: 1.5vmin;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  min-height: 0; flex: 0 1 auto;
}
.summary li {
  display: grid; grid-template-columns: 9vmin 1fr; gap: 2.4vmin; align-items: center;
  text-align: left;
  padding: 1.6vmin 2.4vmin;
  border-radius: 2vmin;
  background: linear-gradient(90deg, rgba(60, 26, 104, .55), rgba(30, 12, 54, .35));
  box-shadow: 0 0 0 1px rgba(227, 182, 90, .22) inset;
}
.summary .die { --size: 9vmin; filter: drop-shadow(0 0 1vmin rgba(227, 182, 90, .3)); }
.summary .die .num { font-size: 76px; }
.summary::-webkit-scrollbar { display: none; }
.summary { scrollbar-width: none; mask-image: linear-gradient(180deg, #000 92%, transparent); -webkit-mask-image: linear-gradient(180deg, #000 92%, transparent); padding-bottom: 3vmin; }
.summary .s-topic { display: block; font-family: var(--f-script); color: var(--gold); font-size: clamp(16px, 2.8vmin, 32px); }
.summary .s-text { display: block; font-size: clamp(16px, 2.7vmin, 31px); line-height: 1.35; color: var(--ink); }

/* ---------- Кнопка «заново» и подтверждение ---------- */
.home-btn {
  position: fixed; z-index: 6;
  top: calc(var(--safe-t) + 4.4vmin); left: 4.4vmin;
  width: 7vmin; height: 7vmin; min-width: 44px; min-height: 44px;
  border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(36, 16, 64, .5);
  box-shadow: 0 0 0 1px rgba(227, 182, 90, .3) inset;
  color: var(--gold); opacity: .55;
  display: grid; place-items: center;
  transition: opacity .3s, transform .2s;
}
.home-btn[hidden] { display: none; }
.home-btn:active { transform: scale(.92); opacity: 1; }
.home-btn svg { width: 55%; height: 55%; }

.confirm {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: rgba(8, 2, 16, .72);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  animation: fadeIn .3s ease both;
}
.confirm[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } }
.confirm-card {
  text-align: center;
  padding: 5vmin 6vmin;
  border-radius: 3vmin;
  background: linear-gradient(180deg, #26103f, #160828);
  box-shadow: 0 0 0 1px var(--line) inset, 0 3vmin 8vmin rgba(0, 0, 0, .6);
  animation: rise .5s var(--ease-out) both;
}
.confirm-title { margin: 0 0 1.4vmin; font-family: var(--f-script); font-size: clamp(32px, 6.4vmin, 72px); color: var(--gold-hi); }
.confirm-text { margin: 0 0 4vmin; font-size: clamp(18px, 3.2vmin, 36px); color: var(--muted); }
.confirm-actions { display: flex; gap: 2.4vmin; justify-content: center; }

/* ---------- Альбомная ориентация ---------- */
@media (orientation: landscape) {
  .screen { gap: 2.4vmin; }
  .input-layout { flex-direction: row; gap: 9vmin; align-items: center; }
  .keypad { grid-template-columns: repeat(3, 11.5vmin); gap: 1.6vmin; }
  .key { height: 10vmin; }
  .die { --size: 28vmin; }
  .result-die { --size: 20vmin; }
  .result-pair .die { --size: 17vmin; }
  .season-word { font-size: clamp(56px, 12vmin, 150px); }
  .season-icon { width: 12vmin; height: 12vmin; }
  .screen.result { gap: 1.8vmin; }
  .title { font-size: clamp(54px, 11.5vmin, 140px); }
  .answer { max-width: 120vmin; }
  .summary { width: min(130vmin, 100%); display: grid; grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .write { clip-path: none; }
}

/* ровные (не «старинные») цифры у Cormorant */
.key, .valuebox .digits, .die .num, .roll-call b, .hint b { font-variant-numeric: lining-nums; font-feature-settings: "lnum" 1; }
