/* ═══════════════════════════════════════════════════════════════
   LOCALWORKS - the 3D phone (phone3d.css)

   A solid-looking flagship phone built from CSS 3D transforms. No
   images, no WebGL. The look works with JavaScript off; phone3d.js only
   adds a small pointer tilt on desktop.

   USAGE (copy the markup exactly; the edge needs all 44 tags):

     <div class="p3d" style="--p3d-w: 320px">
       <div class="p3d-body">
         <div class="p3d-screen">
           ...the page's own screen content...
         </div>
         <span class="p3d-edge" aria-hidden="true"><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><b></b><b></b><b></b><b></b><b></b><b></b><b></b><b></b></span>
       </div>
     </div>
     <script src="phone3d.js" defer></script>   (optional: pointer tilt)

   KNOBS (set inline or from page CSS on .p3d or any ancestor):
     --p3d-w    body width. An absolute length: px, vw or clamp(). Not %.
                Works from 260px to 420px. Everything else scales from it.
     --p3d-ry   resting turn left/right   (default -24deg: right edge shows;
                use a positive angle to show the left edge, the light follows)
     --p3d-rx   resting lean back/forward (default 4deg)
     class "p3d--no-island"   hide our dynamic island when the screen
                              content draws its own.
     data-p3d-tilt="off"      on .p3d to keep a phone still.

   INSIDE THE SCREEN
     .p3d-screen is a plain block with overflow hidden and the display's
     rounded corners. Scroll, tap and click work as normal; put scrolling
     on an element inside it (not on .p3d-screen itself, or the island
     would scroll away). var(--p3d-safe-top) is the height the island
     needs, for the content's top padding.

   RULES THAT KEEP IT 3D
     Never put overflow, filter, opacity below 1, clip-path, mask,
     mix-blend-mode or contain:paint on .p3d-body or .p3d-edge: any of
     those flattens the solid into a sticker. Animate a wrapper around
     .p3d instead (an entrance fade on a parent is fine).
     The screen sits on the front plane (z = 0) and the body is extruded
     backwards, so the screen is never scaled: text stays sharp.
     The turned phone stays inside its own box; only the ground glow
     reaches 12% past each side. On a 390px screen keep --p3d-w at or
     below about 100vw - 96px.
     content-visibility on .p3d or a wrapper is fine; on .p3d-body it is not.

   REAL PROPORTIONS (a 6.1 inch flagship, millimetres):
     body 71.5 x 147.6 x 7.8, corner radius 11.1
     glass border 3.3 each side, so the display is 64.9 x 141 (19.5:9)
     display corner radius 7.8 (concentric with the body)
     dynamic island 20.8 x 6.1, 1.8 below the display's top
     right edge: side button. Left edge: action button, volume up, down.

   The one place this site uses a shadow: the contact shadow under the
   phone. A solid object standing on nothing reads as a sticker, which is
   the exact thing this file exists to fix.
   ═══════════════════════════════════════════════════════════════ */

