:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, "PingFang SC", sans-serif;
  color: #f9e8c8;
  background: #050d1a;
  --bottom: max(1rem, env(safe-area-inset-bottom));
}

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

#gift {
  position: relative;
  isolation: isolate;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #050d1a;
  touch-action: none;
  user-select: none;
}

#scene { position: absolute; inset: 0; }
#scene canvas { display: block; width: 100%; height: 100%; }
#scene[data-turnable] { cursor: grab; }
#scene[data-turnable]:active { cursor: grabbing; }
#gift[data-can-advance] { cursor: pointer; }

.heading {
  position: absolute;
  inset: max(1.3rem, env(safe-area-inset-top)) 1.2rem auto;
  text-align: center;
  pointer-events: none;
}
.heading h1 {
  margin: 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(1.7rem, 6.3vw, 3.2rem);
  font-weight: 400;
  letter-spacing: .045em;
  line-height: 1.15;
  text-shadow: 0 2px 16px #08070a, 0 0 22px #f0a74244;
}
#gift[data-order] .heading { inset-inline: 3.3rem; }
.gift-menu, .preview-return {
  position: absolute;
  z-index: 3;
  top: max(.65rem, env(safe-area-inset-top));
}
.gift-menu { right: max(.55rem, env(safe-area-inset-right)); }
.gift-menu button { width: 44px; padding: 0; font-size: 1.3rem; }
.gift-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  padding: .45rem .85rem;
  border-radius: .65rem;
  border: 1px solid #b9975d85;
  background: #0a111ded;
  color: #f7e8cd;
  font-size: .84rem;
  text-decoration: none;
}
.gift-menu .gift-link { position: absolute; top: calc(100% + .35rem); right: 0; white-space: nowrap; }
.preview-return { left: max(.55rem, env(safe-area-inset-left)); }
#gift[data-preview] .heading { top: max(3.8rem, calc(env(safe-area-inset-top) + 3.1rem)); }
.gift-empty {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 2rem;
  text-align: center;
  background: radial-gradient(ellipse at 50% 42%, #20263b 0%, #050d1a 65%);
}
.gift-empty h2 { font: 400 1.55rem/1.35 Georgia, "Songti SC", serif; }
.heading p {
  margin: .42rem auto 0;
  max-width: 26rem;
  font-size: .83rem;
  line-height: 1.45;
  color: #efe0c7;
}
#gift[data-mode="photo"] .heading p { visibility: hidden; }

.dedication {
  position: absolute;
  pointer-events: none;
  inset: auto 1rem max(5.7rem, calc(var(--bottom) + 4.55rem));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .68rem;
  color: #f8e5ba;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(.9rem, 3vw, 1.23rem);
  line-height: 1.35;
  text-align: center;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 3px #050d1a, 0 0 16px #050d1a, 0 0 4px #050d1a;
  animation: dedication-in 3.4s both;
}
.dedication::before, .dedication::after {
  content: "";
  width: clamp(.75rem, 4vw, 2rem);
  height: 1px;
  background: #ceac70a0;
  flex: 0 0 auto;
}
@keyframes dedication-in {
  0% { opacity: 0; transform: translateY(.35rem); }
  18%, 76% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .dedication { animation: none; }
}

button {
  min-height: 44px;
  padding: .38rem .87rem;
  color: #f7e8cd;
  background: #0a111ddb;
  border: 1px solid #b9975d85;
  border-radius: 999px;
  font: inherit;
  font-size: .83rem;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible { outline: 2px solid #f5d489; outline-offset: 3px; }
button:disabled { opacity: .45; cursor: default; }

.tools {
  position: absolute;
  z-index: 2;
  top: max(1rem, env(safe-area-inset-top));
  right: max(.75rem, env(safe-area-inset-right));
  display: grid;
  gap: .4rem;
}
@media (max-width: 720px) {
  .tools { top: auto; bottom: var(--bottom); }
  .tools button { padding-inline: .6rem; font-size: .73rem; }
}
@media (max-width: 375px) {
  .tools { top: max(3.4rem, calc(env(safe-area-inset-top) + 2.6rem)); bottom: auto; }
}

.modes {
  position: absolute;
  z-index: 1;
  inset: auto .75rem var(--bottom);
  display: grid;
  justify-items: center;
  gap: .63rem;
  pointer-events: none;
}
.modes p {
  margin: 0;
  font-size: .78rem;
  line-height: 1.25;
  color: #f4e4c4;
  text-align: center;
  text-wrap: balance;
  text-shadow: 0 1px 4px #02060a, 0 1px 10px #02060a;
}
.mode-buttons { display: flex; gap: .55rem; pointer-events: auto; }
.mode-buttons button {
  display: grid;
  place-items: center;
  width: 49px;
  height: 46px;
  padding: 0;
  border: 1px solid #c3a36d8f;
  border-radius: 14px;
  background: #070e1a9e;
  color: #f4d591;
}
.mode-buttons button[aria-pressed="true"] {
  background: #191910e8;
  color: #ffe2a0;
  border-color: #f4d591;
  box-shadow: 0 0 14px #ffcf6a28;
}
.mode-buttons button:hover:enabled { border-color: #f4d591; }
.mode-buttons svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.sr-only, .keyboard-next:not(:focus-visible) {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  margin: -1px;
  padding: 0;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
  pointer-events: none;
}
.keyboard-next {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: calc(var(--bottom) + 4.8rem);
  translate: -50% 0;
}
.feedback {
  position: absolute;
  z-index: 3;
  top: max(5.5rem, calc(env(safe-area-inset-top) + 4rem));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 88vw;
  padding: .4rem .7rem;
  text-align: center;
  background: #0a111deb;
  border-radius: .5rem;
  font-size: .8rem;
}

.tree-poster { display: block; width: 100%; height: 100%; object-fit: contain; }
#fallback-frame {
  position: absolute;
  display: grid;
  inset: var(--frame-top) auto auto 50%;
  transform: translate(-50%, -50%);
  width: var(--frame-width);
  height: var(--frame-height);
  margin: 0;
  border: var(--frame-border) solid #c29a4d;
  background: #121923;
}
#fallback-frame img { width: 100%; height: 100%; min-height: 0; object-fit: contain; pointer-events: none; }
@media (max-height: 480px) {
  .heading h1 { font-size: 1.45rem; }
  .heading p { display: none; }
}

.record-player {
  position: absolute;
  z-index: 2;
  right: max(.65rem, env(safe-area-inset-right));
  top: var(--record-top, 5.6rem);
  display: grid;
  justify-items: center;
  pointer-events: none;
}
.record-player button {
  pointer-events: auto;
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  padding: 0;
}
.record {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  border: 1px solid #a99571;
  background: radial-gradient(circle, #241a10 0 4%, #e4bd78 5% 23%, transparent 24%),
    conic-gradient(from 35deg, transparent, #faf1ce45 20deg, transparent 57deg 165deg, #ddcca22e 200deg, transparent 238deg),
    repeating-radial-gradient(circle, #161922 0 1px, #34333a 1.3px 2px, #141720 2.2px 3.2px);
  box-shadow: 0 2px 6px #0007;
  animation: spin-record 8s linear infinite paused;
}
#sound[aria-pressed="true"] .record { animation-play-state: running; }
.tonearm {
  position: absolute;
  right: 5px;
  top: 3px;
  width: 5px;
  height: 18px;
  border-right: 2px solid #f3d194;
  border-bottom: 3px solid #f3d194;
  border-radius: 0 1px 3px 0;
  transform-origin: top right;
  transition: transform .35s;
}
#sound[aria-pressed="true"] .tonearm { transform: rotate(27deg); }
#next-track span {
  display: grid;
  place-items: center;
  font: 14px/1 system-ui;
  color: #e7c794;
  background: #101828d9;
  border: 1px solid #947d5880;
  border-radius: 12px;
  padding: 4px 6px;
}
#track-name { position: absolute; right: 48px; top: 10px; max-width: calc(100vw - 5.5rem); text-align: right; font-size: .78rem; text-shadow: 0 1px 4px #000; }
@keyframes spin-record { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .record { animation: none; } .tonearm { transition: none; } }
#gift[data-order] .tools { top: max(3.6rem, calc(env(safe-area-inset-top) + 3rem)); }
