/* The phone's volume buttons turning up the TV, and the home-screen widgets. */

/* Volume buttons
   Without script (or with reduced motion) this is one still: the phone turned to show its side
   buttons in front of the TV, its volume bar up, and the three captions in a row. With script,
   main.js adds .is-live: the stage pins under the nav for the length of .volume-pin, and the
   scroll through it is written to --vp (0 to 1). The phone turns to its side, the volume-up
   button presses five times and the TV climbs, then volume-down brings it back. main.js also
   sets --level (the bar, 0 to 1), the number, .is-press on the button that went down and
   .is-pulse on the TV as each press lands. */

.volume {
  --vp: 0.5;
  --level: 0.6;
  position: relative;
  padding-bottom: clamp(6rem, 12vw, 10rem);
  background: #07080b;
  color: #fff;
  --orb-1: rgba(231, 163, 74, 0.16);
  --orb-2: rgba(126, 182, 255, 0.1);
  --orb-3: rgba(240, 160, 184, 0.08);
}

.volume-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: clamp(4rem, 9vw, 7rem);
}

.volume-copy {
  position: relative;
  z-index: 3;
  width: min(980px, calc(100% - 40px));
  text-align: center;
}

.volume-title {
  margin: 0 auto;
  font-size: clamp(2.2rem, 5.2vw, 4.25rem);
  font-weight: 600;
  letter-spacing: -0.045em;
  line-height: 1;
  text-wrap: balance;
}

.volume-title .line { display: block; }

