﻿/* ------------------------------------------------------------------
   Craftsmanship: a scroll-driven film of a river table being made.

   Structure (index.html → js/craft-film.js):
     .craft-heading        the only prominent text: heading + italic line
     .craft-film           tall scroll track (height set by the script)
       .craft-film-stage   sticky viewport holding the <canvas> scene,
                           the opening/closing lines, a small stage label
                           and a hairline progress bar
       .craft-film-stages  the nine stage names; visually hidden while the
                           film runs, shown as plain text without JS or
                           with reduced motion
   Colours and type come from the site tokens in base.css; brand.css keeps
   the section's forest background and heading colours.
   ------------------------------------------------------------------ */

.craft-section {
  position: relative;
  /* `hidden` would make the section the scroll container for the sticky
     stage, which then could never stick. `clip` clips without doing that. */
  overflow: hidden;
  overflow: clip;
  /* No bottom padding: the river divider is in normal flow here (see
     "the river as progress" below) and closes the section itself. */
  padding: clamp(56px, 7vw, 96px) 0 0;
  color: var(--cream);
}

/* ---------- heading ---------- */

.craft-heading {
  margin: 0 auto clamp(28px, 4vw, 48px);
  text-align: center;
}

.craft-heading h2 {
  margin: 0;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: var(--type-h2);
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.05;
  text-transform: uppercase;
  white-space: nowrap;
}

.craft-heading h2 em {
  color: var(--walnut);
  font-style: normal;
  font-weight: 500;
}

.craft-sub {
  margin: 12px auto 0;
  max-width: 36ch;
  color: rgba(255, 251, 208, 0.82);
  font-family: var(--font-accent);
  font-size: clamp(1.1rem, 1.9vw, 1.5rem);
  font-style: italic;
  font-weight: 400;
  line-height: 1.3;
}

/* ---------- the film ---------- */

.craft-film {
  position: relative;
  margin-bottom: clamp(40px, 5vw, 72px);
}

.craft-film-stage {
  position: sticky;
  top: var(--anchor-offset, 73px);
  height: calc(100vh - var(--anchor-offset, 73px));
  height: calc(100svh - var(--anchor-offset, 73px));
  overflow: hidden;
  background: var(--forest);
}

.craft-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Soft studio vignette and a little lift at the edges of the frame. */
.craft-film-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 46%, transparent 46%, rgba(4, 32, 15, 0.58) 100%),
    linear-gradient(to bottom, rgba(4, 32, 15, 0.42), transparent 16%, transparent 78%, rgba(4, 32, 15, 0.55));
}

