/* =====================================================================
   HERO 3D STAGE — homepage only.
   .hero-stage      perspective + shared sizing
     .clock-float   idle float (after the intro)
       .clock-body  intro turn: tilted forward (top visible) -> face-on
         .clock-shell  the casing's top + rounded top edges (intro only)
         #live-clock   the device itself (flat; sheen in ::after)
     .clock-ground  soft ground shadow, synced to float + intro

   Default (no JS / reduced motion) is the final, face-on, lit state.
   JS adds .is-intro.is-pre, then drops .is-pre to play the turn.
   ===================================================================== */

.hero-stage {
  --casing-w: min(854px, calc(100vw - 96px));
  --depth: calc(var(--casing-w) * 152 / 854);  /* casing depth: 854W x 334H x 152D */
  --intro-tilt: -22deg;
  --turn-ms: 1500ms;
  --turn-ease: cubic-bezier(0.2, 0.75, 0.15, 1);

  position: relative;
  width: var(--casing-w);
  margin: 56px auto 40px;
  perspective: 1600px;
  perspective-origin: 50% 0%;                 /* camera sits slightly above */
}

.clock-float,
.clock-body {
  transform-style: preserve-3d;
}

/* the device takes its width from the stage; the stage owns the margins */
.hero-stage .clock-container {
  --casing-w: inherit;
  margin: 0;
  /* the separate ground shadow replaces the big baked-in drop shadow;
     keep the casing modelling + a tight contact shadow */
  box-shadow:
    inset 0 3px 2px var(--casing-top-glow),
    inset 0 1px 0 var(--casing-top-glow-hair),
    inset 0 -16px 26px rgba(0,0,0,0.20),
    inset 0 -3px 4px rgba(0,0,0,0.24),
    inset 3px 0 6px rgba(0,0,0,0.07),
    inset -3px 0 6px rgba(0,0,0,0.07),
    0 4px 10px -6px rgba(0,0,0,0.5);
}

/* ---- key light: fixed, from upper left, on a matte surface ----
   A broad, low-contrast falloff (no specular streak — the casing is matte).
   During the intro it drifts across as the device turns into the light. */
.hero-stage .clock-container::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(120% 140% at 18% -10%,
      rgba(255,255,255,0.075) 0%,
      rgba(255,255,255,0.03) 38%,
      rgba(0,0,0,0) 62%,
      rgba(0,0,0,0.07) 100%);
  background-size: 170% 100%;
  background-position: 0% 0;
  mix-blend-mode: soft-light;
}

/* ---- top of the casing, as real geometry ----
   The front face has rounded corners (radius r). On the product those
   corners run straight back through the depth, so from above you see:
   a flat top between the two corners + a quarter-round edge each side.
   Each quarter-round is 8 flat facets (11.25° each) hinged back from the
   front face's corner arc, shaded darker as they turn away from the light.
   Every piece: placed at a point on the front outline (left/top), turned
   to follow the arc (rotateZ), then folded back by the depth (rotateX). */
.clock-shell {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  pointer-events: none;
  --r: calc(var(--casing-w) * 32 / 854);   /* same radius as the casing */
  --facet: calc(var(--r) * 0.19603 + 1px);  /* chord of 11.25°, +1px overlap */
}
.clock-shell > span {
  position: absolute;
  /* each piece starts --seam in FRONT of the front face (and is that much
     longer), so it overlaps the join instead of meeting it edge-to-edge —
     edge-to-edge leaves an anti-aliased hairline that flickers as it floats */
  --seam: 2px;
  height: calc(var(--depth) + var(--seam));
  transform-origin: 0 0;
  transform: rotateZ(var(--a, 0deg)) rotateX(-90deg) translateY(calc(-1 * var(--seam)));
  /* matte, lit from above: front edge (local top) brightest, falling off
     toward the back; --shade darkens facets that face sideways */
  background:
    linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0) 45%, rgba(0,0,0,0.08)),
    linear-gradient(rgba(0,0,0,var(--shade, 0)), rgba(0,0,0,var(--shade, 0))),
    var(--casing-bg);
}
.clock-shell .ct-flat {
  left: calc(var(--r) - 1px);
  top: 0;
  width: calc(100% - 2 * var(--r) + 2px);
}
/* left edge: runs from the top of the arc (x=r, y=0) round to the side */
.clock-shell [class^="ct-l"] { width: var(--facet); }
.clock-shell .ct-l1 { left: var(--r); top: 0; --a: 174.375deg; --shade: 0.027; }
.clock-shell .ct-l2 { left: calc(var(--r) * 0.80491); top: calc(var(--r) * 0.01921); --a: 163.125deg; --shade: 0.05; }
.clock-shell .ct-l3 { left: calc(var(--r) * 0.61732); top: calc(var(--r) * 0.07612); --a: 151.875deg; --shade: 0.077; }
.clock-shell .ct-l4 { left: calc(var(--r) * 0.44443); top: calc(var(--r) * 0.16853); --a: 140.625deg; --shade: 0.109; }
.clock-shell .ct-l5 { left: calc(var(--r) * 0.29289); top: calc(var(--r) * 0.29289); --a: 129.375deg; --shade: 0.143; }
.clock-shell .ct-l6 { left: calc(var(--r) * 0.16853); top: calc(var(--r) * 0.44443); --a: 118.125deg; --shade: 0.18; }
.clock-shell .ct-l7 { left: calc(var(--r) * 0.07612); top: calc(var(--r) * 0.61732); --a: 106.875deg; --shade: 0.218; }
.clock-shell .ct-l8 { left: calc(var(--r) * 0.01921); top: calc(var(--r) * 0.80491); --a: 95.625deg; --shade: 0.259; }
/* right edge: mirror image */
.clock-shell [class^="ct-r"] { width: var(--facet); }
.clock-shell .ct-r1 { left: calc(100% - var(--r)); top: 0; --a: 5.625deg; --shade: 0.027; }
.clock-shell .ct-r2 { left: calc(100% - var(--r) * 0.80491); top: calc(var(--r) * 0.01921); --a: 16.875deg; --shade: 0.05; }
.clock-shell .ct-r3 { left: calc(100% - var(--r) * 0.61732); top: calc(var(--r) * 0.07612); --a: 28.125deg; --shade: 0.077; }
.clock-shell .ct-r4 { left: calc(100% - var(--r) * 0.44443); top: calc(var(--r) * 0.16853); --a: 39.375deg; --shade: 0.109; }
.clock-shell .ct-r5 { left: calc(100% - var(--r) * 0.29289); top: calc(var(--r) * 0.29289); --a: 50.625deg; --shade: 0.143; }
.clock-shell .ct-r6 { left: calc(100% - var(--r) * 0.16853); top: calc(var(--r) * 0.44443); --a: 61.875deg; --shade: 0.18; }
.clock-shell .ct-r7 { left: calc(100% - var(--r) * 0.07612); top: calc(var(--r) * 0.61732); --a: 73.125deg; --shade: 0.218; }
.clock-shell .ct-r8 { left: calc(100% - var(--r) * 0.01921); top: calc(var(--r) * 0.80491); --a: 84.375deg; --shade: 0.259; }

