/* ═══════════════════════════════════════════
   HATLEY CASTLE — V5 OPTIMIZED
   
   Identical visuals to V5.
   GPU-friendly compositing, CSS containment,
   content-visibility for off-screen sections.
   ═══════════════════════════════════════════ */

:root {
    --dark: #1e1b18;
    --paper: #f5f0e8;
    --sage-wash: #eef2eb;
    --pink-wash: #f5eeec;
    --terra-wash: #f3ede6;
    --ink: #2a2420;
    --ink-muted: rgba(42, 36, 32, .38);
    --ink-caption: rgba(42, 36, 32, .58);
    --cream: #f0e9dc;
    --cream-muted: rgba(240, 233, 220, .38);
    --cream-cap: rgba(240, 233, 220, .55);
    --sage: #7a8b6e;
    --sage-deep: #5d7050;
    --sage-light: #8fa07f;
    --gold: #b89e6f;
    --pink: #c4928a;
    --blush: #d4b0a8;
    --lavender: #9e8bb0;
    --mauve: #b8a0c4;
    --display: 'Cormorant Garamond', Georgia, serif;
    --body: 'EB Garamond', Georgia, serif;
    --script: 'Pinyon Script', cursive;
    --pad: clamp(1.25rem, 5vw, 3.5rem);
    --gap: clamp(3rem, 9vh, 6rem);
    --ease: cubic-bezier(.16, 1, .3, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; overflow-x: hidden; }
body { background: var(--dark); color: var(--ink); font: 400 clamp(.88rem, 2vw, .98rem)/1.85 var(--body); overflow-x: hidden; }
img { display: block; max-width: 100%; }

/* ═══ GRAIN — GPU-isolated layer ═══
   Key change: transform: translateZ(0) forces own compositor layer.
   The blend still happens but the grain texture itself never repaints. */
.grain {
    position: fixed; inset: 0; z-index: 9000;
    pointer-events: none; opacity: .04;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
    background-size: 150px;
    mix-blend-mode: overlay;
    /* PERF: force own compositor layer — no repaint on scroll */
    transform: translateZ(0);
    will-change: transform;
    contain: strict;
}

/* ═══ PRELOADER ═══ */
#preloader { position: fixed; inset: 0; z-index: 9999; background: var(--dark); display: flex; align-items: center; justify-content: center; contain: layout style paint; }
.pre-inner { text-align: center; color: var(--cream); }
.pre-wreath { width: clamp(70px, 18vw, 95px); height: auto; margin: 0 auto 1.25rem; opacity: 0; }
.wr-ring { stroke: var(--sage); fill: none; stroke-dasharray: 300; stroke-dashoffset: 300; }
.wr-leaf { stroke: var(--sage); fill: rgba(122,139,110,.15); stroke-dasharray: 60; stroke-dashoffset: 60; stroke-width: .5; }
.wr-bud { fill: var(--sage); opacity: 0; }
.wr-star { fill: var(--sage-light); opacity: 0; }
.pre-names { display: flex; align-items: baseline; justify-content: center; gap: .4em; opacity: 0; transform: translateY(12px); }
.pre-names .pn { font: 300 clamp(1.8rem, 7vw, 3.5rem)/1.1 var(--display); letter-spacing: .05em; }
.pre-names .pa { font: normal clamp(1rem, 3vw, 1.6rem) var(--script); color: var(--sage-light); margin: 0 .1em; }
.pre-where { font-size: .55rem; letter-spacing: .3em; text-transform: uppercase; color: var(--cream-muted); margin-top: .75rem; opacity: 0; }

/* ═══ HERO ═══ */
.hero { position: relative; height: 100svh; overflow: hidden; color: var(--cream); contain: layout style; }
.hero-img-box { position: absolute; inset: 0; }
.hero-img {
    width: 100%; height: 100%; object-fit: cover; object-position: center center;
    animation: heroSettle 11s var(--ease) forwards;
    /* PERF: GPU layer for the animation */
    will-change: transform;
}
@keyframes heroSettle { from { transform: scale(1.05) translateZ(0); } to { transform: scale(1) translateZ(0); } }
.hero-shade { position: absolute; inset: 0; z-index: 1; background: linear-gradient(to top, var(--dark) 0%, rgba(30,27,24,.88) 14%, rgba(30,27,24,.3) 40%, rgba(30,27,24,.18) 100%); }
.hero-text { position: absolute; bottom: 0; left: 0; right: 0; z-index: 2; padding: 0 var(--pad) clamp(2.5rem, 7vh, 5rem); text-align: center; opacity: 0; transform: translateY(20px); }
.hero-kicker { font: 300 .55rem/1 var(--body); letter-spacing: .5em; text-transform: uppercase; color: var(--cream-muted); margin-bottom: .6rem; }
.hero-names { font: 300 clamp(2.6rem, 11vw, 6.5rem)/.9 var(--display); letter-spacing: .04em; }
.hero-date { font: italic 400 clamp(.65rem, 1.8vw, .78rem)/1 var(--body); color: var(--cream-muted); letter-spacing: .08em; margin-top: .9rem; }
.script-amp { font: normal clamp(1.2rem, 4.5vw, 2.8rem)/.9 var(--script); color: var(--sage-light); margin: 0 .12em; vertical-align: .08em; }

/* ═══ VINE ═══ */
main { position: relative; }
.vine-thread {
    position: absolute; left: 5px; top: 0; width: 20px; height: 100%; z-index: 5; pointer-events: none;
    /* PERF: own layer for scrub animation */
    transform: translateZ(0);
    will-change: auto; /* JS will toggle to stroke-dashoffset during scrub */
}
.vine-stem { stroke: var(--sage); fill: none; stroke-dasharray: 6000; stroke-dashoffset: 6000; }
.vine-leaf { stroke: var(--sage); fill: rgba(122,139,110,.15); stroke-dasharray: 50; stroke-dashoffset: 50; }
.vine-bud { fill: var(--sage); opacity: 0; }

/* ═══ SECTIONS — with CSS containment ═══ */
.sect {
    position: relative; z-index: 1; padding-bottom: var(--gap); overflow: hidden;
    /* PERF: contain layout/style/paint so browser doesn't recalc the world */
    contain: layout style paint;
}
.sect--paper { background: var(--paper); }
.sect--sage { background: var(--sage-wash); }
.sect--pink { background: var(--pink-wash); }
.sect--terra { background: var(--terra-wash); }
.sect--dark { background: var(--dark); color: var(--cream); overflow: hidden; contain: layout style paint; }
.diagonal-top { clip-path: polygon(0 clamp(14px, 2.5vw, 26px), 100% 0, 100% 100%, 0 100%); margin-top: calc(-1 * clamp(14px, 2.5vw, 26px)); padding-top: calc(clamp(14px, 2.5vw, 26px) + 1rem); }

/* ═══ BRACKET QUOTES ═══ */
.epi { padding: var(--gap) var(--pad); display: flex; flex-direction: column; align-items: center; }
.bracket-quote { display: flex; align-items: stretch; gap: .75rem; }
.bracket { width: 10px; flex-shrink: 0; color: var(--sage); }
.bracket-line { stroke: currentColor; fill: none; stroke-dasharray: 150; stroke-dashoffset: 150; }
.bracket-quote blockquote { font: italic 400 clamp(.92rem, 2.6vw, 1.08rem)/2 var(--body); color: var(--ink-caption); text-align: center; opacity: 0; transform: translateY(12px); }

/* ═══ CHAPTERS ═══ */
.chapter { padding: 0; }
.ch-head { display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: var(--gap) var(--pad) clamp(1.5rem, 4vh, 2.5rem); opacity: 0; }
.ch-head--light { color: var(--cream); }
.ch-orn { width: clamp(160px, 55vw, 240px); height: auto; color: var(--sage); }
.ch-orn--light { color: var(--sage-light); }
.orn-l { stroke: currentColor; fill: none; }
.orn-lf { stroke: currentColor; fill: rgba(122,139,110,.1); }
.orn-ring { stroke: currentColor; fill: none; }
.orn-num { font-family: var(--body); fill: currentColor; letter-spacing: .05em; }
.ch-title { font: italic 500 clamp(1.05rem, 3vw, 1.35rem)/1 var(--display); letter-spacing: .03em; }
.chapter-note { font: italic 400 clamp(.88rem, 2.5vw, 1rem)/2 var(--body); color: var(--ink-caption); text-align: center; max-width: 30ch; margin: 1rem auto var(--gap); padding: 0 var(--pad); opacity: 0; transform: translateY(10px); }
.dark-note { font: italic 300 clamp(.9rem, 2.5vw, 1.05rem)/2 var(--display); color: var(--cream-cap); text-align: center; max-width: 34ch; margin: 0 auto 2rem; padding: 0 var(--pad); opacity: 0; transform: translateY(10px); }

/* ═══ ALBUM PHOTOS — shadow via pseudo for GPU isolation ═══ */
.album-photo {
    position: relative; opacity: 0; transform: translateY(20px);
    /* PERF: GPU layer hint — JS will set will-change before anim and remove after */
}
.album-photo img {
    width: 100%; height: auto; aspect-ratio: 3/2; object-fit: cover; border-radius: 2px;
    /* PERF: filter applied via class, removed after transition to free GPU texture */
    filter: sepia(.35) saturate(.78) brightness(1.02);
    transition: filter 2s var(--ease);
}
.album-photo img.in-view { filter: none; }
.album-photo .portrait-img { aspect-ratio: 2/3; }
.album--detail img { aspect-ratio: 1/1; }

/* PERF: shadow on pseudo-element — doesn't repaint with the image */
.album-photo::after {
    content: '';
    position: absolute; inset: 0;
    border-radius: 2px;
    box-shadow: 0 4px 20px rgba(0,0,0,.12), 0 1px 4px rgba(0,0,0,.08);
    pointer-events: none;
    z-index: 1;
}
.sect--dark .album-photo::after { box-shadow: 0 6px 30px rgba(0,0,0,.5); }

/* ARCH */
.arch img { border-radius: 999px 999px 6px 6px; }
.arch::after { border-radius: 999px 999px 6px 6px; }
.arch .mount { display: none; }

/* ARCH CROWN */
.arch-wrap { position: relative; }
.arch-crown { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); width: 80%; max-width: 240px; z-index: 3; color: var(--sage); }
.crown-line { stroke: currentColor; fill: none; stroke-dasharray: 250; stroke-dashoffset: 250; }
.crown-leaf { stroke: var(--sage); stroke-dasharray: 30; stroke-dashoffset: 30; }
.crown-bud { opacity: 0; }

