/* Home page recommendations chat, dressed as iOS Messages inside an iPhone.
   Theirs are gray bubbles on the left with name + avatar; mine are blue on the
   right with no avatar. I react to each of theirs with an emoji tapback.
   Loaded on top of style.css. The frame is drawn with box-shadow, not borders:
   .mainHome *:not(a) forces every border-color to var(--border). */

.iosPhone {
  --ios-bezel: 11px;
  --ios-radius: 58px;
  --ios-rim: #d7d9de;
  --ios-gray: #e9e9eb;
  --ios-blue: #0070f0; /* iMessage blue, deepened just enough for AA white text */
  --ios-label: #6c6c70;
  position: relative;
  box-sizing: border-box;
  width: min(380px, 100%, max(300px, calc(86vh * 9 / 19.5)));
  width: min(380px, 100%, max(300px, calc(86svh * 9 / 19.5)));
  aspect-ratio: 9 / 19.5;
  margin: 32px auto 8px;
  padding: var(--ios-bezel);
  border-radius: var(--ios-radius);
  background: #0b0b0d;
  box-shadow:
    0 0 0 3px var(--ios-rim),
    0 0 0 4px #b8bbc2,
    0 40px 80px -30px rgba(5, 0, 56, 0.4),
    0 16px 32px -16px rgba(5, 0, 56, 0.25);
}

/* Side buttons: volume up / down on the left, power on the right. */
.iosPhone::before,
.iosPhone::after {
  content: "";
  position: absolute;
  width: 3px;
  border-radius: 2px;
  background: #b8bbc2;
}

.iosPhone::before {
  left: -7px;
  top: 22%;
  height: 44px;
  box-shadow: 0 56px 0 #b8bbc2;
}

.iosPhone::after {
  right: -7px;
  top: 28%;
  height: 72px;
}

