/* The Telegram chat replica (iOS, light theme), drawn in our own CSS with our own glyphs (spec §3.3, §5.1).
   The screen is laid out at 402×874 CSS px (the iPhone 18 Pro's 6.3-inch display in points) with 18 px message
   text and scaled into the scene by CSS3D. iOS geometry: display corners 62 px, the Dynamic Island 82×37 px at
   14 px from the top, the status bar's safe area 62 px, the home indicator's 34 px. */

/* fix eng2 (review B, Move D and S4): the platform's colour emoji at 1.1em of the text (Segoe UI Emoji draws 📧
   small beside 18 px text on Windows). Only the emoji planes (U+1F000-1FAFF), so arrows, ✅ and ✖ keep their glyphs. */
@font-face {
  font-family: 'Chat Emoji';
  src: local('Apple Color Emoji'), local('AppleColorEmoji'), local('Segoe UI Emoji'), local('SegoeUIEmoji'), local('Noto Color Emoji'), local('NotoColorEmoji');
  unicode-range: U+1F000-1FAFF;
  size-adjust: 110%;
}

.phone-screen {
  --tg-bg: #dfe7ee;
  --tg-bar: #f6f6f7;
  --tg-hair: rgba(60, 60, 67, .2);
  --tg-accent: #2481cc;
  --tg-gray: #8e8e93;
  --tg-out: #e1ffc7;
  --tg-out-meta: #5fae5a;
  --tg-in-meta: #a0a8b1;
  position: absolute; left: 0; top: 0;
  width: 402px; height: 874px;
  /* No clip, radius or background on the CSS3DObject's root: any clip there (overflow, clip-path) stops Chrome
     hit-testing its descendants under the 3D transform, and real clicks fall through to the canvas (Part 2 review).
     The screen's clip, rounded corners and wallpaper live on the inner .tg-frame. */
  overflow: visible;
  border-radius: 0;
  background: none;
  color: #000;
  font-family: var(--device), 'Chat Emoji', 'Apple Color Emoji', 'Segoe UI Emoji';
  font-size: 18px;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  pointer-events: none;
  backface-visibility: hidden;
}

.tg-frame { position: absolute; inset: 0; overflow: hidden; border-radius: 62px; background: var(--tg-bg); }

