/* Live tree stage */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
}

.stage-wrapper {
  width: 100vw;
  height: 100vh;
  background: #7ec0ee;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
}

/* Side ambient: ONLY in empty gutters — never overlap .tree-container at 100% zoom. */
.ambient-column {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
  width: 0;
  min-width: 0;
}

.ambient-left {
  left: 0;
  padding-right: 10px;
  box-sizing: border-box;
}

.ambient-right {
  right: 0;
  text-align: right;
  padding-left: 10px;
  box-sizing: border-box;
}

.ambient-item {
  position: absolute;
  top: -5%;
  font-weight: 800;
  white-space: nowrap;
  opacity: 0;
  will-change: transform, opacity;
  animation: ambientFall 9s linear forwards;
  pointer-events: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ambient-name {
  font-size: clamp(1.05rem, 2.1vw, 1.7rem);
  letter-spacing: 0.02em;
  color: #fff8e7;
  text-shadow:
    0 2px 5px rgba(15, 61, 110, 0.85),
    0 0 16px rgba(255, 215, 100, 0.5);
}

.ambient-heart {
  font-size: clamp(1.7rem, 3vw, 2.6rem);
  line-height: 1;
  color: #ff3b5c;
  text-shadow:
    0 2px 6px rgba(120, 10, 40, 0.55),
    0 0 16px rgba(255, 80, 120, 0.55);
  filter: drop-shadow(0 3px 5px rgba(180, 30, 50, 0.4));
}

.ambient-icon-img {
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.25));
}

.ambient-icon-img img {
  display: block;
  height: clamp(1.7rem, 3vw, 2.6rem);
  width: auto;
  max-width: 3.2rem;
  object-fit: contain;
}

@keyframes ambientFall {
  0% {
    transform: translateY(0) translateX(0);
    opacity: 0;
  }
  5% { opacity: 1; }
  82% { opacity: 0.95; }
  100% {
    transform: translateY(112vh) translateX(var(--drift, 0px));
    opacity: 0;
  }
}

@media (max-width: 900px) {
  .ambient-name { font-size: clamp(0.85rem, 2.5vw, 1.15rem); }
  .ambient-heart { font-size: clamp(1.3rem, 3.2vw, 1.9rem); }
}

@media (max-width: 640px) {
  .ambient-right { display: none !important; }
}

.event-title-bar {
  position: absolute;
  top: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  max-width: 90vw;
  text-align: center;
  color: #0f3d6e;
  font-weight: 700;
  font-size: clamp(0.75rem, 1.6vw, 1.15rem);
  letter-spacing: 0.04em;
  text-shadow: 0 1px 0 rgba(255,255,255,0.6);
  pointer-events: none;
  display: none; /* title already in tree artwork */
}

.tree-container {
  position: relative;
  aspect-ratio: 1086 / 1448;
  width: min(100vw, calc(96vh * 1086 / 1448));
  height: auto;
  max-height: 96vh;
  margin: auto;
  z-index: 15;
}

.tree-bg {
  width: 100%;
  height: 100%;
  object-fit: fill; /* box matches image ratio — no letterbox */
  display: block;
  user-select: none;
  pointer-events: none;
}

#apples-layer,
#ground-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

#ground-layer {
  z-index: 22;
}

.apple-node {
  position: absolute;
  width: 4.8%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  cursor: pointer;
  z-index: 20;
  pointer-events: auto;
  /* No left/top slide on sync — only intentional fall animates */
  transition: none;
}

.apple-node.apple-on-ground {
  width: 4.2%;
  z-index: 22;
  filter: none;
}

.apple-node.apple-on-ground img {
  animation: none;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.35));
  transform: rotate(var(--ground-rot, 12deg));
}

.apple-node.apple-falling {
  z-index: 30;
  /* Vertical ease-in (gravity) + soft horizontal drift */
  transition:
    top 1.2s cubic-bezier(0.55, 0.05, 0.85, 0.35),
    left 1.2s cubic-bezier(0.4, 0.2, 0.4, 1);
}

