/* ==========================================================================
   CozyWorld — анимированный пасторальный мир Home Nexus (Cozy Wheat Edition).
   Владелец: worldsmith. Только селекторы #cozy-world / .cw-*.
   Контракт: public/cozy/CONTRACT.md §2, §4.1, §6.

   Палитра: тёплая пшеница #d9a441 / #ecc56a / #f3d488, крем, шалфей,
   пыльно-голубое небо, тёмный шоколад (чернила). День — золотой полдень,
   ночь — глубокий индиго/шоколад с тёплым светом окна.
   ========================================================================== */

#cozy-world {
  /* --- локальная палитра (день; ночные значения — ниже) --- */
  --cw-ink: #332a1e;
  --cw-line: #4a3624;
  --cw-line-soft: rgba(74, 54, 36, 0.45);
  --cw-cream: #fff6e6;
  --cw-wheat: #d9a441;
  --cw-wheat-soft: #ecc56a;
  --cw-wheat-light: #f3d488;
  --cw-wheat-deep: #a87422;
  --cw-sage: #7d9a62;
  --cw-rose: #d47b9a;

  /* небо */
  --cw-sky-day: linear-gradient(180deg, #7fa7c0 0%, #a9c0c6 18%, #d3d3b4 36%,
    #eddfbe 52%, #f7e8c8 68%, #f6dfae 84%, #efcf94 100%);
  --cw-sky-night: linear-gradient(180deg, #0b1224 0%, #141b32 26%, #1f2440 48%,
    #2b2a3c 68%, #352e2c 86%, #3d3124 100%);

  /* светила */
  --cw-sun-core: #fff6d5;
  --cw-sun-disc: #f9d47e;
  --cw-sun-ray: #eab94f;
  --cw-sun-glow: rgba(255, 220, 140, 0.55);
  --cw-sun-glow-op: 0.85;
  --cw-moon-core: #fdf6e3;
  --cw-moon-shade: #e3d3b2;
  --cw-moon-glow: rgba(214, 228, 255, 0.36);

  /* облака / птицы */
  --cw-cloud: #fff8ec;
  --cw-cloud-hi: #fffdf6;
  --cw-cloud-shade: rgba(214, 219, 208, 0.5);
  --cw-cloud-op: 0.88;
  --cw-bird: #6b6353;
  --cw-tree: rgba(112, 134, 95, 0.42);
  --cw-tree-trunk: rgba(94, 74, 44, 0.45);

  /* холмы */
  --cw-hill-far: #b8c3a5;
  --cw-hill-mid: #9aa97f;
  --cw-hill-near: #b9a462;

  /* пшеница */
  --cw-grain: #d9a441;
  --cw-stem: #a8792b;
  --cw-grain-front: #b98330;
  --cw-stem-front: #96692a;
  --cw-haze-back: rgba(214, 178, 98, 0.55);
  --cw-haze-front: rgba(204, 162, 78, 0.9);

  /* забор / дерево */
  --cw-wood: #c9a875;
  --cw-wood-hi: #dfc496;
  --cw-wood-shade: #a9885a;

  /* домик */
  --cw-wall: #f7e7c6;
  --cw-roof: #8a5a3a;
  --cw-roof-hi: #a06c46;
  --cw-timber: #7a5a34;
  --cw-door: #a87422;
  --cw-window: #ffd98a;
  --cw-window-bright: #ffe6a6;
  --cw-window-off: #b3a184;
  --cw-smoke: rgba(255, 250, 240, 0.72);
  --cw-smoke-2: rgba(180, 165, 140, 0.18);

  /* огоньки / звёзды */
  --cw-mote: rgba(255, 232, 173, 0.95);
  --cw-mote-glow: rgba(255, 214, 130, 0.55);
  --cw-firefly: #ffe6a0;
  --cw-firefly-glow: rgba(255, 224, 140, 0.8);
  --cw-star: rgba(255, 249, 232, 0.95);

  /* фонарь / гирлянда */
  --cw-bulb: #ffd98a;
  --cw-bulb-off: #7a6a4a;
  --cw-garland-wire: #6b5030;

  /* кот */
  --cw-cat: #dc9c5e;
  --cw-cat-shade: #c9854a;
  --cw-cat-chest: #f8e6c8;
  --cw-cat-ear: #d47b9a;

  /* оверлеи */
  --cw-focus-veil: linear-gradient(180deg, rgba(247, 238, 219, 0.74),
    rgba(247, 238, 219, 0.34));
  --cw-grain-ink: rgba(84, 58, 22, 0.05);
  --cw-grain-light: rgba(255, 255, 255, 0.05);
  --cw-vignette: radial-gradient(ellipse at 50% 42%, rgba(0, 0, 0, 0) 44%,
    rgba(84, 58, 22, 0.2) 100%);
  --cw-ground: linear-gradient(0deg, rgba(74, 50, 18, 0.22) 0%,
    rgba(74, 50, 18, 0.09) 12%, rgba(0, 0, 0, 0) 30%);

  /* геометрия сцены */
  --cw-fence-h: clamp(64px, 10.4vh, 94px);
  --cw-garland-w: clamp(160px, 24vw, 360px);
  --cw-garland-h: calc(var(--cw-garland-w) * 0.21);

  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  contain: layout paint;
  font-family: var(--cozy-font, "Trebuchet MS", "Segoe UI", Tahoma, sans-serif);
}

/* --- ночная палитра --- */
#cozy-world.cw--night {
  --cw-ink: #f3e7cf;
  --cw-line: #0f0a06;
  --cw-line-soft: rgba(15, 10, 6, 0.5);
  --cw-cream: #f3e7cf;
  --cw-wheat: #ecc56a;
  --cw-wheat-soft: #c99b46;
  --cw-wheat-light: #f7d98c;
  --cw-wheat-deep: #8a6a2e;
  --cw-sage: #52603f;
  --cw-rose: #d47b9a;

  --cw-moon-glow: rgba(214, 228, 255, 0.3);

  --cw-cloud: #454b6b;
  --cw-cloud-hi: #555b7d;
  --cw-cloud-shade: rgba(40, 44, 70, 0.6);
  --cw-cloud-op: 0.6;
  --cw-bird: #8b8ea6;
  --cw-tree: rgba(38, 50, 36, 0.85);
  --cw-tree-trunk: rgba(18, 14, 8, 0.6);

  --cw-hill-far: #2b3247;
  --cw-hill-mid: #2f3229;
  --cw-hill-near: #3a3122;

  --cw-grain: #b8893a;
  --cw-stem: #7d5a26;
  --cw-grain-front: #6e5226;
  --cw-stem-front: #4e3a1c;
  --cw-haze-back: rgba(42, 33, 18, 0.6);
  --cw-haze-front: rgba(30, 24, 14, 0.88);

  --cw-wood: #6b5335;
  --cw-wood-hi: #7d6140;
  --cw-wood-shade: #4e3c26;

  --cw-wall: #3e3225;
  --cw-roof: #2b2118;
  --cw-roof-hi: #38291e;
  --cw-timber: #241b12;
  --cw-door: #6b4a1d;
  --cw-window: #ffd489;
  --cw-window-bright: #ffe8ae;
  --cw-window-off: #4a4032;
  --cw-smoke: rgba(200, 194, 190, 0.34);
  --cw-smoke-2: rgba(140, 135, 140, 0.12);

  --cw-mote: rgba(255, 232, 173, 0.95);
  --cw-mote-glow: rgba(255, 214, 130, 0.6);
  --cw-star: rgba(255, 248, 230, 0.95);

  --cw-bulb: #ffd489;
  --cw-bulb-off: #4a4032;
  --cw-garland-wire: #2a2118;

  --cw-cat: #c98f52;
  --cw-cat-shade: #b07a42;
  --cw-cat-chest: #d8c09a;
  --cw-cat-ear: #b06a86;

  --cw-focus-veil: linear-gradient(180deg, rgba(23, 19, 14, 0.76),
    rgba(23, 19, 14, 0.5));
  --cw-grain-ink: rgba(0, 0, 0, 0.16);
  --cw-grain-light: rgba(255, 240, 210, 0.03);
  --cw-vignette: radial-gradient(ellipse at 50% 42%, rgba(0, 0, 0, 0) 38%,
    rgba(5, 4, 8, 0.55) 100%);
  --cw-ground: linear-gradient(0deg, rgba(8, 6, 4, 0.55) 0%,
    rgba(8, 6, 4, 0.2) 14%, rgba(0, 0, 0, 0) 34%);
}

