/* ─────────────────────────────────────────────────────────────
   HERO WINDOW — four-layer opening window, embedded in the wall
   Loaded after style.css. Layers (assets/window/, 1086 × 1448,
   satin walnut grade): frame + sill, left panel, right panel, hinges.
   Built by hero-window.js; independent of script.js (pull cord).
   ───────────────────────────────────────────────────────────── */

/* Same on-screen footprint as before: frame top → sill bottom.
   Old asset spanned y 101→1246 (1145); new spans y 65→1296 (1231). */
.window-wrap {
  --fs: 0.3964;                                   /* 488 / 1231 */
  top: calc(var(--wrap-top) - 65px * var(--fs));
  translate: calc(-532.5px * var(--fs)) 0;
}
@media (max-width: 600px) {
  .window-wrap { --fs: 0.3055; }                  /* 376 / 1231 */
}

/* the view now fills the new sash opening (x 207–855, y 178–1170) */
.window {
  left:   calc(207px * var(--fs));
  top:    calc(178px * var(--fs));
  width:  calc(648px * var(--fs));
  height: calc(992px * var(--fs));
  border-radius: calc(324px * var(--fs)) calc(324px * var(--fs)) 0 0;
}

/* ── layer group ── */
.ww { position: absolute; inset: 0; z-index: 2; pointer-events: none;
  /* moonlight: same treatment the old window had at night, a touch softer */
  filter: brightness(1) saturate(1);
  transition: filter 1.4s ease-in-out; }
body.night .ww { filter: brightness(0.5) saturate(0.7); }

.ww-layer { position: absolute; inset: 0; isolation: isolate; }
.ww-layer img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; user-select: none; }

/* Room light: the wood takes the wall's own colour temperature.
   A multiply tint built from the hero's --room-* colours (they already
   cross-fade with the pull cord), masked to each layer's own pixels so
   glass and wall are never tinted. Brighter where the window light
   falls, deeper toward the sill and outer edges. */
