/* «Наряди ёлку»: a night room with the tree in the middle and boxes of toys on the shelves. */
.elka-page { --top: 52px; background: var(--pine-950); color: var(--cream); }
.elka-page :focus-visible { outline-color: var(--gold); }

.elka-top { position: relative; z-index: 5; display: flex; align-items: center; gap: 16px; height: var(--top); padding: 0 clamp(12px, 2vw, 24px); border-bottom: 1px solid var(--line-dark); background: rgba(11,26,20,.86); }
.elka-brand { display: inline-flex; align-items: center; gap: 8px; font: 400 1.35rem/1 var(--script); color: var(--gold-hi); text-decoration: none; }
.elka-title { flex: 1; text-align: center; font: 700 1.05rem/1 var(--display); letter-spacing: .02em; }
.elka-title em { font: 400 1.4rem/1 var(--script); font-style: normal; color: var(--gold-hi); }
.elka-tools { display: flex; align-items: center; gap: 10px; }
.elka-count { font: 600 .82rem/1 var(--ui); color: var(--cream-dim); white-space: nowrap; }
.elka-count b { color: var(--gold-hi); }

/* ---------- Stage ---------- */
.elka-stage { position: relative; display: grid; grid-template-columns: minmax(190px, 1fr) auto minmax(190px, 1fr); grid-template-rows: minmax(0, 1fr); gap: clamp(8px, 2vw, 28px);
  height: calc(100svh - var(--top)); min-height: 560px; padding: 14px clamp(10px, 2vw, 24px) 10px; overflow: hidden;
  background: radial-gradient(ellipse 60% 70% at 50% 58%, rgba(241,217,164,.13), transparent 70%), radial-gradient(ellipse at 50% 120%, #1d3d2f, transparent 60%), linear-gradient(180deg, #08130e, #0f2219 70%, #142c21); }
.elka-stage::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 9%; background: linear-gradient(180deg, transparent, rgba(5,12,9,.55)); pointer-events: none; }

.tree-zone { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 8px; min-height: 0; }
.tree { position: relative; width: min(calc((100svh - var(--top) - 96px) * .75), 46vw); aspect-ratio: 3 / 4; flex: none; transform-origin: 50% 100%; transition: transform .9s var(--ease); touch-action: none; }
.tree-img { width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; pointer-events: none;  -webkit-mask: linear-gradient(transparent 10.6%, #000 11.2%); mask: linear-gradient(transparent 10.6%, #000 11.2%); }
/* The mask cuts the bare leader above y 175 of 1600: the star covers the rest of it. */
.tree-hint { min-height: 1.3em; font-size: .86rem; color: var(--cream-dim); text-align: center; }
.elka-ready { position: absolute; bottom: 4px; animation: ready-pulse 1.6s ease-in-out infinite; box-shadow: 0 0 0 0 rgba(241,217,164,.6); }
@keyframes ready-pulse { 50% { box-shadow: 0 0 0 12px rgba(241,217,164,0); transform: scale(1.04); } }

/* Lights: dark glass bulbs that come on as the tree fills. */
.tree-lights, .tree-toys { position: absolute; inset: 0; }
.tree-lights { pointer-events: none; }
.bulb { position: absolute; width: 1.7%; aspect-ratio: 1; margin: -.85% 0 0 -.85%; border-radius: 50%; background: #233a2d; box-shadow: inset 0 -1px 2px rgba(0,0,0,.5); transition: background .5s, box-shadow .5s; }
.bulb.is-on { background: var(--c); box-shadow: 0 0 6px 2px var(--c), 0 0 16px 4px color-mix(in srgb, var(--c) 45%, transparent); animation: twinkle 2.6s ease-in-out infinite; animation-delay: var(--d); }
@keyframes twinkle { 50% { opacity: .55; } }

.tree-star { position: absolute; z-index: 1; width: 14%; aspect-ratio: 1; transform: translate(-50%, -50%); pointer-events: none; }
.tree-star img { position: absolute; inset: 0; width: 100%; height: 100%; transition: opacity .6s; }
.tree-star .star-on { opacity: 0; }
.tree-star.is-lit .star-on { opacity: 1; filter: drop-shadow(0 0 10px rgba(255,210,110,.75)); animation: star-glow 2.2s ease-in-out infinite; }
.tree-star.is-lit::before { content: ''; position: absolute; inset: -55%; border-radius: 50%; background: conic-gradient(from 0deg, transparent 0 8%, rgba(255,226,140,.35) 10%, transparent 12% 33%, rgba(255,226,140,.3) 35%, transparent 37% 58%, rgba(255,226,140,.35) 60%, transparent 62% 83%, rgba(255,226,140,.3) 85%, transparent 87%); animation: rays 9s linear infinite; mask: radial-gradient(circle, #000 20%, transparent 70%); }
.tree-star.is-burst img { animation: star-burst .9s var(--ease); }
@keyframes star-glow { 50% { transform: scale(1.08); } }
@keyframes star-burst { 0% { transform: scale(.6); } 55% { transform: scale(1.5); } 100% { transform: scale(1); } }
@keyframes rays { to { transform: rotate(1turn); } }

/* Toys on the tree hang from their loop and swing around it. */
.hung { position: absolute; transform: translateX(-50%); transform-origin: 50% 0; cursor: grab; touch-action: none; }
.hung img { width: 100%; height: auto; pointer-events: none; filter: drop-shadow(0 4px 4px rgba(0,0,0,.45)); user-select: none; -webkit-user-drag: none; }
.hung.is-new { animation: hang-in .5s var(--ease); }
.hung.is-swing { animation: swing 1.4s ease-out; }
@keyframes hang-in { 0% { transform: translateX(-50%) translateY(-18px) scale(1.2); opacity: .4; } 100% { transform: translateX(-50%); } }
@keyframes swing { 15% { transform: translateX(-50%) rotate(9deg); } 35% { transform: translateX(-50%) rotate(-7deg); } 55% { transform: translateX(-50%) rotate(4deg); } 75% { transform: translateX(-50%) rotate(-2deg); } }
.hung.is-golden img, .toy.is-golden img, .drag-ghost.is-golden img { filter: drop-shadow(0 0 6px rgba(255,210,110,.9)); }
.toy.is-golden::after { content: '✦'; position: absolute; top: -2px; right: 0; color: #ffd76a; font-size: .8rem; animation: twinkle 1.4s infinite; }

/* Wishes float up in the free space beside the top of the cone, on the side away from the new toy. */
.wish { position: absolute; z-index: 1000; top: 22%; width: min(36%, 240px); padding: 12px 14px 13px; border: 1px solid rgba(217,178,111,.55); border-radius: 14px; background: linear-gradient(180deg, rgba(255,250,238,.97), rgba(246,236,214,.97)); color: var(--ink); font: 600 .86rem/1.35 var(--ui); text-align: center; text-wrap: balance; box-shadow: 0 14px 30px -14px rgba(0,0,0,.8), 0 0 24px -6px rgba(255,210,120,.35); pointer-events: none; animation: wish 3s ease forwards; }
.wish::before { content: '✦'; display: block; margin-bottom: 3px; color: var(--gold, #c9a25a); font-size: .8rem; line-height: 1; }
.wish.is-left { left: 0; --from: -14px; }
.wish.is-right { right: 0; --from: 14px; }
@keyframes wish { 0% { opacity: 0; translate: var(--from, 0) 10px; scale: .94; } 14%, 78% { opacity: 1; translate: 0 0; scale: 1; } 100% { opacity: 0; translate: 0 -14px; scale: 1; } }

/* ---------- Shelves: boxes of toys ---------- */
.shelf { position: relative; z-index: 2; display: flex; flex-direction: column; gap: 8px; min-height: 0; overflow-y: auto; padding: 2px 4px 40px; scrollbar-width: thin; scrollbar-color: var(--pine-700) transparent; transition: opacity .6s, transform .8s var(--ease); }
.box { border: 1px solid var(--line-dark); border-radius: var(--r); background: linear-gradient(180deg, rgba(33,70,58,.55), rgba(16,36,28,.75)); }
.box-head { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; background: none; text-align: left; font: 600 .86rem/1.2 var(--ui); color: var(--cream); }
.box-head img { width: 26px; height: 30px; object-fit: contain; flex: none; }
.box-head span { flex: 1; }
.box-head::after { content: '›'; color: var(--gold); transition: transform .3s; }
.box.is-open .box-head::after { transform: rotate(90deg); }
.box.is-open { border-color: var(--gold); }
.box-toys { display: none; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 0 8px 10px; }
.box.is-open .box-toys { display: grid; }
.toy { position: relative; display: grid; place-items: center; min-width: 0; aspect-ratio: 1; padding: 4px; border: 1px solid transparent; border-radius: 8px; background: rgba(5,12,9,.25); cursor: grab; touch-action: pan-y; }
.toy img { max-width: 100%; max-height: 100%; object-fit: contain; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.toy:hover { background: rgba(241,217,164,.1); }
.toy.is-picked { border-color: var(--gold-hi); background: rgba(241,217,164,.18); box-shadow: 0 0 0 2px rgba(241,217,164,.25); }
.drag-ghost { position: fixed; z-index: 60; width: 64px; pointer-events: none; transform: translate(-50%, -12%) scale(1.15); filter: drop-shadow(0 12px 10px rgba(0,0,0,.5)); }
.drag-ghost img { width: 100%; }

.elka-snow { position: absolute; inset: 0; z-index: 3; width: 100%; height: 100%; pointer-events: none; }

/* ---------- Shared tree ---------- */
.shared-bar { position: absolute; left: 50%; bottom: 16px; z-index: 6; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; padding: 12px 16px; border: 1px solid var(--line-dark); border-radius: var(--r-lg); background: var(--glass); backdrop-filter: blur(8px); transform: translateX(-50%); }
.shared-bar p { width: 100%; text-align: center; font: 400 1.4rem/1.2 var(--script); color: var(--gold-hi); }
.is-shared .shelf { visibility: hidden; }
.is-shared #shared-open:not(:disabled) { animation: invite 2s ease-in-out infinite; }
@keyframes invite { 50% { box-shadow: 0 0 0 6px rgba(241,217,164,.18), 0 0 28px rgba(255,210,120,.45); } }
.is-shared .tree-hint { visibility: hidden; }

/* ---------- Finale ---------- */
.finale { position: absolute; inset: 0; z-index: 8; pointer-events: none; }
.finale > * { pointer-events: auto; }
.finale-sky { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.is-finale .shelf-left { opacity: 0; transform: translateX(-60px); pointer-events: none; }
.is-finale .shelf-right { opacity: 0; transform: translateX(60px); pointer-events: none; }
.is-finale .tree { transform-origin: 50% 0; transform: scale(.88); }
.is-finale .tree-hint, .is-finale .elka-ready, .is-finale .shared-bar { visibility: hidden; }
.hero-char { position: absolute; bottom: 2%; width: auto; height: 46%; max-width: 30%; object-fit: contain; filter: drop-shadow(0 18px 18px rgba(0,0,0,.55)); opacity: 0; pointer-events: none; }
.hero-moroz { left: 3%; transform: translateX(-120%); }
.hero-snegurochka { right: 13%; height: 42%; transform: translateX(160%); }
.hero-snowman { right: 2%; height: 25%; transform: translateX(160%); }
.hero-char.hero-gifts { height: auto; max-width: none; transform: translateY(24px) scale(.92); transform-origin: 50% 100%; filter: drop-shadow(0 10px 12px rgba(0,0,0,.5)); }
.finale.is-on .hero-char { opacity: 1; transform: none; transition: transform 1.3s var(--ease), opacity .6s; }
.finale.is-on .hero-snegurochka { transition-delay: .25s; }
.finale.is-on .hero-gifts { transition-delay: .6s; }
.finale.is-on .hero-snowman { transition-delay: .45s; animation: hop 1.6s ease-in-out 2s infinite; }
@keyframes hop { 50% { translate: 0 -10px; } }
.finale-title { position: absolute; top: 1.5%; left: 0; right: 0; text-align: center; font: 400 clamp(2rem, 4.8vw, 4.2rem)/1.1 var(--script); color: #ffe3a0; text-shadow: 0 0 18px rgba(255,200,90,.7), 0 4px 0 #7e5c26, 0 10px 30px rgba(0,0,0,.6); pointer-events: none; }
.finale-title.is-long { font-size: clamp(1.7rem, 3.6vw, 3.2rem); }
.finale-title .word { display: inline-block; margin: 0 .14em; white-space: nowrap; }
.finale-title .ch { display: inline-block; opacity: 0; transform: translateY(30px) scale(.6); }
.finale.is-on .finale-title .ch { opacity: 1; transform: none; transition: transform .7s cubic-bezier(.3,1.6,.5,1), opacity .4s; transition-delay: calc(var(--i) * 55ms + .7s); }
.finale-note { position: absolute; top: calc(2.5% + clamp(2.6rem, 6.4vw, 5.6rem)); left: 0; right: 0; text-align: center; font: 600 .95rem/1.3 var(--ui); color: var(--gold-hi); animation: wish-in .8s 2s both; }
@keyframes wish-in { from { opacity: 0; translate: 0 10px; } }
.finale-actions { position: absolute; left: 50%; bottom: 12px; display: flex; flex-wrap: nowrap; white-space: nowrap; justify-content: center; gap: 10px; padding: 12px 44px 12px 14px; border: 1px solid var(--line-dark); border-radius: var(--r-lg); background: var(--glass); backdrop-filter: blur(8px); transform: translateX(-50%); animation: wish-in .6s both; }
.finale-close { position: absolute; top: 50%; right: 8px; display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--cream-dim); font-size: 1.3rem; line-height: 1; transform: translateY(-50%); transition: background-color .2s, color .2s; }
.finale-close:hover { background: rgba(246,238,220,.1); color: var(--cream); }

/* ---------- Share dialog ---------- */
.share-dialog { width: min(420px, calc(100vw - 24px)); padding: 0; border: 0; border-radius: var(--r-lg); background: var(--paper); color: var(--ink); box-shadow: 0 30px 60px -20px rgba(0,0,0,.7); }
.share-dialog { max-height: calc(100svh - 24px); overflow: auto; }
.share-hint { margin-top: -6px; font-size: .86rem; color: var(--ink-mute); }
.share-card { display: grid; gap: 12px; padding-top: 16px; border-top: 1px solid var(--line-light); }
.share-card h3 { font: 400 1.4rem/1.1 var(--script); }
.share-card textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line-light); border-radius: var(--r-sm); background: #fff; font: inherit; font-size: 1rem; resize: vertical; }
.card-random { justify-self: start; margin-top: -6px; }
.card-formats { display: flex; gap: 8px; }
.card-formats .chip { color: var(--ink); border-color: var(--line-light); }
.card-formats .chip[aria-pressed=true] { border-color: var(--gold-lo); box-shadow: inset 0 0 0 1px var(--gold-lo); background: rgba(217,178,111,.14); }
.card-preview { display: block; width: 100%; max-height: 380px; object-fit: contain; border-radius: var(--r-sm); background: #0d2219; }
.card-preview:not([src]) { aspect-ratio: 1; }
.share-dialog::backdrop { background: rgba(5,12,9,.6); backdrop-filter: blur(3px); }
.share-form { position: relative; display: grid; gap: 14px; padding: 24px 22px 22px; }
.share-form h2 { font: 400 1.7rem/1.1 var(--script); }
.share-label { display: grid; gap: 6px; font: 600 .85rem/1 var(--ui); color: var(--ink-mute); }
.share-label input, .share-result input { width: 100%; padding: 10px 12px; border: 1px solid var(--line-light); border-radius: var(--r-sm); background: #fff; font-size: 1rem; }
.share-result { display: grid; gap: 10px; }
.share-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.share-buttons .btn-ghost { color: var(--ink); border-color: var(--line-light); }
.share-error { color: var(--ruby); font-size: .88rem; }
.share-mail { display: grid; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line-light); }
.share-mail-row { display: flex; gap: 8px; }
.share-mail-row input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--line-light); border-radius: var(--r-sm); background: #fff; font-size: 1rem; }
.share-mail-status { min-height: 1.2em; font-size: .86rem; color: var(--ink-mute); }
.share-mail-status:empty { display: none; }
.share-mail-status.is-error { color: var(--ruby); }
.share-close { position: absolute; top: 8px; right: 10px; width: 32px; height: 32px; border: 0; background: none; font-size: 1.4rem; color: var(--ink-mute); }

.elka-about { padding: var(--section) 0; background: var(--ivory); color: var(--ink); }
.elka-about .wrap { max-width: 760px; margin: 0 auto; padding: 0 20px; }
.elka-about h2 { margin-bottom: 14px; font: 800 clamp(1.4rem, 2.6vw, 2rem)/1.15 var(--display); }
.elka-about ol { margin: 0 0 14px; padding-left: 1.3em; display: grid; gap: 8px; }

/* ---------- Phones: tree on top, a tray of boxes below ---------- */
@media (max-width: 760px) {
  .wish, .wish.is-left, .wish.is-right { top: auto; bottom: 93.5%; left: 50%; right: auto; width: min(84%, 320px); transform: translateX(-50%); --from: 0; }
  .elka-page { --top: 48px; }
  .elka-title { display: none; }
  .elka-top { justify-content: space-between; }
  .elka-stage { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); min-height: 520px; }
  .tree { width: min(calc((100svh - var(--top) - 236px) * .75), calc(100vw - 16px)); }
  .shelf-right { display: none; }
  .shelf-left { order: 3; min-width: 0; overflow: visible; padding: 0; gap: 6px; }
  .tray-tabs, .tray-toys { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; }
  .tray-tabs::-webkit-scrollbar, .tray-toys::-webkit-scrollbar { display: none; }
  .tray-tab { flex: none; display: flex; align-items: center; gap: 6px; padding: 5px 10px 5px 6px; border: 1px solid var(--line-dark); border-radius: 999px; background: rgba(16,36,28,.8); font: 600 .76rem/1 var(--ui); color: var(--cream); white-space: nowrap; }
  .tray-tab img { width: 20px; height: 24px; object-fit: contain; }
  .tray-tab[aria-pressed="true"] { border-color: var(--gold); background: rgba(217,178,111,.2); }
  .tray-toys { padding: 2px 0; touch-action: pan-x; }
  .tray-toys .toy { flex: 0 0 58px; touch-action: pan-x; }
  .elka-ready { bottom: 0; }
  .is-finale .shelf-left { transform: translateY(40px); }
  .hero-char { height: 24%; bottom: 112px; }
  .hero-moroz { left: 1%; }
  .hero-snegurochka { right: 17%; height: 22%; }
  .hero-snowman { right: 1%; height: 15%; }
  .finale-actions { display: grid; grid-template-columns: 1fr 1fr; width: calc(100% - 16px); gap: 6px; padding: 8px 36px 8px 8px; backdrop-filter: none; background: rgba(11,26,20,.9); }
  .finale-actions .btn { min-height: 38px; padding: 6px 8px; font-size: .8rem; }
  .finale-close { top: 6px; transform: none; }
  .finale-actions #finale-cta { grid-column: 1 / -1; }
  .finale-actions #share-open[hidden] + .btn { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .bulb.is-on, .tree-star.is-lit .star-on, .tree-star.is-lit::before, .elka-ready, .hero-snowman { animation: none !important; }
  .hung.is-swing, .hung.is-new { animation: none; }
  .is-shared #shared-open { animation: none; }
}
