/* Site-wide polish: page continuity, browser surfaces, touch feedback, and the home hero's opening reveal.
   On the home page this file is merged into the deferred home shell; the view-transition and hero-wipe rules
   are duplicated in src/styles/home-first-screen.css so they apply at first paint (the custom cross-fade timings stay
   here only). Keep both in sync. */

/* Page-to-page continuity: a short cross-fade instead of a hard cut. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root) { animation: 160ms cubic-bezier(.4, 0, 1, 1) both polish-fade-out; }
  ::view-transition-new(root) { animation: 320ms cubic-bezier(.16, 1, .3, 1) both polish-fade-in; }
}
@keyframes polish-fade-out { to { opacity: 0; } }
@keyframes polish-fade-in { from { opacity: 0; translate: 0 8px; } }

/* Browser surfaces carry the brand's navy and cream. */
::selection { background: #123349; color: #fffaf0; }
html { scrollbar-color: #496171 transparent; }
:where(a, button, summary, select, [tabindex]):focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

/* Small links keep their look but get a 44px tap target. */
:where(.portfolio-contact-link, [data-privacy-link] a) { position: relative; }
:where(.portfolio-contact-link, [data-privacy-link] a)::before { content: ""; position: absolute; inset: -6px -2px; }

/* Press feedback: controls acknowledge the tap. `scale` composes with any motion transform. */
:where(.desktop-button, .local-nav, .download-cv, .work-link, .portfolio-contact-link, .motion-toggle):active { scale: .97; }

/* Home hero: the five keywords wipe in once, in reading order, like ink across a page. Scoped to the layers
   painted first (server opening on desktop, word stage on mobile) so the later desktop layout does not replay it. */
@media (prefers-reduced-motion: no-preference) {
  :is(.opening, .mobile-wordstage) .about-keyword { animation: polish-ink-wipe 720ms cubic-bezier(.16, 1, .3, 1) both; }
  :is(.opening, .mobile-wordstage) .keyword-1 { animation-delay: 90ms; }
  :is(.opening, .mobile-wordstage) .keyword-2 { animation-delay: 180ms; }
  :is(.opening, .mobile-wordstage) .keyword-3 { animation-delay: 270ms; }
  :is(.opening, .mobile-wordstage) .keyword-4 { animation-delay: 360ms; }
}
@keyframes polish-ink-wipe { from { clip-path: inset(-10% 100% -10% 0); } to { clip-path: inset(-10% -2% -10% 0); } }

/* Career stats use lining figures so the count-up does not jitter. */
dd { font-variant-numeric: tabular-nums; }

/* Chapter transitions (desktop): each chapter band reveals the way its medium would, tied to scroll position.
   Fill is `backwards` only, so after the reveal no clip or mask remains and nothing that overflows the band is cut.
   Browsers without scroll-driven animations, reduced motion and paused motion all get the static bands. */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) and (min-width: 761px) {
    #chun-five-stops .desktop-chapter .desktop-hero {
      animation: 1s cubic-bezier(.3, .7, .4, 1) backwards;
      animation-timeline: view();
      animation-range: entry 0% entry 90%;
    }
    /* Video: no band reveal; the opening's own cloud band already joins this chapter. */
    #chun-five-stops [data-discipline="video"] .desktop-hero { animation: none; }
    /* Publication: a page rises with a curved paper edge that flattens as it lands. */
    #chun-five-stops [data-discipline="publication"] .desktop-hero { animation-name: chapter-page; }
    /* Brand: colour blooms like ink from the "Up next" link above it. */
    #chun-five-stops [data-discipline="brand"] .desktop-hero { animation-name: chapter-ink; }
    /* Digital: the band scans in from the top in eight hard steps, like a screen refreshing. */
    #chun-five-stops [data-discipline="digital"] .desktop-hero { animation-name: chapter-signal; animation-timing-function: steps(8, end); }
    /* Copywriting: one slanted pen stroke sweeps left to right. */
    #chun-five-stops [data-discipline="copy"] .desktop-hero { animation-name: chapter-stroke; }
    /* Creative writing: the book opens from its spine. */
    #chun-five-stops [data-discipline="creative"] .desktop-hero { animation-name: chapter-book; }
    #chun-five-stops[data-ambient="paused"] .desktop-chapter .desktop-hero { animation: none; }
  }
}
@keyframes chapter-page { from { clip-path: ellipse(70% 0% at 50% 100%); } to { clip-path: ellipse(160% 150% at 50% 100%); } }
@keyframes chapter-ink { from { clip-path: circle(0% at 8% 0%); } to { clip-path: circle(140% at 8% 0%); } }
@keyframes chapter-signal { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0); } }
@keyframes chapter-stroke { from { clip-path: polygon(0 0, 0 0, -14% 100%, 0 100%); } to { clip-path: polygon(0 0, 114% 0, 100% 100%, 0 100%); } }
@keyframes chapter-book { from { clip-path: inset(0 50% 0 50%); } to { clip-path: inset(0); } }

