.app[data-scene=tree] {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

:root:has(.app[data-scene=tree]) { overscroll-behavior: none; }

.app[data-scene=tree] .game-world {
  background: radial-gradient(ellipse at 50% 44%, #2d4265, #141e35 63%, #10192d 88%);
}

.app[data-scene=tree] .game-world::before {
  opacity: 0;
}

.app[data-scene=tree] .app-main {
  min-height: 100dvh;
  padding: 0;
}

.preview-toggle .preview-toggle-icon,
.app:not([data-scene=tree]) .tree-time {
  display: none;
}

.app[data-scene=tree] .app-header {
  position: absolute;
  inset: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px 8px;
  padding-top: calc(9px + env(safe-area-inset-top));
  background: none;
  pointer-events: none;
}

.app[data-scene=tree] .game-score,
.app[data-scene=tree] #preview-toggle-label {
  display: none;
}

.app[data-scene=tree] :is(.header-actions, .preview-controls) {
  display: flex;
  align-items: center;
  gap: 0;
  width: max-content;
  border: 1px solid #fcf2e64a;
  border-radius: 999px;
  background: #191a29a8;
  box-shadow: inset 0 1px #ffffff26, 0 4px 14px #10101d30;
  backdrop-filter: blur(18px) saturate(1.25);
  pointer-events: auto;
}

.app[data-scene=tree] .header-actions {
  flex-shrink: 0;
  margin-inline-start: auto;
}

.app[data-scene=tree] .preview-controls {
  flex-wrap: wrap;
  max-inline-size: 100%;
}

.completed-tree-link { display: none; }
.app[data-scene=tree] .completed-tree-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding-inline: 13px;
  color: #fff3dd;
  font-size: .78rem;
  font-weight: 590;
  text-decoration: none;
}

.app[data-scene=tree] :is(.preview-toggle, .sound-toggle, .tree-time, .preview-date select) {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  color: #fff7ea;
  background: transparent;
  box-shadow: none;
}

.app[data-scene=tree] :is(.preview-toggle, .sound-toggle, .tree-time) {
  display: grid;
  place-items: center;
  width: 44px;
  padding: 0;
}

.app[data-scene=tree] :is(.preview-toggle, .sound-toggle)[aria-pressed=true] {
  color: #ffe8b8;
  background: #ffe9ba2b;
}

.app[data-scene=tree] :is(.preview-toggle .preview-toggle-icon, .tree-time .icon) {
  display: block;
  width: 20px;
  height: 20px;
}

.app[data-scene=tree] .preview-date select {
  padding: 0 24px 0 11px;
  font-size: .8125rem;
  font-weight: 650;
}

.app[data-scene=tree] .preview-date .icon { right: 8px; top: 17px; }

@media (max-width: 360px) {
  .app[data-scene=tree] .completed-tree-link { padding-inline: 9px; }
  .app[data-scene=tree] .preview-date select { padding-inline: 8px 21px; }
}

#screen-tree {
  position: relative;
}

.tree-stage {
  position: relative;
  isolation: isolate;
  height: 100dvh;
  overflow: hidden;
  background: #182440;
}