/* ==========================================================================
   Сцена и слои
   ========================================================================== */

#cozy-world .cw-scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#cozy-world .cw-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

#cozy-world .cw-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#cozy-world .cw-layer--sky { z-index: 0; }
#cozy-world .cw-layer--clouds { z-index: 1; }
#cozy-world .cw-layer--hills { z-index: 2; }
#cozy-world .cw-layer--wheatback { z-index: 3; }
#cozy-world .cw-layer--mid { z-index: 4; }
#cozy-world .cw-layer--wheatfront { z-index: 5; }
#cozy-world .cw-layer--motes { z-index: 6; }
#cozy-world .cw-layer--overlay { z-index: 7; }

/* Плавная смена красок день <-> ночь (fill/stroke у SVG). */
#cozy-world .cw-tone {
  transition: fill 1.2s ease, stroke 1.2s ease;
}

/* ==========================================================================
   Небо, звёзды, светила
   ========================================================================== */

#cozy-world .cw-sky {
  position: absolute;
  inset: 0;
  transition: opacity 1.15s ease;
}

#cozy-world .cw-sky--day {
  opacity: 1;
  background: var(--cw-sky-day);
}

#cozy-world .cw-sky--day::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 46% 34% at 76% 15%, rgba(255, 231, 168, 0.85),
      rgba(255, 231, 168, 0) 62%),
    radial-gradient(ellipse 60% 30% at 18% 10%, rgba(150, 184, 205, 0.42),
      rgba(150, 184, 205, 0) 72%),
    linear-gradient(180deg, rgba(255, 246, 224, 0) 58%,
      rgba(255, 240, 206, 0.3) 100%);
}