/* Chapter seams (built by site-polish.js on desktop). Later seams replace the straight edge between chapters with a
   20px edge shaped like the incoming chapter's medium, filled with that band's own top colour so it reads as part of
   the band. 20px clears the previous chapter's "Up next" link (25-45px above the seam at 1280px). */
#chun-five-stops .chapter-sky-layer { position: relative; z-index: 4; height: 0; pointer-events: none; }
#chun-five-stops .chapter-sky { position: absolute; left: 0; width: 100%; pointer-events: none; }
#chun-five-stops .chapter-edge { margin-top: -20px; height: 22px; background: var(--band, transparent); -webkit-mask-repeat: repeat-x; mask-repeat: repeat-x; -webkit-mask-position: 0 100%; mask-position: 0 100%; transform-origin: 50% 100%; }
#chun-five-stops .chapter-edge[data-discipline="publication"] { -webkit-mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20240%2024%27%20%3E%3Cpath%20d%3D%27M0%2024V12C40%204%2080%204%20120%2012S200%2020%20240%2012V24Z%27%2F%3E%3C%2Fsvg%3E"); mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20240%2024%27%20%3E%3Cpath%20d%3D%27M0%2024V12C40%204%2080%204%20120%2012S200%2020%20240%2012V24Z%27%2F%3E%3C%2Fsvg%3E"); -webkit-mask-size: 240px 100%; mask-size: 240px 100%; }
#chun-five-stops .chapter-edge[data-discipline="brand"] { -webkit-mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20180%2024%27%20%3E%3Crect%20y%3D%2716%27%20width%3D%27180%27%20height%3D%278%27%2F%3E%3Ccircle%20cx%3D%2720%27%20cy%3D%2716%27%20r%3D%2710%27%2F%3E%3Ccircle%20cx%3D%2758%27%20cy%3D%2718%27%20r%3D%277%27%2F%3E%3Ccircle%20cx%3D%2796%27%20cy%3D%2713%27%20r%3D%2711%27%2F%3E%3Ccircle%20cx%3D%27138%27%20cy%3D%2717%27%20r%3D%278%27%2F%3E%3Ccircle%20cx%3D%27168%27%20cy%3D%2715%27%20r%3D%279%27%2F%3E%3C%2Fsvg%3E"); mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20180%2024%27%20%3E%3Crect%20y%3D%2716%27%20width%3D%27180%27%20height%3D%278%27%2F%3E%3Ccircle%20cx%3D%2720%27%20cy%3D%2716%27%20r%3D%2710%27%2F%3E%3Ccircle%20cx%3D%2758%27%20cy%3D%2718%27%20r%3D%277%27%2F%3E%3Ccircle%20cx%3D%2796%27%20cy%3D%2713%27%20r%3D%2711%27%2F%3E%3Ccircle%20cx%3D%27138%27%20cy%3D%2717%27%20r%3D%278%27%2F%3E%3Ccircle%20cx%3D%27168%27%20cy%3D%2715%27%20r%3D%279%27%2F%3E%3C%2Fsvg%3E"); -webkit-mask-size: 180px 100%; mask-size: 180px 100%; }
#chun-five-stops .chapter-edge[data-discipline="digital"] { -webkit-mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2064%2024%27%20%3E%3Cpath%20d%3D%27M0%2024V16H16V8H32V16H48V12H64V24Z%27%2F%3E%3C%2Fsvg%3E"); mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2064%2024%27%20%3E%3Cpath%20d%3D%27M0%2024V16H16V8H32V16H48V12H64V24Z%27%2F%3E%3C%2Fsvg%3E"); -webkit-mask-size: 64px 100%; mask-size: 64px 100%; }
#chun-five-stops .chapter-edge[data-discipline="copy"] { -webkit-mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20120%2024%27%20%3E%3Cpath%20d%3D%27M0%2024V16L40%2010L44%2014L84%206L88%2012L120%2016V24Z%27%2F%3E%3C%2Fsvg%3E"); mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20120%2024%27%20%3E%3Cpath%20d%3D%27M0%2024V16L40%2010L44%2014L84%206L88%2012L120%2016V24Z%27%2F%3E%3C%2Fsvg%3E"); -webkit-mask-size: 120px 100%; mask-size: 120px 100%; }
#chun-five-stops .chapter-edge[data-discipline="creative"] { -webkit-mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%201000%2024%27%20preserveAspectRatio%3D%27none%27%3E%3Cpath%20d%3D%27M0%2024V18Q250%202%20500%2016Q750%202%201000%2018V24Z%27%2F%3E%3C%2Fsvg%3E"); mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%201000%2024%27%20preserveAspectRatio%3D%27none%27%3E%3Cpath%20d%3D%27M0%2024V18Q250%202%20500%2016Q750%202%201000%2018V24Z%27%2F%3E%3C%2Fsvg%3E"); -webkit-mask-size: 100% 100%; mask-size: 100% 100%; }
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* The edge follows its own band's reveal: it grows over the last quarter of the band's entry. */
    #chun-five-stops { timeline-scope: --band-publication, --band-brand, --band-digital, --band-copy, --band-creative; }
    #chun-five-stops [data-discipline="publication"] .desktop-hero { view-timeline: --band-publication block; }
    #chun-five-stops .chapter-edge[data-discipline="publication"] { animation-timeline: --band-publication; }
    #chun-five-stops [data-discipline="brand"] .desktop-hero { view-timeline: --band-brand block; }
    #chun-five-stops .chapter-edge[data-discipline="brand"] { animation-timeline: --band-brand; }
    #chun-five-stops [data-discipline="digital"] .desktop-hero { view-timeline: --band-digital block; }
    #chun-five-stops .chapter-edge[data-discipline="digital"] { animation-timeline: --band-digital; }
    #chun-five-stops [data-discipline="copy"] .desktop-hero { view-timeline: --band-copy block; }
    #chun-five-stops .chapter-edge[data-discipline="copy"] { animation-timeline: --band-copy; }
    #chun-five-stops [data-discipline="creative"] .desktop-hero { view-timeline: --band-creative block; }
    #chun-five-stops .chapter-edge[data-discipline="creative"] { animation-timeline: --band-creative; }
    #chun-five-stops .chapter-edge { animation-name: edge-grow; animation-duration: 1s; animation-timing-function: linear; animation-fill-mode: both; animation-range: entry 70% entry 100%; }
    #chun-five-stops[data-ambient="paused"] .chapter-edge { animation: none; }
  }
}
@keyframes edge-grow { from { scale: 1 0; } to { scale: 1 1; } }