/* ---- the Dynamic Island: a black pill cut into the display, its front camera at the right */
.tg-island { position: absolute; z-index: 3; left: 50%; top: 14px; width: 82px; height: 37px; margin-left: -41px; border-radius: 18.5px; background: #000; }
.tg-lens {
  position: absolute; right: 12px; top: 13px; width: 11px; height: 11px; border-radius: 50%;
  background:
    radial-gradient(circle at 34% 32%, rgba(150, 170, 230, .55) 0 .7px, transparent 1.5px),
    radial-gradient(circle at 50% 50%, #101a30 0 28%, #0a0f1c 46%, #05070c 68%, #020203 100%);
  box-shadow: 0 0 0 1px #07080b, inset 0 0 1.5px rgba(70, 90, 140, .35);
}

/* ---- status bar: the clock centred in the left ear, our signal / wifi / battery glyphs in the right one, both on
   the island's centre line */
.tg-status { position: absolute; left: 0; right: 0; top: 0; height: 62px; background: var(--tg-bar); }
.tg-clock, .tg-sys { position: absolute; top: 14px; height: 37px; width: 154px; display: flex; align-items: center; justify-content: center; }
.tg-clock { left: 6px; font-size: 19px; font-weight: 700; letter-spacing: -.015em; font-variant-numeric: tabular-nums; }
.tg-sys { right: 6px; gap: 7px; color: #000; }
.tg-sys svg { display: block; height: 13.5px; width: auto; fill: currentColor; }
.tg-sys svg:last-child { height: 14.5px; }

/* ---- header: back chevron, title + "bot" / "typing…", the bot's avatar */
.tg-head {
  position: absolute; left: 0; right: 0; top: 62px; height: 54px;
  display: grid; grid-template-columns: 56px 1fr 56px; align-items: center;
  background: var(--tg-bar);
  box-shadow: 0 .5px 0 var(--tg-hair);
}
.tg-back { display: flex; align-items: center; padding-left: 16px; color: var(--tg-accent); }
.tg-back svg { width: 12px; height: 21px; }
.tg-title { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.tg-name { font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.tg-sub { font-size: 13px; color: var(--tg-gray); }
.tg-sub.typing { color: var(--tg-accent); }
/* the "…" of "typing…" is drawn as three dots that pulse in turn (the glyph stays in the text, transparent) */
.tyd { position: relative; display: inline-block; color: transparent; }
.tyd::before {
  content: ''; position: absolute; left: 1.5px; bottom: .3em; width: 2.6px; height: 2.6px; border-radius: 50%;
  background: var(--tg-accent); box-shadow: 4.2px 0 0 var(--tg-accent), 8.4px 0 0 var(--tg-accent);
  animation: tg-dots 1.05s linear infinite;
}
@keyframes tg-dots {
  0%, 100% { background: rgba(36, 129, 204, 1); box-shadow: 4.2px 0 0 rgba(36, 129, 204, .3), 8.4px 0 0 rgba(36, 129, 204, .3); }
  33% { background: rgba(36, 129, 204, .3); box-shadow: 4.2px 0 0 rgba(36, 129, 204, 1), 8.4px 0 0 rgba(36, 129, 204, .3); }
  66% { background: rgba(36, 129, 204, .3); box-shadow: 4.2px 0 0 rgba(36, 129, 204, .3), 8.4px 0 0 rgba(36, 129, 204, 1); }
}
html.rm .tyd::before, html.shot .tyd::before { animation: none; }
.tg-ava { justify-self: end; margin-right: 12px; width: 38px; height: 38px; border-radius: 50%; overflow: hidden; background: #1a66b0; }
.tg-ava svg { display: block; width: 100%; height: 100%; }

/* ---- messages */
/* The list is anchored to the bottom of the body and overflows (clipped) at the top, so the newest message is in
   view without depending on scrollTop: CSS3DRenderer re-parents the screen on its first render, which resets any
   scroll position (Part 2c). */
.tg-body { position: absolute; left: 0; right: 0; top: 116px; bottom: 90px; overflow: hidden; display: flex; flex-direction: column; justify-content: unsafe flex-end;
  /* the oldest bubble fades out under the opaque header instead of being sliced by it (review Should-fix 6) */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 22px); mask-image: linear-gradient(to bottom, transparent 0, #000 22px); }
.tg-list { flex: none; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; padding: 10px 10px 12px; }
.tg-date { align-self: center; margin: 4px 0 6px; }
/* Telegram's service style: the inline keyboard's dark translucent tint, white text */
.tg-date span { display: block; padding: 3px 10px; border-radius: 12px; background: rgba(16, 32, 48, .32); color: #fff; font-size: 14px; font-weight: 500; }

.msg { position: relative; display: flex; flex-direction: column; max-width: 84%; transition: opacity .26s ease, transform .26s cubic-bezier(.2, .8, .2, 1); }
.msg.enter { opacity: 0; transform: translateY(12px); }
.msg.in { align-self: flex-start; align-items: flex-start; margin-left: 8px; }
.msg.out { align-self: flex-end; align-items: flex-end; margin-right: 8px; }
.bub {
  position: relative;
  display: inline-block;
  padding: 7px 12px 7px 13px;
  border-radius: 17px;
  background: #fff;
  box-shadow: 0 1px .5px rgba(16, 35, 47, .13);
  word-wrap: break-word;
}
.msg.out .bub { background: var(--tg-out); }
.tx strong { font-weight: 600; }

/* bubble tails (bottom corner), drawn against the flat chat background */
.msg.in .bub { border-bottom-left-radius: 5px; }
.msg.out .bub { border-bottom-right-radius: 5px; }
.msg .bub::before, .msg .bub::after { content: ''; position: absolute; bottom: 0; width: 18px; height: 18px; }
.msg.in .bub::before { left: -7px; background: #fff; border-bottom-right-radius: 15px 13px; }
.msg.in .bub::after { left: -18px; width: 18px; background: var(--tg-bg); border-bottom-right-radius: 11px; }
.msg.out .bub::before { right: -7px; background: var(--tg-out); border-bottom-left-radius: 15px 13px; }
.msg.out .bub::after { right: -18px; width: 18px; background: var(--tg-bg); border-bottom-left-radius: 11px; }
/* photos and voice notes carry the tail too (iOS draws it on every last bubble of a group) */

/* time, "edited", ticks: floated to the end of the last line, as Telegram does */
.meta { float: right; display: inline-flex; align-items: center; gap: 4px; margin: 10px -3px -4px 12px; font-size: 13px; line-height: 1; color: var(--tg-in-meta); font-variant-numeric: tabular-nums; white-space: nowrap; }
.msg.out .meta { color: var(--tg-out-meta); }
.meta .ed { font-size: 13px; }
.meta .tk { width: 18px; height: 11px; color: #4fae4e; }

/* the status line: one bubble edited in place */
.msg.status .tx { color: #000; }
.msg.tick .tx { animation: tg-edit .32s ease-out; }
@keyframes tg-edit { from { opacity: .35; } to { opacity: 1; } }

/* the card + the inline keyboard */
.msg.card { width: 86%; max-width: 86%; }
.msg.card .bub { width: 100%; }
/* the email send card (S4) keeps its line breaks (To:, Subject:, the body); the S0/S1 cards have none, so no change */
.msg.card .tx { white-space: pre-line; }
.kb { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; width: 100%; margin-top: 5px; transition: opacity .18s ease, transform .18s ease; }
.kb.leave { opacity: 0; transform: translateY(-4px); }
.kb-b {
  height: 44px; border: 0; border-radius: 10px;
  background: rgba(16, 32, 48, .32); color: #fff;
  font: 500 16px/1 var(--device); letter-spacing: -.005em;
  pointer-events: auto; cursor: pointer;
  transition: background-color .12s ease, transform .12s ease;
}
.kb-b:hover { background: rgba(16, 32, 48, .4); }
.kb-b.press, .kb-b:active { background: rgba(16, 32, 48, .5); transform: scale(.97); }
.kb-b:focus-visible { outline: 2px solid var(--blue, #1a66b0); outline-offset: 2px; border-radius: 10px; } /* the page's ring (Part 6a) */

/* notifications: plain text with line breaks */
.msg.notify .tx { white-space: pre-wrap; }

/* a photo: the receipt on a counter, time on a dark pill */
/* a captionless photo sits edge to edge in its bubble, as iOS draws it (review Note 6) */
.msg.photo .bub { padding: 0; border-radius: 17px; }
.msg.out.photo .bub { border-bottom-right-radius: 5px; }
.msg.out.photo .ph { border-bottom-right-radius: 5px; }
/* a photo keeps its share of the screen when the text is set larger (Phone.setTextScale: --tg-photo-zoom = 1/k) */
.ph { position: relative; width: 258px; height: 324px; border-radius: 17px; overflow: hidden; background: #cdc6ba; zoom: var(--tg-photo-zoom, 1); }
.ph .rc {
  position: absolute; left: 50%; top: 50%; width: 214px;
  transform: translate(-50%, -50%) rotate(-3.2deg);
  padding: 16px 14px 18px;
  background: #fdfdfb;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .12), 0 8px 18px -6px rgba(40, 30, 10, .45);
  font: 500 11px/1.45 ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  color: #2a2b2d;
  display: flex; flex-direction: column;
}
.rc-v { font-size: 17px; font-weight: 800; letter-spacing: .1em; text-align: center; }
.rc-a, .rc-d { text-align: center; color: #555; font-size: 10.5px; }
.rc ul { list-style: none; margin: 10px 0 8px; padding: 8px 0 0; border-top: 1px dashed #9a9a9a; }
.rc li { display: flex; justify-content: space-between; gap: 8px; }
.rc li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-t { display: flex; justify-content: space-between; padding-top: 7px; border-top: 1px dashed #9a9a9a; font-size: 14px; font-weight: 800; }
.ph .scan { position: absolute; left: 6px; right: 6px; top: 0; height: 2px; border-radius: 1px; background: #2481cc; opacity: 0; }
.msg.scanning .scan { animation: tg-scan 1.2s cubic-bezier(.45, 0, .55, 1) forwards; }
html.rm .msg.scanning .scan { animation: none; } /* reduced motion: no scan line (review Note 4) */
@keyframes tg-scan { 0% { top: 4%; opacity: 0; } 10% { opacity: .9; } 90% { opacity: .9; } 100% { top: 96%; opacity: 0; } }
.msg.photo .meta { position: absolute; right: 10px; bottom: 10px; float: none; margin: 0; padding: 4px 8px; border-radius: 11px; background: rgba(0, 0, 0, .42); color: #fff; }
.msg.photo .meta .tk { color: #fff; }

/* a voice message */
.msg.voice .bub { display: flex; align-items: center; gap: 10px; padding: 9px 12px 9px 9px; min-width: 268px; }
.vc-play { flex-shrink: 0; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: #5fae5a; color: #fff; }
.vc-play svg { width: 22px; height: 22px; fill: currentColor; margin-left: 2px; }
.vc-body { display: flex; flex-direction: column; gap: 5px; }
.vc-wave { display: flex; align-items: flex-end; gap: 2px; height: 24px; }
.vc-wave i { display: block; width: 3px; height: calc(4px + var(--h) * 20px); border-radius: 2px; background: #9fd28f; }
.msg.voice.playing .vc-wave i { animation: tg-played .16s linear forwards; animation-delay: calc(var(--i) * 48ms); }
@keyframes tg-played { to { background: #4c9e47; } }
/* reduced motion: the waveform does not sweep, it shows played at once (as the scan line, review Note 4) */
html.rm .msg.voice.playing .vc-wave i { animation: none; background: #4c9e47; }
.vc-len { font-size: 13px; color: var(--tg-out-meta); font-variant-numeric: tabular-nums; }
.msg.voice .meta { align-self: flex-end; margin: 0 0 -2px 4px; }

/* ---- input bar and home indicator */
.tg-input { position: absolute; left: 0; right: 0; bottom: 34px; height: 56px; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--tg-bar); box-shadow: 0 -.5px 0 var(--tg-hair); color: var(--tg-gray); }
.tg-ico svg { display: block; width: 28px; height: 28px; }
.tg-field { flex: 1; height: 38px; display: flex; align-items: center; padding: 0 14px; border-radius: 19px; background: #fff; box-shadow: inset 0 0 0 .5px rgba(60, 60, 67, .3); color: #a3a3a8; font-size: 17px; justify-content: space-between; padding-right: 7px; }
.tg-field .sticker { display: block; width: 25px; height: 25px; color: var(--tg-gray); }
.tg-home { position: absolute; left: 0; right: 0; bottom: 0; height: 34px; background: var(--tg-bar); }
.tg-home::after { content: ''; position: absolute; left: 50%; bottom: 8px; width: 140px; height: 5px; margin-left: -70px; border-radius: 2.5px; background: #000; }

html.shot .phone-screen *, html.rm .phone-screen * { transition: none !important; }
