/* KI-Adventkalender 2026 - Dorf-Zustaende und Animationen (WP1)
   Schnittstelle zu app.js: ARCHITEKTUR.md 3.6.
   Auf jedem <g class="door"> steht genau eine der Klassen locked | open | started | done,
   dazu optional is-current und kurzzeitig opening. Ohne Zustandsklasse sieht ein Haus wie
   "locked" aus (Standard). Farben als Literale (Tokens siehe ARCHITEKTUR 6). */

/* ---------- Basis (= gesperrt) ---------- */
.door { outline: none; cursor: not-allowed; }
.door .hit { pointer-events: all; }
.door .door-num {
  fill: #E3ECFA; stroke: #0B1D3A; stroke-width: 4px; paint-order: stroke fill;
  stroke-linejoin: round; pointer-events: none; user-select: none; -webkit-user-select: none;
  transition: fill .3s ease;
}
.door .win-glow, .door .win-light, .door .cone, .door .dots, .door .check,
.door .garland, .door .frame, .door .ring { opacity: 0; transition: opacity .35s ease; }
.door .win-dark, .door .snowcap, .door .lock { opacity: 1; transition: opacity .35s ease; }
.door .shutter { transform-box: fill-box; transform: scaleX(1); transition: transform .5s ease; }
.door .shutter.sl { transform-origin: 0 50%; }
.door .shutter.sr { transform-origin: 100% 50%; }
.door .win-halo { transform-box: fill-box; transform-origin: 50% 50%; }
.door .cone { pointer-events: none; }