.tree-sky,
.tree-stage canvas,
.tree-fallback,
.tree-stage::after {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.tree-sky {
  background:
    radial-gradient(ellipse 85% 36% at 75% 40%, #ffceae20, transparent 82%),
    linear-gradient(177deg, #23294070 0%, #4035518f 19%, #956b8296 33%, #dfa28f9c 46%, #bf989078 58%, #6d748c57 81%),
    url("assets/village-twilight.jpg") center top / cover,
    linear-gradient(160deg, #251b33, #524058 48%, #9f6a69);
}

.tree-sky::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 84% 35% at 66% 37%, #fff3d82e, transparent 82%),
    linear-gradient(178deg, #9abedb80 0%, #b7d1e188 20%, #e2d5d094 35%, #ffe3c894 47%, #d5cbdc70 67%, #b0bfd360 87%),
    url("assets/village-morning.jpg") center top / cover,
    linear-gradient(#8badd1, #ffdbbe 42%, #8d9eb7);
  opacity: 0;
  transition: opacity .8s ease;
}

.tree-stage[data-period=morning] .tree-sky::after { opacity: 1; }

.tree-stage canvas {
  display: block;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  cursor: grab;
}

.tree-stage canvas:active {
  cursor: grabbing;
}

.tree-stage canvas:focus-visible {
  outline: 2px solid #f4d098;
  outline-offset: -3px;
}

.tree-stage::after {
  content: "";
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(180deg, #16132321 0%, transparent 12%, transparent 75%, #191a2c69 92%, #151528bd 100%);
}

.tree-stage[data-renderer=fallback][data-snowing]::before {
  content: "";
  position: absolute;
  z-index: 2;
  inset: -90px 0 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 13px 17px, #fffcf7 1.2px, transparent 2.1px) 0 0 / 73px 89px,
    radial-gradient(circle at 6px 21px, #eae8ffbc 1px, transparent 1.7px) 0 0 / 49px 89px;
  animation: tree-fallback-snow 5s linear infinite;
}

@keyframes tree-fallback-snow { to { transform: translateY(89px); } }

.tree-plaza-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 7px;
  margin: 0 max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
}

.tree-stick {
  --stick-x: 0px;
  --stick-y: 0px;
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  padding: 0;
  border: 1px solid #ffffff33;
  border-radius: 50%;
  background: #16171b4d;
  box-shadow: inset 0 0 20px #ffffff05;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  pointer-events: auto;
}

.tree-stick-knob {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  border: 1px solid #ffffff55;
  background: #e6e7ebaa;
  transform: translate(var(--stick-x), var(--stick-y));
  pointer-events: none;
}

.tree-stick[data-moving] { cursor: grabbing; }
@media (max-width: 600px) {
  .tree-stick { width: 83px; height: 83px; }
}

@media (prefers-reduced-motion: reduce) {
  .tree-sky::after,
  .tree-stick-knob { transition: none; }
  .tree-stage[data-renderer=fallback][data-snowing]::before { animation: none; }
}

.tree-loading:not([hidden]) {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  margin: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.tree-loading-icon {
  display: block;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: 2.25rem;
  line-height: 1.2;
  transform-origin: 50% 92%;
  animation: tree-loading-sway 1.3s ease-in-out infinite;
}

@keyframes tree-loading-sway {
  0%, 100% { transform: rotate(-7deg); }
  50% { transform: translateY(-3px) rotate(7deg); }
}

@media (prefers-reduced-motion: reduce) {
  .tree-loading-icon { animation: none; }
}

.tree-fallback {
  background: url("assets/village-fir.webp") center / contain no-repeat;
}

.tree-fallback[data-complete] { background-image: url("assets/village-fir-complete.webp"); }

#tree-fallback-gifts {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(100%, 80dvh);
  aspect-ratio: 4 / 5;
  translate: -50% -50%;
}

#tree-fallback-gifts img {
  position: absolute;
  top: var(--gift-y);
  left: var(--gift-x);
  width: 7.7%;
  height: auto;
  translate: -50% -8%;
  object-fit: contain;
  filter: drop-shadow(0 2px 3px #0c122a7f);
}

#tree-fallback-gifts img[data-tree-topper] { width: 15%; translate: -50% -89%; }

.tree-tray {
  position: absolute;
  z-index: 2;
  right: 0;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 9px);
  left: 0;
  pointer-events: none;
}

.tree-items {
  display: flex;
  gap: 5px;
  padding: 5px calc(16px + env(safe-area-inset-right, 0px)) 6px calc(16px + env(safe-area-inset-left, 0px));
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x proximity;
  scroll-padding-inline: calc(16px + env(safe-area-inset-left, 0px)) calc(16px + env(safe-area-inset-right, 0px));
  scrollbar-width: none;
  pointer-events: auto;
}

.tree-item {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 50px;
  width: 50px;
  height: 50px;
  padding: 0;
  border: 1px solid #ced8f43b;
  border-radius: 15px;
  background: linear-gradient(153deg, #43526b97, #1a233686);
  box-shadow: inset 0 1px #fff4de15, 0 2px 6px #0d111e31;
  scroll-snap-align: start;
  transition: scale .15s, border-color .18s;
}

.tree-item[aria-disabled=false]:active {
  scale: .95;
}

.tree-item[aria-disabled=true] {
  cursor: default;
}

.tree-item[data-hanging=true],
:where(:root:not([data-touch-input])) .tree-item:focus-visible {
  border-color: #e7b569;
}

.tree-item:focus-visible { outline-offset: -2px; }

.tree-item img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  filter: drop-shadow(0 2px 3px #060d286e);
  transition: transform .15s ease;
}

.tree-item-name {
  position: absolute;
  inset: auto 3px 3px;
  overflow: hidden;
  color: #fff2d8;
  font-size: .625rem;
  font-weight: 650;
  line-height: 1;
  text-align: center;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px #0e1220, 0 0 5px #0e1220;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .14s ease;
}

.tree-item[data-hanging=true] img,
:where(:root:not([data-touch-input])) .tree-item:focus-visible img {
  transform: translateY(-4px) scale(.86);
}

.tree-item[data-hanging=true] .tree-item-name,
:where(:root:not([data-touch-input])) .tree-item:focus-visible .tree-item-name {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .tree-item,
  .tree-item img,
  .tree-item-name {
    transition: none;
  }
}
