/* ============================================================
   BOT DEMO — the chat that runs inside the 3D phone.

   Every length is written in iPhone points and multiplied by --tgd-s, which
   JavaScript sets to (screen width in CSS px / 393). At --tgd-s: 1 this is
   pixel-for-pixel a real screenshot; at 0.6 it is the same screenshot,
   smaller. Nothing here is a guess about how big the stage will be.
   ============================================================ */

.tgd {
  --tgd-s: 1;
  --p: calc(1px * var(--tgd-s));

  --tg-bg: #0e1621;
  --tg-head: #17212b;
  --tg-in: #182533;
  --tg-out: #2b5278;
  --tg-fg: #ffffff;
  --tg-dim: #7d8e9e;
  --tg-link: #64b5ef;

  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--tg-bg);
  color: var(--tg-fg);
  font-family: -apple-system, "SF Pro Text", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-align: left;
  contain: paint;
}

/* The doodle wallpaper, drawn rather than downloaded: two soft washes and a
   fine diagonal weave. It only has to survive being looked at past a chat. */
.tgd::before {
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(90% 46% at 14% 6%, rgba(86,128,176,0.3), transparent 64%),
    radial-gradient(80% 44% at 92% 34%, rgba(58,96,140,0.22), transparent 62%),
    radial-gradient(120% 60% at 72% 100%, rgba(38,72,108,0.34), transparent 64%),
    repeating-linear-gradient(42deg, rgba(255,255,255,0.016) 0 calc(2 * var(--p)), transparent calc(2 * var(--p)) calc(9 * var(--p)));
  pointer-events: none;
}

