:root {
  --sky-top: #f9d9a8;
  --sky-mid: #fbe8c6;
  --sky-low: #eaf1dc;
  --ink: #2f2a22;
  --ink-soft: #6b604f;
  --btn-bg: rgba(255, 252, 244, .82);
  --btn-border: rgba(60, 45, 25, .16);
  --sun: #ffcf6b;
  --cloud: rgba(255, 255, 255, .75);
  --label-bg: rgba(255, 252, 244, .92);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --sky-top: #141a33;
    --sky-mid: #26294a;
    --sky-low: #3b3552;
    --ink: #f3ead8;
    --ink-soft: #c2b59c;
    --btn-bg: rgba(30, 30, 52, .78);
    --btn-border: rgba(255, 240, 210, .18);
    --sun: #f2ead0;
    --cloud: rgba(200, 200, 230, .16);
    --label-bg: rgba(28, 28, 48, .9);
  }
}
:root[data-theme="dark"] {
  --sky-top: #141a33;
  --sky-mid: #26294a;
  --sky-low: #3b3552;
  --ink: #f3ead8;
  --ink-soft: #c2b59c;
  --btn-bg: rgba(30, 30, 52, .78);
  --btn-border: rgba(255, 240, 210, .18);
  --sun: #f2ead0;
  --cloud: rgba(200, 200, 230, .16);
  --label-bg: rgba(28, 28, 48, .9);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: var(--sky-mid);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.scene {
  position: fixed;
  inset: 0;
  height: 100dvh;
  background: linear-gradient(to bottom, var(--sky-top) 0%, var(--sky-mid) 45%, var(--sky-low) 100%);
  overflow: hidden;
}

canvas#tree { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* Slunce / měsíc a mraky */
.sun {
  position: absolute;
  top: 9%;
  right: 12%;
  width: clamp(54px, 9vw, 96px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--sun);
  box-shadow: 0 0 60px 20px color-mix(in srgb, var(--sun) 45%, transparent);
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 2.5s ease, transform 2.5s ease;
}
.scene.day .sun { opacity: 1; transform: none; }

.cloud {
  position: absolute;
  height: 26px;
  border-radius: 30px;
  background: var(--cloud);
  filter: blur(1px);
  opacity: 0;
  transition: opacity 3s ease;
  animation: drift 60s linear infinite;
}
.cloud::before, .cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border-radius: 50%;
}
.cloud::before { width: 46%; height: 180%; left: 16%; bottom: 20%; }
.cloud::after  { width: 34%; height: 140%; left: 50%; bottom: 25%; }
.cloud.c1 { top: 16%; left: -10%; width: 120px; animation-duration: 70s; }
.cloud.c2 { top: 28%; left: -30%; width: 86px; animation-duration: 95s; animation-delay: -40s; }
.scene.day .cloud { opacity: 1; }
@keyframes drift { to { transform: translateX(140vw); } }

/* Nadpis */
.heading {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 1.2s ease, transform 1.2s ease;
}
.heading h1 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  font-size: clamp(1.6rem, 4.6vw, 2.8rem);
  margin: 0;
  letter-spacing: -.01em;
}
.heading p { margin: .25rem 0 0; color: var(--ink-soft); font-size: clamp(.95rem, 2.4vw, 1.1rem); }
.scene.done .heading { opacity: 1; transform: none; }

/* Vyprávění během intra */
.story {
  position: absolute;
  left: 16px; right: 16px;
  top: calc(max(18px, env(safe-area-inset-top)) + .6rem);
  text-align: center;
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(1.05rem, 3vw, 1.4rem);
  color: var(--ink-soft);
  opacity: 0;
  transition: opacity .6s ease;
  pointer-events: none;
}
.story.show { opacity: 1; }

/* Plody = odkazy */
.fruits { position: absolute; inset: 0; pointer-events: none; }
.fruit {
  --size: 64px;
  position: absolute;
  width: var(--size);
  height: var(--size);
  margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
  pointer-events: auto;
  text-decoration: none;
  color: var(--ink);
  transform: scale(0);
  transform-origin: 50% 0;
  outline: none;
}
.fruit.ripe {
  animation: pop .7s cubic-bezier(.34, 1.56, .64, 1) forwards, sway 5s ease-in-out .7s infinite;
  animation-delay: var(--delay, 0s), calc(var(--delay, 0s) + .7s + var(--phase, 0s));
}
.fruit .stem {
  position: absolute;
  left: 50%;
  top: -10px;
  width: 3px;
  height: 14px;
  margin-left: -1.5px;
  background: #5b3d22;
  border-radius: 2px;
}
.fruit .stem::after {
  content: "";
  position: absolute;
  left: 2px; top: 1px;
  width: 14px; height: 8px;
  background: #5f9d43;
  border-radius: 0 100% 0 100%;
}
.fruit .ball {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .55), transparent 42%), var(--color, #e4572e);
  box-shadow: inset -6px -8px 14px rgba(0, 0, 0, .22), 0 6px 14px rgba(40, 25, 10, .28);
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, .85);
  transition: transform .25s ease, box-shadow .25s ease;
}
.fruit .ball img { width: 100%; height: 100%; object-fit: cover; }
.fruit .ball .initial {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  font-size: calc(var(--size) * .42);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
.fruit .label {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
  font-size: .82rem;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--label-bg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .12);
}
.fruit:hover .ball, .fruit:focus-visible .ball {
  transform: scale(1.12);
  box-shadow: inset -6px -8px 14px rgba(0, 0, 0, .22), 0 10px 22px rgba(40, 25, 10, .35);
}
.fruit:focus-visible .ball { outline: 3px solid var(--ink); outline-offset: 3px; }
.fruit.picked { animation: pick .55s ease-in forwards !important; }

@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes sway {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(var(--swing, 4deg)); }
}
@keyframes pick {
  30% { transform: scale(1.15) translateY(-6px); }
  100% { transform: scale(.9) translateY(60px); opacity: 0; }
}

/* Ovládací prvky */
.controls {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 10;
}
.btn, .ig {
  font: inherit;
  font-weight: 700;
  font-size: .9rem;
  color: var(--ink);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 999px;
  min-height: 44px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  text-decoration: none;
  transition: transform .2s ease, opacity .4s ease;
}
.btn:hover, .ig:hover { transform: translateY(-2px); }
.btn.ghost, .ig { width: 44px; padding: 0; justify-content: center; }
.btn.hide { opacity: 0; pointer-events: none; }
.ig:hover { color: #d62976; }

.fallback { position: absolute; top: 30%; left: 16px; right: 16px; text-align: center; list-style: none; padding: 0; }
.fallback a { color: var(--ink); font-size: 1.2rem; }

@media (max-width: 520px) {
  .fruit .label { font-size: .74rem; max-width: 110px; padding: 1px 7px; }
  .btn { font-size: .85rem; padding: 0 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .fruit.ripe { animation: none; transform: none; }
  .cloud { animation: none; }
}

@media (max-height: 500px) {
  .heading { top: 10px; }
  .heading h1 { font-size: 1.4rem; }
  .heading p { font-size: .85rem; margin-top: 0; }
}