/* CORNER MOUNTS */
.mount { position: absolute; width: 12px; height: 12px; border: solid var(--gold); border-width: 0; opacity: .25; z-index: 2; }
.mount.tl { top: -3px; left: -3px; border-top-width: 1px; border-left-width: 1px; }
.mount.tr { top: -3px; right: -3px; border-top-width: 1px; border-right-width: 1px; }
.mount.bl { bottom: -3px; left: -3px; border-bottom-width: 1px; border-left-width: 1px; }
.mount.br { bottom: -3px; right: -3px; border-bottom-width: 1px; border-right-width: 1px; }

/* ═══ BOTANICAL BEDS ═══ */
.botanical-bed { position: relative; }
.bed-art { position: absolute; z-index: 0; pointer-events: none; }
.botanical-bed .album-photo,
.botanical-bed .arch-wrap,
.botanical-bed .cinema-img { position: relative; z-index: 1; }

.bed--left .bed-art { left: -30px; top: -20px; width: calc(100% + 40px); height: calc(100% + 40px); }
.bed--right .bed-art { right: -30px; top: -20px; width: calc(100% + 40px); height: calc(100% + 40px); }
.bed--both .bed-art { left: -20px; top: -15px; width: calc(100% + 40px); height: calc(100% + 30px); }
.bed--br .bed-art { right: -25px; bottom: -20px; width: calc(100% + 35px); height: calc(100% + 30px); }
.bed--tr .bed-art { right: -25px; top: -20px; width: calc(100% + 35px); height: calc(100% + 30px); }
.bed--corners { position: relative; margin-bottom: var(--gap); }
.bed--corners .bed-art { position: absolute; inset: -12px; width: calc(100% + 24px); height: calc(100% + 24px); z-index: 0; }
.bed--corners .cinema-img { position: relative; z-index: 1; margin-bottom: 0; }