.p3d{
  /* the pose: resting angle plus the pointer tilt phone3d.js writes */
  --ax: calc(var(--p3d-rx, 4deg) + var(--p3d-tx, 0deg));
  --ay: calc(var(--p3d-ry, -24deg) + var(--p3d-ty, 0deg));
  /* which side the key light sits: the side the phone is turned toward,
     so the edge you can see is always the lit one. +1 right, -1 left. */
  --lx: clamp(-1, calc(sin(var(--p3d-ry, -24deg)) * -40), 1);

  /* every dimension comes from one number */
  --W:  var(--p3d-w, 320px);
  --H:  calc(var(--W) * 2.0643);            /* 147.6 / 71.5 */
  --mm: calc(var(--W) / 71.5);              /* one real millimetre */
  --R:  calc(var(--mm) * 11.1);             /* body corner radius */
  --T:  calc(var(--mm) * 7.8);              /* thickness */
  --b:  calc(var(--mm) * 3.3);              /* glass border, edge to display */
  --rim:calc(var(--mm) * .6);               /* metal seen from the front */
  --sr: calc(var(--R) - var(--b));          /* display corner radius */
  --p3d-safe-top: calc(var(--mm) * 10.4);

  /* graphite titanium */
  --p3d-lo: #0e0f12;
  --p3d-hi: #858b94;

  position:relative; display:block; flex:none;
  width:var(--W); height:var(--H);
  /* No perspective, on purpose: a long-lens (orthographic) view, like a
     product shot from a distance. With a perspective, Chrome drew the
     screen's text at 1x: measured in tools/phone3d_check.mjs at 3x, text
     kept 3% of its flat sharpness under a perspective and 39% without
     (the rest is the turn itself). A bonus: the turned phone stays
     inside its own layout box, so it never adds page overflow. */
  isolation:isolate;
}
/* whole pixels for the box and the screen, so text lands on the pixel grid */
@supports (width: round(1px, 1px)){
  .p3d{
    --W: round(var(--p3d-w, 320px), 1px);
    --H: round(calc(var(--W) * 2.0643), 1px);
    --b: round(calc(var(--mm) * 3.3), 1px);
    --rim: max(2px, round(calc(var(--mm) * .6), 1px));
  }
}

/* ── the ground: a contact shadow and the faint pool of light the screen
   throws on the surface it stands on. Flat, outside the rotating body. ── */
.p3d::before,.p3d::after{content:''; position:absolute; z-index:-1; pointer-events:none}
.p3d::after{
  left:-12%; right:-12%; bottom:calc(var(--H) * -.065); height:calc(var(--W) * .30);
  background:radial-gradient(closest-side, rgba(var(--orb-glow, 86,131,218), .40), rgba(var(--orb-glow, 86,131,218), .15) 50%, rgba(var(--orb-glow, 86,131,218), .04) 78%, transparent);
}
.p3d::before{
  z-index:0;
  left:6%; right:6%; bottom:calc(var(--H) * -.032); height:calc(var(--W) * .075);
  border-radius:50%;
  background:radial-gradient(closest-side, rgba(0,0,0,.95), rgba(0,0,0,.8) 35%, rgba(0,0,0,.35) 70%, transparent);
}