/* ---- status bar ------------------------------------------------------- */
.tgd-status {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  height: calc(50 * var(--p));
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(6 * var(--p)) calc(30 * var(--p)) 0 calc(44 * var(--p));
  background: var(--tg-head);
}
.tgd-clock {
  font-size: calc(16 * var(--p));
  font-weight: 650;
  letter-spacing: calc(-0.16 * var(--p));
}
.tgd-sicons { height: calc(12 * var(--p)); width: auto; fill: currentColor; color: #fff; }
/* The cut-out. A hole, so: flat black, no outline. */
.tgd-island {
  position: absolute;
  top: calc(11 * var(--p));
  left: 50%;
  width: calc(122 * var(--p));
  height: calc(35 * var(--p));
  margin-left: calc(-61 * var(--p));
  border-radius: 999px;
  background: #000;
}
.tgd-island::after {
  content: "";
  position: absolute;
  right: 22%;
  top: 50%;
  width: calc(11 * var(--p));
  height: calc(11 * var(--p));
  margin-top: calc(-5.5 * var(--p));
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #2b3a6b, #070910 60%);
}

/* ---- header ----------------------------------------------------------- */
.tgd-head {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  height: calc(54 * var(--p));
  display: flex; align-items: center;
  gap: calc(10 * var(--p));
  padding: 0 calc(12 * var(--p));
  background: var(--tg-head);
  box-shadow: 0 calc(1 * var(--p)) 0 rgba(0,0,0,0.3);
}
.tgd-back { width: calc(22 * var(--p)); height: calc(22 * var(--p)); color: var(--tg-link); flex: 0 0 auto; }
.tgd-back svg { width: 100%; height: 100%; display: block; }
.tgd-ava {
  width: calc(38 * var(--p)); height: calc(38 * var(--p));
  border-radius: 50%;
  flex: 0 0 auto;
  overflow: hidden;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #9ad24a, #5c8f1f);
  color: #0e1621;
  font-weight: 700;
  font-size: calc(17 * var(--p));
}
.tgd-ava img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tgd-who { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; gap: calc(1 * var(--p)); }
.tgd-name {
  font-size: calc(16 * var(--p)); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tgd-sub {
  font-size: calc(13 * var(--p));
  color: var(--tg-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color 0.2s ease;
}
.tgd-sub.typing { color: var(--tg-link); }
/* The three dots that follow "друкує". Written as a clipped ellipsis rather
   than three elements, so it costs one animation instead of three. */
.tgd-sub.typing::after {
  content: "…";
  display: inline-block;
  width: calc(10 * var(--p));
  overflow: hidden;
  vertical-align: bottom;
  animation: tgd-dots 1.1s steps(4, end) infinite;
}
@keyframes tgd-dots { from { width: 0; } to { width: calc(10 * var(--p)); } }
.tgd-dots { display: flex; flex-direction: column; gap: calc(3 * var(--p)); padding: calc(4 * var(--p)); flex: 0 0 auto; }
.tgd-dots i { width: calc(3.4 * var(--p)); height: calc(3.4 * var(--p)); border-radius: 50%; background: var(--tg-dim); }

/* ---- the feed --------------------------------------------------------- */
.tgd-body {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: calc(10 * var(--p)) calc(9 * var(--p)) calc(12 * var(--p));
  scrollbar-width: none;
}
.tgd-body::-webkit-scrollbar { width: 0; height: 0; }
.tgd-feed { display: flex; flex-direction: column; gap: calc(8 * var(--p)); min-height: 100%; justify-content: flex-end; }

/* The date chip above the first message of the day. */
.tgd-day {
  align-self: center;
  margin: calc(2 * var(--p)) 0 calc(4 * var(--p));
  padding: calc(3 * var(--p)) calc(11 * var(--p));
  border-radius: 999px;
  background: rgba(0,0,0,0.3);
  font-size: calc(12.5 * var(--p));
  font-weight: 500;
  color: rgba(255,255,255,0.72);
  backdrop-filter: blur(calc(4 * var(--p)));
  -webkit-backdrop-filter: blur(calc(4 * var(--p)));
}

/* Telegram gives a message and the keyboard stapled under it one shared
   width — whichever of the two is wider sets it. fit-content on the column
   plus stretch on the children is exactly that rule. */
.tgd-msg {
  display: flex; flex-direction: column;
  align-items: stretch;
  width: fit-content;
  max-width: 86%;
  position: relative;
}
.tgd-msg.out { align-self: flex-end; }
.tgd-msg.hidden { visibility: hidden; }

.tgd-bubble {
  position: relative;
  background: var(--tg-in);
  border-radius: calc(14 * var(--p));
  border-bottom-left-radius: calc(5 * var(--p));
  padding: calc(7 * var(--p)) calc(10 * var(--p)) calc(6 * var(--p));
  box-shadow: 0 calc(1 * var(--p)) calc(2 * var(--p)) rgba(0,0,0,0.22);
  will-change: transform;
}
.tgd-msg.out .tgd-bubble {
  background: var(--tg-out);
  border-radius: calc(14 * var(--p));
  border-bottom-right-radius: calc(5 * var(--p));
}
/* The copy that dissolves while the real bubble resizes under it. It is
   taken out of the flow, so it has to be told the width the flex column was
   giving it, and clipped to the height it had when it was cloned. */
.tgd-ghost {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
}
.tgd-bubble.thinking { opacity: 0.72; }

.tgd-text {
  font-size: calc(15.5 * var(--p));
  line-height: 1.33;
  white-space: normal;
  word-break: break-word;
}
.tgd-text b { font-weight: 650; }
.tgd-text code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: calc(14 * var(--p));
  background: rgba(0,0,0,0.26);
  padding: 0 calc(3 * var(--p));
  border-radius: calc(3 * var(--p));
}
.tgd-text blockquote {
  margin: calc(6 * var(--p)) 0 calc(2 * var(--p));
  padding-left: calc(9 * var(--p));
  border-left: calc(3 * var(--p)) solid var(--tg-link);
  color: #cfe0ee;
}

.tgd-media { display: none; }
.tgd-media.on {
  display: block;
  margin: calc(-3 * var(--p)) calc(-6 * var(--p)) calc(6 * var(--p));
  border-radius: calc(10 * var(--p));
  overflow: hidden;
  background: rgba(0,0,0,0.3);
}
.tgd-photo {
  display: block;
  width: 100%;
  height: auto;
  animation: tgd-photo-in 0.45s cubic-bezier(.16,1,.3,1) both;
}
@keyframes tgd-photo-in {
  from { opacity: 0; transform: scale(1.03); filter: blur(calc(6 * var(--p))); }
  to   { opacity: 1; transform: none; filter: none; }
}

.tgd-foot {
  display: flex; align-items: center; justify-content: flex-end;
  gap: calc(3 * var(--p));
  margin-top: calc(1 * var(--p));
  height: calc(13 * var(--p));
}
.tgd-time { font-size: calc(11.5 * var(--p)); color: rgba(255,255,255,0.45); }
.tgd-msg.out .tgd-time { color: rgba(205,230,255,0.6); }
.tgd-tick { width: calc(15 * var(--p)); height: calc(10 * var(--p)); color: #6ec8ff; }

/* file / video card inside a bubble */
.tgd-file {
  display: flex; align-items: center; gap: calc(9 * var(--p));
  margin-top: calc(8 * var(--p));
}
.tgd-fic {
  width: calc(40 * var(--p)); height: calc(40 * var(--p));
  border-radius: 50%;
  background: var(--tg-link);
  color: #0e1621;
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.tgd-fic svg { width: calc(22 * var(--p)); height: calc(22 * var(--p)); fill: currentColor; }
.tgd-fmeta { min-width: 0; }
.tgd-fname {
  font-size: calc(14.5 * var(--p)); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tgd-fsize { font-size: calc(12.5 * var(--p)); color: var(--tg-dim); }

/* ---- inline keyboard --------------------------------------------------- */
.tgd-keys {
  width: 100%;
  margin-top: calc(3 * var(--p));
  display: flex; flex-direction: column;
  gap: calc(3 * var(--p));
  transition: opacity 0.16s ease;
}
.tgd-keys.off { opacity: 0.35; pointer-events: none; }
.tgd-krow { display: flex; gap: calc(3 * var(--p)); }
.tgd-key {
  flex: 1 1 0;
  min-width: 0;
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: calc(14 * var(--p));
  font-weight: 500;
  color: #e7f0f8;
  background: rgba(0,0,0,0.26);
  box-shadow: inset 0 0 0 calc(1 * var(--p)) rgba(255,255,255,0.045);
  border-radius: calc(9 * var(--p));
  padding: calc(9 * var(--p)) calc(8 * var(--p));
  line-height: 1.2;
  text-align: center;
  transition: background 0.18s ease, transform 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}
.tgd-key:hover { background: rgba(0,0,0,0.38); }
.tgd-key:active { transform: scale(0.975); }
/* the flash Telegram gives a pressed inline button */
.tgd-key.hit { background: var(--tg-link); color: #10202e; }

/* ---- input bar --------------------------------------------------------- */
.tgd-bar {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  height: calc(52 * var(--p));
  display: flex; align-items: center;
  gap: calc(10 * var(--p));
  padding: 0 calc(12 * var(--p)) calc(8 * var(--p));
  background: var(--tg-head);
  color: var(--tg-dim);
}
.tgd-bar svg { width: calc(22 * var(--p)); height: calc(22 * var(--p)); display: block; fill: currentColor; }
.tgd-bar .tgd-mic svg { fill: currentColor; }
.tgd-ph {
  flex: 1 1 auto;
  height: calc(16 * var(--p));
  border-radius: calc(8 * var(--p));
  background: rgba(255,255,255,0.07);
}

/* The home indicator, so the mock ends the way a phone does. */
.tgd-bar::after {
  content: "";
  position: absolute;
  left: 50%; bottom: calc(5 * var(--p));
  width: calc(134 * var(--p)); height: calc(5 * var(--p));
  margin-left: calc(-67 * var(--p));
  border-radius: 99px;
  background: rgba(255,255,255,0.85);
}

@media (prefers-reduced-motion: reduce) {
  .tgd-photo { animation: none; }
  .tgd-body { scroll-behavior: auto; }
}