.bed-stem { stroke-dasharray: 500; stroke-dashoffset: 500; }
.bed-leaf { stroke-dasharray: 60; stroke-dashoffset: 60; }
.bed-tendril { stroke-dasharray: 50; stroke-dashoffset: 50; }
.bed-bud { opacity: 0; }
[data-bed="static"] .bed-art { opacity: 0; }
[data-bed="static"] .bed-stem { stroke-dashoffset: 0; }
[data-bed="static"] .bed-leaf { stroke-dashoffset: 0; }
[data-bed="static"] .bed-tendril { stroke-dashoffset: 0; }
[data-bed="static"] .bed-bud { opacity: 1; }

/* BOTANICAL DIVIDERS */
.botanical-break { display: flex; justify-content: center; padding: 1.5rem 0 0; }
.botan-div { width: clamp(80px, 35vw, 140px); height: auto; }
.bd-stem { stroke-dasharray: 150; stroke-dashoffset: 150; }
.bd-leaf { stroke-dasharray: 40; stroke-dashoffset: 40; }
.bd-bud { opacity: 0; }

/* ═══ BOKEH — paused by default, JS enables via IntersectionObserver ═══ */
.bokeh-field { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; contain: strict; }
.bokeh-orb {
    position: absolute; border-radius: 50%;
    background: radial-gradient(circle, rgba(184,158,111,.12) 0%, rgba(184,158,111,0) 70%);
    /* PERF: paused by default — only animate when section is in viewport */
    animation: bFloat linear infinite;
    animation-play-state: paused;
    /* PERF: GPU layer */
    transform: translateZ(0);
    will-change: transform, opacity;
}
.bokeh-orb.is-playing { animation-play-state: running; }
.b1 { width: 100px; height: 100px; top: 10%; left: 12%; animation-duration: 18s; }
.b2 { width: 70px; height: 70px; top: 30%; right: 15%; animation-duration: 22s; animation-delay: -5s; }
.b3 { width: 50px; height: 50px; top: 55%; left: 30%; animation-duration: 16s; animation-delay: -8s; }
.b4 { width: 80px; height: 80px; top: 75%; right: 10%; animation-duration: 20s; animation-delay: -3s; }
@keyframes bFloat {
    0%   { transform: translate3d(0,0,0) scale(1);    opacity: .25; }
    25%  { transform: translate3d(12px,-20px,0) scale(1.08); opacity: .4; }
    50%  { transform: translate3d(-8px,-40px,0) scale(.92);  opacity: .25; }
    75%  { transform: translate3d(16px,-24px,0) scale(1.04); opacity: .35; }
    100% { transform: translate3d(0,0,0) scale(1);    opacity: .25; }
}