.volume-title .line + .line {
  background: linear-gradient(100deg, #f6c27a 10%, #e7a34a 45%, #f0a0b8 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.volume-scene {
  --t: clamp(0, calc(var(--vp) / 0.16), 1);
  position: relative;
  width: 100%;
  height: min(78vh, 720px);
  margin-top: clamp(1.5rem, 4vw, 3rem);
  container-type: size;
}

/* The TV */

.vtv {
  --tw: min(66cqw, 132cqh);
  position: absolute;
  top: 4cqh;
  left: calc(50% + 6cqw);
  width: var(--tw);
  translate: -50% 0;
  scale: calc(0.94 + var(--t) * 0.06);
}

.vtv-panel {
  aspect-ratio: 16 / 9;
  padding: 0.7%;
  border-radius: 1.4% / 2.5%;
  background: linear-gradient(180deg, #23252c, #0b0c0f);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.09),
    0 60px 120px -40px rgba(0, 0, 0, 0.9),
    0 0 calc(40px + var(--level) * 140px) calc(var(--level) * 10px) rgba(231, 163, 74, calc(0.06 + var(--level) * 0.16));
  transition: box-shadow 0.6s var(--ease);
}

.vtv-screen {
  position: relative;
  height: 100%;
  overflow: hidden;
  border-radius: 0.8% / 1.4%;
  background: #000;
  container-type: inline-size;
}

/* A dusk over two hills, drifting slowly, so the screen reads as something playing. */
.vtv-film {
  position: absolute;
  inset: -4%;
  background:
    radial-gradient(60% 40% at 50% 64%, rgba(255, 200, 130, 0.55), transparent 70%),
    linear-gradient(180deg, #121a33 0%, #3a2c55 30%, #a0506a 50%, #ec9257 62%, #f7c47c 68%, #3a2430 68.4%, #120c14 100%);
}

.vtv-sun {
  position: absolute;
  left: 50%;
  top: 52%;
  width: 16%;
  aspect-ratio: 1;
  border-radius: 50%;
  translate: -50% -50%;
  background: radial-gradient(circle, #fff3d6 0%, #ffd08a 45%, rgba(255, 168, 92, 0) 72%);
}

.vtv-hill {
  position: absolute;
  bottom: -30%;
  border-radius: 50%;
  background: linear-gradient(180deg, #2a1a26, #0d0910);
}

.vtv-hill--a { left: -20%; width: 80%; height: 70%; }
.vtv-hill--b { right: -24%; width: 90%; height: 62%; background: linear-gradient(180deg, #221520, #0a070c); }

/* The TV's own volume overlay. */
.vtv-hud {
  position: absolute;
  left: 50%;
  bottom: 7%;
  display: flex;
  align-items: center;
  gap: 2.2cqw;
  padding: 1.6cqw 2.6cqw;
  border-radius: 99px;
  background: rgba(12, 13, 17, 0.62);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  color: #fff;
  translate: -50% 0;
}

.vtv-hud svg { width: 3.4cqw; fill: currentColor; }

.vtv-bar {
  width: 30cqw;
  height: 0.9cqw;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.18);
}

.vtv-bar i {
  display: block;
  width: calc(var(--level) * 100%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f6c27a, #fff);
  transition: width 0.42s cubic-bezier(0.34, 1.5, 0.5, 1);
}

.vtv-level {
  min-width: 2.2em;
  font-size: 2.6cqw;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.vtv-foot {
  display: block;
  width: 22%;
  height: 0.7cqh;
  margin: 1.4cqh auto 0;
  border-radius: 99px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.16), transparent);
}

/* Sound leaving the TV on each press. */
.vtv-wave {
  position: absolute;
  top: 18%;
  width: 14%;
  height: 64%;
  pointer-events: none;
}

.vtv-wave--l { right: 100%; }
.vtv-wave--r { left: 100%; }

.vtv-wave i {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(246, 194, 122, 0.7);
  border-radius: 50%;
  opacity: 0;
}

.vtv-wave--l i { clip-path: inset(0 50% 0 0); }
.vtv-wave--r i { clip-path: inset(0 0 0 50%); }

/* The phone, as a thin slab: a front face and the left edge with its buttons. */

.vphone {
  --pw: min(24cqw, 42cqh);
  --depth: calc(var(--pw) * 0.105);
  position: absolute;
  z-index: 2;
  left: calc(50% - 30cqw);
  bottom: 2cqh;
  width: var(--pw);
  perspective: 1500px;
  translate: calc(-50% + (1 - var(--t)) * 10cqw) calc((1 - var(--t)) * 6cqh);
}

.vphone-body {
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(6deg) rotateY(calc(var(--t) * 58deg)) rotateZ(calc(var(--t) * -4deg));
}

.vphone-front {
  transform: translateZ(var(--depth));
}

.vphone-front .device-bezel {
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.2),
    inset 0 0 0 4px #0c0d11;
}

/* The frame is a stack of rounded slices from the back (z 0) to just behind the front glass, so
   the edge stays solid and follows the corners from any angle. --l shades each slice like a
   rounded titanium band: dark at the glass and the back, brightest in the middle. */
.vphone-frame,
.vphone-keys {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.vphone-frame i {
  --i: 0;
  position: absolute;
  inset: 0;
  border-radius: 17% / 8%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0) calc(var(--vp) * 120% - 30%), rgba(255, 255, 255, 0.22) calc(var(--vp) * 120% - 14%), rgba(255, 255, 255, 0) calc(var(--vp) * 120%)),
    linear-gradient(180deg, hsl(225 5% calc(var(--l) + 8%)), hsl(225 5% var(--l)) 30%, hsl(225 5% calc(var(--l) - 5%)) 72%, hsl(225 5% calc(var(--l) + 4%)));
  --l: calc(16% + 44% * sin(var(--i) / 19 * 180deg));
  transform: translateZ(calc(var(--i) * var(--depth) / 20));
}

.vphone-frame i:nth-child(2) { --i: 1; }
.vphone-frame i:nth-child(3) { --i: 2; }
.vphone-frame i:nth-child(4) { --i: 3; }
.vphone-frame i:nth-child(5) { --i: 4; }
.vphone-frame i:nth-child(6) { --i: 5; }
.vphone-frame i:nth-child(7) { --i: 6; }
.vphone-frame i:nth-child(8) { --i: 7; }
.vphone-frame i:nth-child(9) { --i: 8; }
.vphone-frame i:nth-child(10) { --i: 9; }
.vphone-frame i:nth-child(11) { --i: 10; }
.vphone-frame i:nth-child(12) { --i: 11; }
.vphone-frame i:nth-child(13) { --i: 12; }
.vphone-frame i:nth-child(14) { --i: 13; }
.vphone-frame i:nth-child(15) { --i: 14; }
.vphone-frame i:nth-child(16) { --i: 15; }
.vphone-frame i:nth-child(17) { --i: 16; }
.vphone-frame i:nth-child(18) { --i: 17; }
.vphone-frame i:nth-child(19) { --i: 18; }
.vphone-frame i:nth-child(20) { --i: 19; }

/* Each button is a small plate standing out of the left edge, centred in its thickness. */
.vbtn {
  --press: 0;
  position: absolute;
  left: 0;
  width: calc(var(--depth) * 0.42);
  border-radius: 99px;
  background: linear-gradient(90deg, #3a3c43, #c9ccd3 48%, #555861);
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.5);
  transform-origin: 0 50%;
  transform: translateZ(calc(var(--depth) * 0.29)) rotateY(-90deg) translateZ(calc(1.6px - var(--press) * 1.4px));
}

.vbtn--action { top: 16.4%; height: 3.8%; }
.vbtn--up { top: 24%; height: 6.7%; }
.vbtn--down { top: 32.6%; height: 6.7%; }

.vbtn i {
  position: absolute;
  inset: -12% -40%;
  border: 2px solid #f6c27a;
  border-radius: 99px;
  opacity: 0;
}

/* The button about to be used glows, like a hint drawn on the hardware. */
.volume.is-up .vbtn--up,
.volume.is-down .vbtn--down {
  background: linear-gradient(90deg, #6b4a1f, #ffd9a1 48%, #8a5f27);
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.5),
    0 0 10px 3px rgba(246, 194, 122, 0.9),
    0 0 26px 6px rgba(246, 194, 122, 0.45);
}

/* Measured from the untransformed box; the turned phone's edge sits about 1.5cqw inside it. */
.vcall {
  position: absolute;
  right: calc(100% - 1.2cqw);
  display: flex;
  align-items: center;
  gap: 0.7em;
  font-size: clamp(12px, 1.6cqw, 17px);
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.5);
  opacity: calc(var(--t) * 1);
  transition: color 0.4s var(--ease);
}

.vcall::after {
  content: "";
  width: 5cqw;
  height: 1px;
  background: currentColor;
}

.vcall--up { top: 24%; }
.vcall--down { top: 33%; }

.volume.is-up .vcall--up,
.volume.is-down .vcall--down { color: #f6c27a; }

.volume-beats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4em 1em;
  margin: clamp(1.5rem, 4vw, 2.5rem) 0 0;
  padding: 0 20px;
  list-style: none;
  font-size: clamp(1.4rem, 3vw, 2.4rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.1;
  text-align: center;
}

.volume-outro { margin-top: clamp(5rem, 10vw, 8rem); }

.volume-outro .section-title .line + .line { color: rgba(255, 255, 255, 0.5); }

.volume-outro .lede { color: rgba(255, 255, 255, 0.72); }

.facts--light li { background: rgba(255, 255, 255, 0.08); color: #fff; }
.facts--light li::before { border-color: #f6c27a; }

/* These sections are several screens tall, so the page-wide fact drift (motion.css, from --p) would
   carry the pills into each other once they wrap. */
.volume .facts li:nth-child(n),
.widgets .facts li:nth-child(n),
.haptics .facts li:nth-child(n) { translate: none; }

/* Pinned: --vp from main.js drives everything below. */
@media (prefers-reduced-motion: no-preference) {
  .js .volume.is-live .volume-pin { height: 420vh; }

  .js .volume.is-live .volume-stage {
    position: sticky;
    top: calc(var(--nav-h) + env(safe-area-inset-top));
    height: calc(100svh - var(--nav-h) - env(safe-area-inset-top));
    padding-top: clamp(1.5rem, 4vh, 3rem);
    padding-bottom: clamp(1rem, 3vh, 2rem);
  }

  .js .volume.is-live .volume-copy {
    opacity: clamp(0, calc((0.9 - var(--vp)) * 12), 1);
  }

  .js .volume.is-live .volume-scene {
    flex: 1;
    height: auto;
    min-height: 0;
  }

  /* The overlay shows while the buttons are in use, as a TV's would. */
  .js .volume.is-live .vtv-hud {
    opacity: 0;
    translate: -50% 30%;
    transition: opacity 0.5s var(--ease), translate 0.6s var(--ease);
  }

  .js .volume.is-live.is-hud .vtv-hud {
    opacity: 1;
    translate: -50% 0;
  }

  .js .volume.is-live .volume-beats {
    display: grid;
    margin-top: 0.5rem;
    min-height: 2.4em;
  }

  /* Each caption owns a window of the scroll, between --a and --b. */
  .js .volume.is-live .vbeat {
    --o: clamp(0, min(calc((var(--vp) - var(--a)) * 16), calc((var(--b) - var(--vp)) * 16)), 1);
    grid-area: 1 / 1;
    opacity: var(--o);
    filter: blur(calc((1 - var(--o)) * 8px));
    translate: 0 calc((1 - var(--o)) * 14px);
  }

  .vbeat--1 { --a: 0.06; --b: 0.24; }
  .vbeat--2 { --a: 0.26; --b: 0.54; color: #f6c27a; }
  .vbeat--3 { --a: 0.56; --b: 0.86; }

  .volume.is-pulse .vtv-wave i { animation: vwave 1s var(--ease) both; }
  .volume.is-pulse .vtv-wave i:nth-child(2) { animation-delay: 0.09s; }
  .volume.is-pulse .vtv-wave i:nth-child(3) { animation-delay: 0.18s; }

  .vbtn.is-press { animation: vpress 0.34s var(--ease); }
  .vbtn.is-press i { animation: vring 0.8s var(--ease) both; }

  .vtv-film { animation: vfilm 24s ease-in-out infinite alternate; }
}

@keyframes vwave {
  from { opacity: 0.9; scale: 0.35; }
  to { opacity: 0; scale: 1.15; }
}

@keyframes vpress {
  0% { --press: 0; }
  30% { --press: 1; }
  100% { --press: 0; }
}

@keyframes vring {
  from { opacity: 0.95; scale: 0.8; }
  to { opacity: 0; scale: 2.2; }
}

@keyframes vfilm {
  from { transform: scale(1) translate(0, 0); }
  to { transform: scale(1.08) translate(-1.5%, -1%); }
}

@property --press { syntax: "<number>"; inherits: true; initial-value: 0; }

/* Stacked: the TV takes the top 36% of the scene and the phone (about 2.1 times as tall as it is
   wide) fits in the rest, so they never overlap however short the screen is. */
@media (max-width: 899px) {
  .vtv {
    --tw: min(92cqw, 64cqh);
    top: 0;
    left: 50%;
  }

  .vphone {
    --pw: min(30cqw, 27cqh);
    left: 54%;
    bottom: 0;
  }

  .js .volume.is-live .volume-scene {
    flex: 1;
    height: auto;
    min-height: 0;
    margin-top: 1rem;
  }

  .vcall { font-size: 12px; }
  .vcall::after { width: 14px; }
}

/* Widgets
   One markup for every size and theme (views/partials/widget.ejs). Sizes are in widget points
   (--pt), so each widget scales from the iOS layout: large and medium are 338 wide, small 158.
   Palette colours are registered so a theme change cross-fades. --w-hard is 1 for plastic
   hardware themes (side edges, the ring round the arrows) and 0 for soft ones (two-shadow caps). */

@property --w-plate { syntax: "<color>"; inherits: true; initial-value: #14171e; }
@property --w-key-a { syntax: "<color>"; inherits: true; initial-value: #292a2d; }
@property --w-key-b { syntax: "<color>"; inherits: true; initial-value: #252629; }
@property --w-key-c { syntax: "<color>"; inherits: true; initial-value: #222326; }
@property --w-side { syntax: "<color>"; inherits: true; initial-value: #18191b; }
@property --w-ring { syntax: "<color>"; inherits: true; initial-value: #e7a34a; }
@property --w-ring-side { syntax: "<color>"; inherits: true; initial-value: #8a5a1c; }
@property --w-chev { syntax: "<color>"; inherits: true; initial-value: #6e4414; }
@property --w-ok-a { syntax: "<color>"; inherits: true; initial-value: #f0b65c; }
@property --w-ok-b { syntax: "<color>"; inherits: true; initial-value: #e7a34a; }
@property --w-ok-c { syntax: "<color>"; inherits: true; initial-value: #c9842e; }
@property --w-ok-side { syntax: "<color>"; inherits: true; initial-value: #a86b22; }
@property --w-ok-ink { syntax: "<color>"; inherits: true; initial-value: #ffffff; }
@property --w-ink { syntax: "<color>"; inherits: true; initial-value: #f6f1e7; }
@property --w-power { syntax: "<color>"; inherits: true; initial-value: #ff5c5c; }
@property --w-light { syntax: "<color>"; inherits: true; initial-value: #55565a; }
@property --w-dark { syntax: "<color>"; inherits: true; initial-value: #050505; }
@property --w-hard { syntax: "<number>"; inherits: true; initial-value: 1; }

.tw {
  --ref: 338;
  container-type: inline-size;
  width: 100%;
  transition-property: --w-plate, --w-key-a, --w-key-b, --w-key-c, --w-side, --w-ring, --w-ring-side, --w-chev, --w-ok-a, --w-ok-b, --w-ok-c, --w-ok-side, --w-ok-ink, --w-ink, --w-power, --w-light, --w-dark, --w-hard;
  transition-duration: 0.8s;
  transition-timing-function: var(--ease);
  user-select: none;
  -webkit-user-select: none;
}

.tw--large { aspect-ratio: 338 / 354; }
.tw--medium { aspect-ratio: 338 / 158; }
.tw--small { --ref: 158; aspect-ratio: 1; }

/* Palettes from the app's themes (couchbeam-mobile/src/theme/themes.ts, through src/widget/theme.ts). */
.tw[data-look="default"] {
  --w-plate: #14171e; --w-key-a: #292a2d; --w-key-b: #252629; --w-key-c: #222326; --w-side: #18191b;
  --w-ring: #e7a34a; --w-ring-side: #8a5a1c; --w-chev: #6e4414;
  --w-ok-a: #f0b65c; --w-ok-b: #e7a34a; --w-ok-c: #c9842e; --w-ok-side: #a86b22; --w-ok-ink: #ffffff;
  --w-ink: #f6f1e7; --w-power: #ff5c5c; --w-light: #55565a; --w-dark: #050505; --w-hard: 1;
}

.tw[data-look="soft"] {
  --w-plate: #e0e5ec; --w-key-a: #e0e5ec; --w-key-b: #e0e5ec; --w-key-c: #e0e5ec; --w-side: #e0e5ec;
  --w-ring: #e0e5ec; --w-ring-side: #e0e5ec; --w-chev: #4d5566;
  --w-ok-a: #e0e5ec; --w-ok-b: #e0e5ec; --w-ok-c: #e0e5ec; --w-ok-side: #e0e5ec; --w-ok-ink: #5b7cff;
  --w-ink: #4d5566; --w-power: #e25555; --w-light: #ffffff; --w-dark: #a3b1c6; --w-hard: 0;
}

.tw[data-look="graphite"] {
  --w-plate: #2b2b2b; --w-key-a: #3a3a3a; --w-key-b: #303030; --w-key-c: #2e2e2e; --w-side: #303030;
  --w-ring: #2b2b2b; --w-ring-side: #2b2b2b; --w-chev: #ededed;
  --w-ok-a: #3a3a3a; --w-ok-b: #303030; --w-ok-c: #2e2e2e; --w-ok-side: #303030; --w-ok-ink: #6eb6ff;
  --w-ink: #ededed; --w-power: #e5312b; --w-light: #454545; --w-dark: #1a1a1a; --w-hard: 0;
}

.tw[data-look="gold"] {
  --w-plate: #c4a35a; --w-key-a: #c4a35a; --w-key-b: #c4a35a; --w-key-c: #c4a35a; --w-side: #c4a35a;
  --w-ring: #c4a35a; --w-ring-side: #c4a35a; --w-chev: #3a2e18;
  --w-ok-a: #c4a35a; --w-ok-b: #c4a35a; --w-ok-c: #c4a35a; --w-ok-side: #c4a35a; --w-ok-ink: #8a6420;
  --w-ink: #3a2e18; --w-power: #b83a2e; --w-light: #e8d08a; --w-dark: #8e6f2e; --w-hard: 0;
}

.tw[data-look="classic"] {
  --w-plate: #dbe1e8; --w-key-a: #f4f5f7; --w-key-b: #ebecf0; --w-key-c: #e1e5eb; --w-side: #ebecf0;
  --w-ring: #dbe1e8; --w-ring-side: #dbe1e8; --w-chev: #2b303a;
  --w-ok-a: #f4f5f7; --w-ok-b: #ebecf0; --w-ok-c: #e1e5eb; --w-ok-side: #ebecf0; --w-ok-ink: #0062d6;
  --w-ink: #2b303a; --w-power: #e5312b; --w-light: #ffffff; --w-dark: #a3b8cc; --w-hard: 0;
}

.tw-body {
  --pt: calc(100cqw / var(--ref));
  --gap: calc((8 - var(--w-hard) * 2) * var(--pt));
  display: flex;
  flex-direction: column;
  gap: calc(10 * var(--pt));
  height: 100%;
  padding: calc(16 * var(--pt));
  border-radius: calc(22 * var(--pt));
  background: var(--w-plate);
  color: var(--w-ink);
}

.tw--small .tw-body,
.tw--medium .tw-body { gap: calc(8 * var(--pt)); }

.tw-head {
  display: flex;
  align-items: center;
  gap: calc(10 * var(--pt));
  min-height: calc(18 * var(--pt));
}

.tw--large .tw-head { height: calc(40 * var(--pt)); }

.tw-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: calc(15 * var(--pt));
  font-weight: 700;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tw--small .tw-title { font-size: calc(13 * var(--pt)); }

/* A key: its cap is drawn on ::before (plastic with a side edge, or two soft shadows), the
   symbol on the face above it. */
.tw-key {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border-radius: calc(12 * var(--pt));
  cursor: pointer;
  transition: scale 0.18s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.tw-key::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, var(--w-key-a), var(--w-key-b) 55%, var(--w-key-c));
  box-shadow:
    0 calc(var(--w-hard) * 2.5 * var(--pt)) 0 var(--w-side),
    calc((1 - var(--w-hard)) * 2.5 * var(--pt)) calc((1 - var(--w-hard)) * 2.5 * var(--pt)) calc((1 - var(--w-hard)) * 6 * var(--pt)) var(--w-dark),
    calc((1 - var(--w-hard)) * -2 * var(--pt)) calc((1 - var(--w-hard)) * -2 * var(--pt)) calc((1 - var(--w-hard)) * 6 * var(--pt)) var(--w-light);
}

.tw-face {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: calc(13 * var(--pt));
  font-weight: 700;
}

.tw-face svg {
  width: calc(17 * var(--pt));
  height: calc(17 * var(--pt));
  fill: currentColor;
}

.tw-key--power { color: var(--w-power); }
.tw-key--head { flex: none; width: calc(40 * var(--pt)); height: calc(40 * var(--pt)); }

.tw-key.is-pressed { scale: 0.92; }

.tw-main {
  flex: 1;
  display: flex;
  gap: calc(8 * var(--pt));
  min-height: 0;
}

.tw-col {
  flex: none;
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  gap: var(--gap);
  width: calc(52 * var(--pt));
}

.tw-pad {
  position: relative;
  flex: 1;
  display: grid;
  grid-template: ". n ." minmax(0, 1fr) "w ok e" minmax(0, 1fr) ". s ." minmax(0, 1fr) / minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: calc((1 - var(--w-hard)) * 8 * var(--pt));
  padding: calc(4 * var(--pt));
}

.tw-ring {
  position: absolute;
  inset: 0;
  border-radius: calc(28 * var(--pt));
  background: var(--w-ring);
  box-shadow: 0 calc(3 * var(--pt)) 0 var(--w-ring-side);
  opacity: var(--w-hard);
}

.tw-key--arrow { color: var(--w-chev); }
.tw-key--arrow::before { opacity: calc(1 - var(--w-hard)); }
.tw-key--n { grid-area: n; }
.tw-key--s { grid-area: s; }
.tw-key--w { grid-area: w; }
.tw-key--e { grid-area: e; }

.tw-key--ok {
  grid-area: ok;
  place-self: center;
  width: calc(52 * var(--pt));
  height: calc(52 * var(--pt));
  border-radius: 50%;
  color: var(--w-ok-ink);
}

.tw-key--ok::before {
  background: linear-gradient(135deg, var(--w-ok-a), var(--w-ok-b) 55%, var(--w-ok-c));
  box-shadow:
    0 calc(var(--w-hard) * 2.5 * var(--pt)) 0 var(--w-ok-side),
    calc((1 - var(--w-hard)) * 2.5 * var(--pt)) calc((1 - var(--w-hard)) * 2.5 * var(--pt)) calc((1 - var(--w-hard)) * 6 * var(--pt)) var(--w-dark),
    calc((1 - var(--w-hard)) * -2 * var(--pt)) calc((1 - var(--w-hard)) * -2 * var(--pt)) calc((1 - var(--w-hard)) * 6 * var(--pt)) var(--w-light);
}

.tw-row {
  flex: 1;
  display: grid;
  grid-template: minmax(0, 1fr) / repeat(5, minmax(0, 1fr));
  gap: var(--gap);
  min-height: 0;
}

.tw-grid {
  flex: 1;
  display: grid;
  grid-template: repeat(2, minmax(0, 1fr)) / repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  min-height: 0;
}

.tw-apps {
  display: flex;
  justify-content: space-around;
  height: calc(46 * var(--pt));
}

.tw--medium .tw-apps { height: calc(34 * var(--pt)); }

.tw-app {
  flex: none;
  aspect-ratio: 1;
  height: 100%;
  border-radius: 29%;
}

.tw-app .tw-face {
  position: absolute;
  inset: 0;
  display: block;
  width: auto;
  height: auto;
  padding: 13%;
}

.tw-app img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.tw-app--fill .tw-face {
  padding: 0;
  overflow: hidden;
  border-radius: inherit;
}

.tw-app--fill img { object-fit: cover; }

/* The demo phone taps a few keys in turn, the way a thumb would. */
@media (prefers-reduced-motion: no-preference) {
  .tw--demo .tw-tap { animation: tw-tap 11s var(--ease) infinite; }
  .tw--demo .tw-tap--1 { animation-delay: 1.2s; }
  .tw--demo .tw-tap--2 { animation-delay: 3.8s; }
  .tw--demo .tw-tap--3 { animation-delay: 6.2s; }
  .tw--demo .tw-tap--4 { animation-delay: 8.6s; }

  .tw--demo .tw-tap::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: 0 0 0 calc(2 * var(--pt)) var(--w-ok-ink);
    opacity: 0;
    animation: tw-ring 11s var(--ease) infinite;
    animation-delay: inherit;
    pointer-events: none;
  }
}

@keyframes tw-tap {
  0%, 5%, 100% { scale: 1; }
  2% { scale: 0.9; }
}

@keyframes tw-ring {
  0%, 1.5% { opacity: 0; scale: 1; }
  2.5% { opacity: 0.8; scale: 1; }
  8% { opacity: 0; scale: 1.35; }
  100% { opacity: 0; scale: 1.35; }
}

/* The section: a phone's home screen with the widgets, and two more floating beside it. */

.widgets-stage {
  position: relative;
  display: flex;
  justify-content: center;
  margin-top: clamp(3.5rem, 7vw, 5.5rem);
}

.widgets-stage::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 8%;
  width: min(900px, 130vw);
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translateX(-50%);
  background: radial-gradient(circle, var(--glow) 0%, var(--glow-soft) 38%, var(--glow-none) 66%);
  pointer-events: none;
}

.widgets-phone {
  position: relative;
  z-index: 2;
  width: min(380px, 80vw);
}

.home {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  color: #fff;
  background: #0d1020;
}

.home-wall i {
  position: absolute;
  border-radius: 50%;
  filter: blur(8cqw);
}

.home-wall i:nth-child(1) { left: -30%; top: -10%; width: 110%; aspect-ratio: 1; background: #3b3f8f; }
.home-wall i:nth-child(2) { right: -40%; top: 30%; width: 120%; aspect-ratio: 1; background: #b0567a; }
.home-wall i:nth-child(3) { left: -20%; bottom: -30%; width: 120%; aspect-ratio: 1; background: #e09a52; }

.home-status {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 14cqw;
  padding: 1.4cqw 7cqw 0;
  font-size: 4.1cqw;
  font-weight: 600;
}

.home-status .app-battery { border-color: rgba(255, 255, 255, 0.6); }
.home-status .app-battery::before { background: #fff; }

.home-large {
  position: relative;
  width: 86.7cqw;
  margin-top: 3cqw;
}

.home-large .tw-body,
.home-small .tw-body,
.widgets-float .tw-body {
  box-shadow: 0 2cqw 6cqw -2cqw rgba(0, 0, 0, 0.45);
}

.home-row {
  position: relative;
  display: flex;
  gap: 5.6cqw;
  width: 86.7cqw;
  margin-top: 5.6cqw;
}

.home-small { width: 40.5cqw; }

.home-icons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7.6cqw;
  place-content: center;
  flex: 1;
}

.home-icons i,
.home-dock i {
  display: block;
  width: 16.4cqw;
  aspect-ratio: 1;
  border-radius: 23%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.home-icons i:nth-child(1) { background: linear-gradient(160deg, #6ee7a8, #1f9d63); }
.home-icons i:nth-child(2) { background: linear-gradient(160deg, #ffd36e, #f08a2c); }
.home-icons i:nth-child(3) { background: linear-gradient(160deg, #8fb8ff, #3a64e0); }
.home-icons i:nth-child(4) { background: linear-gradient(160deg, #f9f9fb, #c9ccd6); }

.home-dock {
  position: absolute;
  bottom: 3cqw;
  display: flex;
  gap: 5.4cqw;
  padding: 3.6cqw 4.6cqw;
  border-radius: 9cqw;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
}

.home-dock i:nth-child(1) { background: linear-gradient(160deg, #7ef08a, #22b14c); }
.home-dock i:nth-child(2) { background: linear-gradient(160deg, #7cc7ff, #1a7ff0); }
.home-dock i:nth-child(3) { background: linear-gradient(160deg, #ffffff, #dfe3ea); }
.home-dock i:nth-child(4) { background: linear-gradient(160deg, #ff8a8a, #ef3d4d); }

.widgets-float {
  position: absolute;
  z-index: 1;
  top: 22%;
  display: none;
}

.widgets-float--l {
  right: calc(50% + 205px);
  width: 330px;
  rotate: -4deg;
}

.widgets-float--r {
  left: calc(50% + 190px);
  top: 46%;
  width: 176px;
  rotate: 5deg;
}

@media (min-width: 1068px) {
  .widgets-float { display: block; }
}

@media (prefers-reduced-motion: no-preference) and (min-width: 1068px) {
  .widgets-float--l { translate: 0 calc(var(--p, 0) * -160px); }
  .widgets-float--r { translate: 0 calc(var(--p, 0) * 120px); }
}

/* A short hold: once the phone is centred it stays for --hold of scroll, then moves on. The
   floats keep drifting with --p and the theme keeps changing, so the pause never looks frozen.
   The phone is sized from the viewport height so the whole frame fits while it is held. */
@media (prefers-reduced-motion: no-preference) {
  .js .widgets-hold {
    --frame-h: calc(100svh - var(--nav-h) - env(safe-area-inset-top));
    --hold: 45vh;
    height: calc(var(--frame-h) + var(--hold));
    margin-top: clamp(1.5rem, 4vw, 3rem);
  }

  .js .widgets-frame {
    position: sticky;
    top: calc(var(--nav-h) + env(safe-area-inset-top));
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: var(--frame-h);
  }

  .js .widgets-frame .widgets-stage { margin-top: 0; }
  .js .widgets-frame .widgets-themes { margin-top: clamp(1.25rem, 3vh, 2.25rem); }

  .js .widgets-phone {
    width: min(380px, 80vw, calc((var(--frame-h) - 150px) * 0.478));
  }
}

.widgets-themes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: min(980px, calc(100% - 40px));
  margin: clamp(2.5rem, 5vw, 3.5rem) auto 0;
}

.widgets-theme {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--chip);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease), border-color 0.3s var(--ease);
}

.widgets-theme[aria-pressed="true"] {
  border-color: var(--contrast);
  background: var(--contrast);
  color: var(--on-contrast);
}

.widgets-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.widgets-swatch--default { background: conic-gradient(#e7a34a 0 25%, #14171e 0); }
.widgets-swatch--soft { background: linear-gradient(135deg, #ffffff, #a3b1c6); }
.widgets-swatch--graphite { background: linear-gradient(135deg, #454545, #1a1a1a); }
.widgets-swatch--gold { background: linear-gradient(135deg, #e8d08a, #8e6f2e); }
.widgets-swatch--classic { background: linear-gradient(135deg, #ffffff, #a3b8cc); }

.widgets .facts { margin-top: 2rem; }

/* Haptics
   One big hardware key. Without script it is a still with the captions in a row. With script,
   main.js adds .is-live: the stage pins for the length of .haptics-pin and the scroll through it
   goes to --hp (0 to 1). The key presses at set points, each sending rings and a waveform out of
   it (.is-buzz), then the switch flips off and the last press lands with nothing. A visitor can
   press the key and flip the switch at any time; on phones that can, the press is felt too. */

.haptics {
  --hp: 0.3;
  position: relative;
  padding-bottom: clamp(6rem, 12vw, 10rem);
  background: #07080b;
  color: #fff;
  --orb-1: rgba(231, 163, 74, 0.14);
  --orb-2: rgba(240, 160, 184, 0.08);
  --orb-3: rgba(126, 182, 255, 0.08);
}

.haptics-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: clamp(4rem, 9vw, 7rem);
}

.hscene {
  --s: clamp(150px, 20vw, 210px);
  --in: clamp(0, calc(var(--hp) / 0.14), 1);
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: min(50vh, 440px);
  min-height: calc(var(--s) * 1.9);
  perspective: 1100px;
}

.hring {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.hring i {
  grid-area: 1 / 1;
  width: var(--s);
  aspect-ratio: 1;
  border: 1.5px solid rgba(246, 194, 122, 0.85);
  border-radius: 30%;
  opacity: 0;
}

.hkey {
  --press: 0;
  position: relative;
  z-index: 2;
  width: var(--s);
  height: var(--s);
  padding: 0;
  border: 0;
  border-radius: 30%;
  background: none;
  color: #fff;
  font: inherit;
  cursor: pointer;
  transform: rotateX(calc(34deg - var(--in) * 22deg)) scale(calc(0.88 + var(--in) * 0.12));
  -webkit-tap-highlight-color: transparent;
}

.hkey:focus-visible {
  outline: 2px solid #f6c27a;
  outline-offset: 10px;
}

.hkey-cap {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(160deg, #f8c77f 0%, #e7a34a 52%, #c9842e 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -4px 10px rgba(110, 68, 20, 0.25),
    0 calc(2px + (1 - var(--press)) * 12px) 0 #8a5a1c,
    0 calc(36px - var(--press) * 18px) 70px -18px rgba(231, 163, 74, 0.6);
  translate: 0 calc(var(--press) * 12px);
}

.hkey-face {
  font-size: calc(var(--s) * 0.19);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 0 rgba(110, 68, 20, 0.35);
}

.hwave {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(620px, 92%);
  height: 80px;
  translate: -50% 0;
  overflow: visible;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hwave-base { stroke: rgba(255, 255, 255, 0.14); stroke-width: 1.5; }

.hwave-live {
  stroke: #f6c27a;
  stroke-width: 2;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  filter: drop-shadow(0 0 6px rgba(246, 194, 122, 0.7));
}

.hcontrols {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: clamp(1.25rem, 3vh, 2rem);
}

.js .hcontrols { display: flex; }

.hswitch {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 7px 18px 7px 7px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hswitch { position: relative; }

/* A transparent native switch over each target; iOS only plays its tap for a finger on a real switch.
   The key's pad lives while haptics are on and the toggle's while they're off, so only an
   "on" press is felt. */
.haptic-pad {
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  cursor: inherit;
  -webkit-tap-highlight-color: transparent;
}

.haptic-pad input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.haptics.is-off .hkey .haptic-pad,
.haptics:not(.is-off) .hswitch .haptic-pad { display: none; }

.hswitch-track {
  position: relative;
  width: 46px;
  height: 28px;
  border-radius: 99px;
  background: #e7a34a;
  transition: background-color 0.35s var(--ease);
}

.hswitch-track i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  translate: 18px 0;
  transition: translate 0.35s var(--ease);
}

.hswitch[aria-checked="false"] .hswitch-track { background: rgba(255, 255, 255, 0.2); }
.hswitch[aria-checked="false"] .hswitch-track i { translate: 0 0; }

.hhint {
  margin: 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.55);
}

.hhint-touch { display: none; }

@media (hover: none) and (pointer: coarse) {
  .hhint-touch { display: inline; }
  .hhint-pointer { display: none; }
}

.haptics.is-off .hkey-cap {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -4px 10px rgba(110, 68, 20, 0.25),
    0 calc(2px + (1 - var(--press)) * 12px) 0 #8a5a1c,
    0 calc(36px - var(--press) * 18px) 70px -18px rgba(231, 163, 74, 0.2);
}

.hbeat--2 { color: #f6c27a; }

@media (prefers-reduced-motion: no-preference) {
  .js .haptics.is-live .haptics-pin { height: 320vh; }

  .js .haptics.is-live .haptics-stage {
    position: sticky;
    top: calc(var(--nav-h) + env(safe-area-inset-top));
    justify-content: center;
    height: calc(100svh - var(--nav-h) - env(safe-area-inset-top));
    padding-top: 0;
  }

  .js .haptics.is-live .hscene { height: min(42vh, 400px); }

  .js .haptics.is-live .hbeats {
    display: grid;
    margin-top: 1rem;
    min-height: 2.4em;
  }

  .js .haptics.is-live .hbeat {
    --o: clamp(0, min(calc((var(--hp) - var(--a)) * 16), calc((var(--b) - var(--hp)) * 16)), 1);
    grid-area: 1 / 1;
    opacity: var(--o);
    filter: blur(calc((1 - var(--o)) * 8px));
    translate: 0 calc((1 - var(--o)) * 14px);
  }

  .hbeat--1 { --a: 0.06; --b: 0.3; }
  .hbeat--2 { --a: 0.32; --b: 0.56; }
  .hbeat--3 { --a: 0.6; --b: 0.94; }

  .hkey.is-press { animation: vpress 0.32s var(--ease); }
  .haptics.is-buzz:not(.is-off) .hkey-cap { animation: hshake 0.22s linear; }
  .haptics.is-buzz:not(.is-off) .hring i { animation: hring 1.1s var(--ease) both; }
  .haptics.is-buzz:not(.is-off) .hring i:nth-child(2) { animation-delay: 0.09s; }
  .haptics.is-buzz:not(.is-off) .hring i:nth-child(3) { animation-delay: 0.18s; }
  .haptics.is-buzz:not(.is-off) .hwave-live { animation: hwave 1.2s var(--ease) both; }
}

@keyframes hring {
  from { opacity: 0.9; scale: 1; }
  to { opacity: 0; scale: 2; }
}

@keyframes hwave {
  0% { stroke-dashoffset: 1; opacity: 1; }
  45% { stroke-dashoffset: 0; opacity: 1; }
  100% { stroke-dashoffset: 0; opacity: 0; }
}

@keyframes hshake {
  0%, 100% { rotate: 0deg; }
  25% { rotate: -1.4deg; }
  50% { rotate: 1.2deg; }
  75% { rotate: -0.6deg; }
}
