/* 註冊自訂屬性，瀏覽器才能在動畫中平滑插值。 */
@property --ag-lit {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
@property --ag-flash {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
@property --ag-flash-scale {
  syntax: "<number>";
  inherits: true;
  initial-value: 0.55;
}
@property --ag-glow {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
@property --ag-brightness {
  syntax: "<number>";
  inherits: true;
  initial-value: 1;
}
@property --ag-breathe-y {
  syntax: "<length>";
  inherits: true;
  initial-value: 0px;
}

/* 《剪一扇春窗》亮燈／呼吸／閃光 — 程式可直接套用。
   時長與曲線以 lights/*.json 為準，本檔提供對應的自訂屬性與預設關鍵幀。
   亮燈疊法（製作長官已定）：
     底圖 henuan_base.webp
     + 五張各層透明層 henuan_lights_f1.webp～f5.webp（獨立 --ag-lit／--ag-brightness）
     + 單扇窗＝該層圖加上窗框矩形遮罩（窗框待原畫）
   不要把兩張完整立面互切。延遲請用 shared/playback.js。
   正式立面圖未到前，也可以先套在占位窗上。 */

.ag-window {
  position: relative;
  overflow: hidden;
  --ag-lit: 0;
  --ag-flash: 0;
  --ag-flash-scale: 0.55;
  --ag-glow: 0;
  --ag-brightness: 1;
  --ag-breathe-y: 0px;
  --ag-lit-color: #ffe4b0;
  --ag-unlit-color: #2c2834;
  --ag-flash-color: #ffe7c2;
  --ag-paper-red: #c41e3a;
  transform: translateY(var(--ag-breathe-y));
}

.ag-window__unlit,
.ag-window__lit,
.ag-window__silhouette,
.ag-window__paper,
.ag-window__flash,
.ag-window__glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ag-window__unlit {
  background: var(--ag-unlit-color);
  z-index: 0;
}

.ag-window__lit {
  z-index: 1;
  opacity: var(--ag-lit);
  filter: brightness(var(--ag-brightness));
  background: var(--ag-lit-color);
  /* 正式用法：改為 mask 出亮燈立面中對應的窗矩形，而不是純色。 */
}

.ag-window__silhouette {
  z-index: 2;
  opacity: var(--ag-lit);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.ag-window__paper {
  z-index: 3;
  opacity: var(--ag-lit);
  /* 窗花圖由美術長官提供後，用 mask-image 或 <img> 替換。 */
}

.ag-window__glow {
  z-index: 4;
  opacity: var(--ag-glow);
  background: radial-gradient(circle at 50% 55%, rgba(255, 196, 110, 0.55), rgba(255, 196, 110, 0) 70%);
}

.ag-window__flash {
  z-index: 5;
  opacity: var(--ag-flash);
  transform: scale(var(--ag-flash-scale));
  transform-origin: 50% 50%;
  background: radial-gradient(circle at 50% 50%, #fff6e4 0%, #ffe7c2 35%, rgba(255, 231, 194, 0) 70%);
  mix-blend-mode: screen;
}

/* 下列關鍵幀是 JSON 的備援，優先用 window-lights.js 讀 clips 來播。 */
@keyframes ag-window-on {
  0%   { --ag-lit: 0;    --ag-brightness: 0.14; --ag-glow: 0; }
  36%  { --ag-lit: 0.72; --ag-brightness: 0.72; --ag-glow: 0.22; }
  70%  { --ag-lit: 1;    --ag-brightness: 1.06; --ag-glow: 0.42; }
  100% { --ag-lit: 1;    --ag-brightness: 1;    --ag-glow: 0.22; }
}

@keyframes ag-paste-flash {
  0%   { --ag-flash: 0;    --ag-flash-scale: 0.55; }
  35%  { --ag-flash: 0.92; --ag-flash-scale: 1.15; }
  100% { --ag-flash: 0;    --ag-flash-scale: 1.42; }
}

@keyframes ag-idle-breathe {
  0%, 100% { --ag-brightness: 0.97; --ag-glow: 0.18; --ag-breathe-y: 0px; }
  50%      { --ag-brightness: 1.03; --ag-glow: 0.28; --ag-breathe-y: -1px; }
}

@keyframes ag-floor-pulse {
  0%, 100% { --ag-brightness: 1;    --ag-glow: 0.22; }
  54%      { --ag-brightness: 1.12; --ag-glow: 0.5; }
}

.ag-window.is-on .ag-window__lit,
.ag-window.is-on .ag-window__silhouette,
.ag-window.is-on .ag-window__paper {
  opacity: 1;
}

.ag-window.is-breathing {
  animation: ag-idle-breathe 4000ms ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .ag-window.is-breathing {
    animation: none;
  }
}

/* 各層亮燈透明層：與底圖同尺寸對齊，獨立淡入。 */
.ag-facade {
  position: relative;
}
.ag-facade__base {
  display: block;
  width: 100%;
  height: auto;
}
.ag-floor-light {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: var(--ag-lit);
  filter: brightness(var(--ag-brightness));
}
.ag-window-light {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: var(--ag-lit);
  filter: brightness(var(--ag-brightness));
  /* 正式用法：clip-path 或 mask 設為該扇 framePx（相對於 2048×4096）。 */
}