#cozy-world .cw-sky--night {
  opacity: 0;
  background: var(--cw-sky-night);
}

#cozy-world .cw-sky--night::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 76% 14%, rgba(216, 230, 255, 0.2),
      rgba(216, 230, 255, 0) 24%),
    radial-gradient(ellipse 58% 26% at 78% 92%, rgba(255, 176, 96, 0.14),
      rgba(255, 176, 96, 0) 70%),
    linear-gradient(180deg, rgba(10, 10, 24, 0) 50%,
      rgba(20, 14, 8, 0.25) 100%);
}

#cozy-world.cw--night .cw-sky--day { opacity: 0; }
#cozy-world.cw--night .cw-sky--night { opacity: 1; }

/* Млечная дымка — только ночью */
#cozy-world .cw-milky {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1.4s ease;
  background: linear-gradient(112deg, rgba(0, 0, 0, 0) 34%,
    rgba(210, 220, 255, 0.05) 44%, rgba(232, 230, 255, 0.09) 52%,
    rgba(210, 220, 255, 0.03) 60%, rgba(0, 0, 0, 0) 72%);
}

#cozy-world.cw--night .cw-milky { opacity: 1; }

/* Звёзды: % позиции в radial-gradient — адаптивно к любому экрану. */
#cozy-world .cw-stars-wrap {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1.3s ease;
}

#cozy-world.cw--night .cw-stars-wrap { opacity: 1; }

#cozy-world .cw-stars {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
}

#cozy-world .cw-stars--a { animation: cw-twinkle 5.4s ease-in-out infinite alternate; }
#cozy-world .cw-stars--b { animation: cw-twinkle 7.8s ease-in-out infinite alternate-reverse; }

/* Солнечные лучи-«стёкла» — очень лёгкие, только днём */
#cozy-world .cw-sunbeams {
  position: absolute;
  inset: 0;
  opacity: 1;
  transition: opacity 1.1s ease;
  background:
    linear-gradient(104deg, rgba(0, 0, 0, 0) 52%, rgba(255, 240, 200, 0.14) 56%,
      rgba(255, 240, 200, 0) 64%),
    linear-gradient(96deg, rgba(0, 0, 0, 0) 60%, rgba(255, 238, 190, 0.1) 66%,
      rgba(255, 238, 190, 0) 74%);
}

#cozy-world.cw--night .cw-sunbeams { opacity: 0; }

/* Солнце / луна — кликабельно, переключает день/ночь. */
#cozy-world .cw-celestial {
  position: absolute;
  left: 76%;
  top: 12%;
  width: clamp(84px, 9vw, 132px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  pointer-events: auto;
  z-index: 4;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#cozy-world .cw-celestial-stack {
  position: absolute;
  inset: 0;
  transition: transform 0.35s ease;
}

#cozy-world .cw-glow {
  position: absolute;
  inset: -58%;
  border-radius: 50%;
  pointer-events: none;
  transition: opacity 1.1s ease;
}

#cozy-world .cw-glow--sun {
  opacity: var(--cw-sun-glow-op);
  background: radial-gradient(circle, var(--cw-sun-glow) 0%,
    rgba(255, 219, 150, 0.22) 42%, rgba(255, 219, 150, 0) 70%);
}

#cozy-world .cw-glow--moon {
  opacity: 0;
  background: radial-gradient(circle, var(--cw-moon-glow) 0%,
    rgba(214, 228, 255, 0.12) 44%, rgba(214, 228, 255, 0) 72%);
}

#cozy-world.cw--night .cw-glow--sun { opacity: 0; }
#cozy-world.cw--night .cw-glow--moon { opacity: 1; }

