* { box-sizing: border-box; -webkit-font-smoothing: antialiased; }
  body { margin: 0; background: #0a0a0f; color: #fff; font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', 'Roboto', sans-serif; min-height: 100vh; }
  .phone { font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', 'Roboto', sans-serif; }
  #app { display: grid; grid-template-columns: 380px 1fr; min-height: 100vh; }
  #sidebar { background: rgba(255,255,255,0.03); border-right: 1px solid rgba(255,255,255,0.08); padding: 20px; overflow-y: auto; max-height: 100vh; }
  #stage { display: flex; align-items: center; justify-content: center; padding: 30px; background: radial-gradient(ellipse at center, #1a2030 0%, #0a0a0f 80%); }
  .back-link { color: rgba(255,255,255,0.5); text-decoration: none; font-size: 13px; display: inline-flex; gap: 6px; margin-bottom: 16px; }
  .back-link:hover { color: #fff; }
  .title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
  .subtitle { font-size: 12px; color: rgba(255,255,255,0.4); margin-bottom: 20px; }
  .label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: rgba(255,255,255,0.4); font-weight: 600; margin-bottom: 6px; }
  .field { width: 100%; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); border-radius: 10px; padding: 9px 12px; color: #fff; font-size: 13px; margin-bottom: 12px; outline: none; font-family: inherit; }
  .field:focus { border-color: #2AABEE; }
  .btn { padding: 10px 16px; border-radius: 10px; border: none; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; transition: all .15s; }
  .btn-primary { background: linear-gradient(135deg, #2AABEE, #229ED9); color: #fff; width: 100%; justify-content: center; padding: 12px; }
  .btn-primary:hover { box-shadow: 0 8px 20px -8px rgba(42,171,238,0.5); }
  .btn-secondary { background: rgba(255,255,255,0.07); color: #fff; border: 1px solid rgba(255,255,255,0.12); }
  .btn-secondary:hover { background: rgba(255,255,255,0.12); }
  .btn-ghost { background: transparent; color: rgba(255,255,255,0.6); padding: 6px 10px; font-size: 12px; }
  .btn-ghost:hover { color: #fff; background: rgba(255,255,255,0.05); }
  .divider { height: 1px; background: rgba(255,255,255,0.08); margin: 18px 0; }
  .event-row { display: flex; gap: 8px; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; font-size: 12px; align-items: center; }
  .event-row .who { font-weight: 600; font-size: 11px; min-width: 40px; }
  .event-row .who.me { color: #2AABEE; }
  .event-row .who.other { color: #4ade80; }
  .event-row .txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: rgba(255,255,255,0.85); }
  .event-row button { background: transparent; border: none; color: rgba(255,255,255,0.4); cursor: pointer; padding: 0 4px; }
  .event-row button:hover { color: #fff; }
  .fmt-row { display: flex; gap: 6px; margin-bottom: 12px; }
  .fmt-btn { flex: 1; padding: 8px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: rgba(255,255,255,0.7); font-size: 12px; font-weight: 500; cursor: pointer; }
  .fmt-btn.active { background: rgba(42,171,238,0.15); border-color: #2AABEE; color: #2AABEE; }

  /* ═════════ iPHONE FRAME ═════════ */
  .device { width: 393px; height: 852px; background: #000; border-radius: 55px; padding: 12px; position: relative; box-shadow: 0 35px 80px -20px rgba(0,0,0,0.7), 0 0 0 2px #1a1a1a, inset 0 0 0 2px #2a2a2a; }
  .device::before { content: ''; position: absolute; top: 19px; left: 50%; transform: translateX(-50%); width: 124px; height: 36px; background: #000; border-radius: 20px; z-index: 20; }
  .device.vertical { width: 461px; height: 820px; border-radius: 24px; padding: 0; box-shadow: 0 35px 80px -20px rgba(0,0,0,0.7); }
  .device.vertical::before { display: none; }
  .device-screen { width: 100%; height: 100%; border-radius: 44px; overflow: hidden; display: flex; flex-direction: column; position: relative; background: #fff; }
  .device.vertical .device-screen { border-radius: 24px; }

  /* ═════════ TELEGRAM iOS ═════════ */
  .tg {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Helvetica Neue', 'Roboto', sans-serif;
    height: 100%; display: flex; flex-direction: column;
    --accent: #3390EC;
    letter-spacing: -0.24px;
    font-weight: 400;
  }
  .tg .tg-header .name, .tg .bubble .reply-name { font-weight: 600; }

  /* Light: классический голубоватый градиент Telegram iOS */
  .tg-light {
    --bg: #FFFFFF;
    --text: #000000;
    --muted: #8D969C;
    --border: rgba(0,0,0,0.12);
    --bubble-in: #FFFFFF;
    --bubble-in-text: #000000;
    --bubble-out: #EEFFDE;
    --bubble-out-text: #000000;
    --meta-in: #8D969C;
    --meta-out: #4FAE4E;
    --tick: #4FAE4E;
    --header: rgba(247,247,247,0.94);
    --header-text: #000;
    --reaction-in-bg: #EBF5FF;
    --reaction-in-text: #3390EC;
    --reaction-out-bg: #CEEBB9;
    --reaction-out-text: #24742F;
    --reply-line: #3390EC;
    --reply-line-out: #4FAE4E;
    --input-bg: rgba(247,247,247,0.94);
    --input-field-bg: #FFFFFF;
    --input-field-border: rgba(0,0,0,0.14);
    --chat-bg-grad:
      radial-gradient(ellipse at 20% 0%,  #B7D3E8 0%, transparent 55%),
      radial-gradient(ellipse at 90% 10%, #D9C8EF 0%, transparent 55%),
      radial-gradient(ellipse at 10% 90%, #CAD9B3 0%, transparent 55%),
      radial-gradient(ellipse at 90% 95%, #EED5BC 0%, transparent 60%),
      linear-gradient(160deg, #D3E1C8 0%, #C5D4E5 100%);
    --pattern-color: rgba(255,255,255,0.35);
  }
  .tg-dark {
    --bg: #0F0F0F;
    --text: #FFFFFF;
    --muted: #7D8A96;
    --border: rgba(255,255,255,0.1);
    --bubble-in: #1C2733;
    --bubble-in-text: #FFFFFF;
    --bubble-out: #766AC8;
    --bubble-out-text: #FFFFFF;
    --meta-in: #6A7F8E;
    --meta-out: #C3B9FF;
    --tick: #5FB7D4;
    --header: rgba(23,33,43,0.96);
    --header-text: #FFFFFF;
    --reaction-in-bg: rgba(51,144,236,0.2);
    --reaction-in-text: #68B8EB;
    --reaction-out-bg: rgba(255,255,255,0.18);
    --reaction-out-text: #E5E0FF;
    --reply-line: #5FB7D4;
    --reply-line-out: #F5B67C;
    --input-bg: rgba(23,33,43,0.96);
    --input-field-bg: #242F3D;
    --input-field-border: rgba(255,255,255,0.08);
    --chat-bg-grad:
      radial-gradient(ellipse at 20% 0%,  #1E4566 0%, transparent 55%),
      radial-gradient(ellipse at 90% 10%, #3B2860 0%, transparent 55%),
      radial-gradient(ellipse at 10% 90%, #1A4533 0%, transparent 55%),
      radial-gradient(ellipse at 90% 95%, #4A2E1F 0%, transparent 60%),
      linear-gradient(160deg, #152030 0%, #1E1730 100%);
    --pattern-color: rgba(255,255,255,0.08);
  }

  /* Status bar iOS */
  .tg-statusbar { height: 47px; padding: 14px 30px 0; display: flex; justify-content: space-between; align-items: center; font-size: 16px; font-weight: 600; color: var(--header-text); background: var(--header); position: relative; z-index: 15; }
  .tg-statusbar .right { display: flex; gap: 5px; align-items: center; }
  .tg-statusbar .signal { display: inline-flex; gap: 1px; align-items: flex-end; }
  .tg-statusbar .signal span { width: 3px; background: currentColor; border-radius: 0.5px; }
  .tg-statusbar .signal span:nth-child(1) { height: 4px; }
  .tg-statusbar .signal span:nth-child(2) { height: 6px; }
  .tg-statusbar .signal span:nth-child(3) { height: 8px; }
  .tg-statusbar .signal span:nth-child(4) { height: 10px; }
  .tg-statusbar .battery { width: 24px; height: 11px; border: 1.2px solid currentColor; border-radius: 3px; position: relative; padding: 1px; }
  .tg-statusbar .battery::after { content: ''; position: absolute; right: -3px; top: 3px; width: 2px; height: 4px; background: currentColor; border-radius: 0 1px 1px 0; }
  .tg-statusbar .battery::before { content: ''; display: block; width: 75%; height: 100%; background: currentColor; border-radius: 1px; }

  /* Header */
  .tg-header { display: flex; align-items: center; gap: 8px; padding: 5px 10px 8px 6px; background: var(--header); backdrop-filter: saturate(1.5) blur(18px); -webkit-backdrop-filter: saturate(1.5) blur(18px); border-bottom: 0.5px solid var(--border); position: relative; z-index: 10; }
  .tg-header .back { display: flex; align-items: center; gap: 4px; color: var(--accent); font-size: 17px; padding: 4px 2px; cursor: pointer; margin-right: -4px; }
  .tg-header .back svg { width: 12px; height: 20px; }
  .tg-header .back span { display: none; }
  .tg-header .avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, #FF8A65, #FF5252); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 15px; flex-shrink: 0; }
  .tg-header .info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
  .tg-header .name { font-weight: 600; font-size: 16px; color: var(--header-text); line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tg-header .status { font-size: 13px; color: var(--muted); line-height: 1.15; }
  .tg-header .status.typing { color: var(--accent); font-weight: 500; }
  .tg-header .actions { display: flex; gap: 18px; color: var(--accent); padding: 0 6px; }
  .tg-header .actions svg { width: 22px; height: 22px; }

  /* Chat area */
  .tg-chat { flex: 1; overflow-y: auto; padding: 12px 10px 8px; display: flex; flex-direction: column; gap: 2px; background: var(--chat-bg-grad); position: relative; }
  .tg-chat::-webkit-scrollbar { display: none; }
  /* Классический узор Telegram iOS: сердечки, звёздочки, облака, цветы */
  .tg-chat::before {
    content: ''; position: absolute; inset: 0; pointer-events: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260' viewBox='0 0 260 260'><g fill='white' fill-opacity='0.32'><path d='M40 50c-3-6-11-6-12 2 0 6 8 12 12 16 4-4 12-10 12-16-1-8-9-8-12-2z'/><path d='M190 40l3 7 7 1-5 5 1 7-6-3-6 3 1-7-5-5 7-1z'/><path d='M110 95c-4 0-7 2-9 5-2-3-5-5-9-5-6 0-10 4-10 10 0 8 10 14 19 22 9-8 19-14 19-22 0-6-4-10-10-10z'/><path d='M220 140c6 0 10-4 10-10s-4-10-10-10c-2 0-4 1-6 2-1-5-6-9-11-9-6 0-11 5-11 11 0 1 0 2 1 3-5 1-8 5-8 10 0 6 5 10 10 10 1 0 2 0 3-1 2 3 5 5 9 5 6 0 10-4 10-10l3-1z'/><circle cx='60' cy='160' r='3'/><path d='M155 185l2 5 5 1-4 3 1 5-4-2-5 2 1-5-3-3 5-1z'/><path d='M30 220c-3-5-10-5-11 2 0 5 7 10 11 14 3-4 11-9 11-14-1-7-8-7-11-2z'/><path d='M230 215l2 5 5 1-4 3 1 5-4-2-5 2 1-5-3-3 5-1z'/><circle cx='100' cy='230' r='3'/><circle cx='175' cy='250' r='2'/><circle cx='250' cy='80' r='2.5'/><circle cx='10' cy='110' r='2.5'/></g></svg>");
    background-size: 260px 260px;
    filter: brightness(0) invert(1);
    opacity: .45;
    mix-blend-mode: soft-light;
  }
  .tg-dark .tg-chat::before { opacity: .12; mix-blend-mode: screen; }

  .date-divider { align-self: center; background: rgba(0,0,0,0.3); color: #fff; font-size: 13px; font-weight: 500; padding: 3px 11px; border-radius: 14px; margin: 4px 0 8px; backdrop-filter: blur(10px); }
  .tg-dark .date-divider { background: rgba(255,255,255,0.12); }

  /* Bubble groups */
  .tg-group { display: flex; flex-direction: column; gap: 1px; margin-bottom: 6px; max-width: 85%; position: relative; }
  .tg-group.in { align-self: flex-start; }
  .tg-group.out { align-self: flex-end; }

  .bubble {
    padding: 6px 9px 6px 11px;
    border-radius: 13px;
    font-size: 16px;
    line-height: 1.24;
    position: relative;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
    word-wrap: break-word;
    animation: tgIn .25s cubic-bezier(.34,1.56,.64,1) both;
    min-width: 58px;
    max-width: 100%;
  }
  @keyframes tgIn { from { opacity: 0; transform: translateY(6px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }

  .tg-group.in .bubble { background: var(--bubble-in); color: var(--bubble-in-text); align-self: flex-start; }
  .tg-group.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); align-self: flex-end; }

  .tg-group.in  .bubble:last-of-type { border-bottom-left-radius: 4px; }
  .tg-group.out .bubble:last-of-type { border-bottom-right-radius: 4px; }

  /* Tail SVG — клювик в стиле Telegram iOS */
  .bubble .tail { position: absolute; bottom: -0.5px; width: 9px; height: 14px; display: none; }
  .tg-group.in  .bubble:last-of-type .tail { display: block; left: -6px; fill: var(--bubble-in); }
  .tg-group.out .bubble:last-of-type .tail { display: block; right: -6px; transform: scaleX(-1); fill: var(--bubble-out); }
  .tg-group.in  .bubble:last-of-type .tail path { fill: var(--bubble-in); }
  .tg-group.out .bubble:last-of-type .tail path { fill: var(--bubble-out); }

  .bubble .text { padding-right: 56px; white-space: pre-wrap; }
  .bubble .text.has-reaction { padding-bottom: 2px; }

  .bubble .meta {
    position: absolute;
    right: 9px; bottom: 4px;
    font-size: 11px;
    line-height: 1;
    display: inline-flex; align-items: center; gap: 3px;
    color: var(--meta-in);
    letter-spacing: 0.1px;
  }
  .tg-group.out .bubble .meta { color: var(--meta-out); }
  .bubble .meta .tick { display: inline-flex; color: var(--tick); }
  .tg-group.out .bubble .meta .tick { color: var(--meta-out); }
  .bubble .meta .tick svg { width: 16px; height: 11px; }

  /* Reply quote inside bubble */
  .bubble .reply {
    display: block;
    position: relative;
    padding: 2px 8px 3px 9px;
    margin: 1px 0 4px;
    border-radius: 4px;
    background: rgba(51,144,236,0.08);
    font-size: 14px;
    line-height: 1.2;
    overflow: hidden;
  }
  .bubble .reply::before {
    content:''; position: absolute; left: 0; top: 2px; bottom: 2px; width: 3px;
    background: var(--reply-line); border-radius: 2px;
  }
  .tg-group.out .bubble .reply::before { background: var(--reply-line-out); }
  .tg-group.out .bubble .reply { background: rgba(79,174,78,0.14); }
  .bubble .reply .reply-name { color: var(--reply-line); font-size: 13px; font-weight: 600; display: block; line-height: 1.15; }
  .tg-group.out .bubble .reply .reply-name { color: var(--reply-line-out); }
  .bubble .reply .reply-text { color: var(--text); opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; font-size: 13px; }

  /* Forward label */
  .bubble .fwd { display: block; font-size: 13px; font-style: italic; color: var(--reply-line); margin-bottom: 2px; line-height: 1.2; }
  .bubble .fwd .fwd-label { font-size: 12px; opacity: .8; display: block; font-style: normal; }
  .tg-group.out .bubble .fwd { color: var(--reply-line-out); }

  /* Reactions — inline pill with avatar + emoji (gen/2403 pattern) */
  .reaction-bubble {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #E0F2FE;
    border: 1px solid #BAE6FD;
    border-radius: 999px;
    padding: 1px 6px 1px 1px;
  }
  .reaction-bubble .reactor-av {
    width: 16px; height: 16px; border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.5);
    object-fit: cover;
    background: linear-gradient(135deg, #FF8A65, #FF5252);
    display: inline-block;
    flex-shrink: 0;
  }
  .reaction-bubble .r-emoji { font-size: 12px; line-height: 1; }
  .tg-dark .reaction-bubble {
    background: rgba(59,130,246,0.22);
    border-color: rgba(96,165,250,0.38);
  }
  .bubble-footer {
    display: flex;
    justify-content: space-between;
    align-items: end;
    margin-top: 6px;
    gap: 10px;
  }
  .bubble-footer .meta {
    position: static;
    margin-left: auto;
  }
  @keyframes reaction-pop {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
  }
  .animate-reaction {
    animation: reaction-pop 0.5s cubic-bezier(0.175,0.885,0.32,1.275) forwards;
    transform-origin: left center;
  }

  /* Typing bubble (in chat, not header) */
  .tg-typing {
    align-self: flex-start;
    background: var(--bubble-in);
    padding: 10px 14px;
    border-radius: 14px 14px 14px 4px;
    display: inline-flex; gap: 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
    margin-bottom: 4px;
    max-width: fit-content;
  }
  .tg-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: tgDot 1.2s infinite; }
  .tg-typing span:nth-child(2) { animation-delay: .2s; }
  .tg-typing span:nth-child(3) { animation-delay: .4s; }
  @keyframes tgDot { 0%,60%,100%{transform:translateY(0);opacity:.4} 30%{transform:translateY(-5px);opacity:1} }

  /* Input bar */
  .tg-input {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 7px 8px 8px;
    background: var(--input-bg);
    border-top: 0.5px solid var(--border);
  }
  .tg-input .attach { color: var(--muted); padding: 8px 4px; }
  .tg-input .attach svg { width: 24px; height: 24px; }
  .tg-input .field-wrap {
    flex: 1;
    background: var(--input-field-bg);
    border: 0.5px solid var(--input-field-border);
    border-radius: 18px;
    padding: 8px 12px;
    min-height: 36px;
    display: flex;
    align-items: center;
    color: var(--muted);
    font-size: 16px;
  }
  .tg-input .field-wrap .placeholder { flex: 1; }
  .tg-input .field-wrap .emoji { color: var(--muted); }
  .tg-input .field-wrap .emoji svg { width: 22px; height: 22px; display: block; }
  .tg-input .mic {
    color: var(--accent);
    padding: 6px 4px;
  }
  .tg-input .mic svg { width: 26px; height: 26px; }

  .home-bar { width: 134px; height: 5px; background: #000; border-radius: 3px; margin: 6px auto 8px; }
  .tg-dark .home-bar { background: rgba(255,255,255,0.7); }

  /* System message */
  .tg-system { align-self: center; background: rgba(0,0,0,0.3); color: #fff; font-size: 13px; font-weight: 500; padding: 4px 11px; border-radius: 14px; margin: 6px 0; backdrop-filter: blur(10px); text-align: center; max-width: 80%; }
  .tg-dark .tg-system { background: rgba(255,255,255,0.12); }

  /* Sticker */
  .tg-sticker { align-self: flex-start; font-size: 80px; line-height: 1; padding: 4px 2px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.15)); }
  .tg-group.out .tg-sticker { align-self: flex-end; }

  /* Voice message bubble */
  .bubble.voice { display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-width: 180px; }
  .bubble.voice .v-play { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
  .bubble.voice .v-play svg { width: 14px; height: 14px; fill: #fff; }
  .tg-group.out .bubble.voice .v-play { background: #4FAE4E; }
  .bubble.voice .v-body { flex: 1; display: flex; flex-direction: column; gap: 3px; }
  .bubble.voice .v-wave { display: flex; align-items: center; gap: 2px; height: 22px; }
  .bubble.voice .v-wave i { display: block; width: 2px; border-radius: 1px; background: var(--accent); opacity: 0.55; }
  .tg-group.out .bubble.voice .v-wave i { background: #4FAE4E; }
  .bubble.voice .v-wave i.played { opacity: 1; }
  .bubble.voice .v-meta { font-size: 11px; color: var(--muted); }
  .bubble.voice .meta { position: static; margin-left: auto; padding-left: 6px; }

  .controls { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: rgba(15,15,25,0.9); border: 1px solid rgba(255,255,255,0.1); border-radius: 40px; padding: 7px 10px; display: flex; gap: 6px; z-index: 50; backdrop-filter: blur(14px); }
  .ctrl-btn { background: transparent; color: #fff; border: none; padding: 8px 14px; border-radius: 30px; font-size: 13px; font-weight: 600; cursor: pointer; }
  .ctrl-btn.play { background: linear-gradient(135deg, #2AABEE, #229ED9); }
  .ctrl-btn.stop { background: rgba(239,68,68,0.85); }
  .ctrl-btn.rec  { background: rgba(239,68,68,0.2); color: #fca5a5; border: 1px solid rgba(239,68,68,0.4); }
  .ctrl-btn.rec.recording { background: rgba(239,68,68,0.95); color: #fff; }

  .scenarios-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
  .sc-btn { padding: 8px 10px; background: rgba(42,171,238,0.1); border: 1px solid rgba(42,171,238,0.25); border-radius: 8px; color: #8CD4F5; font-size: 11px; cursor: pointer; text-align: left; line-height: 1.3; }
  .sc-btn:hover { background: rgba(42,171,238,0.2); }