.iosPhone__screen {
  /* The keyboard is exactly as tall as its keys: four rows, the gaps under
     them and the emoji / dictation strip. The composer and thread lift by the
     same sum, so they always land 6px above it (the composer rests 26px up). */
  --kb-key-h: 11cqi;
  --kb-row-gap: 2.8cqi;
  --kb-pad-top: 2.4cqi;
  --kb-dock-h: 12cqi;
  --kb-h: calc(var(--kb-pad-top) + 4 * (var(--kb-key-h) + var(--kb-row-gap)) + var(--kb-dock-h));
  --kb-shift: calc(var(--kb-h) - 20px);
  --kb-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  position: relative;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
  border-radius: calc(var(--ios-radius) - var(--ios-bezel));
  container-type: inline-size;
  background: #fff;
  color: #000;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Liquid Glass: the top and bottom bars float over the thread, which fades and
   blurs as it slides beneath them. */
.iosPhone__screen::before,
.iosPhone__screen::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
  pointer-events: none;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.iosPhone__screen::before {
  top: 0;
  height: 152px; /* solid down to the name pill, then fades */
  background: linear-gradient(to bottom, #fff 76%, rgba(255, 255, 255, 0));
  -webkit-mask-image: linear-gradient(to bottom, #000 78%, transparent);
  mask-image: linear-gradient(to bottom, #000 78%, transparent);
}

/* No taller than the thread's bottom padding (76px), or the newest bubble
   sits half under the frost with its lower edge cut and smeared. */
.iosPhone__screen::after {
  bottom: 0;
  height: 76px;
  background: linear-gradient(to top, #fff 45%, rgba(255, 255, 255, 0));
  -webkit-mask-image: linear-gradient(to top, #000 55%, transparent);
  mask-image: linear-gradient(to top, #000 55%, transparent);
}

/* Status bar */
.iosPhone__status {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 22px 0 34px;
  box-sizing: border-box;
}

.iosPhone__time {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.iosPhone__island {
  position: absolute;
  top: 11px;
  left: 50%;
  width: 30%; /* leaves the right "ear" room for signal, wifi and battery */
  height: 32px;
  border-radius: 20px;
  background: #000;
  transform: translateX(-50%);
}

.iosPhone__icons {
  display: flex;
  align-items: center;
  gap: 4px;
}

.iosPhone__icons svg {
  display: block;
  fill: currentColor;
}

/* Navigation: glass back / video buttons around the group avatar + name pill. */
.iosPhone__nav {
  position: absolute;
  top: 50px;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0 14px;
}

.iosPhone__navBtn,
.iosPhone__plus {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-top: 4px;
  border-radius: 50%;
  color: #1c1c1e;
  background: rgba(255, 255, 255, 0.78);
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.06),
    0 2px 10px rgba(0, 0, 0, 0.1);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.iosPhone__navBtn svg,
.iosPhone__plus svg {
  display: block;
}

.iosPhone__contact {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.iosPhone__groupAvatar {
  position: relative;
  display: block;
  width: 50px;
  height: 46px;
}

.iosPhone .iosPhone__groupAvatar .sprite.recommendationimage.rec-sprite {
  --rec-display: 26px;
  position: absolute;
  margin: 0;
  opacity: 1;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #fff;
}

.iosPhone .iosPhone__groupAvatar .sprite.recommendationimage.rec-sprite:nth-child(1) {
  --rec-display: 28px;
  left: 0;
  top: 16px;
}

/* Each face tucks a few pixels under its neighbour, like iOS's group cluster. */
.iosPhone .iosPhone__groupAvatar .sprite.recommendationimage.rec-sprite:nth-child(2) {
  left: 24px;
  top: 18px;
}

.iosPhone .iosPhone__groupAvatar .sprite.recommendationimage.rec-sprite:nth-child(3) {
  --rec-display: 24px;
  left: 13px;
  top: 2px;
}

.iosPhone__name {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: -2px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.85);
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.06),
    0 2px 10px rgba(0, 0, 0, 0.1);
}

.iosPhone__name svg {
  color: var(--ios-label);
}

/* Composer */
.iosPhone__composer {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 26px;
  z-index: 3;
  display: flex;
  align-items: flex-end; /* the + stays on the bottom line when the field grows */
  gap: 8px;
  transition: transform 0.4s var(--kb-ease);
}

.iosPhone__screen.is-typing .iosPhone__composer {
  transform: translateY(calc(-1 * var(--kb-shift)));
}

.iosPhone__plus {
  flex: none;
  width: 38px;
  height: 38px;
  margin: 0;
}

/* One line tall here. When the draft wraps, scriptHome-chat-reply.js sets the
   height to fit it, and the field grows upward from the keyboard. */
.iosPhone__field {
  flex: 1;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  height: 38px;
  padding: 0 8px 0 14px;
  border-radius: 19px; /* a pill at one line, the same corners at two or three */
  overflow: hidden;
  transition: height 0.22s var(--kb-ease);
  font-size: 16px;
  color: #a1a1a6;
  background: rgba(255, 255, 255, 0.85);
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.08),
    0 2px 10px rgba(0, 0, 0, 0.08);
  min-width: 0;
  gap: 4px;
}

.iosPhone__placeholder {
  flex: 1;
  color: #a1a1a6;
}

/* The draft and its caret flow as one run of text, so the caret follows the
   last character onto a new line. Pinned to the bottom of the field: while the
   field is still growing, the line being typed is the one in view. */
.iosPhone__input {
  display: none;
  flex: 1;
  align-self: flex-end;
  min-width: 0;
  padding: 8px 0 9px; /* with the 21px line: 38px, the one-line field */
  line-height: 21px;
  color: #000;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.iosPhone__screen.is-typing .iosPhone__input,
.iosPhone__field.has-draft .iosPhone__input {
  display: block;
}

.iosPhone__caret {
  display: none;
  width: 2px;
  height: 19px;
  margin: -2px 0 -2px 1px; /* never taller than the line it sits on */
  vertical-align: -3px;
  background: var(--ios-blue);
  border-radius: 1px;
}

.iosPhone__screen.is-typing .iosPhone__caret {
  display: inline-block;
  animation: iosCaretBlink 1s steps(1) infinite;
}

@keyframes iosCaretBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.iosPhone__field > svg {
  flex: none;
  margin-left: auto;
  fill: #8e8e93;
  color: #8e8e93;
}

.iosPhone__send {
  display: none;
  flex: none;
  align-self: flex-end; /* on the last line of a wrapped draft */
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-bottom: 5px;
  margin-left: auto;
  border-radius: 50%;
  background: var(--ios-blue);
}

.iosPhone__send svg {
  display: block;
}

.iosPhone__send.is-pressed {
  transform: scale(0.85);
}

.iosPhone__field.has-draft .iosPhone__placeholder,
.iosPhone__screen.is-typing .iosPhone__placeholder,
.iosPhone__field.has-draft > svg {
  display: none;
}

.iosPhone__field.has-draft .iosPhone__send {
  display: flex;
}

.iosPhone__homeBar {
  position: absolute;
  left: 50%;
  bottom: 8px;
  z-index: 5;
  width: 36%;
  height: 5px;
  border-radius: 3px;
  background: #000;
  transform: translateX(-50%);
}

/* Thread. The wrapper is the scroller; column-reverse keeps it pinned to the
   newest message and packs a short thread against the composer. */
.iosPhone .chat-wrapper {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: auto;
  height: auto;
  max-height: none;
  margin: 0;
  border: 0;
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  overflow-y: auto;
  scrollbar-width: none;
}

.iosPhone .chat-wrapper::-webkit-scrollbar {
  display: none;
}

.iosPhone .chat-container {
  order: -1; /* first in column-reverse = bottom */
  flex: none;
  box-sizing: border-box;
  width: 100%;
  max-width: none;
  max-height: none;
  overflow: visible;
  padding: 0 12px 76px;
  background: none;
  transition: transform 0.4s var(--kb-ease);
}

/* --composer-grow is what a wrapped draft adds to the field (set by the
   script), so the newest bubble keeps its distance from the composer. */
.iosPhone__screen.is-typing .chat-container {
  transform: translateY(calc(-1 * (var(--kb-shift) + var(--composer-grow, 0px))));
}

.iosPhone__stamp {
  flex: none;
  margin: 118px 0 12px;
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
  color: var(--ios-label);
}

.iosPhone__stamp strong {
  font-weight: 600;
}

/* Their messages: name above, avatar beside the bubble's lower-left corner.
   The gap has to clear the bubble's tail: its white mask reaches 10px left of
   the bubble, and at 8px it shaved the avatar's lower-right edge. */
.iosPhone .chat-container .singlerecomendation {
  display: grid;
  grid-template-columns: 28px minmax(0, max-content) minmax(0, 1fr);
  column-gap: 12px;
  align-items: end;
  box-sizing: border-box;
  width: 100%;
  max-width: none;
  margin: 0 0 10px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  /* iOS body text is 17pt on a 393pt screen; follow the phone's width, but
     never so small that the testimonials get hard to read. */
  font-size: calc(clamp(14px, 4.4cqi, 16px) * var(--ds-font-scale, 1));
}

.iosPhone .chat-container .sprite.recommendationimage.rec-sprite {
  --rec-display: 28px;
  grid-column: 1;
  grid-row: 2;
  margin: 0;
  opacity: 1;
  border-radius: 50%;
}

.iosPhone .chat-container .recommendationAuthor,
.iosPhone .chat-container .recommendationAuthorRole {
  grid-row: 1;
  margin: 0;
  padding: 0 0 3px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--ios-label);
  opacity: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.iosPhone .chat-container .recommendationAuthor {
  grid-column: 2;
  width: auto;
  padding-left: 12px;
}

.iosPhone .chat-container .recommendationAuthorRole {
  grid-column: 3;
  margin-left: -5px; /* sit right after the name, not a column-gap away */
  padding-right: 40px; /* clear of the tapback on the bubble's top-right corner */
}

.iosPhone .chat-container .recommendationAuthorRole::before {
  content: "· ";
}

.iosPhone .chat-container .recommendation {
  grid-column: 2 / -1;
  grid-row: 2;
  justify-self: start;
  box-sizing: border-box;
  max-width: calc(100% - 24px);
  padding: 7px 12px;
  border-radius: 18px;
  font-family: inherit;
  font-size: 1em;
  line-height: 1.3;
  color: #000;
  background-color: var(--ios-gray);
}

/* Bubble tails: a coloured wedge (::before) trimmed by a screen-white mask (::after). */
.iosPhone .chat-container .recommendation::before {
  border-left-color: var(--ios-gray);
}

.iosPhone .chat-container .recommendation::after {
  background-color: #fff;
}

/* style.css hides the tail of whichever bubble is newest, so it used to pop
   in only once the next message arrived. A sent bubble has its tail at once. */
.iosPhone .chat-container .singlerecomendation.is-sent:first-child .recommendation:not(.bigEmoji):not(.funGif)::before,
.iosPhone .chat-container .singlerecomendation.is-sent:first-child .recommendation:not(.bigEmoji):not(.funGif)::after {
  display: block;
}

/* My replies: blue, right-aligned, no avatar or name. */
.iosPhone .chat-container .singlerecomendation.myreply {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding-left: 48px;
}

.myReplyStack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  width: 100%;
  min-width: 0;
}

.iosPhone .chat-container .myreply .recommendation {
  max-width: 100%;
  color: #fff;
  background-color: var(--ios-blue);
}

.iosPhone .chat-container .myreply .recommendation::before {
  border-left: none;
  border-right: 1rem solid var(--ios-blue);
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0.8rem 0.7rem;
  left: auto;
  right: -0.35rem;
}

.iosPhone .chat-container .myreply .recommendation::after {
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0.5rem;
  left: auto;
  right: 20px;
  transform: translate(30px, -2px);
}

/* Giant emoji sits above the worded bubble, no bubble. */
.iosPhone .chat-container .myreply .recommendation.bigEmoji {
  padding: 0;
  margin-bottom: 4px;
  font-size: 4em;
  line-height: 1;
  color: inherit;
  background: none;
  filter: grayscale(1);
}

/* Reaction GIF replies: just the image.
   .funGifMedia escapes .colleaguesContainer img (max-width / opacity / grayscale). */
.iosPhone .chat-container .myreply .recommendation.funGif {
  max-width: min(200px, 100%);
  padding: 0;
  overflow: hidden;
  background: none;
}

.myreply .recommendation.funGif .funGifMedia {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  border-radius: 18px;
  opacity: 1;
  filter: grayscale(1);
}

.iosPhone .chat-container .myreply .recommendation.bigEmoji::before,
.iosPhone .chat-container .myreply .recommendation.bigEmoji::after,
.iosPhone .chat-container .myreply .recommendation.funGif::before,
.iosPhone .chat-container .myreply .recommendation.funGif::after {
  display: none;
}

/* A reply I just sent rises out of the composer. */
.iosPhone .chat-container .myreply.is-new .myReplyStack {
  transform-origin: 100% 100%;
  animation: iosBubbleSend 0.28s var(--kb-ease) backwards;
}

@keyframes iosBubbleSend {
  from { transform: translateY(14px) scale(0.92); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .iosPhone .chat-container .myreply.is-new .myReplyStack {
    animation: none;
  }
}

/* Tapbacks: my emoji reaction sits on the top-right corner of their bubble,
   in blue, with the two little tail dots pointing back at the message. Added
   by scriptHome-chat-reply.js a beat after the message lands. */
.iosTapback {
  position: absolute;
  top: -17px;
  right: -17px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
  background: var(--ios-blue);
  box-shadow: 0 0 0 2px #fff;
  transform-origin: 20% 100%;
  transition: opacity 0.2s ease;
  pointer-events: none;
  user-select: none;
}

/* Under the frosted top bar a tapback blurs into a blue smudge, so it steps
   out before it gets there (scriptHome-chat-reply.js watches for it). Opacity
   only: resizing the badge would move the box being watched, and it would
   flicker in and out at the bar's edge. */
.iosTapback.is-tucked {
  opacity: 0;
}

.iosTapback::before,
.iosTapback::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: inherit;
}

.iosTapback::before {
  width: 9px;
  height: 9px;
  bottom: -1px;
  left: 1px;
}

.iosTapback::after {
  width: 4px;
  height: 4px;
  bottom: -6px;
  left: -3px;
}

/* Fills backwards only: held forwards, the animation would pin opacity at 1
   and .is-tucked could never hide the badge. */
.iosTapback.is-new {
  animation: iosTapbackPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

@keyframes iosTapbackPop {
  from { transform: scale(0); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .iosTapback {
    transition: none;
  }

  .iosTapback.is-new {
    animation: none;
  }
}

/* Typing. Unsent colleague messages show as dots. My replies are only
   inserted once sent, so they never need a hidden-first-child rule.
   style.css has an older rule that draws whichever bubble is newest as a
   typing GIF unless it carries .last-recomendation; the script puts that
   class on every sent bubble, so only the rules below decide who is typing. */
.iosPhone .chat-container .singlerecomendation:first-child:not(.is-sent) .recommendationAuthor,
.iosPhone .chat-container .singlerecomendation:first-child:not(.is-sent) .recommendationAuthorRole {
  display: none;
}

.iosPhone .chat-container .singlerecomendation:first-child:not(.is-sent) .recommendation:not(.last-recomendation) {
  width: 60px !important;
  height: 38px !important;
  padding: 0;
  overflow: hidden;
  color: transparent;
  background: var(--ios-gray);
}

.iosPhone .chat-container .singlerecomendation:first-child:not(.is-sent) .recommendation:not(.last-recomendation)::after {
  display: block;
  top: 50%;
  bottom: auto;
  left: 13px;
  right: auto;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-radius: 50%;
  transform: none;
  animation: iosTyping 1.2s ease-in-out infinite;
}

@keyframes iosTyping {
  0%, 100% { background-color: #7c7c80; box-shadow: 13px 0 0 #b5b5ba, 26px 0 0 #b5b5ba; }
  33%      { background-color: #b5b5ba; box-shadow: 13px 0 0 #7c7c80, 26px 0 0 #b5b5ba; }
  66%      { background-color: #b5b5ba; box-shadow: 13px 0 0 #b5b5ba, 26px 0 0 #7c7c80; }
}

@media (prefers-reduced-motion: reduce) {
  .iosPhone .chat-container .singlerecomendation:first-child:not(.is-sent) .recommendation:not(.last-recomendation)::after {
    animation: none;
    background-color: #8e8e93;
    box-shadow: 13px 0 0 #8e8e93, 26px 0 0 #8e8e93;
  }
}

/* Fake keyboard. Built on first text reply; slides up while typing. Laid out
   top-down from the --kb-* sizes on .iosPhone__screen: four key rows, then
   the emoji / dictation strip that sits around the home bar. */
.iosKeyboard {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  box-sizing: border-box;
  height: var(--kb-h);
  padding: var(--kb-pad-top) 0.9cqi 0;
  display: flex;
  flex-direction: column;
  gap: var(--kb-row-gap);
  background: rgba(209, 212, 219, 0.92);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  transform: translateY(100%);
  transition: transform 0.4s var(--kb-ease);
  pointer-events: none;
  user-select: none;
}

.iosPhone__screen.is-typing .iosKeyboard {
  transform: none;
  will-change: transform;
}

.iosPhone__screen.is-typing::after {
  opacity: 0;
}

/* Ten keys and nine gaps come to 97.5cqi, inside the 98.2cqi the padding
   leaves, so the top row never spills past the screen edge. */
.iosKeyboard__row {
  flex: none;
  display: flex;
  justify-content: center;
  gap: 1.5cqi;
  height: var(--kb-key-h);
}

.iosKeyboard__key {
  position: relative;
  flex: 0 0 8.4cqi;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 1.5cqi;
  background: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
  font-size: 5.6cqi;
  font-weight: 400;
  color: #000;
  text-transform: none;
}

.iosKeyboard__key--fn {
  background: #abb0bc;
  flex-basis: 11.2cqi;
  font-size: 4cqi;
  font-weight: 400;
}

/* Shift and delete stand a little apart from the letters, as on iOS. */
.iosKeyboard__key--shift {
  margin-right: auto;
}

.iosKeyboard__key--back {
  margin-left: auto;
}

.iosKeyboard__key--wide {
  flex-basis: 23cqi;
}

.iosKeyboard__key--space {
  flex: 1 1 auto;
  font-size: 4cqi;
  text-transform: capitalize;
}

.iosKeyboard__key svg {
  display: block;
  width: 55%;
  height: auto;
}

/* Emoji and dictation, either side of the home bar. */
.iosKeyboard__dock {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  height: var(--kb-dock-h);
  padding: 0 6.5cqi;
  color: #50555c;
}

.iosKeyboard__dockBtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 7.4cqi;
  height: 7.4cqi;
  border-radius: 50%;
}

.iosKeyboard__dockBtn svg {
  display: block;
  width: 86%;
  height: 86%;
}

.iosKeyboard__dockBtn.is-pressed {
  background: rgba(0, 0, 0, 0.14);
}

.iosKeyboard__key.is-pressed {
  background: #abb0bc;
}

.iosKeyboard__key--fn.is-pressed,
.iosKeyboard__key--space.is-pressed {
  background: #fff;
}

/* The pressed letter balloons out of its own key. It rises only a few pixels
   past the key's top edge, so the top row never flashes over the draft in the
   composer just above the keyboard. */
.iosKeyboard__key[data-label].is-pressed::after {
  content: attr(data-label);
  position: absolute;
  left: 50%;
  bottom: 25%;
  z-index: 2;
  box-sizing: border-box;
  width: 13cqi;
  height: 13cqi;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2cqi;
  background: #fff;
  box-shadow:
    0 1px 0 rgba(0, 0, 0, 0.25),
    0 2px 8px rgba(0, 0, 0, 0.18);
  font-size: 7.6cqi;
  font-weight: 400;
  color: #000;
  transform: translateX(-50%);
  pointer-events: none;
}

/* The corner keys' pop-ups lean inward instead of running off the screen. */
.iosKeyboard__key[data-key="q"].is-pressed::after {
  left: 0;
  transform: none;
}

.iosKeyboard__key[data-key="p"].is-pressed::after {
  left: auto;
  right: 0;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .iosKeyboard,
  .iosPhone__composer,
  .iosPhone__field,
  .iosPhone .chat-container {
    transition: none;
  }

  .iosPhone__screen.is-typing .iosPhone__caret {
    animation: none;
    opacity: 1;
  }
}

/* The track spans the section at every size. Without a width it shrinks to its
   content inside the centred flex column, and the phone (sized as a % of it)
   collapses to its bezel. */
.iosPhoneTrack {
  box-sizing: border-box;
  width: 100%;
}

/* Desktop: phone sticks while the track scrolls ~3× its height. Height mirrors
   .iosPhone's width formula × aspect-ratio 9/19.5. Only where the whole phone
   fits in the window: phones, landscape phones and short windows scroll past
   it normally. */
@media only screen and (min-width: 769px) and (min-height: 700px) {
  .iosPhoneTrack {
    --ios-phone-h: min(
      calc(380px * 19.5 / 9),
      max(calc(300px * 19.5 / 9), 86svh)
    );
    height: calc(var(--ios-phone-h) * 3);
  }

  .iosPhoneTrack .iosPhone {
    position: sticky;
    top: max(16px, calc((100svh - var(--ios-phone-h)) / 2));
    margin-top: 0;
    margin-bottom: 0;
  }
}

/* Phones: a slimmer bezel so the screen gets the width. */
@media only screen and (max-width: 768px) {
  .iosPhone {
    --ios-bezel: 7px;
    --ios-radius: 48px;
    margin-top: 24px;
    box-shadow:
      0 0 0 2px var(--ios-rim),
      0 0 0 3px #b8bbc2,
      0 24px 48px -24px rgba(5, 0, 56, 0.35);
  }

  .iosPhone::before,
  .iosPhone::after {
    display: none;
  }
}

/* Touch screens: the thread doesn't scroll on its own, so a swipe over the
   phone always moves the page instead of getting caught inside it. It still
   shows the newest messages, since column-reverse starts at the bottom. */
@media only screen and (max-width: 768px), (pointer: coarse) {
  .iosPhone .chat-wrapper {
    overflow: hidden;
  }
}

/* ==========================================================================
   iPhone Duo. On wide windows the phone unfolds into the foldable: two hinged
   leaves, Split View, Messages on the right and a second app on the left that
   ios-duo.js keeps busy (its app styles are in ios-duo.css, loaded with it).

   Three sizes:
     under 1120px wide (or under 700px tall)  the single iPhone above
     1120px to 1280px                         the Duo, folding at the hinge as
                                              the window narrows (26° at 1120px)
     1280px and wider                         the Duo, flat

   The leaves are siblings so each can turn on the hinge. On the single phone
   the left one is hidden and the right one is just a full-height wrapper. */
.iosPhone__leaf--left,
.iosPhone__shade,
.iosPhone__icons .iosPhone__ring {
  display: none;
}

.iosPhone__leaf--right {
  height: 100%;
}

@media only screen and (min-width: 1120px) and (min-height: 700px) {
  @supports (rotate: atan2(1px, 1px)) {
    /* Wider than the recommendations column: the track is centred on it and
       overflows both sides evenly. The 316px keeps it clear of the canvas rails
       and the video tour bubble (150px a side, plus a scrollbar). Proportions
       are the real device's, 164.6 × 117.8 mm unfolded. */
    .iosPhoneTrack {
      --duo-w: min(1040px, calc(100vw - 316px), calc(86svh * 1.397));
      --duo-h: calc(var(--duo-w) / 1.397);
      --ios-phone-h: var(--duo-h);
      /* 0 from 1280px up, 1 at 1120px. tan(atan2()) divides two lengths. */
      --duo-fold-n: clamp(0, tan(atan2(1280px - 100vw, 160px)), 1);
      --duo-fold: calc(var(--duo-fold-n) * 26deg);
      flex: none;
      align-self: flex-start;
      width: var(--duo-w);
      margin-left: calc((100% - var(--duo-w)) / 2);
    }

    .iosPhoneTrack .iosPhone {
      --duo-R: calc(var(--duo-w) * 0.066);
      --duo-b: calc(var(--duo-w) * 0.012 + 3px);
      --duo-gap: calc(var(--duo-w) * 0.011);
      --duo-ro: calc(var(--duo-R) - var(--duo-b));
      --duo-ri: calc(var(--duo-R) * 0.3);
      --duo-in: 0.6; /* arrives a little closed (0.6 × 26°), opens once in view */
      display: flex;
      width: 100%;
      aspect-ratio: 1.397;
      padding: 0;
      border-radius: 0;
      background: none;
      box-shadow: none;
      perspective: calc(var(--duo-w) * 2.6);
    }

    .iosPhoneTrack .iosPhone.is-unfolded {
      --duo-in: 0;
    }

    .iosPhoneTrack .iosPhone::before,
    .iosPhoneTrack .iosPhone::after {
      display: none;
    }

    /* A leaf: polished titanium rim (the background), black bezel (::before),
       then the display. No rim or bezel along the hinge. */
    .iosPhone__leaf {
      position: relative;
      display: block;
      flex: 1 1 0;
      min-width: 0;
      height: auto;
      box-sizing: border-box;
      padding: var(--duo-b);
      background: linear-gradient(180deg, #f6f7f9, #c4c7ce 14%, #eceef1 46%, #b4b8c0 84%, #dfe1e6);
      box-shadow:
        0 40px 80px -30px rgba(5, 0, 56, 0.4),
        0 16px 32px -16px rgba(5, 0, 56, 0.25);
      transition: transform 1.1s cubic-bezier(0.2, 0.8, 0.2, 1);
    }

    .iosPhone__leaf::before {
      content: "";
      position: absolute;
      top: 3px;
      right: 3px;
      bottom: 3px;
      left: 3px;
      background: #0b0b0d;
    }

    .iosPhone__leaf--left {
      z-index: 1; /* over the other leaf's shadow */
      padding-right: calc(var(--duo-gap) / 2);
      border-radius: var(--duo-R) 0 0 var(--duo-R);
      transform-origin: 100% 50%;
      transform: rotateY(calc(var(--duo-fold) + var(--duo-in) * 26deg));
    }

    .iosPhone__leaf--left::before {
      right: 0;
      border-radius: calc(var(--duo-R) - 3px) 0 0 calc(var(--duo-R) - 3px);
    }

    /* Split View's grabber, in the gutter between the two apps. */
    .iosPhone__leaf--left::after {
      content: "";
      position: absolute;
      top: 46.5%;
      right: -2px;
      z-index: 2;
      width: 4px;
      height: 7%;
      border-radius: 2px;
      background: rgba(255, 255, 255, 0.72);
    }

    .iosPhone__leaf--right {
      padding-left: calc(var(--duo-gap) / 2);
      border-radius: 0 var(--duo-R) var(--duo-R) 0;
      transform-origin: 0 50%;
      transform: rotateY(calc(-1 * (var(--duo-fold) + var(--duo-in) * 26deg)));
    }

    .iosPhone__leaf--right::before {
      left: 0;
      border-radius: 0 calc(var(--duo-R) - 3px) calc(var(--duo-R) - 3px) 0;
    }

    /* Hardware: two buttons on the top edge, the Touch ID button on the side. */
    .iosPhone__leaf--right::after {
      content: "";
      position: absolute;
      top: -3px;
      right: -3px;
      width: 60%;
      height: 60%;
      pointer-events: none;
      background:
        linear-gradient(#b8bbc2, #b8bbc2) 42% 0 / 10% 3px no-repeat,
        linear-gradient(#b8bbc2, #b8bbc2) 60% 0 / 10% 3px no-repeat,
        linear-gradient(#b8bbc2, #b8bbc2) 100% 58% / 3px 27% no-repeat;
    }

    /* The two apps. Outer corners follow the display, inner ones are tighter. */
    .iosDuo {
      --kb-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
      position: relative;
      z-index: 1;
      height: 100%;
      overflow: hidden;
      isolation: isolate;
      container-type: size;
      border-radius: var(--duo-ro) var(--duo-ri) var(--duo-ri) var(--duo-ro);
      color: #000;
      font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
      -webkit-font-smoothing: antialiased;
      /* Wallpaper: a pale sky over three dunes, after the Duo's default. */
      background:
        radial-gradient(130% 52% at 20% 116%, #bfa377 0 40%, rgba(191, 163, 119, 0) 47%),
        radial-gradient(120% 48% at 98% 110%, #cfb98f 0 42%, rgba(207, 185, 143, 0) 50%),
        radial-gradient(150% 42% at 42% 102%, #dccba9 0 44%, rgba(220, 203, 169, 0) 54%),
        linear-gradient(180deg, #7ea3cf 0%, #a9c3df 46%, #d3d6d2 78%);
    }

    .iosPhone__leaf--right .iosPhone__screen {
      z-index: 1;
      border-radius: var(--duo-ri) var(--duo-ro) var(--duo-ro) var(--duo-ri);
    }

    /* The light on a folded display, as in Apple's own pictures of it: the
       leaf turned from the light sits a shade darker all over, both darken in
       a soft band running into the hinge, and the far leaf catches a thin
       highlight just past it. It fades in with the fold and is gone when flat,
       where Split View's gutter covers the crease anyway. */
    .iosPhone__shade {
      position: absolute;
      top: var(--duo-b);
      bottom: var(--duo-b);
      z-index: 2;
      display: block;
      pointer-events: none;
      opacity: calc(var(--duo-fold-n) + var(--duo-in));
      transition: opacity 1.1s cubic-bezier(0.2, 0.8, 0.2, 1);
    }

    .iosPhone__leaf--left .iosPhone__shade {
      left: var(--duo-b);
      right: calc(var(--duo-gap) / 2);
      border-radius: var(--duo-ro) var(--duo-ri) var(--duo-ri) var(--duo-ro);
      background: linear-gradient(90deg, rgba(8, 12, 30, 0.07), rgba(8, 12, 30, 0.08) 62%, rgba(8, 12, 30, 0.2) 90%, rgba(8, 12, 30, 0.34));
    }

    .iosPhone__leaf--right .iosPhone__shade {
      left: calc(var(--duo-gap) / 2);
      right: var(--duo-b);
      border-radius: var(--duo-ri) var(--duo-ro) var(--duo-ro) var(--duo-ri);
      background: linear-gradient(90deg, rgba(8, 12, 30, 0.22), rgba(255, 255, 255, 0.5) 2.4%, rgba(255, 255, 255, 0) 7%, rgba(8, 12, 30, 0.05) 12%, rgba(8, 12, 30, 0) 30%);
    }

    /* A half-display is squat, so the keyboard is shorter than a phone's. */
    .iosDuo,
    .iosPhone__leaf--right .iosPhone__screen {
      --kb-key-h: 8cqi;
      --kb-row-gap: 2.2cqi;
      --kb-pad-top: 2cqi;
      --kb-dock-h: 7.4cqi;
      --kb-h: calc(var(--kb-pad-top) + 4 * (var(--kb-key-h) + var(--kb-row-gap)) + var(--kb-dock-h));
      --kb-shift: calc(var(--kb-h) - 10px);
    }

    .iosPhone__leaf .iosKeyboard__key {
      font-size: 4.7cqi;
    }

    .iosPhone__leaf .iosKeyboard__key--fn,
    .iosPhone__leaf .iosKeyboard__key--space {
      font-size: 3.4cqi;
    }

    .iosPhone__leaf .iosKeyboard__dockBtn {
      width: 5.6cqi;
      height: 5.6cqi;
    }

    .iosPhone__leaf .iosKeyboard__key[data-label].is-pressed::after {
      width: 10.5cqi;
      height: 10.5cqi;
      font-size: 6.2cqi;
    }

    /* Messages in landscape Split View: time, the status ring and the app's
       controls stack down the outer edge; the conversation's name is one pill
       at the top; the thread keeps clear of that rail. */
    .iosPhone__leaf--right .iosPhone__screen::before {
      height: 88px;
      background: linear-gradient(to bottom, #fff 58%, rgba(255, 255, 255, 0));
      -webkit-mask-image: linear-gradient(to bottom, #000 62%, transparent);
      mask-image: linear-gradient(to bottom, #000 62%, transparent);
    }

    .iosPhone__leaf--right .iosPhone__status {
      top: 14px;
      right: 11px;
      left: auto;
      width: 46px;
      height: auto;
      flex-direction: column;
      justify-content: flex-start;
      gap: 5px;
      padding: 0;
    }

    .iosPhone__leaf--right .iosPhone__time {
      font-size: 13px;
      letter-spacing: 0;
    }

    .iosPhone__leaf--right .iosPhone__island,
    .iosPhone__leaf--right .iosPhone__icons svg:not(.iosPhone__ring),
    .iosPhone__leaf--right .iosPhone__homeBar {
      display: none;
    }

    .iosPhone__leaf--right .iosPhone__icons .iosPhone__ring {
      display: block;
    }

    .iosPhone__leaf--right .iosPhone__nav {
      top: 0;
      display: block;
      height: 0;
      padding: 0;
    }

    .iosPhone__leaf--right .iosPhone__navBtn {
      position: absolute;
      top: 78px;
      right: 14px;
      margin: 0;
    }

    .iosPhone__leaf--right .iosPhone__navBtn:last-child {
      top: 126px;
    }

    .iosPhone__leaf--right .iosPhone__contact {
      position: absolute;
      top: 13px;
      left: 50%;
      flex-direction: row;
      gap: 6px;
      padding: 3px 12px 3px 6px;
      border-radius: 999px;
      background: rgba(255, 255, 255, 0.85);
      box-shadow:
        0 0 0 0.5px rgba(0, 0, 0, 0.06),
        0 2px 10px rgba(0, 0, 0, 0.1);
      transform: translateX(-50%);
    }

    .iosPhone__leaf--right .iosPhone__groupAvatar {
      zoom: 0.72;
    }

    .iosPhone__leaf--right .iosPhone__name {
      margin: 0;
      padding: 0;
      background: none;
      box-shadow: none;
    }

    .iosPhone__leaf--right .iosPhone__stamp {
      margin-top: 78px;
    }

    .iosPhone__leaf--right .chat-container {
      padding: 0 66px 72px 12px;
    }

    /* The composer sits lower here, so the frost under it is shorter too. */
    .iosPhone__leaf--right .iosPhone__screen::after {
      height: 70px;
    }

    .iosPhone__leaf--right .iosPhone__composer {
      bottom: 16px;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .iosPhoneTrack .iosPhone {
    --duo-in: 0 !important;
  }

  .iosPhone__leaf,
  .iosPhone__shade {
    transition: none !important;
  }
}
