/* Light belongs to the room: every accent is registered against the still's
   image coordinates. These layers never enter the article's stacking plane. */
.ciki-room-atmosphere {
  --ciki-atmosphere-height: max(480px, calc(100vh - var(--ciki-room-header, 64px)));
  display: block;
  position: sticky;
  top: var(--ciki-room-header, 64px);
  height: var(--ciki-atmosphere-height);
  margin-top: calc(-1 * var(--ciki-atmosphere-height));
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  contain: paint;
  animation: ciki-room-awaken 760ms ease-out both;
}

@supports (height: 100svh) {
  .ciki-room-atmosphere {
    --ciki-atmosphere-height: max(480px, calc(100svh - var(--ciki-room-header, 64px)));
  }
}

.ciki-room-stage {
  position: absolute;
  top: 0;
  overflow: visible;
  pointer-events: none;
}

/* A broad, dim halo extends the baked light; the small stepped flame retains
   the texture's block scale instead of placing a second lamp over it. */
.ciki-room-lamp {
  position: absolute;
  width: calc(var(--room-scale, 1) * var(--radius, 150px));
  height: calc(var(--room-scale, 1) * var(--radius, 150px));
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse at center,
    rgba(255, 210, 119, .24) 0%,
    rgba(244, 158, 61, .15) 22%,
    rgba(213, 102, 32, .06) 46%,
    rgba(197, 90, 27, 0) 72%);
  opacity: var(--lamp-strength, .72);
  animation: ciki-room-lamplight var(--lamp-duration, 3.7s)
    steps(1, end) var(--lamp-delay, -.8s) infinite;
}

.ciki-room-lamp.is-candle {
  background: radial-gradient(ellipse at center,
    rgba(255, 220, 145, .2) 0%,
    rgba(244, 167, 77, .1) 23%,
    rgba(222, 116, 44, .035) 48%,
    rgba(222, 116, 44, 0) 72%);
}

.ciki-room-flame {
  display: block;
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(2px, calc(var(--room-scale, 1) * var(--flame-size, 5px)));
  height: max(3px, calc(var(--room-scale, 1) * var(--flame-size, 5px) * 1.7));
  transform: translate(-50%, -68%);
  transform-origin: center bottom;
  background: #ffe8a6;
  box-shadow:
    0 2px 0 rgba(247, 158, 52, .78),
    -1px 1px 0 rgba(255, 196, 91, .5),
    1px 1px 0 rgba(255, 196, 91, .5);
  opacity: .88;
  image-rendering: pixelated;
  animation: ciki-room-flame var(--flame-duration, 3.1s)
    steps(1, end) var(--lamp-delay, -.8s) infinite;
}

.ciki-room-lamp.is-candle .ciki-room-flame {
  width: max(1px, calc(var(--room-scale, 1) * 2px));
  height: max(2px, calc(var(--room-scale, 1) * 3px));
  opacity: .7;
}

/* The library's window carries a quiet shaft of light. Its soft transverse
   falloff remains inside the architecture; there is no animated screen wash. */
.ciki-room-ray {
  display: block;
  position: absolute;
  transform: rotate(var(--ray-tilt, -19deg));
  transform-origin: 50% 0;
  background: linear-gradient(to bottom,
    rgba(222, 224, 191, .23),
    rgba(221, 222, 184, .11) 50%,
    rgba(221, 222, 184, 0));
  mask-image: linear-gradient(to right,
    transparent, #000 32%, #000 61%, transparent);
  opacity: var(--ray-strength, .7);
  animation: ciki-room-windowlight 14s ease-in-out infinite;
}

.ciki-room-ray::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg,
    transparent 0 25%, rgb(6 13 18 / .18) 25% 28%);
  opacity: .5;
}

.ciki-room-mote {
  display: block;
  position: absolute;
  width: max(1px, calc(var(--room-scale, 1) * 2px));
  height: max(1px, calc(var(--room-scale, 1) * 2px));
  background: var(--mote-color, #e2d3a7);
  opacity: 0;
  image-rendering: pixelated;
  animation: ciki-room-dust var(--duration, 13s) linear var(--delay, -3s) infinite;
}

.ciki-room-mote.is-ember {
  width: max(1px, calc(var(--room-scale, 1) * 1.5px));
  height: max(1px, calc(var(--room-scale, 1) * 2px));
  background: var(--mote-color, #e6a866);
  animation-name: ciki-room-ember;
  animation-timing-function: ease-out;
}

.ciki-room-mote.is-firefly {
  width: 2px;
  height: 2px;
  background: var(--mote-color, #d8d5a0);
  box-shadow: 0 0 4px rgba(205, 204, 139, .32);
  animation-name: ciki-room-firefly;
  animation-timing-function: ease-in-out;
}

@keyframes ciki-room-awaken {
  from { opacity: .18; }
  42% { opacity: .42; }
  to { opacity: 1; }
}

/* Widely spaced holds, with only a small change in intensity. */
@keyframes ciki-room-lamplight {
  0%, 100% { opacity: calc(var(--lamp-strength, .72) * .86); }
  13% { opacity: calc(var(--lamp-strength, .72) * .93); }
  31% { opacity: calc(var(--lamp-strength, .72) * .82); }
  54% { opacity: var(--lamp-strength, .72); }
  78% { opacity: calc(var(--lamp-strength, .72) * .9); }
}

@keyframes ciki-room-flame {
  0%, 100% { transform: translate(-50%, -68%) scaleY(.85); opacity: .72; }
  23% { transform: translate(-50%, -68%) scaleY(1.08); opacity: .96; }
  49% { transform: translate(-50%, -68%) scaleY(.72); opacity: .5; }
  77% { transform: translate(-50%, -68%) scaleY(1); opacity: .88; }
}

@keyframes ciki-room-windowlight {
  0%, 100% { opacity: calc(var(--ray-strength, .7) * .84); }
  54% { opacity: var(--ray-strength, .7); }
}

@keyframes ciki-room-dust {
  0% { transform: translate(0, 0); opacity: 0; }
  17% { opacity: .24; }
  53% { opacity: .36; }
  83% { opacity: .13; }
  100% { transform: translate(var(--drift-x, 12px), var(--drift-y, -35px)); opacity: 0; }
}

@keyframes ciki-room-ember {
  0%, 7% { transform: translate(0, 0); opacity: 0; }
  18% { opacity: .6; }
  46% { opacity: .3; }
  79%, 100% { transform: translate(var(--drift-x, 8px), var(--drift-y, -32px)); opacity: 0; }
}

@keyframes ciki-room-firefly {
  0% { transform: translate(0, 0); opacity: 0; }
  19% { opacity: .48; }
  37% { opacity: .14; }
  61% { opacity: .54; }
  81% { opacity: .2; }
  100% { transform: translate(var(--drift-x, 20px), var(--drift-y, -12px)); opacity: 0; }
}

.ciki-room-atmosphere[data-running="false"] {
  animation: none;
  opacity: .65;
}

.ciki-room-atmosphere[data-running="false"] *,
.ciki-room-atmosphere[data-running="false"] *::before,
.ciki-room-atmosphere[data-running="false"] *::after {
  animation-play-state: paused;
}

.ciki-room-atmosphere[data-running="false"] .ciki-room-mote {
  visibility: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .ciki-room-atmosphere,
  .ciki-room-atmosphere * {
    animation: none !important;
  }

  .ciki-room-atmosphere { opacity: .65; }
  .ciki-room-mote { display: none; }
}

@media print {
  .ciki-room-atmosphere { display: none !important; }
}
