/* 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 {
  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);
}

.iosPhone__screen::after {
  bottom: 0;
  height: 88px;
  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: center;
  gap: 8px;
}

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

.iosPhone__field {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  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);
}

.iosPhone__field svg {
  fill: #8e8e93;
  color: #8e8e93;
}

.iosPhone__homeBar {
  position: absolute;
  left: 50%;
  bottom: 8px;
  z-index: 3;
  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;
}

.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. */
.iosPhone .chat-container .singlerecomendation {
  display: grid;
  grid-template-columns: 28px minmax(0, max-content) minmax(0, 1fr);
  column-gap: 8px;
  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;
}

/* 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;
}

/* 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%;
  pointer-events: none;
  user-select: none;
}

.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;
}

.iosTapback.is-new {
  animation: iosTapbackPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

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

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

/* Typing. The newest block is always the one being typed. iMessage never shows
   your own typing indicator, so my reply waits hidden until it is sent. */
.iosPhone .chat-container > .myreply:first-child {
  display: none;
}

.iosPhone .chat-container .singlerecomendation:first-child .recommendationAuthor,
.iosPhone .chat-container .singlerecomendation:first-child .recommendationAuthorRole {
  display: none;
}

.iosPhone .chat-container .singlerecomendation:first-child .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 .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 .recommendation:not(.last-recomendation)::after {
    animation: none;
    background-color: #8e8e93;
    box-shadow: 13px 0 0 #8e8e93, 26px 0 0 #8e8e93;
  }
}

/* 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;
  }
}
