:root {
  --gold-1: #fff7d1;
  --gold-2: #fbe38e;
  --gold-3: #e7b548;
  --gold-4: #c48a1f;
  --cream: #f6ecc6;
  --lh: 1.16;
  --row: calc(var(--lh) * 1em);
  --bw: min(94vw, 880px, 98dvh);
  --fs: clamp(40px, min(16vw, 16dvh), 156px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #020d08;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  color: var(--cream);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 85% at 50% 36%, #12684a 0%, #0b4530 30%, #062619 62%, #020d08 100%);
}

.scene::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(130% 100% at 50% 42%, transparent 55%, rgba(0, 0, 0, .5) 100%);
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
#fx-back { z-index: 1; }
#fx-front { z-index: 4; }

/* ---------- сцена ---------- */

.stage {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.6dvh, 30px);
  padding:
    max(16px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

/* ---------- купюра ---------- */

.hero {
  position: relative;
  flex: none;
  width: var(--bw);
  aspect-ratio: 1000 / 426;
  perspective: 1500px;
  cursor: pointer;
  outline: none;
  margin-bottom: calc(clamp(6px, 1.6dvh, 18px) + var(--bw) * .00426 * var(--pile, 0));
  animation: hero-in 1.5s cubic-bezier(.16, .84, .24, 1) both;
}
.hero:focus-visible .face { outline: 3px solid var(--gold-2); outline-offset: 4px; }

@keyframes hero-in {
  from { opacity: 0; transform: translateY(26px) scale(.8); }
  to { opacity: 1; transform: none; }
}

.tilt, .flip {
  position: absolute;
  inset: 0;
}
/* Пачка рисуется под верхней купюрой отдельным слоем: при перевороте купюра не проходит сквозь неё. */
.tilt { will-change: transform; perspective: 1500px; }
.flip { transform-style: preserve-3d; transition: transform 1s cubic-bezier(.2, .78, .2, 1); }
.flip.on { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 1.2% / 2.82%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  background: #e6edd6;
  box-shadow: 0 0 0 1px rgba(8, 40, 28, .5), 0 0 60px rgba(255, 222, 130, .22);
}
.face.back { transform: rotateY(180deg); background: #e6f1e3; }
.face svg { display: block; width: 100%; height: 100%; }

/* блик на бумаге */
.face::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(105deg,
      transparent 0%, transparent 34%,
      rgba(255, 255, 255, .5) 47%, rgba(255, 244, 196, .28) 53%,
      transparent 66%, transparent 100%);
  background-size: 260% 100%;
  background-position: var(--shine, 50%) 0;
  mix-blend-mode: soft-light;
  opacity: .9;
}
.face::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(100deg, transparent 42%, rgba(255, 255, 255, .55) 50%, transparent 58%);
  background-size: 300% 100%;
  background-position: 130% 0;
  animation: glint 8s ease-in-out 2.4s infinite;
}
@keyframes glint {
  0% { background-position: 130% 0; }
  16%, 100% { background-position: -40% 0; }
}

.stack i {
  position: absolute;
  inset: 0;
  border-radius: 1.2% / 2.82%;
  background: linear-gradient(135deg, #dfe8cf, #b9cfa9);
  box-shadow: 0 0 0 1px rgba(8, 40, 28, .55), inset 0 0 0 5px #0d3a29, inset 0 0 0 6px #c8922a;
}

.floor {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: -17%;
  height: 16%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, .5), transparent);
  filter: blur(6px);
  pointer-events: none;
}

.count {
  position: absolute;
  z-index: 2;
  right: 1.5%;
  top: -8%;
  min-width: 2.3em;
  padding: .12em .5em .18em;
  border-radius: 99px;
  font: 800 clamp(13px, 2.2vw, 20px)/1.2 'Playfair Display', serif;
  text-align: center;
  color: #1a1203;
  background: linear-gradient(135deg, var(--gold-1), var(--gold-3) 55%, var(--gold-4));
  box-shadow: 0 6px 18px rgba(0, 0, 0, .4);
  opacity: 0;
  transform: scale(.6);
  transition: opacity .5s, transform .5s cubic-bezier(.3, 1.6, .5, 1);
  pointer-events: none;
}
.count.show { opacity: 1; transform: none; }

/* ---------- счёт ---------- */

.amount {
  position: relative;
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  font-family: 'Noto Serif Display', 'Playfair Display', Georgia, serif;
  font-weight: 800;
  font-size: calc(var(--fs) * var(--k, 1));
  line-height: var(--lh);
  height: var(--row);
  white-space: nowrap;
  font-variant-numeric: lining-nums tabular-nums;
  font-feature-settings: 'lnum' 1, 'tnum' 1;
  animation: rise 1.2s .25s cubic-bezier(.16, .84, .24, 1) both;
}
.amount::before {
  content: '';
  position: absolute;
  left: -8%;
  right: -8%;
  top: -30%;
  bottom: -30%;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(255, 214, 110, .2), transparent);
  pointer-events: none;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