/* ═══ SWIPE GALLERY ═══ */
.swipe-gallery { padding: 0 0 .5rem; margin-bottom: var(--gap); }
.swipe-track {
    display: flex; gap: .75rem; overflow-x: auto; overflow-y: hidden;
    scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
    padding: 1rem var(--pad) 1.5rem; scrollbar-width: none;
    /* PERF: contain scroll painting */
    contain: layout style;
}
.swipe-track::-webkit-scrollbar { display: none; }
.swipe-slide { flex: 0 0 85%; scroll-snap-align: center; transition: transform .4s var(--ease); }
.swipe-slide .album-photo { width: 100%; }
.swipe-dots { display: flex; justify-content: center; gap: 6px; padding: .6rem 0 0; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--ink-muted); transition: all .3s; cursor: pointer; }
.dot.active { background: var(--sage); transform: scale(1.3); }

.tilt-a { transform: rotate(-2.5deg); }
.tilt-b { transform: rotate(1.8deg); }
.tilt-c { transform: rotate(-1.2deg); }
.tilt-d { transform: rotate(3deg); }

/* ═══ LAYOUTS ═══ */
.spread { display: grid; gap: 1.5rem; padding: 0 var(--pad); margin-bottom: var(--gap); }
.spread .album-photo { width: 75%; max-width: 320px; }
.spread .botanical-bed { width: 75%; max-width: 320px; }
.spread-text { opacity: 0; transform: translateY(10px); }
.spread-text p { font: italic 400 clamp(.88rem, 2.2vw, .98rem)/2 var(--body); color: var(--ink-caption); max-width: 26ch; }
.spread-note { font: italic 400 clamp(.88rem, 2.2vw, .98rem)/2 var(--body); color: var(--ink-caption); text-align: center; max-width: 26ch; margin-top: 1.5rem; opacity: 0; transform: translateY(10px); }
.spread--center { display: flex; flex-direction: column; align-items: center; padding: 0 var(--pad); margin-bottom: var(--gap); }
.spread--center .album-photo { width: 65%; max-width: 320px; }
.spread--center .botanical-bed { width: 65%; max-width: 320px; }