/* Face-on, a real box shows none of its top or edges, so the shell is only
   shown during the intro turn. Hidden by default (settled / no JS / reduced
   motion); .is-pre shows it, and the intro fades it out over the last few
   degrees of the turn. Opacity goes on each piece, not on .clock-shell —
   opacity on a preserve-3d parent would flatten it mid-fade. */
.clock-shell > span {
  opacity: 0;
  visibility: hidden;
}

/* ---- ground shadow ---- */
.clock-ground {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: calc(var(--casing-w) * -0.06);
  height: calc(var(--casing-w) * 0.07);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0,0,0,0.55), rgba(0,0,0,0.22) 55%, rgba(0,0,0,0) 100%);
  filter: blur(calc(var(--casing-w) * 0.012));
  transform-origin: 50% 50%;
  pointer-events: none;
  z-index: 0;
}
.clock-float { position: relative; z-index: 1; }   /* above the ground shadow */

/* =====================================================================
   Motion — only when the visitor is OK with it
   ===================================================================== */
@media (prefers-reduced-motion: no-preference) {

  /* --- intro: start state --- */
  .hero-stage.is-pre .clock-body {
    transform: translateY(calc(var(--casing-w) * 0.03)) rotateX(var(--intro-tilt));
  }
  .hero-stage.is-pre { opacity: 0; }
  .hero-stage.is-pre .clock-ground {
    transform: scale(1.12, 1.6);
    opacity: 0.45;
  }
  .hero-stage.is-pre .clock-container::after {
    background-position: 100% 0;
  }
  /* screen off: the e-ink panel keeps its normal colour, it's just blank */
  .hero-stage.is-pre .hour,
  .hero-stage.is-pre .dot,
  .hero-stage.is-pre .am-pm-center {
    opacity: 0;
    transform: translateY(3px);
  }
  .hero-stage.is-pre ~ .hero-time { opacity: 0; }
  .hero-stage.is-pre .clock-shell > span {
    opacity: 1;
    visibility: visible;
  }

  /* --- intro: transitions to the final state --- */
  .hero-stage.is-intro {
    transition: opacity 500ms ease-out;
  }
  .hero-stage.is-intro .clock-body {
    transition: transform var(--turn-ms) var(--turn-ease);
  }
  /* the turn is ~95% done by 950ms; fade the top + edges out as it lands */
  .hero-stage.is-intro .clock-shell > span {
    transition: opacity 320ms ease-out 900ms, visibility 0s linear 1220ms;
  }
  .hero-stage.is-intro .clock-ground {
    transition: transform var(--turn-ms) var(--turn-ease), opacity var(--turn-ms) ease-out;
  }
  .hero-stage.is-intro .clock-container::after {
    transition: background-position var(--turn-ms) var(--turn-ease);
  }
  .hero-stage.is-intro .hour {
    transition: opacity 260ms ease-out, transform 260ms ease-out,
                color 0.3s, background-color 0.3s;
    transition-delay: calc(1250ms + var(--i, 0) * 28ms);
  }
  .hero-stage.is-intro .dot {
    transition: opacity 220ms ease-out, transform 220ms ease-out, background-color 0.3s;
    transition-delay: calc(1400ms + var(--i, 0) * 24ms);
  }
  .hero-stage.is-intro .am-pm-center {
    transition: opacity 260ms ease-out 1650ms, transform 260ms ease-out 1650ms;
  }
  .hero-stage.is-intro ~ .hero-time {
    transition: opacity 300ms ease-out 1800ms;
  }

  /* --- idle float (after the intro) --- */
  @keyframes clockFloat {
    /* straight up and down, ~16px at full size — stays face-on */
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(calc(var(--casing-w) * -0.019)); }
  }
  @keyframes groundBreathe {
    0%, 100% { transform: scale(1, 1);       opacity: 1; }
    50%      { transform: scale(0.84, 0.72); opacity: 0.5; }
  }
  .hero-stage.is-floating .clock-float {
    animation: clockFloat 5.5s ease-in-out infinite;
  }
  .hero-stage.is-floating .clock-ground {
    animation: groundBreathe 5.5s ease-in-out infinite;
  }
}

/* small screens: a lighter shadow blur (the float scales with the device) */
@media (max-width: 600px) {
  .hero-stage { margin-top: 40px; }
  .clock-ground { filter: blur(6px); }
}