.amount .g,
.amount .s b {
  background: linear-gradient(180deg, var(--gold-1) 8%, var(--gold-2) 34%, var(--gold-3) 56%, var(--gold-4) 72%, var(--gold-2) 96%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.amount .g { display: inline-block; height: var(--row); }
.amount .cur { font-size: .58em; margin: .12em .05em 0 0; }
.amount .sep { width: .24em; text-align: center; }
.amount .frac { display: inline-flex; font-size: .44em; margin: .2em 0 0 .06em; }

.amount .d {
  display: inline-block;
  width: .575em;
  height: var(--row);
  overflow: hidden;
  text-align: center;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 14%, #000 86%, transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 14%, #000 86%, transparent 100%);
}
.amount .s { display: block; will-change: transform; }
.amount .s b { display: block; height: var(--row); font-weight: inherit; }
.amount .d.fast .s { filter: blur(.035em); opacity: .82; }

/* ---------- сегодня и следующий миллион ---------- */

.meta {
  flex: none;
  width: min(84vw, 560px);
  animation: rise 1.2s .5s cubic-bezier(.16, .84, .24, 1) both;
}
.meta .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: .55em;
  font-size: clamp(14px, min(3.8vw, 2.6dvh), 21px);
  font-variant-numeric: lining-nums tabular-nums;
  font-feature-settings: 'lnum' 1, 'tnum' 1;
}
.today { font-style: italic; font-weight: 500; color: rgba(246, 236, 198, .72); }
.today b, .next { font-family: 'Noto Serif Display', 'Playfair Display', Georgia, serif; font-weight: 800; }
.today b { font-style: normal; color: var(--gold-2); margin-left: .25em; }
.next { color: rgba(246, 236, 198, .5); }

.bar {
  height: 5px;
  border-radius: 9px;
  background: rgba(255, 236, 170, .13);
}
.bar i {
  position: relative;
  display: block;
  height: 100%;
  width: 0;
  min-width: 10px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold-4), var(--gold-2));
  box-shadow: 0 0 14px rgba(251, 227, 142, .85);
}
.bar i::after {
  content: '';
  position: absolute;
  right: -3px;
  top: 50%;
  width: 11px;
  height: 11px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: #fffbe6;
  box-shadow: 0 0 12px 3px rgba(255, 236, 160, .95);
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse {
  50% { transform: scale(1.35); box-shadow: 0 0 20px 6px rgba(255, 236, 160, .95); }
}

/* ---------- слова ---------- */

.say {
  flex: none;
  margin: clamp(2px, 1dvh, 12px) 0 0;
  min-height: 1.3em;
  font-style: italic;
  font-weight: 500;
  font-size: clamp(21px, min(6vw, 4.4dvh), 40px);
  line-height: 1.3;
  letter-spacing: .01em;
  text-align: center;
  color: #fdf3cf;
  text-shadow: 0 2px 24px rgba(255, 214, 110, .35);
  transition: opacity .9s ease, transform .9s ease, filter .9s ease;
  animation: rise 1.2s .75s cubic-bezier(.16, .84, .24, 1) both;
}
.say.out { opacity: 0; transform: translateY(10px); filter: blur(6px); }

/* ---------- кнопки ---------- */

.ctl {
  position: absolute;
  z-index: 5;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
}
.ctl button {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 236, 170, .22);
  background: rgba(2, 20, 13, .35);
  color: var(--gold-2);
  cursor: pointer;
  opacity: .5;
  transition: opacity .25s, background .25s, transform .15s;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.ctl button:hover, .ctl button:focus-visible { opacity: 1; background: rgba(2, 20, 13, .6); outline: none; }
.ctl button:active { transform: scale(.92); }
.ctl svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}
.ctl button[aria-pressed='true'] .off,
.ctl button[aria-pressed='false'] .on { display: none; }
.ctl [hidden] { display: none; }

/* ---------- размеры ---------- */

/* высокий экран телефона: купюра во всю ширину, счёт крупнее */
@media (orientation: portrait) {
  :root {
    --bw: min(95vw, 62dvh);
    --fs: clamp(40px, 16.6vw, 132px);
  }
  .stage { gap: clamp(12px, 4.2dvh, 46px); padding-bottom: max(16px, env(safe-area-inset-bottom), 5dvh); }
  .say { font-size: clamp(22px, 7vw, 40px); }
}

/* низкий экран: телефон на боку */
@media (orientation: landscape) and (max-height: 520px) {
  :root {
    --bw: min(70vw, 100dvh);
    --fs: clamp(34px, 15dvh, 80px);
  }
  .stage { gap: 6px; }
  .hero { margin-bottom: calc(4px + var(--bw) * .00426 * var(--pile, 0)); }
  .say { margin-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .hero, .amount, .meta, .say { animation: none; }
  .face::before, .bar i::after { animation: none; }
  .flip { transition-duration: .01s; }
}