/* ── the solid ── */
.p3d-body{
  position:absolute; inset:0; z-index:1;
  transform-style:preserve-3d;
  transform:rotateX(var(--ax)) rotateY(var(--ay));
  border-radius:var(--R);
  /* front: a hairline of metal, then black glass */
  border:var(--rim) solid transparent;
  background:
    linear-gradient(#040405, #040405) padding-box,
    conic-gradient(from calc(20deg * var(--lx)),
      #e3e7ec 0deg, #8b9098 22deg, #3a3e44 60deg, #6d727a 95deg, #2a2d32 140deg,
      #15171a 190deg, #2c2f34 235deg, #50545b 275deg, #9aa0a8 320deg, #e3e7ec 360deg) border-box;
  -webkit-tap-highlight-color:transparent;
}

/* the display. No transform of its own, ever. */
.p3d-screen{
  position:absolute; z-index:1;
  inset:calc(var(--b) - var(--rim));
  border-radius:var(--sr);
  overflow:hidden;
  background:#000;
  isolation:isolate;
}
@supports (width: round(1px, 1px)){
  .p3d-screen{inset:round(calc(var(--b) - var(--rim)), 1px)}
}

/* the dynamic island, with a camera lens in its right end */
.p3d-body::after{
  content:''; position:absolute; z-index:3; pointer-events:none;
  top:calc(var(--b) - var(--rim) + var(--mm) * 1.8);
  left:calc(50% - var(--mm) * 10.4);
  width:calc(var(--mm) * 20.8); height:calc(var(--mm) * 6.1);
  border-radius:999px;
  background:
    radial-gradient(circle at calc(100% - var(--mm) * 3.05) 50%, #1d2a44 0, #0c1220 calc(var(--mm) * .55), #050507 calc(var(--mm) * 1.1), transparent calc(var(--mm) * 1.2)),
    #000;
}
.p3d--no-island .p3d-body::after{display:none}

/* the glass: a faint reflection sweep that drifts as the phone turns,
   and the bright line where the glass meets the frame */
.p3d-body::before{
  content:''; position:absolute; z-index:4; pointer-events:none;
  inset:calc(var(--rim) * -1);
  border-radius:var(--R);
  background:
    linear-gradient(108deg,
      rgba(255,255,255,0) 0 36%,
      rgba(255,255,255,.075) 44%,
      rgba(255,255,255,.02) 52%,
      rgba(255,255,255,0) 58% 70%,
      rgba(255,255,255,.035) 76%,
      rgba(255,255,255,0) 82% 100%);
  background-size:260% 100%;
  background-position:calc(38% + sin(var(--p3d-ty, 0deg)) * 420%) 0;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.10),
    inset 0 0 0 calc(var(--rim) + 1px) rgba(0,0,0,.55);
}

/* ── the edge: four flat sides and four rounded corners of eight facets,
   each turned to face outward and lit from the upper right. The light
   is worked out from each facet's real direction, so as the phone
   turns, the edge brightens and darkens the way metal does. ── */
.p3d-edge{
  position:absolute; inset:calc(var(--rim) * -1);
  transform-style:preserve-3d;
  pointer-events:none;
}
/* two plates inside the body, so the joins between facets never show
   the page through them */
.p3d-edge::before,.p3d-edge::after{
  content:''; position:absolute; inset:1px; border-radius:var(--R);
  background:#1b1d21;
}
.p3d-edge::before{transform:translateZ(calc(var(--T) * -.45))}
.p3d-edge::after{transform:translateZ(calc(var(--T) * -1 + 1px))}

.p3d-edge>i,.p3d-edge>b{
  --fw:var(--T);           /* how deep the piece is */
  --rc:0px;                /* distance from its centre point */
  --h:0deg;                /* half its angle, for corner facets */
  --a0:calc(var(--a) - var(--h));
  --a1:calc(var(--a) + var(--h));
  /* light = .2 + .8 x (facet normal after the pose . light direction),
     light direction (.5 x lx, -.6, .62): up, toward the turned side and
     toward the viewer */
  --d0:clamp(0, calc(.2 + .8 * (
        .5 * var(--lx) * cos(var(--a0)) * cos(var(--ay))
      - .6 * (sin(var(--a0)) * cos(var(--ax)) + cos(var(--a0)) * sin(var(--ay)) * sin(var(--ax)))
      + .62 * (sin(var(--a0)) * sin(var(--ax)) - cos(var(--a0)) * sin(var(--ay)) * cos(var(--ax)))
    )), 1);
  --d1:clamp(0, calc(.2 + .8 * (
        .5 * var(--lx) * cos(var(--a1)) * cos(var(--ay))
      - .6 * (sin(var(--a1)) * cos(var(--ax)) + cos(var(--a1)) * sin(var(--ay)) * sin(var(--ax)))
      + .62 * (sin(var(--a1)) * sin(var(--ax)) - cos(var(--a1)) * sin(var(--ay)) * cos(var(--ax)))
    )), 1);
  --c0:color-mix(in oklab, var(--p3d-hi) calc(var(--d0) * 100%), var(--p3d-lo));
  --c1:color-mix(in oklab, var(--p3d-hi) calc(var(--d1) * 100%), var(--p3d-lo));

  position:absolute; left:0; top:0;
  width:var(--fw); height:var(--L);
  backface-visibility:hidden; -webkit-backface-visibility:hidden;
  /* stand the piece on the outline, then turn it to face outward.
     Its left edge ends up at the front glass, its right edge at the back. */
  transform:
    translate3d(
      calc(var(--cx) + var(--rc) * cos(var(--a)) - var(--fw) / 2),
      calc(var(--cy) + var(--rc) * sin(var(--a)) - var(--L) / 2),
      calc(var(--T) / -2))
    rotate(var(--a)) rotateY(90deg);
  background:
    /* across the depth: the polished chamfer at the front. (A dark seam at
       the back was tried: it drew hairlines across every corner join.) */
    linear-gradient(to right,
      rgba(255,255,255,.55) 0, rgba(255,255,255,.16) 7%, rgba(255,255,255,0) 15%),
    linear-gradient(to bottom, var(--c0), var(--c1));
}
/* browsers without CSS trig or color-mix cannot place or light the edge,
   so it is left out: they get the front of the phone, turned, still fine */
@supports not ((width: calc(1px * cos(0deg))) and (color: color-mix(in oklab, red, blue))){
  .p3d-edge{display:none}
}

/* the four flat sides: right, bottom, left, top */
.p3d-edge>i:nth-child(-n+4){--rc:0px}
.p3d-edge>i:nth-child(1){--a:0deg;   --cx:var(--W);              --cy:calc(var(--H) / 2); --L:calc(var(--H) - 2 * var(--R) + 2px)}
.p3d-edge>i:nth-child(2){--a:90deg;  --cx:calc(var(--W) / 2);    --cy:var(--H);           --L:calc(var(--W) - 2 * var(--R) + 2px)}
.p3d-edge>i:nth-child(3){--a:180deg; --cx:0px;                   --cy:calc(var(--H) / 2); --L:calc(var(--H) - 2 * var(--R) + 2px)}
.p3d-edge>i:nth-child(4){--a:270deg; --cx:calc(var(--W) / 2);    --cy:0px;                --L:calc(var(--W) - 2 * var(--R) + 2px)}
/* a studio light reflected along the long flat sides, like brushed metal */
.p3d-edge>i:nth-child(1),.p3d-edge>i:nth-child(3){
  background:
    linear-gradient(to right,
      rgba(255,255,255,.55) 0, rgba(255,255,255,.16) 7%, rgba(255,255,255,0) 15%),
    linear-gradient(to bottom,
      rgba(255,255,255,0) 0, rgba(255,255,255,.34) 14%, rgba(255,255,255,.08) 24%, rgba(255,255,255,0) 36%,
      rgba(0,0,0,.22) 56%, rgba(255,255,255,.14) 78%, rgba(255,255,255,.03) 90%, rgba(255,255,255,0) 100%),
    linear-gradient(to bottom, var(--c0), var(--c1));
}

/* the corners: chords of the corner circle, a hair long so they overlap */
.p3d-edge>i:nth-child(n+5){
  --h:5.625deg;
  --rc:calc(var(--R) * 0.99518);              /* R x cos 5.625deg */
  --L:calc(var(--R) * 0.19603 + 1.5px);        /* 2R x sin 5.625deg */
}
.p3d-edge>i:nth-child(n+5):nth-child(-n+12){--cx:calc(var(--W) - var(--R)); --cy:calc(var(--H) - var(--R))}
.p3d-edge>i:nth-child(n+13):nth-child(-n+20){--cx:var(--R);                 --cy:calc(var(--H) - var(--R))}
.p3d-edge>i:nth-child(n+21):nth-child(-n+28){--cx:var(--R);                 --cy:var(--R)}
.p3d-edge>i:nth-child(n+29){--cx:calc(var(--W) - var(--R));                 --cy:var(--R)}
.p3d-edge>i:nth-child(5){--a:5.625deg}
.p3d-edge>i:nth-child(6){--a:16.875deg}
.p3d-edge>i:nth-child(7){--a:28.125deg}
.p3d-edge>i:nth-child(8){--a:39.375deg}
.p3d-edge>i:nth-child(9){--a:50.625deg}
.p3d-edge>i:nth-child(10){--a:61.875deg}
.p3d-edge>i:nth-child(11){--a:73.125deg}
.p3d-edge>i:nth-child(12){--a:84.375deg}
.p3d-edge>i:nth-child(13){--a:95.625deg}
.p3d-edge>i:nth-child(14){--a:106.875deg}
.p3d-edge>i:nth-child(15){--a:118.125deg}
.p3d-edge>i:nth-child(16){--a:129.375deg}
.p3d-edge>i:nth-child(17){--a:140.625deg}
.p3d-edge>i:nth-child(18){--a:151.875deg}
.p3d-edge>i:nth-child(19){--a:163.125deg}
.p3d-edge>i:nth-child(20){--a:174.375deg}
.p3d-edge>i:nth-child(21){--a:185.625deg}
.p3d-edge>i:nth-child(22){--a:196.875deg}
.p3d-edge>i:nth-child(23){--a:208.125deg}
.p3d-edge>i:nth-child(24){--a:219.375deg}
.p3d-edge>i:nth-child(25){--a:230.625deg}
.p3d-edge>i:nth-child(26){--a:241.875deg}
.p3d-edge>i:nth-child(27){--a:253.125deg}
.p3d-edge>i:nth-child(28){--a:264.375deg}
.p3d-edge>i:nth-child(29){--a:275.625deg}
.p3d-edge>i:nth-child(30){--a:286.875deg}
.p3d-edge>i:nth-child(31){--a:298.125deg}
.p3d-edge>i:nth-child(32){--a:309.375deg}
.p3d-edge>i:nth-child(33){--a:320.625deg}
.p3d-edge>i:nth-child(34){--a:331.875deg}
.p3d-edge>i:nth-child(35){--a:343.125deg}
.p3d-edge>i:nth-child(36){--a:354.375deg}

/* ── the buttons. Each is a face standing proud of the side by 0.55 mm,
   plus the little end you see from the front. Right edge: side button.
   Left edge: action button, volume up, volume down. ── */
.p3d-edge>b{
  --fw:calc(var(--mm) * 2.9);
  --p:calc(var(--mm) * .55);                  /* how far it stands out */
  border-radius:calc(var(--mm) * .9);
  background:
    linear-gradient(to right, rgba(255,255,255,.5), rgba(255,255,255,.08) 22%, rgba(255,255,255,0) 60%, rgba(0,0,0,.35)),
    linear-gradient(to bottom, rgba(255,255,255,.18), rgba(255,255,255,0) 20% 80%, rgba(0,0,0,.3)),
    linear-gradient(to bottom, var(--c0), var(--c1));
}
/* faces */
.p3d-edge>b:nth-of-type(1){--a:0deg;   --cx:calc(var(--W) + var(--p)); --cy:calc(var(--mm) * 45.5); --L:calc(var(--mm) * 16)}
.p3d-edge>b:nth-of-type(3){--a:180deg; --cx:calc(var(--p) * -1);      --cy:calc(var(--mm) * 28);   --L:calc(var(--mm) * 6)}
.p3d-edge>b:nth-of-type(5){--a:180deg; --cx:calc(var(--p) * -1);      --cy:calc(var(--mm) * 44);   --L:calc(var(--mm) * 10)}
.p3d-edge>b:nth-of-type(7){--a:180deg; --cx:calc(var(--p) * -1);      --cy:calc(var(--mm) * 58);   --L:calc(var(--mm) * 10)}
/* front ends: flat, facing the viewer, bridging side and button face */
.p3d-edge>b:nth-of-type(even){
  width:var(--p); height:var(--L);
  border-radius:1px;
  background:linear-gradient(to bottom, #8d939b, #5d6168 50%, #34373c);
  transform:translate3d(var(--x), calc(var(--cy) - var(--L) / 2), calc(var(--T) / -2 + var(--fw) / 2));
}
.p3d-edge>b:nth-of-type(2){--x:var(--W);                    --cy:calc(var(--mm) * 45.5); --L:calc(var(--mm) * 16)}
.p3d-edge>b:nth-of-type(4){--x:calc(var(--p) * -1);         --cy:calc(var(--mm) * 28);   --L:calc(var(--mm) * 6)}
.p3d-edge>b:nth-of-type(6){--x:calc(var(--p) * -1);         --cy:calc(var(--mm) * 44);   --L:calc(var(--mm) * 10)}
.p3d-edge>b:nth-of-type(8){--x:calc(var(--p) * -1);         --cy:calc(var(--mm) * 58);   --L:calc(var(--mm) * 10)}

/* less motion: the phone holds its resting pose, whatever the script says */
@media (prefers-reduced-motion: reduce){
  .p3d{--p3d-tx:0deg !important; --p3d-ty:0deg !important}
}