/* Featured work (desktop): the timed overlay reveals (.story-mark) felt abrupt, so they are hidden and the image
   frame instead floats at its own scroll speed and settles in as it enters. The image keeps its natural ratio;
   only the frame moves, nothing is cropped. */
@media (min-width: 761px) { #chun-five-stops .story-mark { display: none; } }
/* Editorial & Publication: Chun stands between the text and the cover. */
@media (min-width: 761px) {
  #chun-five-stops[data-desktop="flow"] :is([data-discipline="publication"], [data-discipline="digital"]) .desktop-project-grid:has(> .desktop-return-art) { grid-template-columns: minmax(0, 1.4fr) minmax(130px, .55fr) minmax(0, 1.3fr); }
  #chun-five-stops[data-desktop="flow"] :is([data-discipline="publication"], [data-discipline="digital"]) .desktop-project-grid > .desktop-project-copy { grid-area: 1 / 1; }
  #chun-five-stops[data-desktop="flow"] :is([data-discipline="publication"], [data-discipline="digital"]) .desktop-project-grid > .desktop-return-art { grid-area: 1 / 2; }
  #chun-five-stops[data-desktop="flow"] :is([data-discipline="publication"], [data-discipline="digital"]) .desktop-project-grid > .desktop-project-visual { grid-area: 1 / 3; }
}
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) and (min-width: 761px) {
    #chun-five-stops .desktop-project-visual { animation: work-float linear both; animation-timeline: view(); animation-range: cover 0% cover 100%; }
    #chun-five-stops[data-ambient="paused"] .desktop-project-visual { animation: none; }
  }
}
@keyframes work-float { 0% { translate: 0 64px; opacity: 0; scale: .97; } 28% { opacity: 1; scale: 1; } 100% { translate: 0 -48px; } }