#cozy-world .cw-sun,
#cozy-world .cw-moon {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  transition: opacity 1s ease, transform 1.1s cubic-bezier(0.2, 0.8, 0.2, 1);
}

#cozy-world .cw-sun { opacity: 1; transform: scale(1); }
#cozy-world .cw-moon { opacity: 0; transform: scale(0.7) rotate(-14deg); }

#cozy-world.cw--night .cw-sun { opacity: 0; transform: scale(0.82) rotate(10deg); }
#cozy-world.cw--night .cw-moon { opacity: 1; transform: scale(1) rotate(0deg); }

#cozy-world .cw-sun-rays {
  transform-box: view-box;
  transform-origin: 60px 60px;
  animation: cw-spin 160s linear infinite;
}

#cozy-world .cw-celestial.is-poked .cw-celestial-stack {
  animation: cw-pop 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ==========================================================================
   Облака и птицы
   ========================================================================== */

#cozy-world .cw-clouds { position: absolute; inset: 0; }

#cozy-world .cw-cloud {
  position: absolute;
  left: var(--cw-x, -20%);
  top: var(--cw-y, 10%);
  width: var(--cw-w, 180px);
  animation: cw-drift var(--cw-dur, 170s) linear var(--cw-delay, 0s) infinite;
}

#cozy-world .cw-cloud svg {
  display: block;
  width: 100%;
  height: auto;
  opacity: var(--cw-cloud-op);
  transition: opacity 1.1s ease;
}

#cozy-world .cw-cloud-puff { fill: url(#cw-cloud-grad); }
#cozy-world .cw-cloud-hi { fill: var(--cw-cloud-hi); opacity: 0.72; }
#cozy-world .cw-cloud-shade { fill: var(--cw-cloud-shade); }

#cozy-world .cw-birds {
  position: absolute;
  left: 24%;
  top: 22%;
  width: clamp(110px, 11vw, 190px);
  opacity: 0.55;
  transition: opacity 1.1s ease;
  animation: cw-birds-fly 78s linear infinite;
}

#cozy-world .cw-birds svg { display: block; width: 100%; height: auto; }

#cozy-world.cw--night .cw-birds { opacity: 0; }

/* ==========================================================================
   Холмы
   ========================================================================== */

#cozy-world .cw-hills {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 64%;
  display: block;
}

#cozy-world .cw-trees { position: absolute; inset: 0; pointer-events: none; }

#cozy-world .cw-tree {
  position: absolute;
  width: calc(var(--cw-tree-size, 18px) * 0.74);
  height: calc(var(--cw-tree-size, 18px) * 1.65);
  transform: translateX(-50%);
  background-color: var(--cw-tree);
  border-radius: 50% 50% 40% 40% / 60% 60% 42% 42%;
  transition: background-color 1.2s ease;
}

#cozy-world .cw-tree::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -26%;
  width: 2px;
  height: 34%;
  transform: translateX(-50%);
  background-color: var(--cw-tree-trunk);
  border-radius: 1px;
}

#cozy-world .cw-hill--far { fill: var(--cw-hill-far); }
#cozy-world .cw-hill--mid { fill: var(--cw-hill-mid); }
#cozy-world .cw-hill--near { fill: var(--cw-hill-near); }

/* ==========================================================================
   Домик с тёплым окном и дымом
   ========================================================================== */

#cozy-world .cw-cottage {
  position: absolute;
  /* правее — под рейл панели/карточки не прячем домик (см. реальный лэйаут) */
  right: 27.5%;
  bottom: 35.2%;
  width: clamp(140px, 13vw, 192px);
}

#cozy-world .cw-cottage-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 10px 16px rgba(70, 48, 18, 0.16));
}

#cozy-world .cw-cottage-shadow { fill: rgba(60, 40, 15, 0.16); }

#cozy-world .cw-chimney,
#cozy-world .cw-chimney-cap {
  fill: var(--cw-roof);
  stroke: var(--cw-line);
  stroke-width: 2;
  stroke-linejoin: round;
}

#cozy-world .cw-wall {
  fill: var(--cw-wall);
  stroke: var(--cw-line);
  stroke-width: 3;
  stroke-linejoin: round;
}

#cozy-world .cw-timber-line { stroke: var(--cw-timber); }

#cozy-world .cw-roof {
  fill: var(--cw-roof);
  stroke: var(--cw-line);
  stroke-width: 3.2;
  stroke-linejoin: round;
}

#cozy-world .cw-roof-edge { stroke: var(--cw-line); stroke-linejoin: round; }
#cozy-world .cw-roof-line { stroke: var(--cw-roof-hi); }
#cozy-world .cw-eave-shadow { stroke: var(--cw-line); }

