:root {
  --bg: #11142b;
  --navy: #1b1f3b;
  --gold: #d9b25f;
  --gold-dim: rgba(217, 178, 95, 0.55);
  --serif: 'Playfair Display', 'Times New Roman', serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg);
  color: var(--gold);
  font-family: var(--serif);
  font-weight: 500;
  padding: 12px 16px calc(6px + env(safe-area-inset-bottom));
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1.5px 1.5px at 12% 18%, var(--gold) 50%, transparent 52%),
    radial-gradient(1px 1px at 82% 12%, var(--gold) 50%, transparent 52%),
    radial-gradient(2px 2px at 70% 38%, var(--gold) 50%, transparent 52%),
    radial-gradient(1px 1px at 24% 52%, var(--gold) 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 90% 66%, var(--gold) 50%, transparent 52%),
    radial-gradient(1px 1px at 8% 84%, var(--gold) 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 56% 92%, var(--gold) 50%, transparent 52%),
    radial-gradient(1px 1px at 40% 8%, var(--gold) 50%, transparent 52%),
    radial-gradient(ellipse at 50% 38%, #1d2250 0%, var(--bg) 62%);
  opacity: 0.9;
}

header { text-align: center; max-width: 520px; }
h1 {
  margin: 2px 0 4px;
  font-size: clamp(26px, 6.4vw, 42px);
  font-weight: 500;
  letter-spacing: 0.04em;
  line-height: 1.15;
}
.sub {
  margin: 0;
  font-style: italic;
  font-size: clamp(14px, 3.6vw, 18px);
  color: var(--gold-dim);
  color: color-mix(in srgb, var(--gold) 75%, transparent);
}
.note {
  margin: 8px auto 0;
  font-size: 13px;
  padding: 5px 14px;
  width: fit-content;
  max-width: 100%;
  border: 1px dashed var(--gold-dim);
  border-radius: 999px;
}

main {
  flex: 1;
  min-height: 260px;
  width: calc(100% + 32px);
  margin: 0 -16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0;
  container-type: size;
}

.deck {
  position: relative;
  width: min(88vw, calc((100vh - 215px) * 0.625), 440px);
  width: min(88vw, calc((100dvh - 215px) * 0.625), 440px);
  width: min(92cqw, calc(100cqh * 0.625), 540px);
  min-width: 190px;
  aspect-ratio: 200 / 320;
  perspective: 1400px;
}
.deck::before,
.deck::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: var(--navy);
  border: 1.5px solid var(--gold-dim);
}
.deck::before { transform: rotate(-4.5deg) translateX(-3%); }
.deck::after { transform: rotate(3.5deg) translateX(3%); }

.card {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  border-radius: 14px;
  transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transform-style: preserve-3d;
  transition: transform 0.25s ease;
}
.hit {
  position: absolute;
  inset: 0;
  z-index: 4;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 14px;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}
.hit:focus-visible { outline: 2px solid var(--gold); outline-offset: 6px; }
@media (hover: hover) {
  .deck:hover .card { transform: translateY(-6px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); }
}
.card.shuffle { animation: shake 0.65s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: none; }
  15% { transform: translateX(-14px) rotate(-5deg); }
  35% { transform: translateX(14px) rotate(5deg); }
  55% { transform: translateX(-9px) rotate(-3deg); }
  75% { transform: translateX(9px) rotate(3deg); }
}

