:root {
    --bg: #070506;
    --surface: #101010;
    --surface-soft: #151113;
    --surface-active: #1d1518;
    --text: #e8e8e8;
    --muted: #969696;
    --muted-dark: #686669;
    --line: #282828;
    --red: #ef3348;
    --red-soft: #ef334514;
    --red-line: #ef334555;
    --incoming: #141414;
    --outgoing: #2a171b;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); color-scheme: dark; scroll-behavior: smooth; }
body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background: radial-gradient(circle at 50% 35%, #21080e 0, #0d0608 52%, #070506 100%);
    background-attachment: fixed;
    color: var(--text);
    font: 400 15px/1.48 Inter, Arial, sans-serif;
}
body.no-scroll { overflow: hidden; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 1px solid var(--red); outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }

.loader { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: #080808; transition: opacity .35s ease, visibility .35s ease; }
.loader span, .mark { display: grid; place-items: center; border: 1px solid var(--red); color: var(--red); font-weight: 800; }
.loader span { width: 42px; height: 42px; animation: loader-pulse 1s ease-in-out infinite alternate; }
body.loaded .loader { opacity: 0; visibility: hidden; }
@keyframes loader-pulse { to { transform: scale(1.1); box-shadow: 0 0 22px #ef334444; } }

.app { width: min(100%, 720px); min-height: 100vh; margin: 0 auto; padding: env(safe-area-inset-top) 22px env(safe-area-inset-bottom); }
.header { display: flex; align-items: center; height: 64px; }
.brand { color: var(--text); font-size: 13px; font-weight: 800; letter-spacing: .14em; text-decoration: none; }
.brand span { color: var(--red); }
.eyebrow { margin: 0; color: var(--muted); font-size: 9px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; }

/* Archive */
.dashboard { padding: 12px 0 52px; }
.dashboard-heading { display: flex; align-items: end; justify-content: space-between; padding: 12px 0 22px; border-bottom: 1px solid var(--line); }
.dashboard-heading .eyebrow { margin-bottom: 6px; }
.dashboard-heading h1 { margin: 0; font-size: clamp(2.25rem, 10vw, 3.4rem); font-weight: 600; letter-spacing: -.065em; line-height: .9; }
.search-box { display: flex; align-items: center; gap: 10px; margin: 18px 0 11px; padding: 0 12px; border: 1px solid var(--line); background: #0d0d0d; color: var(--red); transition: border-color .2s ease, background .2s ease; }
.search-box:focus-within { border-color: var(--red-line); background: #101010; }
.search-box input { width: 100%; height: 44px; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 13px; }
.search-box input::placeholder { color: var(--muted-dark); }
.archive-filters { display: flex; gap: 7px; overflow-x: auto; margin: 0 0 10px; padding: 0 0 4px; scrollbar-width: none; }
.archive-filters::-webkit-scrollbar { display: none; }
.archive-filters button { flex: 0 0 auto; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: #0b0b0b; color: var(--muted); cursor: pointer; font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; transition: border-color .2s ease, color .2s ease, background .2s ease; }
.archive-filters button.active { border-color: var(--red-line); background: var(--red-soft); color: var(--red); }
.dialog-list { border-top: 1px solid var(--line); }
.dialog-button { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 12px; width: 100%; min-height: 72px; padding: 12px 2px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); cursor: pointer; text-align: left; transition: background .18s ease; }
.dialog-button:hover, .dialog-button:active { background: #ffffff05; }
.avatar { display: grid; width: 34px; height: 34px; place-items: center; flex: 0 0 auto; overflow: hidden; border: 1px solid var(--red-line); border-radius: 50%; background: #211015; color: var(--red); font-size: 10px; font-weight: 600; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.dialog-button .avatar { width: 48px; height: 48px; font-size: 12px; }
.dialog-content { min-width: 0; padding-top: 1px; }
.dialog-topline { display: flex; align-items: baseline; gap: 10px; }
.dialog-title { min-width: 0; overflow: hidden; flex: 1; font-size: 15px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.dialog-time { flex: 0 0 auto; color: var(--muted-dark); font-size: 10px; }
.dialog-preview { display: block; overflow: hidden; margin-top: 5px; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.dialog-preview.is-event { color: #d96b78; }
.empty-state, .error-state, .loading-state { margin: 0; padding: 30px 12px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.6; text-align: center; }
.error-state { color: #d98992; }
.loading-state::before { display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 50%; background: var(--red); animation: loader-pulse .7s ease-in-out infinite alternate; content: ""; }
.load-dialogs, .load-more { display: block; width: 100%; margin: 14px 0; padding: 10px 12px; border: 1px solid var(--red-line); border-radius: 6px; background: var(--red-soft); color: var(--red); cursor: pointer; font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.load-dialogs:disabled, .load-more:disabled { cursor: wait; opacity: .55; }

/* Chat */
body.in-conversation .header, body.in-conversation .dashboard-heading, body.in-conversation .search-box, body.in-conversation .archive-filters, body.in-conversation .load-dialogs { display: none; }
body.in-conversation .app { width: min(100%, 820px); padding-top: env(safe-area-inset-top); }
body.in-conversation .dashboard { padding: 0; }
.conversation { min-height: 100vh; margin: 0 -22px; }
.conversation-nav { position: sticky; top: 0; z-index: 8; display: flex; align-items: center; min-height: 66px; padding: 8px 18px; border-bottom: 1px solid var(--line); background: #080808ed; backdrop-filter: blur(14px); }
.back-button { display: grid; width: 36px; height: 36px; place-items: center; flex: 0 0 auto; padding: 0; border: 0; background: transparent; color: var(--text); cursor: pointer; font-size: 28px; line-height: 1; }
.back-button:hover, .back-button:active { color: var(--red); }
.conversation-header { display: flex; align-items: center; min-width: 0; gap: 10px; margin-left: 5px; }
.avatar-large { width: 40px; height: 40px; font-size: 12px; }
.conversation-title-wrap { min-width: 0; }
.conversation h2 { overflow: hidden; margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -.025em; text-overflow: ellipsis; white-space: nowrap; }
.conversation-title-wrap p { display: flex; align-items: center; gap: 5px; margin: 2px 0 0; color: var(--muted); font-size: 10px; }
.conversation-title-wrap p span { color: var(--red); font-size: 8px; }
.conversation-body { min-height: calc(100vh - 66px); padding: 15px 18px 34px; background: transparent; }
.new-messages { position: sticky; top: 76px; z-index: 6; display: block; margin: 0 auto 10px; padding: 7px 11px; border: 1px solid var(--red-line); border-radius: 14px; background: #101010ee; color: var(--red); cursor: pointer; font-size: 10px; font-weight: 600; letter-spacing: .04em; }
.message-list { display: flex; flex-direction: column; gap: 3px; }
.message-card { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 7px; width: min(87%, 520px); padding: 8px 10px; border: 1px solid #242424; border-radius: 5px 9px 9px; background: var(--incoming); }
.message-card.is-outgoing { align-self: flex-end; display: block; border-color: #4b262e; border-radius: 9px 5px 9px 9px; background: var(--outgoing); }
.message-card.is-outgoing > .avatar { display: none; }
.message-card.is-deleted { border-color: var(--red-line); background: #211014; }
.message-card.is-continuation { margin-top: -1px; }
.message-card.is-continuation > .avatar { visibility: hidden; }
.message-sender { display: block; margin-bottom: 4px; color: #d67580; font-size: 11px; font-weight: 600; }
.is-outgoing .message-sender { display: none; }
.message-text { margin: 0; color: var(--text); font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; white-space: pre-wrap; }
.reply-preview { display: block; width: 100%; overflow: hidden; margin: 0 0 7px; padding: 4px 7px; border: 0; border-left: 2px solid var(--red); background: #ffffff06; color: var(--muted); cursor: pointer; font: 400 11px/1.4 Inter, Arial, sans-serif; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.reply-preview.target-missing { color: #d27c86; }
.media-button { width: 100%; margin-top: 8px; padding: 9px 10px; border: 1px solid #ffffff12; border-radius: 6px; background: #ffffff07; color: #d2b4b8; cursor: pointer; font-size: 12px; text-align: left; }
.media-preview { position: relative; display: grid; min-height: 46px; margin-top: 8px; place-items: center; overflow: hidden; border: 1px solid #242424; border-radius: 7px; background: #080808; }
.media-preview img, .media-preview video { display: block; width: 100%; max-height: 340px; object-fit: contain; }
.media-preview audio { width: min(100%, 300px); margin: 10px; }
.voice-player { width: 100%; min-height: 48px; padding: 10px 14px; border: 0; background: linear-gradient(90deg, #ef33451c, transparent); color: var(--text); cursor: pointer; font-size: 12px; text-align: left; }
.media-unavailable { min-height: 42px; padding: 10px; color: var(--muted-dark); font-size: 11px; }
.sticker-preview { width: min(190px, 65vw); min-height: 120px; border: 0; background: transparent; }
.telegram-sticker { display: grid; width: min(180px, 60vw); height: min(180px, 60vw); place-items: center; font-size: 58px; }
.telegram-sticker img, .telegram-sticker video { width: 100%; height: 100%; object-fit: contain; }
.custom-emoji { display: inline-grid; width: 1.25em; height: 1.25em; margin: 0 .04em; place-items: center; vertical-align: -.25em; }
.custom-emoji img, .custom-emoji video { width: 100%; height: 100%; object-fit: contain; }
.structured-card { margin-top: 6px; padding: 9px 11px; border-left: 2px solid var(--red); border-radius: 3px; background: #ffffff08; color: var(--text); font-size: 12px; line-height: 1.5; white-space: pre-wrap; }
.structured-card a { color: var(--red); }
.media-placeholder { color: var(--muted-dark); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
.media-open { position: absolute; right: 7px; bottom: 7px; padding: 6px 8px; border: 1px solid #ffffff18; border-radius: 5px; background: #080808dd; color: var(--text); cursor: pointer; font-size: 9px; letter-spacing: .05em; text-transform: uppercase; }
.date-divider { align-self: center; margin: 15px 0 7px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 5px; background: #0b0b0bcc; color: var(--muted); font-size: 9px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; }
.message-footer { display: flex; align-items: center; justify-content: flex-end; gap: 7px; margin-top: 5px; color: var(--muted-dark); font-size: 9px; }
.event-badge { color: #db7884; }
.history-button { padding: 0; border: 0; background: transparent; color: #cf7c86; cursor: pointer; font-size: 9px; text-decoration: underline; text-underline-offset: 2px; }
.jump-bottom { position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); z-index: 7; display: grid; width: 42px; height: 42px; place-items: center; border: 1px solid var(--red-line); border-radius: 50%; background: #101010ee; color: var(--red); cursor: pointer; font-size: 20px; }

/* Bottom sheet and media viewer */
.history-panel { position: fixed; inset: 0; z-index: 30; display: grid; align-items: end; }
.history-scrim { position: absolute; inset: 0; border: 0; background: #000b; backdrop-filter: blur(4px); }
.history-sheet { position: relative; z-index: 1; width: min(100%, 720px); max-height: min(76vh, 680px); margin: 0 auto; overflow-y: auto; padding: 12px 20px max(24px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-radius: 10px 10px 0 0; background: #0d0d0d; }
.sheet-handle { width: 34px; height: 3px; margin: 0 auto 18px; border-radius: 2px; background: #3a3a3a; }
.sheet-close { position: absolute; top: 17px; right: 17px; width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 50%; background: #131313; color: var(--muted); cursor: pointer; font-size: 20px; }
.history-sheet h3 { margin: 7px 40px 18px 0; font-size: 22px; font-weight: 600; letter-spacing: -.04em; }
.revision-card { margin-bottom: 9px; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: #101010; }
.revision-meta { margin-bottom: 8px; color: #d36f7a; font-size: 9px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.revision-card p { margin: 0; color: var(--muted); font-size: 13px; white-space: pre-wrap; }
.revision-card p + p { margin-top: 7px; color: var(--text); }
.media-modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom)); background: #050505f5; }
.media-modal > div { display: grid; width: 100%; max-width: 820px; max-height: 88vh; place-items: center; }
.media-modal img, .media-modal video { max-width: 100%; max-height: 84vh; }
.media-modal audio { width: min(100%, 420px); }
.media-modal a { padding: 11px 14px; border: 1px solid var(--red-line); color: var(--red); text-decoration: none; }
.modal-close { position: fixed; top: max(16px, env(safe-area-inset-top)); right: 16px; z-index: 2; width: 38px; height: 38px; border: 1px solid #ffffff20; border-radius: 50%; background: #101010cc; color: var(--text); cursor: pointer; font-size: 23px; }

/* Landing */
body.has-dialogs .hero, body.has-dialogs .features, body.has-dialogs .connect, body.has-dialogs .finish { display: none; }
.hero { padding: 74px 0 68px; text-align: center; }
.mark { width: 28px; height: 28px; margin: 0 auto 22px; font-size: 11px; }
.hero .eyebrow { margin-bottom: 16px; }
h1 { margin-bottom: 22px; font-size: clamp(3.6rem, 17vw, 6.4rem); font-weight: 800; letter-spacing: .1em; line-height: .84; }
h1 span { color: var(--red); }
.lead { width: min(100%, 380px); margin: 0 auto 28px; color: var(--muted); font-size: 14px; }
.primary-button, .support-button, .copy-button { border: 1px solid var(--red-line); border-radius: 0; background: var(--red-soft); color: var(--red); cursor: pointer; font-size: 10px; font-weight: 600; letter-spacing: .11em; text-transform: uppercase; transition: border-color .2s ease, background .2s ease, color .2s ease, transform .2s ease; }
.primary-button, .support-button { display: inline-flex; align-items: center; gap: 24px; padding: 12px 13px; }
.primary-button:hover, .support-button:hover, .copy-button:hover:not(:disabled) { border-color: var(--red); background: var(--red); color: #fff; }
.primary-button:active, .support-button:active, .copy-button:active:not(:disabled) { transform: scale(.98); }
.features { border-top: 1px solid var(--line); }
.features article { position: relative; min-height: 116px; padding: 22px 0 22px 45px; border-bottom: 1px solid var(--line); }
.features article::before { position: absolute; top: 24px; left: 0; width: 1px; height: 34px; background: var(--red); box-shadow: 0 0 10px #ef334444; content: ""; }
.features span, .step-number { position: absolute; top: 23px; left: 15px; color: var(--red); font-size: 9px; font-weight: 600; letter-spacing: .08em; }
.features h2, .steps h3 { margin-bottom: 5px; font-size: 17px; font-weight: 500; letter-spacing: -.03em; }
.features p, .steps p, .finish > p:not(.eyebrow) { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.connect { padding: 72px 0 42px; }
.section-heading { padding-left: 20px; border-left: 1px solid var(--red); }
.section-heading h2, .finish h2 { margin: 7px 0 0; font-size: clamp(2.25rem, 10vw, 3.4rem); font-weight: 600; letter-spacing: -.06em; line-height: .95; }
.steps { margin: 34px 0 0; padding: 0; list-style: none; }
.steps li { position: relative; min-height: 112px; padding: 0 0 24px 44px; border-bottom: 1px solid var(--line); }
.steps li + li { padding-top: 24px; }
.steps li + li .step-number { top: 25px; }
.step-number { left: 0; }
.copy-button { margin-top: 12px; padding: 9px 10px; }
.copy-button:disabled { border-color: var(--line); background: transparent; color: var(--muted-dark); cursor: not-allowed; }
.finish { margin: 0 -22px; padding: 46px 22px 58px; border-top: 1px solid var(--line); background: linear-gradient(135deg, #ef33440a, transparent 55%); }
.finish h2 { margin-bottom: 13px; }
.finish > p:not(.eyebrow) { margin-bottom: 22px; }

@media (min-width: 721px) {
    .app { padding-right: 38px; padding-left: 38px; }
    .conversation { margin-right: -38px; margin-left: -38px; }
    .conversation-nav, .conversation-body { padding-right: 38px; padding-left: 38px; }
    .finish { margin-right: -38px; margin-left: -38px; padding-right: 38px; padding-left: 38px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