#cozy-world .cw-attic-window {
  fill: var(--cw-window);
  stroke: var(--cw-line);
  stroke-width: 2;
}

#cozy-world .cw-window-glow-group { opacity: 0.68; transition: opacity 0.9s ease; }
#cozy-world.cw--night .cw-window-glow-group { opacity: 1; }

#cozy-world .cw-window-halo {
  transform-box: fill-box;
  transform-origin: center;
  animation: cw-halo-breathe 6s ease-in-out infinite;
}

#cozy-world .cw-window-glass {
  fill: var(--cw-window);
  stroke: var(--cw-line);
}

#cozy-world .cw-window-frame { stroke: var(--cw-timber); }

#cozy-world .cw-door {
  fill: var(--cw-door);
  stroke: var(--cw-line);
  stroke-width: 2.6;
  stroke-linejoin: round;
}

#cozy-world .cw-door-frame { stroke: var(--cw-timber); }
#cozy-world .cw-door-knob { fill: var(--cw-wheat-light); }
#cozy-world .cw-wreath { stroke: var(--cw-sage); }

#cozy-world .cw-flowerbox rect {
  fill: var(--cw-roof);
  stroke: var(--cw-line);
  stroke-width: 1.6;
}

#cozy-world .cw-flower { fill: var(--cw-rose); }
#cozy-world .cw-flower-stem { stroke: var(--cw-sage); }

#cozy-world .cw-window-spill {
  opacity: 0.3;
  transition: opacity 0.9s ease;
}

#cozy-world.cw--night .cw-window-spill { opacity: 0.72; }

#cozy-world .cw-bush { fill: var(--cw-sage); opacity: 0.92; }
#cozy-world .cw-stone { fill: var(--cw-wood-shade); opacity: 0.7; }

/* Дым из трубы */
#cozy-world .cw-smoke {
  position: absolute;
  left: 66%;
  top: 4%;
  width: 20%;
  height: 17%; /* низ контейнера = верх трубы, дым поднимается в небо */
  pointer-events: none;
}

#cozy-world .cw-smoke-puff {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 92%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 36%, var(--cw-smoke),
    var(--cw-smoke-2) 58%, rgba(0, 0, 0, 0) 74%);
  opacity: 0;
  animation: cw-smoke 7.4s linear infinite;
}

/* ==========================================================================
   Пшеница (SVG генерится в world.js под реальный размер слоя)
   ========================================================================== */

#cozy-world .cw-wheat {
  position: absolute;
  left: 0;
  right: 0;
  overflow: hidden;
}

/* «гуща» поля: тёплая дымка у корней, чтобы стебли не читались частоколом */
#cozy-world .cw-wheat::before {
  content: "";
  position: absolute;
  left: -2%;
  right: -2%;
  bottom: -1%;
  pointer-events: none;
}

#cozy-world .cw-wheat--back::before {
  height: 80%;
  background: linear-gradient(0deg, var(--cw-haze-back) 0%, rgba(0, 0, 0, 0) 88%);
}

#cozy-world .cw-wheat--front::before {
  height: 90%;
  background: linear-gradient(0deg, var(--cw-haze-front) 0%, rgba(0, 0, 0, 0) 90%);
}

#cozy-world .cw-wheat--back {
  bottom: 18%;
  height: 26%;
}

#cozy-world .cw-wheat--front {
  bottom: 0;
  height: 28%;
}

#cozy-world .cw-wheat-svg {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
}

#cozy-world .cw-wheat-leaf { stroke: var(--cw-stem); }
#cozy-world .cw-wheat--front .cw-wheat-leaf { stroke: var(--cw-stem-front); }

#cozy-world .cw-ear {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: cw-sway var(--cw-dur, 6s) ease-in-out var(--cw-delay, 0s) infinite alternate;
}

/* ==========================================================================
   Забор, гирлянда и кот
   ========================================================================== */

#cozy-world .cw-fence {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 20%;
  height: var(--cw-fence-h);
}

#cozy-world .cw-fence-posts { position: absolute; inset: 0; }

#cozy-world .cw-post {
  position: absolute;
  bottom: 0;
  width: clamp(5px, 0.55vw, 9px);
  height: var(--cw-ph, 100%);
  transform: translateX(-50%);
  background-color: var(--cw-wood);
  border-radius: 4px 4px 1px 1px;
  box-shadow: inset -2px 0 0 var(--cw-wood-shade),
    inset 0 2px 0 var(--cw-wood-hi);
  transition: background-color 1.2s ease;
}

