/* phone3d: a CSS-3D phone with real thickness, built by assets/js/phone3d.js.
   Size it with --pw (phone width) on .p3d. Everything else scales from that. */

.p3d {
  --pw: 300px;
  --ph: calc(var(--pw) * 2.06);
  --pt: calc(var(--pw) * .105);            /* thickness */
  --pr: calc(var(--pw) * .168);            /* body corner radius */
  --bezel: calc(var(--pw) * .034);
  --sr: calc(var(--pr) - var(--bezel));    /* screen corner radius */
  --k: 2;                                  /* the glass is drawn this many times too big, then scaled down: see .p3d__front */
  position: relative;
  width: var(--pw); height: var(--ph);
  perspective: calc(var(--pw) * 5.2);
  perspective-origin: 50% 42%;
  /* Swiping across the phone must not select or drag what is on its screen (Firefox does both). */
  -webkit-user-select: none; user-select: none;
}
.p3d img, .p3d video { pointer-events: none; -webkit-user-drag: none; }

.p3d__body {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transform: rotateX(6deg) rotateY(-18deg);
  will-change: transform;
}

/* The frame: slabs stacked through the thickness read as one solid, rounded band of metal. */
.p3d__slab {
  position: absolute; inset: 0;
  border-radius: var(--pr);
  background: #3b3e45;
  backface-visibility: visible;
}
.p3d__slab--chamfer { background: #565a63; }
.p3d__slab--mid { background: linear-gradient(180deg, #4b4f58, #2d3036 50%, #454850); }
/* Side buttons live on the middle slabs so they get thickness too. */
.p3d__slab--btn::before, .p3d__slab--btn::after {
  content: ""; position: absolute; width: calc(var(--pw) * .02); border-radius: 2px;
}
.p3d__slab--btn::before {          /* action, volume up, volume down */
  left: calc(var(--pw) * -.009); top: 17%; height: 27%;
  background: linear-gradient(180deg, #5a5e68 0 15%, transparent 15% 27%, #5a5e68 27% 60%, transparent 60% 67%, #5a5e68 67% 100%);
}
.p3d__slab--btn::after {           /* side button */
  right: calc(var(--pw) * -.009); top: 27%; height: 15%;
  background: #5a5e68;
}

.p3d__face {
  position: absolute; inset: 0;
  border-radius: var(--pr);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
/* The glass is laid out --k times too big and scaled back down by phone3d.js. Firefox paints a
   3D-turned layer at its layout size and then resamples it, which made the screen look soft;
   starting from more pixels than it shows keeps the screenshots and the status bar sharp.
   Everything inside sizes from --fw (the enlarged width), not --pw. */
.p3d__front {
  --fw: calc(var(--pw) * var(--k));
  --pr: calc(var(--fw) * .168);
  --bezel: calc(var(--fw) * .034);
  --sr: calc(var(--pr) - var(--bezel));
  inset: auto; left: 50%; top: 50%;
  width: var(--fw); height: calc(var(--fw) * 2.06);
  margin: calc(var(--fw) * -1.03) 0 0 calc(var(--fw) * -.5);
  background: #04060a;
  box-shadow: inset 0 0 0 calc(1px * var(--k)) rgba(255,255,255,.14), inset 0 0 0 calc(var(--fw) * .008) #1a1d23;
}
/* Dense screens already have the pixels to spare. */
@media (min-resolution: 2dppx) { .p3d { --k: 1; } }
.p3d__back {
  background:
    radial-gradient(120% 80% at 30% 10%, rgba(255,255,255,.10), transparent 60%),
    linear-gradient(160deg, #3a3d45, #23252b 60%, #2e3138);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.p3d__cam {
  position: absolute; left: 6%; top: 3.2%;
  width: 44%; aspect-ratio: 1;
  border-radius: 24%;
  background: linear-gradient(150deg, #454851, #292b31);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.14), 0 2px 6px rgba(0,0,0,.5);
}
.p3d__cam i {
  position: absolute; width: 40%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #3d4b66 0 8%, #0b0e15 30%, #05070b 62%, #2b2e36 64% 100%);
  box-shadow: 0 0 0 1px rgba(255,255,255,.15);
}
.p3d__cam i:nth-child(1) { left: 8%; top: 8%; }
.p3d__cam i:nth-child(2) { left: 8%; bottom: 8%; }
.p3d__cam i:nth-child(3) { right: 8%; top: 30%; }

/* Light sliding across the glass as the phone turns. */
.p3d__glare {
  position: absolute; inset: 0; border-radius: var(--pr);
  background: linear-gradient(112deg, rgba(255,255,255,0) 30%, rgba(255,255,255,.13) 44%, rgba(255,255,255,.03) 52%, rgba(255,255,255,0) 62%);
  background-size: 260% 100%;
  background-position: var(--gx, 50%) 0;
  pointer-events: none;
  mix-blend-mode: screen;
}

.p3d__shadow {
  position: absolute; left: 50%; bottom: calc(var(--pw) * -.2);
  width: 92%; height: calc(var(--pw) * .16);
  transform: translateX(calc(-50% + var(--sx, 0px)));
  background: radial-gradient(closest-side, rgba(0,0,0,.6), transparent);
  filter: blur(10px);
  pointer-events: none;
}

/* ================= Screen ================= */
.p3d__screen {
  position: absolute; inset: var(--bezel);
  border-radius: var(--sr);
  overflow: hidden;
  background: #000;
  font: 600 calc(var(--fw) * .04)/1 -apple-system, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  color: #fff;
  isolation: isolate;
}

/* Home screen */
.p3d__home {
  position: absolute; inset: 0;
  background:
    radial-gradient(70% 45% at 20% 18%, rgba(23,162,255,.6), transparent 70%),
    radial-gradient(70% 50% at 85% 70%, rgba(206,234,253,.28), transparent 70%),
    linear-gradient(170deg, #0c2a52, #071426 60%, #0a2038);
}
.p3d__grid {
  position: absolute; left: 7%; right: 7%; top: 12%;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6.5% 7.5%;
  transform-origin: 50% 40%;
}
.p3d__ico { display: grid; justify-items: center; gap: .45em; min-width: 0; }
.p3d__ico img {
  width: 100%; aspect-ratio: 1; height: auto;
  border-radius: 23%;
  box-shadow: 0 calc(2px * var(--k)) calc(6px * var(--k)) rgba(0,0,0,.35);
  transition: transform .14s, filter .14s;
}
.p3d__ico.is-tap img { transform: scale(.9); filter: brightness(.65); }
.p3d__ico span {
  max-width: 130%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-size: .62em; font-weight: 500; letter-spacing: -.01em; text-shadow: 0 1px 2px rgba(0,0,0,.5);
}

.p3d__dim { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; }

/* An app, as a card. JS animates its box between an icon's rect and the full screen. */
.p3d__card {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  overflow: hidden;
  border-radius: var(--sr);
  background: #000;
  display: none;
  will-change: left, top, width, height, transform;
}
.p3d__card.is-live { display: block; }
.p3d__content { position: absolute; inset: 0; display: flex; flex-direction: column; }
.p3d__band { flex: none; height: 6.4%; }
.p3d__media { position: relative; flex: 1; min-height: 0; }
.p3d__media > * {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: top;
}
.p3d__cardicon { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; pointer-events: none; }

/* Chrome above everything: clock, island, home indicator. */
.p3d__status {
  position: absolute; left: 0; right: 0; top: 0; height: 6.4%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 9% 0 11%;
  font-size: .95em; letter-spacing: -.01em;
  color: #fff;
  transition: color .3s;
  pointer-events: none;
  z-index: 5;
}
.p3d__status svg { height: .82em; width: auto; fill: currentColor; }
.p3d__screen[data-tone="light"] .p3d__status { color: #0b0d12; }
.p3d__island {
  position: absolute; left: 50%; top: 1.5%;
  width: 29%; height: 3.5%;
  transform: translateX(-50%);
  border-radius: 999px; background: #000;
  pointer-events: none;
  z-index: 5;
}
.p3d__bar {
  position: absolute; left: 50%; bottom: 1%;
  width: 36%; height: .55%; min-height: calc(3px * var(--k));
  transform: translateX(-50%);
  border-radius: 999px; background: #fff; opacity: .9;
  transition: background-color .3s;
  pointer-events: none;
  z-index: 5;
}
.p3d__screen[data-tone="light"] .p3d__bar { background: #0b0d12; }

@media (prefers-reduced-motion: reduce) {
  .p3d__ico img, .p3d__status, .p3d__bar { transition: none; }
}