.solo-wide { padding: 0 var(--pad); margin-bottom: var(--gap); }
.solo-wide .album-photo { width: 85%; max-width: 450px; }

.cake-moment { display: flex; flex-direction: column; align-items: center; padding: 0 var(--pad) var(--gap); }
.cake-moment .botanical-bed { width: 60%; max-width: 260px; }
.cake-moment .album-photo { width: 100%; }
.cake-note { font: italic 400 clamp(.88rem, 2.2vw, .98rem)/2 var(--body); color: var(--ink-caption); text-align: center; max-width: 26ch; margin-top: 1.5rem; opacity: 0; transform: translateY(10px); }

.ceremony-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: 0 var(--pad); margin-bottom: var(--gap); }
.ceremony-pair .album-photo { width: 100%; }

.cinema-img { width: 100%; overflow: hidden; margin-bottom: var(--gap); }
.cinema-img img {
    width: 100%; aspect-ratio: 16/9; object-fit: cover;
    filter: sepia(.35) saturate(.78) brightness(1.02);
    transition: filter 2s var(--ease);
}
.cinema-img img.in-view { filter: none; }
.cinema-img--paper { margin: 0 var(--pad) var(--gap); width: auto; }
.cinema-img--paper img { border-radius: 2px; box-shadow: 0 4px 20px rgba(0,0,0,.12); }

/* ═══ WIPE ═══ */
.wipe-wrap {
    position: relative; width: 100%; background: var(--dark);
    /* PERF: contain for pin section */
    contain: layout style;
}
.wipe-inner { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 2rem var(--pad) 3rem; }
.wipe-frame {
    position: relative; width: 100%; max-width: 700px; aspect-ratio: 3/2; overflow: hidden;
    border-radius: 2px; box-shadow: 0 6px 35px rgba(0,0,0,.5);
}
.wipe-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center center; box-shadow: none; filter: none; }
.wipe-bw { filter: grayscale(1) contrast(1.06) brightness(1.02) !important; }
.wipe-overlay {
    position: absolute; inset: 0;
    clip-path: polygon(0 0, 0 0, 0 100%, 0 100%);
    /* PERF: GPU layer for clip-path animation */
    will-change: clip-path;
}