#cozy-world .cw-rail {
  position: absolute;
  left: -2%;
  right: -2%;
  z-index: 2;
  border-radius: 3px;
  background-color: var(--cw-wood-hi);
  box-shadow: inset 0 -2px 0 var(--cw-wood-shade),
    0 1px 0 rgba(255, 255, 255, 0.14);
  transition: background-color 1.2s ease;
}

#cozy-world .cw-rail--top { top: 8%; height: 12%; }

#cozy-world .cw-rail--bottom {
  top: 56%;
  height: 11%;
  background-color: var(--cw-wood);
}

/* Гирлянда: висит вдоль верхней жерди, лампочки провисают. */
#cozy-world .cw-garland {
  position: absolute;
  left: 12%;
  bottom: calc(var(--cw-fence-h) * 0.9 - var(--cw-garland-h));
  width: var(--cw-garland-w);
  height: var(--cw-garland-h);
  z-index: 3;
  pointer-events: none;
}

#cozy-world .cw-garland svg { display: block; width: 100%; height: 100%; }

#cozy-world .cw-garland-wire {
  stroke: var(--cw-garland-wire);
  opacity: 0.9;
  transition: opacity 0.5s ease;
}

#cozy-world .cw-bulb {
  fill: var(--cw-bulb);
  animation: cw-bulb-twinkle 2.4s ease-in-out var(--cw-bulb-delay, 0s) infinite alternate;
}

#cozy-world .cw-bulb-halo { opacity: 0.85; transition: opacity 0.5s ease; }

#cozy-world.cw--lamp-off .cw-bulb {
  animation: none;
  opacity: 0.16;
}

#cozy-world.cw--lamp-off .cw-bulb-halo { opacity: 0; }
#cozy-world.cw--lamp-off .cw-garland-wire { opacity: 0.5; }

/* --- кот --- */
#cozy-world .cw-cat {
  position: absolute;
  left: 57%;
  bottom: 88%;
  width: clamp(60px, 5.4vw, 82px);
  transform: translateX(-50%);
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  pointer-events: auto;
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#cozy-world .cw-cat-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 5px 8px rgba(60, 40, 15, 0.22));
  transition: transform 0.28s ease;
}

@media (hover: hover) {
  #cozy-world .cw-cat:hover .cw-cat-svg { transform: translateY(-2px); }
}

#cozy-world .cw-cat-body,
#cozy-world .cw-cat-head,
#cozy-world .cw-cat-ear,
#cozy-world .cw-cat-paw {
  fill: var(--cw-cat);
  stroke: var(--cw-line);
  stroke-width: 2.6;
  stroke-linejoin: round;
}

#cozy-world .cw-cat-chest { fill: var(--cw-cat-chest); opacity: 0.92; }

#cozy-world .cw-cat-ear-inner {
  fill: var(--cw-cat-ear);
  stroke: none;
  opacity: 0.85;
}

#cozy-world .cw-cat-face { stroke: var(--cw-line); }
#cozy-world .cw-cat-whisker { stroke: var(--cw-line); }
#cozy-world .cw-cat-blush { fill: var(--cw-rose); opacity: 0.28; }

#cozy-world .cw-cat-tail {
  stroke: var(--cw-cat);
  animation: cw-tail 6s ease-in-out -1.5s infinite alternate;
}

#cozy-world .cw-cat.is-purring .cw-cat-tail {
  animation: cw-tail-fast 0.38s ease-in-out 3;
}

#cozy-world .cw-cat-bodywrap {
  transform-box: fill-box;
  transform-origin: 50% 100%;
}

#cozy-world .cw-cat.is-purring .cw-cat-bodywrap {
  animation: cw-purr 0.34s ease-in-out 3;
}

#cozy-world .cw-cat-hearts {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#cozy-world .cw-heart {
  position: absolute;
  left: 50%;
  bottom: 68%;
  font-size: 15px;
  line-height: 1;
  color: var(--cw-rose);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  pointer-events: none;
  animation: cw-heart 1.4s ease-out forwards;
}

#cozy-world .cw-purr {
  position: absolute;
  left: 50%;
  top: -16%;
  transform: translateX(-50%);
  font-family: var(--cozy-font, "Trebuchet MS", "Segoe UI", Tahoma, sans-serif);
  font-size: 12px;
  font-style: italic;
  letter-spacing: 0.02em;
  color: var(--cw-ink);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

#cozy-world .cw-cat.is-purring .cw-purr {
  animation: cw-purr-text 0.9s ease-out;
}

/* ==========================================================================
   Фонарь (кликабельный — переключает гирлянду)
   ========================================================================== */

#cozy-world .cw-lamp {
  position: absolute;
  left: 8%;
  bottom: 20%;
  width: clamp(40px, 4vw, 58px);
  aspect-ratio: 64 / 190;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  pointer-events: auto;
  z-index: 6;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#cozy-world .cw-lamp-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