.apple-node.apple-falling img {
  animation: appleFallSpin 1.2s ease-in forwards;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.4));
}

@keyframes appleFallSpin {
  0% {
    transform: rotate(0deg) scale(1);
  }
  70% {
    transform: rotate(calc(var(--ground-rot, 18deg) * 0.7)) scale(1.05);
  }
  100% {
    transform: rotate(var(--ground-rot, 18deg)) scale(0.92);
  }
}

.apple-node::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 180%;
  height: 180%;
}

.apple-node img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: 50% 0%;
  animation: appleSway 3s ease-in-out infinite alternate;
  filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.85));
  transition: transform 0.25s ease, filter 0.25s ease;
  pointer-events: none;
}

.apple-node:hover img {
  transform: scale(1.35);
  filter: drop-shadow(0 0 14px rgba(255, 30, 30, 1));
}

@keyframes appleSway {
  0%   { transform: rotate(-5deg); }
  100% { transform: rotate(5deg); }
}

.apple-spawn {
  animation: spawnIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes spawnIn {
  0%   { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.wish-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
  padding: 0.75rem;
}

.wish-modal.hidden {
  display: none;
}

.modal-apple {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  max-width: min(92vw, 420px);
  width: 100%;
  animation: zoomIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.2);
}

.modal-card--apple {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: min(78vh, 420px);
  background: transparent url('../images/apple_note.png') center / contain no-repeat;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-apple-body {
  /* Safe zone inside cream apple fill (stem/leaf above, curved red rim) */
  box-sizing: border-box;
  width: 58%;
  height: 52%;
  margin-top: 10%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0.35rem;
  overflow: hidden;
}

.modal-card--apple h2 {
  margin: 0;
  flex: 0 0 auto;
  color: #f07a1a;
  font-size: clamp(0.95rem, 3.6vw, 1.25rem);
  font-weight: 400;
  line-height: 1.25;
  max-width: 100%;
  padding: 0 0.15rem;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.modal-message-wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 0.1rem 0.15rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(180, 40, 40, 0.45) transparent;
}

.modal-message-wrap::-webkit-scrollbar {
  width: 4px;
}
.modal-message-wrap::-webkit-scrollbar-thumb {
  background: rgba(180, 40, 40, 0.4);
  border-radius: 999px;
}

.modal-card--apple #modal-message,
.modal-card--apple p {
  margin: 0;
  color: #1a6b2c;
  font-size: clamp(0.78rem, 2.8vw, 0.98rem);
  font-weight: 700;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  text-align: left;
}

#btn-close-modal {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1.4rem;
  background: linear-gradient(135deg, #c41e3a, #e85d04);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
}

#btn-close-modal:hover {
  filter: brightness(1.06);
}

@keyframes zoomIn {
  0%   { transform: scale(0.72); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 640px) {
  .modal-apple {
    max-width: min(94vw, 360px);
  }
  .modal-card--apple {
    max-height: min(72vh, 360px);
  }
  .modal-apple-body {
    width: 60%;
    height: 50%;
    margin-top: 11%;
  }
}

#qrcode-box {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  z-index: 50;
  background: #fff;
  padding: 0.5rem;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  text-align: center;
}

#qrcode-box .qr-label {
  font-size: 0.7rem;
  color: #1e293b;
  margin-top: 0.35rem;
  font-weight: 600;
}

.audio-controls {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  display: flex;
  gap: 0.5rem;
}

.audio-controls button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  cursor: pointer;
  font-size: 1.25rem;
}

#start-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 61, 110, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
}

#start-overlay.hidden { display: none; }

#start-overlay button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 1rem 1.75rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f3d6e;
  background: #fff;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  cursor: pointer;
}

.wish-count {
  display: none !important;
}

@media (max-width: 640px) {
  #qrcode-box { transform: scale(0.85); transform-origin: bottom left; }
  .apple-node { width: 6.2%; }
}
