/* tree: Marilyn's secret tree game. Rounds of 30 s, baubles hang on your own tree. */
.tree { display: flex; flex-direction: column; gap: 6px; height: 100%; min-height: 0; }
.tree__title { margin: 0; font-size: clamp(20px, 3.2dvh, 26px); font-weight: 400; text-align: center; line-height: 1.1; }

/* No page scroll while you play: the screen is exactly the visible viewport (minus the garland
   strip on top and the corner-pill zone below); the tree shrinks to leave the stage its room. */
#screen:has(> .tree) {
  --tree-h: clamp(168px, calc(100vh - 382px), 250px); /* fallback; tree.js measures the real height */
  --tree-h: clamp(168px, calc(100dvh - 382px), 250px);
  height: 100vh; height: 100dvh; min-height: 0; overflow: hidden;
  padding: calc(80px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column;
}
#screen:has(> .tree) > .tree { flex: 1 1 auto; }
@media (max-height: 560px) { #screen:has(> .tree) { overflow-y: auto; } } /* too short to fit: scroll rather than clip */

.tree__top { display: flex; align-items: flex-start; gap: 14px; height: var(--tree-h, 250px); flex: 0 0 auto; }
.tree__hang { position: relative; flex: 0 0 auto; height: var(--tree-h, 250px); aspect-ratio: 4 / 5; max-width: 60%; }
.tree__svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.t-pine { fill: var(--pine); }
.t-pine--mid { fill: oklch(0.39 0.085 155); }
.t-pine--top { fill: oklch(0.42 0.09 155); }
.t-lit { fill: oklch(1 0 0 / 0.07); }
.t-trunk { fill: oklch(0.42 0.06 55); }
.t-pot { fill: var(--kraft); }
.t-rim { fill: var(--kraft-dark); }
.t-star { fill: var(--gold); stroke: oklch(0.7 0.14 80); stroke-width: 1; stroke-linejoin: round;
  filter: drop-shadow(0 0 6px oklch(0.85 0.15 90 / 0.8)); }

.tree__baubles { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.tree__bauble {
  position: absolute; display: block; border-radius: 50%;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle at 34% 30%, oklch(1 0 0 / 0.9) 0 9%, transparent 24%),
    radial-gradient(circle at 50% 55%, var(--c), color-mix(in oklch, var(--c) 62%, black));
  box-shadow: 0 1.5px 2px oklch(0.2 0.05 150 / 0.55);
}
.tree__bauble::before { /* the little gold cap */
  content: ""; position: absolute; left: 50%; top: -14%; width: 28%; height: 20%;
  transform: translateX(-50%); background: oklch(0.82 0.14 85); border-radius: 1px;
}

.tree__side { flex: 1; min-width: 0; height: 100%; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.tree__stats { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; column-gap: 8px; }
.tree__clock {
  --p: 100;
  position: relative; display: grid; place-items: center;
  --ring: var(--ring-px, 72px); flex: 0 0 auto; width: var(--ring); height: var(--ring); border-radius: 50%;
  background:
    radial-gradient(circle, var(--tag) 0 56%, transparent 57%),
    conic-gradient(var(--red) calc(var(--p) * 1%), oklch(0.86 0.03 75) 0);
  box-shadow: 0 6px 8px -4px oklch(0.3 0.03 50 / 0.4), inset 0 0 0 2px var(--kraft-dark);
  font-family: "Young Serif", serif; font-size: calc(var(--ring) * 0.43); line-height: 1; color: var(--red-dark, var(--red));
}
.tree__clock.is-low { animation: tree-pulse 0.5s ease-in-out infinite alternate; color: var(--red); }
@keyframes tree-pulse { to { transform: scale(1.09); } }
.tree__count { margin: 0; font-weight: 600; font-size: 16px; text-align: center; }
.tree__best { margin: 0; font-size: 20px; color: var(--soft); text-align: center; line-height: 1.1; }

.tree__stage { position: relative; width: 100%; flex: 1 1 0; min-height: 280px; max-height: 440px; touch-action: none; user-select: none; -webkit-user-select: none; }
.tree__box { position: absolute; top: 20px; z-index: 2; transform-origin: 50% 100%; }
.tree__box.is-hop { animation: tree-hop 0.4s ease-out; }
@keyframes tree-hop {
  0% { transform: translateY(0) scale(1, 1); }
  30% { transform: translateY(-12px) scale(1.03, 0.97); }
  60% { transform: translateY(0) scale(0.98, 1.03); }
  100% { transform: translateY(0) scale(1, 1); }
}
.tree__hint {
  margin: 0; min-height: 2.2em; font-size: 18px; line-height: 1.1; text-align: center; color: var(--soft);
}
/* short screens: the title goes (still read aloud), count and best share one line */
.tree.is-compact .tree__title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.tree__ball {
  --c: oklch(0.55 0.19 27);
  position: absolute; left: 0; top: 0; z-index: 3;
  width: 48px; height: 48px; border-radius: 50%; pointer-events: none; will-change: transform;
  background:
    radial-gradient(circle at 34% 30%, oklch(1 0 0 / 0.9) 0 9%, transparent 24%),
    radial-gradient(circle at 50% 55%, var(--c), color-mix(in oklch, var(--c) 62%, black));
  box-shadow: 0 6px 8px -3px oklch(0.3 0.03 50 / 0.45);
  transition: opacity 0.5s, filter 0.3s;
}
.tree__ball::before { content: ""; position: absolute; left: 50%; top: -7px; width: 14px; height: 10px; transform: translateX(-50%); background: oklch(0.82 0.14 85); border-radius: 2px; }
/* knocked out by a collision: it can't count any more */
.tree__ball.is-knocked { opacity: 0.5; filter: grayscale(0.7) brightness(0.95); }
/* No ring for touch/mouse focus; keyboard users still see where they are, just quietly. */
.tree__stage:focus { outline: none; }
.tree__stage:focus-visible { outline: 2px solid var(--kraft-dark, #a07c55); outline-offset: -2px; border-radius: 14px; }

.tree__start { position: absolute; left: 50%; bottom: 10px; z-index: 4; transform: translateX(-50%); min-width: 170px; font-size: 20px; }
.tree__start:active:not(:disabled) { transform: translateX(-50%) translateY(3px); }
.tree__start[hidden], .tree__end[hidden] { display: none; }

.tree__end { position: absolute; left: 8px; right: 8px; top: 40px; z-index: 6; }
.tree__end .tag { padding: 20px 20px 20px 56px; }
.tree__end-title { margin: 4px 0 2px; font-size: 24px; font-weight: 400; line-height: 1.15; }
.tree__end-new { margin: 0 0 10px; font-size: 26px; color: var(--red); min-height: 1em; }
.tree__end-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.tree__end-actions .btn { padding: 0 18px; min-height: 44px; font-size: 16px; }

.tree__done { flex: 0 0 auto; min-width: 0; min-height: 44px; padding: 0 16px; font-size: 15px; }

@media (prefers-reduced-motion: reduce) {
  .tree__clock.is-low, .tree__box.is-hop { animation: none; }
  .tree__ball { transition: none; }
}
.tree__done[hidden] { display: none; }