/* Traveller (built by site-polish.js on desktop): a full-size stand-in for Chun between sections. Width, height
   and transform are set per frame from the two real characters' live boxes. It lives inside the page root so it
   can pass behind the opening's cloud band. Holes hide where he is cut when he drops through one. */
.traveller, .traveller-hole, .traveller-underlay { position: fixed; left: 0; top: 0; pointer-events: none; opacity: 0; }
.traveller { z-index: 20; will-change: transform; transform-origin: 50% 100%; filter: drop-shadow(0 14px 18px rgb(18 51 73 / .22)); }
.traveller img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; }
/* The brand chapter's rope continues above the image; carried with him as one piece while he swings. */
.traveller-rope { position: absolute; inset: 0; display: none; width: 100%; height: 100%; overflow: visible; }
.traveller.has-rope .traveller-rope { display: block; }
.traveller-twin { z-index: 5; }
.traveller-underlay { z-index: 1; overflow: hidden; box-sizing: border-box; border-bottom: 3px solid transparent; }
.traveller-hole { z-index: 19; border-radius: 50%; background: radial-gradient(closest-side, #0b1d2b 0 62%, #17344a 80%, rgb(23 52 74 / 0) 100%); box-shadow: 0 0 0 3px rgb(255 249 238 / .55); }
.traveller-hole-front { z-index: 21; box-shadow: none; }
.traveller.is-on, .traveller-hole.is-on, .traveller-underlay.is-on { opacity: 1; }
#chun-five-stops .traveller-carried { opacity: 0 !important; }
#chun-five-stops .traveller-rope-carried .desktop-brand-rope { opacity: 0 !important; }
/* While he passes behind the opening clouds, the band's flat sky (its backdrop and the SVG sky rect) and its dark
   underside (the SVG path, redrawn behind him by .traveller-underlay) are cleared, so only the cloud artwork hides him. */
#chun-five-stops .declaration-cloud-band.traveller-see-through { background: none !important; }
#chun-five-stops .declaration-cloud-band.traveller-see-through::after { visibility: hidden; }
#chun-five-stops .declaration-cloud-band.traveller-see-through svg > rect, #chun-five-stops .declaration-cloud-band.traveller-see-through svg > path { visibility: hidden; }
/* Behind the 匠 text: the stand-in is drawn inside the project card, under its copy, which frosts over like glass. */
.traveller-inner { position: absolute; left: 0; top: 0; z-index: 1; pointer-events: none; opacity: 0; will-change: transform; filter: drop-shadow(0 14px 18px rgb(18 51 73 / .22)); }
.traveller-inner.is-on { opacity: 1; }
/* The empty armchair that waits for him in Editorial & Publication, under the holes and under him. */
.traveller-prop { position: fixed; left: 0; top: 0; z-index: 18; pointer-events: none; opacity: 0; background: url(/motion-assets/traveller/chair.webp) center / 100% 100% no-repeat; }
.traveller-prop.is-on { opacity: 1; }
/* Sits down and rocks back and forth a few times, dying away. Runs on the stand-in and the real image together. */
@keyframes traveller-rock {
  0%, 100% { rotate: 0deg; }
  14% { rotate: -3.2deg; }
  34% { rotate: 2.6deg; }
  54% { rotate: -1.8deg; }
  76% { rotate: 1deg; }
}
#chun-five-stops .traveller img.traveller-rock, #chun-five-stops[data-desktop="flow"]:not([data-ambient="paused"]) .desktop-outbound.traveller-rock { animation: traveller-rock 3s ease-in-out 1; transform-origin: 50% 100%; }
.traveller-inner img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; }
#chun-five-stops .desktop-project-copy.traveller-frost { position: relative; z-index: 2; }
#chun-five-stops .desktop-project-copy.traveller-frost::before { content: ''; position: absolute; inset: -18px -22px; z-index: -1; border-radius: 16px; opacity: var(--frost, 0); background: rgb(255 253 245 / .42); -webkit-backdrop-filter: blur(5px) saturate(1.1); backdrop-filter: blur(5px) saturate(1.1); box-shadow: inset 0 0 0 1px rgb(255 255 255 / .7), 0 10px 30px rgb(18 51 73 / .08); }
@media (min-width: 761px) {
  /* The 匠 and Social Media text and character sit further right, so he shows in the clear margin as he flies off past the glass. */
  #chun-five-stops[data-desktop="flow"] :is([data-discipline="publication"], [data-discipline="digital"]) .desktop-project-grid:has(> .desktop-return-art) > :is(.desktop-project-copy, .desktop-return-art) { position: relative; left: clamp(24px, 3.2vw, 64px); }
  /* He walks out from behind the cover, drawn in the same card. */
  #chun-five-stops[data-desktop="flow"] :is([data-discipline="publication"], [data-discipline="digital"]) .desktop-project-grid:has(> .desktop-return-art) > .desktop-project-visual { position: relative; z-index: 2; }
}
/* Video Storytelling: he stays in the landing pose the traveller brought him down in. */
#chun-five-stops[data-desktop="flow"]:not([data-ambient="paused"]) [data-discipline="video"] .desktop-outbound.traveller-landed { content: url(/motion-assets/traveller/chun-superland.webp); aspect-ratio: 2 / 3; object-fit: contain; object-position: 50% 100%; scale: 1.2; transform-origin: 50% 100%; }
/* Copywriting: he stays up on his beanbag like a magic carpet, rocking gently. */
@keyframes traveller-hover {
  0%, 100% { translate: 0 calc(var(--hover-lift, 17px) * -1 - 7px); rotate: -1.4deg; }
  50% { translate: 0 calc(var(--hover-lift, 17px) * -1 + 7px); rotate: 1.4deg; }
}
@media (min-width: 761px) and (prefers-reduced-motion: no-preference) {
  #chun-five-stops[data-desktop="flow"]:not([data-ambient="paused"]) [data-discipline="copy"] .desktop-outbound { animation: traveller-hover 5s ease-in-out infinite; transform-origin: 50% 85%; }
}
@media (max-width: 760px), (prefers-reduced-motion: reduce) { .traveller, .traveller-hole, .traveller-underlay, .traveller-inner, .traveller-prop { display: none; } }