#cozy-world .cw-lamp-post,
#cozy-world .cw-lamp-arm,
#cozy-world .cw-lamp-hook {
  fill: var(--cw-wood);
  stroke: var(--cw-line);
  stroke-width: 2;
  stroke-linecap: round;
}

#cozy-world .cw-lamp-arm,
#cozy-world .cw-lamp-hook { fill: none; stroke-width: 3.4; }

#cozy-world .cw-lamp-cap,
#cozy-world .cw-lamp-basecap {
  fill: var(--cw-timber);
  stroke: var(--cw-line);
  stroke-width: 1.8;
  stroke-linejoin: round;
}

#cozy-world .cw-lamp-pane {
  fill: var(--cw-window);
  stroke: var(--cw-line);
  stroke-width: 2;
  transition: fill 0.6s ease;
}

#cozy-world .cw-lamp-frame { stroke: var(--cw-timber); }

#cozy-world .cw-lamp-flame {
  fill: var(--cw-window-bright);
  transition: opacity 0.5s ease;
}

#cozy-world .cw-lamp-base-shadow { fill: rgba(60, 40, 15, 0.2); }

#cozy-world .cw-lamp-glow {
  position: absolute;
  left: 80%;
  top: 30%;
  width: 210%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 219, 150, 0.8) 0%,
    rgba(255, 196, 106, 0.22) 34%, rgba(255, 196, 106, 0) 68%);
  opacity: 0.42;
  transition: opacity 0.6s ease;
  animation: cw-lamp-breathe 5.5s ease-in-out infinite;
  pointer-events: none;
}

#cozy-world.cw--night .cw-lamp-glow { opacity: 0.82; }
#cozy-world.cw--lamp-off .cw-lamp-glow { opacity: 0; }
#cozy-world.cw--lamp-off .cw-lamp-pane { fill: var(--cw-window-off); }
#cozy-world.cw--lamp-off .cw-lamp-flame { opacity: 0; }

#cozy-world .cw-lamp.is-flicker .cw-lamp-svg {
  animation: cw-lamp-flicker 0.62s ease-out;
}

/* ==========================================================================
   Светлячки / пыльца
   ========================================================================== */

#cozy-world .cw-motes { position: absolute; inset: 0; }

#cozy-world .cw-mote {
  position: absolute;
  width: var(--cw-mote-size, 3px);
  height: var(--cw-mote-size, 3px);
  border-radius: 50%;
  background: var(--cw-mote);
  box-shadow: 0 0 5px 1px var(--cw-mote-glow);
  opacity: 0;
  animation: cw-mote-float var(--cw-mote-dur, 12s) ease-in-out
    var(--cw-mote-delay, 0s) infinite;
}

#cozy-world.cw--night .cw-mote {
  background: var(--cw-firefly);
  box-shadow: 0 0 7px 2px var(--cw-firefly-glow);
}

/* ==========================================================================
   Оверлеи: виньетка, «бумага», фокус-вуаль
   ========================================================================== */

#cozy-world .cw-vignette {
  position: absolute;
  inset: 0;
  background: var(--cw-vignette);
  transition: background 1.2s ease;
}

#cozy-world .cw-ground {
  position: absolute;
  inset: 0;
  background: var(--cw-ground);
}

#cozy-world .cw-grain {
  position: absolute;
  inset: 0;
  opacity: 0.55;
  background-image:
    repeating-linear-gradient(0deg, var(--cw-grain-ink) 0 1px,
      rgba(0, 0, 0, 0) 1px 3px),
    repeating-linear-gradient(90deg, var(--cw-grain-ink) 0 1px,
      rgba(0, 0, 0, 0) 1px 4px),
    repeating-linear-gradient(45deg, var(--cw-grain-light) 0 1px,
      rgba(0, 0, 0, 0) 1px 5px);
}

#cozy-world .cw-focus-veil {
  position: absolute;
  inset: 0;
  background: var(--cw-focus-veil);
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

#cozy-world.cw--focus .cw-focus-veil { opacity: 1; }

/* Фокус-режим: приглушаем «сочные» слои и замираем сцену. */
#cozy-world.cw--focus .cw-layer--clouds,
#cozy-world.cw--focus .cw-layer--motes {
  opacity: 0.45;
  transition: opacity 0.5s ease;
}

#cozy-world.cw--focus .cw-anim { animation-play-state: paused; }

/* setEnabled(false) — пауза всех анимаций мира. */
#cozy-world.cw--paused .cw-anim { animation-play-state: paused !important; }