.inner {
  position: absolute;
  inset: 0;
  display: block;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card.flipped .inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: 14px;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.face svg { width: 100%; height: 100%; display: block; }
.front { transform: rotateY(180deg); }

footer { margin-top: 0; text-align: center; font-size: 14px; font-style: italic; }
footer p { margin: 0; }
footer a { color: var(--gold); text-underline-offset: 3px; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-style: normal;
  letter-spacing: 0.06em;
  color: color-mix(in srgb, var(--gold) 70%, transparent);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.brand img { height: 17px; width: auto; display: block; }
.brand, .brand:hover, .brand:active, .brand:focus, .brand span { text-decoration: none; -webkit-text-decoration: none; }
.brand:hover { background: rgba(217, 178, 95, 0.12); color: var(--gold); }
.brand:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#share { right: auto; left: 12px; }
.ibtn.busy { animation: pulse 0.8s ease-in-out infinite; pointer-events: none; }
@keyframes pulse { 50% { opacity: 0.4; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  background: var(--gold);
  color: var(--navy);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  max-width: 90vw;
  text-align: center;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.sr {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (min-width: 900px) {
  body { padding-top: 32px; }
  .deck { width: min(calc((100vh - 250px) * 0.625), 460px); width: min(calc((100dvh - 250px) * 0.625), 460px); }
}

@media (max-height: 560px) {
  .sub { display: none; }
  .deck { min-width: 150px; }
}

/* ---- satisfying bits ---- */
.sky { animation: twinkle 5s ease-in-out infinite; }
@keyframes twinkle { 0%, 100% { opacity: 0.75; } 50% { opacity: 1; } }

.deck:not(.revealed) { animation: float 4.5s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.deck.shuffling::before { animation: riffleL 0.65s ease-in-out; }
.deck.shuffling::after { animation: riffleR 0.65s ease-in-out; }
@keyframes riffleL {
  0%, 100% { transform: rotate(-4.5deg) translateX(-3%); }
  25% { transform: rotate(-15deg) translateX(-24%); }
  50% { transform: rotate(7deg) translateX(10%); }
  75% { transform: rotate(-11deg) translateX(-15%); }
}
@keyframes riffleR {
  0%, 100% { transform: rotate(3.5deg) translateX(3%); }
  25% { transform: rotate(14deg) translateX(24%); }
  50% { transform: rotate(-8deg) translateX(-10%); }
  75% { transform: rotate(11deg) translateX(15%); }
}

.halo {
  position: absolute;
  inset: -14%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(217, 178, 95, 0.5), rgba(217, 178, 95, 0) 62%);
  opacity: 0;
  pointer-events: none;
}
.deck.pop .halo { animation: halo 0.9s ease-out; }
@keyframes halo {
  0% { opacity: 0; transform: scale(0.7); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.3); }
}
.deck.pop .card { animation: lift 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.3); }
@keyframes lift {
  0% { transform: scale(1); }
  40% { transform: scale(1.07) translateY(-8px); }
  100% { transform: scale(1); }
}

.star {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--s, 10px);
  height: var(--s, 10px);
  background: var(--gold);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  pointer-events: none;
  z-index: 3;
  animation: burst 0.9s cubic-bezier(0.1, 0.7, 0.3, 1) forwards;
}
@keyframes burst {
  0% { transform: translate(-50%, -50%) scale(0.2) rotate(0deg); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1) rotate(var(--r)); opacity: 0; }
}

.front::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 35%, rgba(255, 240, 200, 0.38) 50%, transparent 65%);
  transform: translateX(-130%);
  pointer-events: none;
}
.card.flipped .front::after { animation: shine 1s 0.55s ease-out; }
@keyframes shine { to { transform: translateX(130%); } }

.ibtn {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: 12px;
  z-index: 5;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid var(--gold-dim);
  background: rgba(17, 20, 43, 0.65);
  color: var(--gold);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.ibtn:hover { background: rgba(217, 178, 95, 0.15); }
.ibtn:active { transform: scale(0.94); }
.ibtn:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.ibtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ibtn .off { display: none; }
.ibtn[aria-pressed='true'] .on { display: none; }
.ibtn[aria-pressed='true'] .off { display: block; }

@media (prefers-reduced-motion: reduce) {
  .inner { transition-duration: 0.01s; }
  .card, .btn, .toast { transition: none; }
  .card:hover { transform: none; }
  .sky, .deck, .deck::before, .deck::after, .deck .card, .card.flipped .front::after { animation: none !important; }
  .halo, .star { display: none; }
}