/* Opening and closing lines */
.craft-film-quote {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(720px, calc(100% - 48px));
  margin: 0;
  transform: translate(-50%, -50%);
  color: var(--cream);
  font-family: var(--font-accent);
  font-size: clamp(1.3rem, 2.5vw, 2.2rem);
  font-style: italic;
  font-weight: 400;
  line-height: 1.28;
  text-align: center;
  text-shadow: 0 2px 28px rgba(4, 32, 15, 0.9), 0 0 2px rgba(4, 32, 15, 0.8);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.craft-film-quote em {
  color: var(--walnut);
  font-style: italic;
  font-weight: 500;
}

/* The opening line sits over light raw wood, so it gets a soft dark scrim. */
.craft-film-quote-open {
  padding: 36px 44px;
  background: radial-gradient(ellipse at center, rgba(4, 32, 15, 0.72) 30%, rgba(4, 32, 15, 0) 72%);
}

/* The closing line sits in the centre of the frame; the stage label and the
   finished table fade out underneath it (see updateChrome in craft-film.js).
   One colour throughout, last line bold. */
.craft-film-quote-close {
  line-height: 1.34;
}

.craft-film-quote-close strong {
  font-weight: 700;
}

/* Static scene (reduced motion): the table stays, so the line keeps its old
   place beneath it. */
.craft-film.is-static .craft-film-quote-close {
  top: auto;
  bottom: clamp(64px, 13vh, 132px);
  transform: translateX(-50%);
}

/* Stage label: number, name, one short cue */
.craft-film-label {
  position: absolute;
  bottom: calc(38px + clamp(20px, 5vh, 48px)); /* clear of the river */
  left: clamp(16px, 4vw, 56px);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 2px 14px;
  align-items: baseline;
  max-width: min(520px, calc(100% - 32px));
  color: var(--cream);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}

.craft-film-label.is-on {
  opacity: 1;
  transform: none;
}

.craft-film-index {
  grid-row: 1 / span 2;
  align-self: start;
  color: var(--walnut);
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 0.95;
}

.craft-film-title {
  font-family: var(--font-body);
  font-size: clamp(0.76rem, 1vw, 0.9rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.3;
  text-transform: uppercase;
}

.craft-film-cue {
  color: rgba(255, 251, 208, 0.78);
  font-family: var(--font-accent);
  font-size: clamp(0.95rem, 1.3vw, 1.15rem);
  font-style: italic;
  line-height: 1.3;
}

.craft-film-label.is-fresh .craft-film-title,
.craft-film-label.is-fresh .craft-film-cue {
  animation: craft-label-in 0.5s ease both;
}

.craft-film-label.is-fresh .craft-film-cue {
  animation-delay: 0.08s;
}

@keyframes craft-label-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.craft-film-hint {
  position: absolute;
  bottom: calc(38px + clamp(20px, 5vh, 48px));
  left: 50%;
  margin: 0;
  transform: translateX(-50%);
  color: rgba(255, 251, 208, 0.62);
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- the river as progress ----------
   The section's own river divider (brand.css) shows how far the journey has
   come. It sticks to the bottom of the viewport while the film plays, then
   settles into its usual place at the section's end. Three copies of the
   same wave sit on top of each other: a dimmed base, the full-colour river
   revealed by a clip the script widens with progress, a soft lit leading
   edge and a slow shimmer, both masked to the revealed part. */
.craft-section .river-divider {
  position: sticky;
  right: auto;
  bottom: 0;
  left: auto;
}

/* With reduced motion there is no film to ride along, so the river simply
   closes the section, fully coloured. */
.craft-section:has(.craft-film.is-static) .river-divider {
  position: static;
}

.craft-river-base {
  fill: var(--river-deep);
  opacity: 0.6;
}

.craft-river-done {
  fill: var(--river-blue);
}

.craft-river-lead {
  fill: var(--cream);
  opacity: 0.22;
}

/* The shimmer is a travelling gradient fill (animated inside the SVG), which
   is far cheaper than an animated mask. */
.craft-river-shimmer {
  fill: url(#craft-river-shimmer-grad);
  opacity: 0.16;
}

/* ---------- the stage list ---------- */

/* Plain text version: shown without JS, with reduced motion, or if the
   canvas is unavailable. Visually hidden while the film runs. */
.craft-film-stages {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  max-width: 980px;
  margin: 18px auto 0;
  padding: 0 16px;
  color: rgba(255, 251, 208, 0.82);
  counter-reset: craft-stage;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  line-height: 1.5;
  list-style: none;
  text-transform: uppercase;
}

.craft-film-stages li {
  counter-increment: craft-stage;
  flex: 0 1 290px;
}

/* The one-line description of each stage: part of the page text for
   readers and search engines; the film shows it as the label's cue. */
.craft-film-stage-cue {
  display: block;
  margin-top: 2px;
  color: rgba(255, 251, 208, 0.6);
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: none;
}

.craft-film-stages li::before {
  content: counter(craft-stage, decimal-leading-zero) " ";
  color: var(--walnut);
  font-family: var(--font-display);
  letter-spacing: 0.04em;
}

.craft-film.is-ready:not(.is-static) .craft-film-stages {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* With reduced motion there is no scroll track: the stage becomes an
   ordinary framed picture of the finished table above the stage list. */
.craft-film.is-static .craft-film-stage {
  position: static;
  width: min(1180px, calc(100% - 32px));
  height: auto;
  max-height: 72vh;
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  border-radius: 18px 10px 22px 12px;
}

.craft-film.is-static .craft-film-hint,
.craft-film.is-static .craft-film-label {
  display: none;
}

/* Without the script (or without canvas support) only the text remains:
   the closing line and the nine stage names. */
.craft-film:not(.is-ready) .craft-film-stage {
  display: none;
}

.craft-film:not(.is-ready) .craft-film-stages {
  margin-top: 0;
}

.craft-film:not(.is-ready)::before {
  content: "Nature creates the character. Craftsmanship reveals it. You make it yours.";
  display: block;
  max-width: 34ch;
  margin: 0 auto 26px;
  color: var(--cream);
  font-family: var(--font-accent);
  font-size: clamp(1.2rem, 2.2vw, 1.8rem);
  font-style: italic;
  line-height: 1.3;
  text-align: center;
}

/* ---------- responsive ---------- */

/* Tablets and phones: the label keeps the desktop arrangement (big walnut
   number, bold uppercase title beside it, italic cue beneath the title) but
   sits centred above the scene, where the portrait composition leaves room,
   over a soft forest scrim so it reads against every stage, including the
   bright close-up of the resin pour. */
@media (max-width: 1024px) {
  .craft-film-label {
    top: clamp(14px, 3vh, 30px);
    right: auto;
    bottom: auto;
    left: 50%;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 2px 16px;
    align-items: baseline;
    width: calc(100% - 32px);
    max-width: 560px;
    padding: 10px 14px 12px;
    transform: translate(-50%, -8px);
    text-align: left;
    isolation: isolate;
  }

  .craft-film-label.is-on {
    transform: translate(-50%, 0);
  }

  /* The scrim: a feathered pool of the section's own green, no edges. */
  .craft-film-label::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: -26px -40px -38px;
    background: radial-gradient(ellipse at 50% 45%, rgba(4, 32, 15, 0.84) 0%, rgba(4, 32, 15, 0.62) 42%, rgba(4, 32, 15, 0) 76%);
    pointer-events: none;
  }

  .craft-film-index {
    grid-row: 1 / span 2;
    font-size: clamp(2.4rem, 5vw, 3rem);
    text-shadow: 0 2px 14px rgba(4, 32, 15, 0.85);
  }

  .craft-film-title {
    font-size: 0.86rem;
    letter-spacing: 0.14em;
    text-shadow: 0 1px 10px rgba(4, 32, 15, 0.9);
  }

  .craft-film-cue {
    font-size: 1.1rem;
    text-shadow: 0 1px 10px rgba(4, 32, 15, 0.9);
  }
}

@media (max-width: 780px) {
  .craft-film-stage {
    top: var(--anchor-offset, 60px);
    height: calc(100vh - var(--anchor-offset, 60px));
    height: calc(100svh - var(--anchor-offset, 60px));
  }

  /* Phone sizes for the label (its arrangement is set in the tablet block
     above): a little smaller, same hierarchy. */
  .craft-film-label {
    gap: 0 12px;
    max-width: 460px;
    padding: 8px 10px 10px;
  }

  .craft-film-index {
    font-size: clamp(2rem, 9.5vw, 2.6rem);
  }

  .craft-film-title {
    font-size: 0.74rem;
    letter-spacing: 0.12em;
  }

  .craft-film-cue {
    font-size: 0.96rem;
  }

  .craft-film-quote {
    width: calc(100% - 40px);
    font-size: clamp(1.15rem, 5.4vw, 1.5rem);
  }

  /* Portrait, static scene: the table sits mid-frame, so the line goes above it. */
  .craft-film.is-static .craft-film-quote-close {
    top: clamp(20px, 6vh, 56px);
    bottom: auto;
    transform: translateX(-50%);
  }
}

@media (max-width: 680px) {
  .craft-section {
    /* Bottom stays 0: the river divider is in flow and closes the section.
       (The old 82px clearance was for the absolutely positioned divider.) */
    padding: 56px 0 0;
  }

  .craft-heading {
    margin-bottom: 24px;
  }

  .craft-heading h2 {
    font-size: clamp(2rem, 9vw, 3.2rem);
    line-height: 0.98;
    white-space: normal;
  }

  .craft-sub {
    margin-top: 10px;
    font-size: 1rem;
  }

  .craft-film-stages {
    gap: 6px 14px;
    font-size: 0.7rem;
  }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .craft-film-label,
  .craft-film-label .craft-film-title,
  .craft-film-label .craft-film-cue {
    transition: none;
    animation: none;
  }

  .craft-river-shimmer {
    display: none;
  }
}