/* prefers-reduced-motion / body.reduce-motion: сцена есть, движения нет. */
#cozy-world.cw--reduced .cw-anim { animation: none !important; }

@media (prefers-reduced-motion: reduce) {
  #cozy-world .cw-anim { animation: none !important; }
}

/* ==========================================================================
   Адаптив
   ========================================================================== */

@media (max-width: 760px) {
  #cozy-world {
    --cw-fence-h: clamp(64px, 10vh, 84px);
    --cw-garland-w: clamp(150px, 42vw, 240px);
  }

  #cozy-world .cw-hills { height: 60%; }

  #cozy-world .cw-celestial {
    left: 73%;
    top: 10.5%;
    width: clamp(78px, 21vw, 104px);
  }

  #cozy-world .cw-cottage {
    right: 3.5%;
    bottom: 37%;
    width: clamp(136px, 35vw, 176px);
  }

  #cozy-world .cw-lamp {
    left: 3.5%;
    width: clamp(36px, 9vw, 46px);
  }

  #cozy-world .cw-cat {
    left: 52%;
    width: clamp(60px, 16vw, 78px);
  }

  #cozy-world .cw-cloud { width: calc(var(--cw-w) * 0.66); }
  #cozy-world .cw-cloud--hide-sm { display: none; }

  #cozy-world .cw-mote:nth-child(n + 11) { display: none; }

  #cozy-world .cw-wheat--back { bottom: 15%; }
  #cozy-world .cw-cottage { bottom: 36%; }
  #cozy-world .cw-tree { opacity: 0.8; }
}

@media (max-width: 420px) {
  #cozy-world .cw-cottage { right: 2%; width: clamp(128px, 36vw, 156px); }
  #cozy-world .cw-cat { left: 51%; }
  #cozy-world .cw-garland { left: 10%; }
}

@media (max-height: 660px) {
  #cozy-world { --cw-fence-h: clamp(52px, 9vh, 68px); }
  #cozy-world .cw-cottage { width: clamp(116px, 11vw, 148px); }
  #cozy-world .cw-cat { width: clamp(46px, 4.4vw, 60px); }
}

/* ==========================================================================
   Ключевые кадры (все имена — cw-*)
   ========================================================================== */

@keyframes cw-twinkle {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

@keyframes cw-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes cw-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

@keyframes cw-drift {
  0% { opacity: 0; transform: translate3d(0, 0, 0); }
  5% { opacity: 1; }
  95% { opacity: 1; }
  100% { opacity: 0; transform: translate3d(var(--cw-travel, 150vw), 0, 0); }
}

@keyframes cw-birds-fly {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(118vw, 0, 0); }
}

@keyframes cw-halo-breathe {
  0%, 100% { opacity: 0.78; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.06); }
}

@keyframes cw-smoke {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.42); }
  18% { opacity: 0.6; }
  70% { opacity: 0.24; }
  100% { opacity: 0; transform: translate(calc(-50% + 18px), -74px) scale(1.6); }
}

@keyframes cw-sway {
  0% { transform: rotate(calc(var(--cw-amp, 2deg) * -1)); }
  100% { transform: rotate(var(--cw-amp, 2deg)); }
}

@keyframes cw-tail {
  0% { transform: rotate(-3deg); }
  100% { transform: rotate(6deg); }
}

@keyframes cw-tail-fast {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(11deg); }
}

@keyframes cw-purr {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-1px) scale(1.015); }
}

@keyframes cw-purr-text {
  0% { opacity: 0; transform: translate(-50%, 4px); }
  25% { opacity: 0.9; }
  100% { opacity: 0; transform: translate(-50%, -18px); }
}

@keyframes cw-heart {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.6) rotate(var(--cw-hr, 0deg)); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--cw-hx, 0px)), -54px)
    scale(1.15) rotate(var(--cw-hr, 0deg)); }
}

@keyframes cw-bulb-twinkle {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

@keyframes cw-lamp-breathe {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.07); }
}

@keyframes cw-lamp-flicker {
  0% { opacity: 1; }
  18% { opacity: 0.35; }
  32% { opacity: 1; }
  48% { opacity: 0.55; }
  66% { opacity: 1; }
  82% { opacity: 0.8; }
  100% { opacity: 1; }
}

@keyframes cw-mote-float {
  0% { opacity: 0; transform: translate3d(0, 8px, 0) scale(0.6); }
  18% { opacity: 0.9; }
  50% { opacity: 0.35; transform: translate3d(calc(var(--cw-mote-drift, 12px) * 0.5), -22px, 0) scale(1); }
  78% { opacity: 0.85; }
  100% { opacity: 0; transform: translate3d(var(--cw-mote-drift, 12px), -54px, 0) scale(0.7); }
}