/* ---------- open: freigeschaltet, noch nicht geoeffnet ---------- */
.door.open, .door.started, .door.done { cursor: pointer; }
.door.open .snowcap, .door.open .lock { opacity: 0; }
.door.open .win-glow { opacity: 1; animation: ak-flicker 2.6s infinite; }
.door.open .win-halo { animation: ak-halo 2.4s ease-in-out infinite; }
.door.open .shutter { transform: scaleX(.78); }
.door.open .door-num { fill: #FFE9A8; stroke: #4A2F19; animation: ak-numpulse 2.4s ease-in-out infinite; }

/* ---------- started: Laden halb offen, Lichtkegel, "..." ---------- */
.door.started .snowcap, .door.started .lock { opacity: 0; }
.door.started .win-light { opacity: 1; }
.door.started .cone { opacity: .3; }
.door.started .dots { opacity: 1; }
.door.started .shutter { transform: scaleX(.46); }
.door.started .door-num { fill: #1B2A41; stroke: #FFE9A8; stroke-width: 3px; }

/* ---------- done: voll erleuchtet, Girlande, Haken ---------- */
.door.done .snowcap, .door.done .lock { opacity: 0; }
.door.done .win-light { opacity: 1; }
.door.done .garland { opacity: 1; }
.door.done .check { opacity: 1; }
.door.done .shutter { transform: scaleX(.2); }
.door.done .door-num { fill: #1B2A41; stroke: #FFE9A8; stroke-width: 3px; }
.door.done .garland circle { animation: ak-twinkle 2.2s ease-in-out infinite; }
.door.done .garland circle:nth-of-type(2n) { animation-delay: -.7s; }
.door.done .garland circle:nth-of-type(3n) { animation-delay: -1.4s; }

/* ---------- Markierung / Hover / Fokus ---------- */
.door.is-current .frame { opacity: .95; }
.door.open:hover .ring, .door.started:hover .ring, .door.done:hover .ring,
.door.open:focus .ring, .door.started:focus .ring, .door.done:focus .ring,
.door.open:focus-visible .ring, .door.started:focus-visible .ring, .door.done:focus-visible .ring { opacity: 1; }
.door.locked:focus .ring, .door.locked:focus-visible .ring { opacity: 1; stroke: #8FA3C7; }
.door.locked:hover .ring { opacity: 0; }
.door.locked { cursor: not-allowed; }

/* ---------- opening: Tuer schwingt auf (600 ms) ---------- */
.door.opening .shutter.sl { animation: ak-swing .6s ease-in-out forwards; }
.door.opening .shutter.sr { animation: ak-swing .6s ease-in-out forwards; }
.door.opening .win-light { animation: ak-fadein .6s ease-in forwards; }
.door.opening .win-glow { opacity: 1; animation: none; }
.door.opening .snowcap, .door.opening .lock { opacity: 0; }
.door.opening .door-num { animation: none; }

/* ---------- Baum, Stern, Geschenk, Kerzen ---------- */
#tree .ball { opacity: 0; transition: opacity .6s ease; }
#tree .ball.lit { opacity: 1; transform-box: fill-box; transform-origin: 50% 0%;
  animation: ak-drop .7s cubic-bezier(.3, 1.4, .5, 1) both, ak-sway 5.2s ease-in-out .8s infinite; }
#tree .ball.lit:nth-of-type(3n) { animation-duration: .7s, 6.4s; animation-delay: 0s, -1.3s; }
#tree .ball.lit:nth-of-type(3n+1) { animation-duration: .7s, 4.6s; animation-delay: 0s, -2.9s; }
#tree .ball.just-lit { animation: ak-drop .7s cubic-bezier(.3, 1.4, .5, 1) both, ak-justlit 1.6s ease-out .2s 1; transform-box: fill-box; transform-origin: 50% 50%; }
#star .star-on { opacity: 0; transition: opacity .8s ease; }
#star.lit .star-on { opacity: 1; animation: ak-starpulse 2.6s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 50%; }
#star.lit .star-off { opacity: 0; }
/* 24/24: Lichterkette am Baum (id tree-lights, twinkelt per Klasse vl-tl in village.svg) */
#tree-lights { opacity: 0; transition: opacity 1s ease; pointer-events: none; }
#sparkle.on ~ #tree #tree-lights { opacity: 1; }

#gift .gift-glow { opacity: 0; transition: opacity .6s ease; }
#gift .gift-lid { transform-box: fill-box; transform-origin: 100% 100%; transition: transform .7s cubic-bezier(.3, 1.3, .5, 1); }
#gift.open .gift-lid { transform: translate(14px, -26px) rotate(18deg); }
#gift.open .gift-glow { opacity: 1; animation: ak-giftglow 2.4s ease-in-out infinite; }

[id^="candle-"] .flame, [id^="candle-"] .glow { opacity: 0; transition: opacity .5s ease; }
[id^="candle-"].lit .glow { opacity: 1; }
[id^="candle-"].lit .flame { opacity: 1; transform-box: fill-box; transform-origin: 50% 100%; animation: ak-flame 1.3s ease-in-out infinite; }
#candle-2.lit .flame { animation-delay: -.3s; }
#candle-3.lit .flame { animation-delay: -.6s; }
#candle-4.lit .flame { animation-delay: -.9s; }

/* ---------- Rauch: gesperrte Haeuser rauchen schwach, freigeschaltete kraeftiger ---------- */
.door .vl-smoke { pointer-events: none; transition: opacity .5s ease; }
.door.open .vl-smoke, .door.started .vl-smoke, .door.done .vl-smoke { opacity: .8; }

/* ---------- Hover/Fokus auf offenem Tuerchen: Haus hebt sich, Licht wird waermer ----------
   Das transform-Attribut der Gruppe (Layout, WP8) bleibt unberuehrt: es werden nur die Kinder
   verschoben (Treffer-Polygon und Schatten bleiben stehen, sonst flackert der Hover am Rand). */
.door > :not(.hit):not(ellipse) { transition: translate .25s ease; }
.door.open:hover > :not(.hit):not(ellipse), .door.started:hover > :not(.hit):not(ellipse), .door.done:hover > :not(.hit):not(ellipse),
.door.open:focus-visible > :not(.hit):not(ellipse), .door.started:focus-visible > :not(.hit):not(ellipse), .door.done:focus-visible > :not(.hit):not(ellipse) { translate: 0 -4px; }
.door.open:hover .cone, .door.open:focus-visible .cone { opacity: .22; }
.door.started:hover .cone, .door.done:hover .cone, .door.started:focus-visible .cone, .door.done:focus-visible .cone { opacity: .45; }
.door.open:hover .win-halo, .door.open:focus-visible .win-halo { animation: none; transform: scale(1.3); }
.door.open:hover .win-glow, .door.open:focus-visible .win-glow { animation: none; opacity: 1; }
.door.started:hover .win-light, .door.done:hover .win-light, .door.started:focus-visible .win-light, .door.done:focus-visible .win-light { fill: #FFC857; }
.door .win-halo { transition: transform .3s ease; }

/* ---------- Schnee und Goldglitzer ---------- */
#snow { pointer-events: none; }
#snow .flake { animation: ak-fall 24s linear infinite; }
#snow .f1 { animation-duration: 18s; animation-delay: -2s; }
#snow .f2 { animation-duration: 24s; animation-delay: -10s; }
#snow .f3 { animation-duration: 30s; animation-delay: -18s; }
#snow .f4 { animation-duration: 20s; animation-delay: -6s; }
#snow .f5 { animation-duration: 26s; animation-delay: -14s; }
#snow .f6 { animation-duration: 34s; animation-delay: -24s; }
#sparkle { pointer-events: none; opacity: 0; transition: opacity 1s ease; }
#sparkle.on { opacity: 1; }
#sparkle .spark { transform-box: fill-box; transform-origin: 50% 50%; }
#sparkle.on .spark { animation: ak-twinkle2 2.4s ease-in-out infinite; }
#sparkle.on .s2 { animation-delay: -.5s; animation-duration: 2.9s; }
#sparkle.on .s3 { animation-delay: -1s;  animation-duration: 2.1s; }
#sparkle.on .s4 { animation-delay: -1.5s; animation-duration: 3.3s; }
#sparkle.on .s5 { animation-delay: -2s;  animation-duration: 2.6s; }
/* bei 24/24 wird aus Schneefall Goldglitzer: Flocken werden warm und fallen langsamer */
#sparkle.on ~ #snow .flake { fill: #FFE9A8; animation-duration: 40s; }

/* ---------- Keyframes ---------- */
@keyframes ak-flicker {
  0%, 100% { opacity: 1; } 8% { opacity: .78; } 14% { opacity: .96; } 31% { opacity: .84; }
  47% { opacity: 1; } 63% { opacity: .8; } 78% { opacity: .95; } 90% { opacity: .86; }
}
@keyframes ak-halo { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.16); } }
@keyframes ak-numpulse { 0%, 100% { fill: #FFE9A8; } 50% { fill: #FFFFFF; } }
@keyframes ak-twinkle { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes ak-twinkle2 { 0%, 100% { opacity: .25; transform: scale(.6); } 50% { opacity: 1; transform: scale(1.15); } }
@keyframes ak-swing { from { transform: scaleX(.8); } to { transform: scaleX(.06); } }
@keyframes ak-fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes ak-drop { from { transform: translateY(-22px); } to { transform: translateY(0); } }
@keyframes ak-justlit { 0% { filter: brightness(1); } 25% { filter: brightness(1.9) drop-shadow(0 0 10px #FFE9A8); } 100% { filter: brightness(1); } }
@keyframes ak-starpulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@keyframes ak-giftglow { 0%, 100% { opacity: .85; } 50% { opacity: 1; } }
@keyframes ak-flame { 0%, 100% { transform: scale(1, 1) rotate(-2deg); } 35% { transform: scale(.93, 1.08) rotate(2deg); } 70% { transform: scale(1.05, .95) rotate(-1deg); } }
@keyframes ak-sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes ak-fall {
  0% { transform: translate(0, -900px); }
  50% { transform: translate(30px, 0); }
  100% { transform: translate(-6px, 900px); }
}

/* ---------- Bewegung reduzieren ---------- */
@media (prefers-reduced-motion: reduce) {
  .door *, #tree *, #star *, #gift *, [id^="candle-"] *, #snow *, #sparkle *, #aurora *, #sky-deco *, .vl-halo, .vl-smoke * {
    animation: none !important; transition: none !important;
  }
  #snow .flake { opacity: .8; }
}