.ww-tint {
  position: absolute; inset: 0;
  mix-blend-mode: multiply;
  background:
    radial-gradient(ellipse 62% 56% at 50% 38%,
      color-mix(in srgb, var(--room-core) 10%, #fff) 0%,
      color-mix(in srgb, var(--room-core) 22%, #fff) 55%,
      color-mix(in srgb, var(--room-mid) 30%, #fff) 82%,
      color-mix(in srgb, var(--room-edge) 30%, #fff) 100%);
  -webkit-mask: var(--src) 0 0 / 100% 100% no-repeat;
          mask: var(--src) 0 0 / 100% 100% no-repeat;
}
/* the reveal: wood nearest the glass sits in the opening's shadow */
.ww-frame .ww-tint::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse 34% 40% at 48.9% 47%, transparent 78%, rgba(40, 20, 10, 0.28) 92%, transparent 100%);
}

/* ── embedding in the wall ── */
/* 1 · ambient occlusion: wide, very soft darkening of the plaster around the casing */
.ww-ao {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background: #000;
  -webkit-mask: url(assets/window/window-frame-sill.png) 0 0 / 100% 100% no-repeat;
          mask: url(assets/window/window-frame-sill.png) 0 0 / 100% 100% no-repeat;
  filter: blur(calc(22px * var(--fs) / 0.4));
  opacity: 0.42;
  transform: scale(1.025) translateY(calc(6px * var(--fs) / 0.4));
  transform-origin: 50% 45%;
}
body.night .ww-ao { opacity: 0.55; }
/* 2 · tight contact shadow where the casing meets the wall (the existing .window-shadow, retuned softer) */
.window-shadow {
  filter:
    brightness(0)
    blur(calc(3px * var(--fs) / 0.4))
    drop-shadow(0 calc(8px * var(--fs) / 0.4) calc(10px * var(--fs) / 0.4) rgba(0, 0, 0, 0.55));
  opacity: 0.6;
  translate: 0 calc(2px * var(--fs) / 0.4);
}
/* 3 · contact shadow under the sill: soft, wider than the sill, fading down the wall */
.ww-sill-shadow {
  position: absolute; z-index: 0; pointer-events: none;
  left: calc(80px * var(--fs)); width: calc(926px * var(--fs));
  top: calc(1282px * var(--fs)); height: calc(110px * var(--fs));
  background: radial-gradient(ellipse 50% 60% at 50% 0%, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.22) 45%, transparent 100%);
  filter: blur(calc(6px * var(--fs) / 0.4));
}

/* ── opening panels (same values as the approved preview) ── */
.ww-leaves { position: absolute; inset: 0; perspective: calc(3200px * var(--fs)); perspective-origin: 48.9% 20.7%; clip-path: var(--casing); }
.ww-leaf { position: absolute; inset: 0; backface-visibility: visible; will-change: transform;
  transition: transform 1.9s cubic-bezier(.22,.8,.24,1), filter 1.9s cubic-bezier(.22,.8,.24,1); }
.ww-leaf--l { transform-origin: 19.20% 50%; }
.ww-leaf--r { transform-origin: 78.59% 50%; transition-delay: .12s; }
.ww-glass { position: absolute; inset: 0; opacity: 0; transition: opacity 1.9s ease;
  background: linear-gradient(105deg, rgba(255,240,220,.16), rgba(255,240,220,.04) 45%, rgba(255,240,220,.11)); }
.ww-leaf--l .ww-glass { clip-path: var(--half-l); }
.ww-leaf--r .ww-glass { clip-path: var(--half-r); }
.window-wrap[data-win="ajar"] .ww-leaf--l { transform: rotateY(-32deg); filter: brightness(.9); }
.window-wrap[data-win="ajar"] .ww-leaf--r { transform: rotateY(32deg);  filter: brightness(.92); }
.window-wrap[data-win="ajar"] .ww-glass { opacity: .55; }
.window-wrap[data-win="open"] .ww-leaf--l { transform: rotateY(-70deg); filter: brightness(.7) drop-shadow(calc(6px * var(--fs) / .4) calc(10px * var(--fs) / .4) calc(12px * var(--fs) / .4) rgba(0,0,0,.35)); }
.window-wrap[data-win="open"] .ww-leaf--r { transform: rotateY(70deg);  filter: brightness(.75) drop-shadow(calc(-6px * var(--fs) / .4) calc(10px * var(--fs) / .4) calc(12px * var(--fs) / .4) rgba(0,0,0,.35)); }
.window-wrap[data-win="open"] .ww-glass { opacity: 1; }
.window-wrap.is-closing .ww-leaf { transition-duration: 1.5s; transition-timing-function: cubic-bezier(.5,0,.25,1); }
.window-wrap.is-closing .ww-leaf--r { transition-delay: 0s; } .window-wrap.is-closing .ww-leaf--l { transition-delay: .1s; }
.window-wrap[data-win="closed"].is-nudge .ww-leaf--l { transform: rotateY(-5deg); transition-duration: .9s; }
.window-wrap[data-win="closed"].is-nudge .ww-leaf--r { transform: rotateY(5deg);  transition-duration: .9s; }
/* glass reflection belongs to the sash */
.window-wrap .glass { transition: opacity 1.2s ease; }
.window-wrap[data-win="open"] .glass { opacity: 0; }

.ww-handle { position: absolute; z-index: 4; left: 49.86%; top: 50.62%;
  width: max(44px, calc(70px * var(--fs))); height: max(44px, calc(130px * var(--fs)));
  transform: translate(-50%, -50%); background: none; border: 0; border-radius: 12px; cursor: pointer;
  pointer-events: auto; -webkit-tap-highlight-color: transparent; }
.ww-handle:focus-visible { outline: 1px solid rgba(245,232,213,.7); outline-offset: 4px; }

/* sound control (as approved) */
.ww-sound { position: absolute; z-index: 10; right: 44px; bottom: 28px; display: inline-flex; align-items: center; gap: 10px;
  background: none; border: 0; padding: 6px 0; cursor: pointer; font-family: var(--font-body); font-weight: 300;
  font-size: .68rem; letter-spacing: .24em; text-transform: uppercase; color: rgba(245,232,213,.52);
  opacity: 0; visibility: hidden; transition: opacity .8s ease, visibility 0s .8s; }
.ww-sound.is-shown { opacity: 1; visibility: visible; transition: opacity .8s ease; }
.ww-sound .bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 10px; }
.ww-sound .bars i { width: 2px; height: 3px; background: currentColor; }
.ww-sound[aria-pressed="true"] .bars i { animation: wwBar 1.4s ease-in-out infinite; }
.ww-sound[aria-pressed="true"] .bars i:nth-child(2) { animation-delay: -.5s; }
.ww-sound[aria-pressed="true"] .bars i:nth-child(3) { animation-delay: -.9s; }
@keyframes wwBar { 50% { height: 10px; } }
@media (max-width: 720px) {
  .ww-sound { right: auto; bottom: auto; left: 20px; top: 22px; padding: 6px; }
  .ww-sound .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .ww-leaf { transition: opacity .6s ease !important; transform: none !important; filter: none !important; }
  .window-wrap[data-win="open"] .ww-leaf, .window-wrap[data-win="ajar"] .ww-leaf { opacity: 0; }
  .ww-sound[aria-pressed="true"] .bars i { animation: none; height: 7px; }
}
