:root {
  color-scheme: dark;
  --ink: #f8ead8;
  --muted: #d0bda9;
  --gold: #efc793;
  --line: #c1966944;
  --serif: "Baskerville", Georgia, serif;
  background: #160f16;
  color: var(--ink);
  font: 16px Arial, Helvetica, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100svh; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible { outline: 2px solid #ffe2a6; outline-offset: 5px; }

header {
  display: flex; justify-content: space-between; align-items: center;
  height: 68px; padding: 0 max(22px, 4.8vw);
  border-bottom: 1px solid var(--line);
  background: #181015;
}
.brand { color: #f6dfc1; font: italic 34px/1 var(--serif); letter-spacing: -.05em; display: flex; gap: 9px; align-items: center; }
.mark { color: var(--gold); font: 24px/1 var(--serif); }
.header-end { color: #d5b694; font: italic 16px var(--serif); }

main {
  display: grid; grid-template-columns: minmax(340px, .76fr) minmax(0, 1.24fr);
  min-height: calc(100svh - 68px);
  background:
    radial-gradient(ellipse at 21% 43%, #43212e8c, transparent 53%),
    repeating-linear-gradient(114deg, #de9f6f04 0 1px, transparent 1px 4px),
    linear-gradient(110deg, #1c1119, #21161c 52%, #150e15);
}
.paper {
  margin: 0; padding: 42px max(28px, 5vw); display: flex; flex-direction: column;
  justify-content: center; align-items: center; gap: clamp(27px, 5vh, 48px);
}
.intro, .controls { max-width: 395px; width: 100%; }
.edition {
  display: flex; align-items: center; gap: 12px;
  color: var(--gold); font: 600 11px/1.4 Arial, sans-serif; letter-spacing: .21em; text-transform: uppercase;
}
.edition i, .flourish i { width: 29px; height: 1px; background: #c99b6991; }
.intro h1 {
  margin: 22px 0 17px; font: 400 clamp(57px, 6.6vw, 99px)/.84 var(--serif);
  letter-spacing: -.072em; text-wrap: balance;
}
.intro h1 span, .intro h1 em { display: block; }
.intro h1 em { color: var(--gold); font-weight: 400; padding-top: .13em; }
.flourish { display: flex; gap: 10px; align-items: center; margin-top: 25px; color: var(--gold); font: 22px var(--serif); }
.intro p { max-width: 31ch; margin: 13px 0; color: var(--muted); font: 400 clamp(19px, 1.6vw, 24px)/1.42 var(--serif); }
.signature { display: inline-block; transform: rotate(-7deg); margin-top: 6px; color: var(--gold); font: italic 32px/1.2 "Snell Roundhand", "Apple Chancery", var(--serif); }
.signature small { font-size: 16px; }

.controls { max-width: 325px; margin-right: auto; }
#lucky, .solid {
  width: 100%; padding: 15px 18px; border: 1px solid #daaa7c90; border-radius: 5px;
  background: linear-gradient(120deg, #75323e, #4a1d2d); color: #fff0dc;
  font-size: 14px; font-weight: 600; transition: filter .2s, transform .2s;
}
#lucky:hover:not(:disabled), .solid:hover { filter: brightness(1.2); transform: translateY(-1px); }
#lucky { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
#lucky:disabled { opacity: .6; }
.controls p { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.controls #balance { font-size: 14px; margin: 0 0 11px; color: var(--gold); font-weight: 600; }
.controls details { margin-top: 20px; color: var(--gold); font-size: 14px; }
.controls summary { cursor: pointer; }
.controls ol { padding-left: 23px; line-height: 1.5; color: #f5e4ca; max-height: 175px; overflow: auto; }
.controls li button { padding: 4px 2px; border: 0; background: none; text-align: left; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }

.theatre { display: grid; place-items: center; padding: 16px 24px 16px 0; min-width: 0; }
.tree-stage { position: relative; width: min(100%, max(520px, calc((100svh - 101px) * .8)), 800px); }
.scene {
  position: relative; isolation: isolate; width: 100%;
  aspect-ratio: 4 / 5; container-type: inline-size; overflow: hidden;
  border: 1px solid #d8a87350; border-radius: 5px; background: #201319;
  box-shadow: 0 0 0 5px #140d133f, 0 18px 60px #11080e83;
}
#winter-library, #winter-effects, #balls { position: absolute; inset: 0; width: 100%; height: 100%; }
#winter-library { display: block; object-fit: cover; pointer-events: none; }
#winter-snow {
  position: absolute; top: 0; left: 72%; width: 24%; height: 54.5%;
  overflow: hidden;
  clip-path: polygon(38% 0, 100% 0, 100% 100%, 39% 100%, 39% 85%, 27% 85%, 27% 69%, 10% 66%, 2% 55%, 2% 23%, 11% 14%);
  pointer-events: none;
}
#winter-snow span {
  position: absolute; top: -4%; aspect-ratio: 1; border-radius: 50%; background: #e6f0f1;
  opacity: .52; animation: snowfall var(--period) var(--phase) linear infinite;
}
@keyframes snowfall { to { transform: translate(var(--drift), 68cqw); } }
#winter-effects { pointer-events: none; }
.fairy-light {
  position: absolute; width: 2.95cqw; aspect-ratio: 1; border-radius: 50%; translate: -50% -50%;
  background: radial-gradient(circle, #fff9dfbb 0 4%, #ffde9f92 7%, #ffab4c61 17%, #ff934a18 37%, transparent 70%);
  mix-blend-mode: screen;
  animation: fairy-rise var(--period) var(--phase) ease-in-out infinite alternate,
    light-arrive 1.1s var(--arrive) ease-out both;
}
@keyframes light-arrive {
  0% { filter: brightness(0); }
  58% { filter: brightness(1.7); }
  100% { filter: brightness(1); }
}
@keyframes fairy-rise {
  from { opacity: .38; scale: .81; }
  50% { opacity: .96; scale: 1.15; }
  to { opacity: .67; scale: .95; }
}
.flame {
  position: absolute; width: .64cqw; height: 1.7cqw; translate: -50% -95%;
  transform-origin: 50% 100%;
  border-radius: 63% 45% 54% 47% / 83% 80% 23% 22%;
  background: radial-gradient(ellipse at 53% 73%, #fff8e5 4%, #ffe4a0 44%, #fb9f44 68%, #a9502a 95%);
  box-shadow: 0 0 5px 1px #ffb95177, 0 0 16px 3px #ef8f3a32;
  animation: flicker var(--period) var(--phase) ease-in-out infinite;
}
@keyframes flicker {
  0%, 100% { transform: scale(.9, 1.02) rotate(-4deg); }
  31% { transform: scale(1.03, .84) rotate(7deg); }
  63% { transform: scale(.76, 1.14) rotate(-9deg); }
  82% { transform: scale(.97, .95) rotate(2deg); }
}

.ribbon-bow {
  position: absolute; width: 7.8cqw; height: 6.3cqw; translate: -50% -32%;
  rotate: var(--tilt); scale: var(--size); filter: drop-shadow(1px 2px 2px #100607dd);
}
.ribbon-bow i { position: absolute; display: block; }
.ribbon-bow .loop {
  width: 47%; height: 44%; top: 8%;
  background: linear-gradient(31deg, #2e0710 2%, #791b2a 36%, #9a3f46 54%, #4c0c19 77%, #370913);
  box-shadow: inset 0 1px 1px #e7977759, inset 0 -2px 3px #23050f96;
}
.ribbon-bow .loop.left { left: 5%; border-radius: 34% 73% 55% 30%; rotate: 15deg; }
.ribbon-bow .loop.right { right: 5%; border-radius: 73% 35% 30% 55%; rotate: -15deg; }
.ribbon-bow .tail {
  width: 25%; height: 66%; top: 33%; border-radius: 15%;
  background: linear-gradient(90deg, #380712 2%, #823041 45%, #4d101d 98%);
  clip-path: polygon(5% 0, 96% 0, 82% 100%, 47% 82%, 2% 100%);
  transform-origin: center 8%;
}
.ribbon-bow .tail.left { left: 38%; rotate: 20deg; }
.ribbon-bow .tail.right { right: 38%; rotate: -26deg; }
.ribbon-bow .knot {
  left: 39%; top: 23%; width: 22%; height: 28%; border-radius: 27% 44% 36% 30%;
  background: linear-gradient(114deg, #490c16, #9d4851 49%, #4d0c19 93%);
  box-shadow: inset 0 1px 1px #d5976d69, 0 1px 2px #23050f8a;
}

.ruby { --glass: var(--ruby-glass); --tone: #8f363e; --dark: #301119; }
.gold { --glass: var(--gold-glass); --tone: #af7b43; --dark: #37261c; }
.jade { --glass: var(--jade-glass); --tone: #3c6851; --dark: #102720; }
.ball {
  display: grid; place-items: center; position: absolute; z-index: 1;
  width: max(37px, var(--hit)); aspect-ratio: 1; padding: 0; border: 0; border-radius: 50%;
  background: none; translate: -50% -50%;
}
.ball:focus-visible { outline-offset: 2px; }
.glass-motion {
  position: absolute; inset: 8%; isolation: isolate; border-radius: 50%; perspective: 180px;
  box-shadow: 1px 5px 7px #080805cc, 2px 9px 9px #090c0863;
  transition: filter .24s; pointer-events: none;
}
.glass-motion::before, .glass-motion::after {
  content: ''; position: absolute; inset: 0; z-index: 2; border-radius: inherit;
  background: var(--glass, none) center / 100% 100%,
    radial-gradient(circle at 34% 25%, var(--tone), var(--dark) 95%);
}
.glass-motion::before { clip-path: inset(0 49.8% 0 0); transform-origin: 10% 60%; }
.glass-motion::after { clip-path: inset(0 0 0 49.8%); transform-origin: 90% 60%; }
.ornament-cap {
  content: ''; position: absolute; z-index: 3; bottom: 96%; left: 38%; width: 24%; height: 13%;
  border: 1px solid #f5d29c7a; border-radius: 3px 3px 1px 1px;
  background: repeating-linear-gradient(90deg, #714b2b, #d7ad68 2px, #f7db97 3px, #a77642 5px);
  box-shadow: 0 1px 2px #160f14b0;
}
.ornament-cap::before {
  content: ''; position: absolute; bottom: 92%; left: 30%; width: 40%; height: 118%;
  border: 1px solid #ceb67f; border-radius: 50%;
}
.ornament-cap::after {
  content: ''; position: absolute; bottom: 154%; left: 57%; height: 154%; width: 1px;
  background: linear-gradient(transparent, #b69d69 45%, #d6af72);
  rotate: 14deg; transform-origin: center bottom;
}
.orb {
  z-index: 3; color: #fff3da; font: 600 clamp(14px, 4.05cqw, 29px)/1 var(--serif);
  letter-spacing: -.035em; font-variant-numeric: lining-nums tabular-nums;
  text-shadow: 0 1px 3px #281019, 0 0 9px #180d16a6; pointer-events: none;
}
.ball:hover:not(:disabled) .glass-motion, .ball:focus-visible .glass-motion { filter: brightness(1.27); }
.ball.picked .glass-motion { box-shadow: 0 5px 9px #120c13ac; filter: saturate(.7); }
.ball.picked .glass-motion::before { transform: translate(-13%, 4%) rotateY(26deg) rotate(-11deg); }
.ball.picked .glass-motion::after { transform: translate(13%, 4%) rotateY(-26deg) rotate(11deg); }
.gift-slip {
  position: absolute; left: 20%; top: 34%; width: 60%; height: 42%; z-index: 1; display: grid; place-items: center;
  background: repeating-linear-gradient(103deg, #7050280b 0 1px, transparent 1px 3px),
    linear-gradient(145deg, #f9ebc6, #caa476);
  border: 1px solid #efd49a; border-radius: 1px; opacity: 0;
  box-shadow: 0 0 12px #ffe0a5ac, 0 4px 7px #231204ac;
}
.gift-slip::before {
  content: ''; position: absolute; inset: 0 0 23%;
  clip-path: polygon(0 0, 100% 0, 50% 87%);
  background: linear-gradient(145deg, #fbefcd, #dabb88 73%);
}
.wax-seal {
  position: relative; display: grid; place-items: center; margin-top: 11%;
  width: 32%; aspect-ratio: 1; border-radius: 45% 52% 48% 48%;
  background: radial-gradient(circle at 38% 31%, #ab5257, #631321 72%);
  box-shadow: 0 1px 1px #522521, inset 0 0 0 1px #d58475a3;
  color: #ffe3b1; font: italic 600 clamp(5px,1.48cqw,10px)/1 var(--serif);
}
.ball.picked .gift-slip { opacity: .95; }
.ball.unwrapping, .ball.spotlit { z-index: 6; }
.ball.unwrapping::before, .ball.spotlit::before {
  content: ''; position: absolute; inset: -93%; pointer-events: none; border-radius: 50%;
  background: radial-gradient(ellipse, #ffcc766b, #ed9b3e2c 31%, transparent 65%);
  mix-blend-mode: screen;
}
.ball.unwrapping::before { animation: branch-glow 1.1s ease-out both; }
.ball.spotlit::before { opacity: .70; }
.ball.picked.spotlit .gift-slip { transform: translateY(-108%) rotate(-10deg) scale(1.27); }
.ball.unwrapping .glass-motion {
  box-shadow: none; filter: none;
  background: radial-gradient(ellipse, #fff1b6 0 12%, #ffcd75 22%, #f6935052 45%, transparent 67%);
  animation: gift-glow .96s ease-out both;
}
.ball.unwrapping .glass-motion::before { animation: open-left .96s cubic-bezier(.2,.66,.21,1) both; }
.ball.unwrapping .glass-motion::after { animation: open-right .96s cubic-bezier(.2,.66,.21,1) both; }
.ball.unwrapping .orb { animation: number-out .52s ease-out both; }
.ball.unwrapping .gift-slip { animation: letter-lift 1.1s cubic-bezier(.25,.72,.25,1) both; }
.sparkle {
  position: absolute; top: 50%; left: 50%; font-size: 13px; color: #fff1c9;
  text-shadow: 0 0 8px #ffb24d; opacity: 0; pointer-events: none;
  animation: spark .64s .24s ease-out both;
}
@keyframes open-left {
  0%, 8% { transform: none; }
  24% { transform: translateX(-5%) rotate(-3deg); }
  75%, 100% { transform: translate(-29%, 9%) rotateY(39deg) rotate(-23deg); }
}
@keyframes open-right {
  0%, 8% { transform: none; }
  24% { transform: translateX(5%) rotate(3deg); }
  75%, 100% { transform: translate(29%, 9%) rotateY(-39deg) rotate(23deg); }
}
@keyframes letter-lift {
  0%, 21% { opacity: 0; transform: scale(.4); }
  44% { opacity: 1; }
  100% { opacity: 1; transform: translateY(-108%) rotate(-10deg) scale(1.27); }
}
@keyframes branch-glow { 0% { opacity: 0; scale: .35; } 46% { opacity: 1; scale: 1.1; } 100% { opacity: .70; scale: 1; } }
@keyframes gift-glow { 0% { background-size: 0 0; } 100% { background-size: 100% 100%; } }
@keyframes number-out { 28% { opacity: 1; } 100% { opacity: 0; transform: translateY(-7px) scale(.85); } }
@keyframes spark { from { opacity: 1; } to { opacity: 0; transform: translate(var(--x), var(--y)) rotate(94deg) scale(.55); } }

.card {
  --card-width: min(234px, 42%);
  --card-edge: clamp(10px, var(--note-x), calc(100% - var(--card-width) - 10px));
  position: absolute; z-index: 10; top: clamp(10px, var(--note-y), calc(100% - 220px)); left: var(--card-edge);
  width: var(--card-width); padding: 19px 17px 14px; border-radius: 4px;
  color: #462320; background: radial-gradient(ellipse at 26% 8%, #fff6df, #eddbba);
  border: 1px solid #c59a68; outline: 1px solid #bb915a91; outline-offset: -5px;
  box-shadow: 0 13px 34px #120a0ca1, 0 0 16px #ffd0893a;
  animation: note-arrive .45s cubic-bezier(.21,.63,.23,1) both;
}
.card.gift-left { --card-edge: clamp(10px, calc(var(--note-x) - var(--card-width)), calc(100% - var(--card-width) - 10px)); }
.card .edition { gap: 6px; letter-spacing: .09em; color: #735034; font-size: 9px; }
.card .edition i { width: 12px; flex: none; }
.card h2 { font: 400 clamp(21px, 2.4vw, 29px)/1.02 var(--serif); margin: 10px 0 5px; letter-spacing: -.045em; outline: none; }
.card p { color: #664640; font: 15px/1.26 var(--serif); margin: 5px 0 11px; }
.card .solid { width: auto; min-height: 33px; padding: 5px 9px; border-color: #8f4b3f; font-size: 11px; }
#reset { display: block; color: #68483e; border: 0; background: none; text-decoration: underline; text-underline-offset: 4px; margin: 9px 0 0; padding: 4px 0 2px; font-size: 11px; }
@keyframes note-arrive { from { opacity: 0; transform: translateY(7px) scale(.98); } }

@media (max-width: 720px) {
  header { height: 48px; padding: 0 16px; }
  .brand { font-size: 26px; gap: 6px; }
  .mark { font-size: 18px; }
  .header-end { font-size: 13px; }
  main { display: flex; align-items: center; flex-direction: column; min-height: calc(100svh - 48px); }
  .paper { display: contents; }
  .intro { order: 0; text-align: center; padding: 15px 17px 13px; margin: 0; max-width: none; }
  .intro .edition { justify-content: center; font-size: 9px; }
  .intro .edition i, .intro .flourish, .signature { display: none; }
  .intro h1 { margin: 8px 0 5px; font-size: clamp(39px, 11vw, 66px); line-height: .93; }
  .intro h1 span, .intro h1 em { display: inline; }
  .intro h1 span::after { content: ' '; }
  .intro p { max-width: 39ch; margin: 5px auto 0; font: 16px/1.27 var(--serif); }
  .theatre { order: 1; width: 100%; padding: 0 6px; }
  .tree-stage { width: min(100%, 490px); }
  .scene { border-radius: 4px; }
  .card { position: relative; inset: auto; width: 100%; margin-top: 8px; padding: 14px 16px; }
  .card h2 { font-size: 26px; }
  .controls { order: 2; width: 100%; margin: 0; padding: 14px 14px 23px; }
  .controls p { text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  #winter-snow span { animation: none !important; top: var(--snow-y); opacity: .4; }
  .fairy-light { animation: none; opacity: .64; }
}