/* ═══ CLOSING ═══ */
.closing { background: var(--dark); color: var(--cream); display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 50vh; padding: var(--gap) var(--pad) clamp(3rem, 8vh, 5rem); text-align: center; }
.close-seal { width: clamp(50px, 13vw, 70px); height: auto; color: var(--sage); opacity: 0; }
.seal-ring { stroke: currentColor; fill: none; stroke-dasharray: 250; stroke-dashoffset: 250; }
.seal-leaf { stroke: currentColor; fill: rgba(122,139,110,.15); stroke-dasharray: 50; stroke-dashoffset: 50; }
.seal-star { fill: var(--sage-light); opacity: 0; }
.close-line { font: italic 300 clamp(1.4rem, 5vw, 2.3rem)/1.35 var(--display); margin: 1.5rem 0; opacity: 0; transform: translateY(12px); }
.close-rule { width: 0; height: 1px; background: var(--sage); margin: 0 auto 1.25rem; opacity: .4; }
.close-names { font: 300 clamp(1rem, 3.5vw, 1.3rem)/1 var(--display); letter-spacing: .06em; opacity: 0; }
.close-date { font-size: .55rem; letter-spacing: .3em; text-transform: uppercase; color: var(--cream-muted); margin-top: .6rem; opacity: 0; }

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: var(--paper); }
::-webkit-scrollbar-thumb { background: rgba(122,139,110,.3); border-radius: 10px; }
::selection { background: var(--sage); color: var(--paper); }

/* ═══ DESKTOP ═══ */
@media (min-width: 768px) {
    .hero-text { text-align: left; padding-left: clamp(3rem, 7vw, 5.5rem); }
    .vine-thread { left: 12px; width: 24px; }
    .spread { grid-template-columns: 1.2fr 1fr; align-items: end; gap: 2.5rem; }
    .spread .album-photo,
    .spread .botanical-bed { width: 100%; max-width: 420px; }
    .spread-text { padding-bottom: 1.5rem; }
    .spread--right { grid-template-columns: 1fr 1.2fr; }
    .spread--right .album-photo,
    .spread--right .botanical-bed { order: 2; }
    .spread--right .spread-text { order: 1; text-align: right; }
    .spread--right .spread-text p { margin-left: auto; }
    .spread--center { flex-direction: row; justify-content: center; gap: 3rem; }
    .spread--center .album-photo,
    .spread--center .botanical-bed { width: 38%; max-width: 340px; }
    .spread-note { margin-top: 0; text-align: left; align-self: center; }
    .solo-wide .album-photo { max-width: 500px; }
    .swipe-track { overflow: visible; flex-wrap: wrap; padding: 1rem var(--pad) 1.5rem; }
    .swipe-slide { flex: 0 0 calc(50% - .375rem); scroll-snap-align: none; }
    .swipe-dots { display: none; }
    .cinema-img img { aspect-ratio: 21/9; }
    .cinema-img--paper img { aspect-ratio: 16/9; }
    .ceremony-pair { gap: 2rem; }
    .cake-moment { flex-direction: row; justify-content: center; gap: 3rem; }
    .cake-moment .botanical-bed { width: 35%; max-width: 300px; }
    .cake-note { text-align: left; margin-top: 0; align-self: center; }
    .wipe-frame { max-width: 800px; }
    .bed--left .bed-art { left: -50px; width: calc(100% + 60px); }
    .bed--right .bed-art { right: -50px; width: calc(100% + 60px); }
    .bed--both .bed-art { left: -40px; width: calc(100% + 80px); }
}

@media (min-width: 1100px) {
    .sect > .chapter, .ch-head, .spread, .swipe-gallery, .cake-moment, .ceremony-pair, .solo-wide { max-width: 1050px; margin-left: auto; margin-right: auto; }
    .cinema-img, .bed--corners { max-width: 1200px; margin-left: auto; margin-right: auto; }
    .cinema-img--paper { max-width: 900px; }
    .wipe-frame { max-width: 900px; }
    #ch-details .swipe-slide { flex: 0 0 calc(25% - .5625rem); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
