/* Wave 4: one finite opening, then sparse ambient decoration. All copy stays HTML. */
.doc .sec-cover { position: relative; isolation: isolate; overflow: hidden; }
.opening-layer { position: absolute; z-index: 4; inset: 0; overflow: hidden; pointer-events: none; opacity: 0; visibility: hidden; animation: studio-opening-life 2.3s linear both; }
.opening-layer *, .opening-layer *::before, .opening-layer *::after { pointer-events: none; }
@keyframes studio-opening-life { 0%, 94% { opacity: 1; visibility: visible; } 100% { opacity: 0; visibility: hidden; } }

/* A translucent wash makes a gentle first impression without waiting for JavaScript. */
.opening-fade { background: color-mix(in srgb, var(--paper) 72%, transparent); animation: studio-fade 1.7s ease-out both; }
@keyframes studio-fade { 0% { opacity: .8; visibility: visible; } 100% { opacity: 0; visibility: hidden; } }
.doc[data-opening="fade"] #sec-cover :is(.cover-names, .obit-name) { animation: studio-name-fade 1.7s ease-out both; }
@keyframes studio-name-fade { from { opacity: .4; transform: translateY(.3rem); } to { opacity: 1; transform: none; } }

/* Two softly folded textile panels part toward the cover edges. */
.opening-panel { position: absolute; top: 0; bottom: 0; width: 50.5%; background: linear-gradient(90deg, color-mix(in srgb, var(--paper) 90%, #b9aa91) 0%, var(--paper) 22%, color-mix(in srgb, var(--paper) 92%, #a7977c) 49%, var(--paper) 77%, color-mix(in srgb, var(--paper) 92%, #baa78c) 100%); opacity: .9; }
.opening-left { left: 0; transform-origin: left center; animation: studio-curtain-left 1.85s .15s cubic-bezier(.22,.65,.28,1) both; }
.opening-right { right: 0; transform-origin: right center; animation: studio-curtain-right 1.85s .15s cubic-bezier(.22,.65,.28,1) both; }
.opening-seam { position: absolute; left: 50%; top: 0; height: 100%; width: 1px; background: var(--accent); opacity: .35; animation: studio-seam 1.5s ease-out both; }
@keyframes studio-curtain-left { from { transform: translateX(0) scaleX(1); } to { transform: translateX(-103%) scaleX(.75); opacity: 0; } }
@keyframes studio-curtain-right { from { transform: translateX(0) scaleX(1); } to { transform: translateX(103%) scaleX(.75); opacity: 0; } }
@keyframes studio-seam { from { opacity: .35; } to { opacity: 0; } }

/* Four paper folds lift from an envelope; the text itself remains in place. */
.opening-envelope { perspective: 55rem; }
.opening-fold { position: absolute; inset: 0; background: var(--paper); opacity: .92; backface-visibility: hidden; }
.opening-fold-left { clip-path: polygon(0 0, 57% 50%, 0 100%); transform-origin: left center; background: color-mix(in srgb, var(--paper) 94%, var(--accent)); animation: studio-fold-left 1.7s .25s ease-in-out both; }
.opening-fold-right { clip-path: polygon(100% 0, 43% 50%, 100% 100%); transform-origin: right center; background: color-mix(in srgb, var(--paper) 91%, var(--accent)); animation: studio-fold-right 1.7s .25s ease-in-out both; }
.opening-fold-bottom { clip-path: polygon(0 100%, 50% 42%, 100% 100%); transform-origin: center bottom; animation: studio-fold-bottom 1.6s .4s ease-in-out both; }
.opening-fold-top { clip-path: polygon(0 0, 50% 57%, 100% 0); transform-origin: center top; background: color-mix(in srgb, var(--paper) 96%, var(--accent)); animation: studio-fold-top 1.65s ease-in-out both; }
@keyframes studio-fold-left { to { transform: rotateY(-145deg); opacity: 0; } }
@keyframes studio-fold-right { to { transform: rotateY(145deg); opacity: 0; } }
@keyframes studio-fold-bottom { to { transform: rotateX(-145deg); opacity: 0; } }
@keyframes studio-fold-top { to { transform: rotateX(150deg); opacity: 0; } }

/* A widening circular aperture, with a fine edge rather than a full-screen gate. */
.opening-ring { position: absolute; left: 50%; top: 50%; width: 1rem; height: 1rem; border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 50%; box-shadow: 0 0 0 70rem color-mix(in srgb, var(--paper) 90%, transparent); transform: translate(-50%,-50%); animation: studio-iris 2.1s cubic-bezier(.2,.65,.3,1) both; }
@keyframes studio-iris { 0% { width: 1rem; height: 1rem; opacity: .95; } 85% { opacity: .75; } 100% { width: 120rem; height: 120rem; opacity: 0; } }

/* Six calm columns leave in sequence, once. Last column ends at 2.1 seconds. */
.opening-blade { position: absolute; top: 0; bottom: 0; left: calc(var(--blade) * 100% / 6); width: calc(100% / 6 + 1px); background: linear-gradient(90deg, var(--paper), color-mix(in srgb, var(--paper) 93%, var(--accent))); opacity: .9; transform-origin: top; animation: studio-shutter 1.55s calc(var(--blade) * .11s) cubic-bezier(.25,.65,.3,1) both; }
@keyframes studio-shutter { 0% { transform: scaleY(1); } 100% { transform: scaleY(0); opacity: 0; } }

/* A single continuous drawn frame is quiet enough for a memorial cover. */
.opening-frame { position: absolute; inset: 8% 7%; width: 86%; height: 84%; overflow: visible; }
.opening-frame rect { fill: none; stroke: var(--accent); stroke-width: .8; vector-effect: non-scaling-stroke; stroke-dasharray: 1; stroke-dashoffset: 1; opacity: .6; animation: studio-trace 2.2s ease-out both; }
@keyframes studio-trace { 0% { stroke-dashoffset: 1; opacity: .35; } 65% { stroke-dashoffset: 0; opacity: .6; } 100% { stroke-dashoffset: 0; opacity: 0; } }
.doc[data-opening="trace"] #sec-cover :is(.cover-names, .obit-name) { animation: studio-trace-name 1.9s ease-out both; }
@keyframes studio-trace-name { from { opacity: .35; letter-spacing: .12em; } to { opacity: 1; letter-spacing: inherit; } }

/* A stop request always finishes an opening; it never freezes over the content. */
.doc.opening-reset .opening-layer, .doc.opening-reset .opening-layer *, .doc.opening-reset[data-opening] #sec-cover :is(.cover-names, .obit-name) { animation: none !important; }
.doc.opening-finished .opening-layer, .doc.is-paused .opening-layer, .doc.is-offscreen .opening-layer { animation: none !important; opacity: 0 !important; visibility: hidden !important; }
.doc.opening-finished .opening-layer *, .doc.is-paused .opening-layer *, .doc.is-offscreen .opening-layer * { animation: none !important; }
.doc.opening-finished[data-opening]:not([data-opening="none"]) #sec-cover :is(.cover-names, .obit-name) { animation: none !important; opacity: 1; transform: none; }

/* New sprites use independent trajectories. Existing twelve effects retain their CSS. */
.fx-ribbons .particle { width: 3.2rem; height: 2.2rem; background-image: url('/assets/generated/decor-ribbon-wave4.webp'); animation: studio-ribbon-drift 24s linear infinite; animation-delay: calc(var(--i) * -2.7s); left: calc(3% + var(--i) * 11.5%); }
.fx-ribbons .particle:nth-child(2n) { width: 2.4rem; height: 1.7rem; animation-duration: 29s; }
@keyframes studio-ribbon-drift { 0% { opacity: 0; transform: translate3d(-1rem,-2rem,0) rotate(-30deg); } 12%, 75% { opacity: .5; } 50% { transform: translate3d(1.8rem,23rem,0) rotate(75deg); } 100% { opacity: 0; transform: translate3d(-1rem,52rem,0) rotate(170deg); } }
.fx-butterflies .particle { top: 108%; left: calc(4% + var(--i) * 17%); width: 3.4rem; height: 2.6rem; background-image: url('/assets/generated/decor-butterfly-wave4.webp'); animation: studio-butterfly-drift 25s ease-in-out infinite; animation-delay: calc(var(--i) * -4.3s); }
.fx-butterflies .particle:nth-child(2n) { width: 2.5rem; height: 2rem; animation-duration: 31s; }
@keyframes studio-butterfly-drift { 0% { opacity: 0; transform: translate3d(0,0,0) rotate(-12deg) scaleX(.8); } 15%, 70% { opacity: .5; } 33% { transform: translate3d(2rem,-18rem,0) rotate(8deg) scaleX(1); } 66% { transform: translate3d(-1.5rem,-35rem,0) rotate(-9deg) scaleX(.78); } 100% { opacity: 0; transform: translate3d(1rem,-53rem,0) rotate(12deg) scaleX(1); } }
.fx-feathers .particle { left: calc(2% + var(--i) * 15.5%); width: 3.1rem; height: 2.4rem; background-image: url('/assets/generated/decor-feather-wave4.webp'); animation: studio-feather-drift 38s linear infinite; animation-delay: calc(var(--i) * -5.7s); }
.fx-feathers .particle:nth-child(2n) { width: 2.5rem; height: 2rem; animation-duration: 44s; }
@keyframes studio-feather-drift { 0% { opacity: 0; transform: translate3d(0,-2rem,0) rotate(-18deg); } 15%, 75% { opacity: .35; } 50% { transform: translate3d(2rem,24rem,0) rotate(25deg); } 100% { opacity: 0; transform: translate3d(-1rem,51rem,0) rotate(-12deg); } }
.doc-funeral .fx-feathers .particle { animation-duration: 46s; }
.doc-funeral .fx-feathers .particle:nth-child(2n) { animation-duration: 53s; }
.fx-rain .particle { left: calc(2% + var(--i) * 8.7%); width: 1px; height: 1.8rem; background: linear-gradient(transparent, color-mix(in srgb, var(--accent) 32%, transparent), transparent); animation: studio-rain 8s linear infinite; animation-delay: calc(var(--i) * -.73s); }
.fx-rain .particle:nth-child(2n) { width: 1px; height: 1.3rem; animation-duration: 10s; }
@keyframes studio-rain { 0% { opacity: 0; transform: translate3d(0,-2rem,0) rotate(8deg); } 15%, 80% { opacity: .24; } 100% { opacity: 0; transform: translate3d(-4rem,53rem,0) rotate(8deg); } }
.fx-bokeh { z-index: 0; }
.fx-bokeh .particle { top: calc(5% + var(--i) * 14%); left: calc(-8% + var(--i) * 18%); width: 5.8rem; height: 5.8rem; border-radius: 50%; background: radial-gradient(circle, color-mix(in srgb, var(--accent) 22%, #fff) 0%, transparent 68%); filter: blur(1rem); animation: studio-bokeh 24s ease-in-out infinite alternate; animation-delay: calc(var(--i) * -3.7s); }
.fx-bokeh .particle:nth-child(2n) { width: 8rem; height: 8rem; animation-duration: 30s; }
@keyframes studio-bokeh { 0% { opacity: .06; transform: translate3d(-1rem,1rem,0) scale(.8); } 100% { opacity: .17; transform: translate3d(1.5rem,-2rem,0) scale(1.12); } }
.doc-funeral .fx-bokeh .particle { opacity: .1; }

.sample-effects { display: flex; align-items: center; flex-wrap: wrap; gap: .2rem .55rem; border-radius: .65rem; padding: .35rem .55rem; }
.sample-effects label { display: grid; gap: 0; }
.sample-effects select { max-width: 7.6rem; min-height: 2.1rem; }
.sample-effects button { min-height: 44px; border: 0; border-left: 1px solid var(--line); padding: .3rem .25rem .3rem .6rem; background: transparent; color: var(--ink); font: inherit; cursor: pointer; }
.sample-effects :is(button, select):focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .opening-layer { display: none !important; animation: none !important; }
  .doc[data-opening] #sec-cover :is(.cover-names, .obit-name) { animation: none !important; opacity: 1 !important; transform: none !important; }
  .sample-effects [data-opening-replay] { display: none; }
}
@media (forced-colors: active) { .opening-layer { display: none !important; } }
