.ga-tg-message {
    position: relative;
    isolation: isolate;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 1fr auto 1fr;
    row-gap: .375rem;
    width: min(100%, 33rem);
    min-width: 0;
    align-self: center;
    margin: 0;
    padding-block: .3rem;
    border-radius: 14px;
    background-color: var(--mud-palette-background-grey);
    background-image: linear-gradient(145deg,
        color-mix(in srgb, var(--mud-palette-surface) 76%, var(--mud-palette-success)),
        color-mix(in srgb, var(--mud-palette-surface) 82%, var(--mud-palette-info)));
    --tg-bubble: color-mix(in srgb, var(--mud-palette-surface) 90%, var(--mud-palette-info));
    --tg-key: color-mix(in srgb, var(--mud-palette-surface) 83%, var(--mud-palette-info));
}

/* Chat wallpaper from https://telegram.org/img/tgme/pattern.svg */
.ga-tg-message::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    pointer-events: none;
    background-color: var(--mud-palette-text-primary);
    opacity: .25;
    -webkit-mask: url("../images/telegram-chat-pattern.svg") center / 22rem auto repeat;
    mask: url("../images/telegram-chat-pattern.svg") center / 22rem auto repeat;
}

.ga-tg-post {
    grid-row: 2;
    margin-inline: clamp(1rem, 7%, 2.375rem);
}

.ga-tg-bubble {
    position: relative;
    display: flow-root;
    padding: 10px 13px 8px;
    border-radius: 16px 16px 12px 4px;
    box-shadow: var(--mud-elevation-1);
    color: var(--mud-palette-text-primary);
    background: var(--mud-palette-surface);
    background: var(--tg-bubble);
    text-align: start;
    font-size: .95rem;
    line-height: 1.42;
    overflow-wrap: anywhere;
}

.ga-tg-bubble::before {
    content: "";
    position: absolute;
    inset-inline-start: -5px;
    bottom: 0;
    width: 8px;
    height: 9px;
    background: inherit;
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

.ga-tg-body { display: inline; white-space: pre-wrap; }
.ga-tg-body strong { font-weight: 700; }
.ga-tg-body em { font-style: italic; }
.ga-tg-body a { color: var(--mud-palette-info); text-decoration: underline; text-underline-offset: .12em; }
.ga-tg-body pre, .ga-tg-body blockquote, .ga-tg-quote {
    margin: .3em 0;
    padding: .35em .65em;
    border-radius: 5px;
    background: rgba(var(--mud-palette-info-rgb), .08);
}
.ga-tg-body blockquote, .ga-tg-quote { border-inline-start: 3px solid var(--mud-palette-info); }
.ga-tg-quote summary { cursor: pointer; color: var(--mud-palette-info); }
.ga-tg-quote:not([open]) .ga-tg-quote-close, .ga-tg-quote[open] .ga-tg-quote-open { display: none; }
.ga-tg-quote blockquote { margin: 0; border: 0; background: none; }
.ga-tg-body pre { white-space: pre-wrap; }
.ga-tg-body code, .ga-tg-body pre { font: .93em/1.45 ui-monospace, Consolas, monospace; }
.ga-tg-body :not(pre) > code { background: rgba(var(--mud-palette-info-rgb), .09); border-radius: 3px; padding-inline: 2px; }
.ga-tg-spoiler {
    display: inline;
    max-width: 100%;
    border-radius: 4px;
    border: 0;
    padding: 0 2px;
    background: var(--mud-palette-text-secondary);
    color: transparent;
    font: inherit;
    white-space: inherit;
    overflow-wrap: anywhere;
    cursor: pointer;
}
.ga-tg-bubble time {
    float: inline-end;
    margin: .55em 0 0 .7em;
    font-size: .68rem;
    color: var(--mud-palette-text-secondary);
    font-variant-numeric: tabular-nums;
}
.ga-tg-row {
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    gap: 3px;
    margin-top: 3px;
}
.ga-tg-key {
    position: relative;
    display: grid;
    align-items: center;
    min-width: 0;
    min-height: 38px;
    padding: 6px 12px;
    border-radius: 6px;
    background: var(--mud-palette-background-grey);
    background: var(--tg-key);
    color: var(--mud-palette-text-primary);
    text-align: center;
    font-size: .875rem;
    line-height: 1.25;
    font-weight: 600;
    text-decoration: none;
}
.ga-tg-key span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ga-tg-key .mud-icon-root { position: absolute; right: 4px; top: 4px; width: 9px; height: 9px; opacity: .75; }
.ga-tg-row:last-of-type .ga-tg-key:first-child { border-end-start-radius: 12px; }
.ga-tg-row:last-of-type .ga-tg-key:last-child { border-end-end-radius: 12px; }
.ga-tg-key.ga-tg-primary { background: var(--mud-palette-info); color: var(--mud-palette-info-text); }
.ga-tg-key.ga-tg-success { background: var(--mud-palette-success); color: var(--mud-palette-success-text); }
.ga-tg-key.ga-tg-danger { background: var(--mud-palette-error); color: var(--mud-palette-error-text); }
.ga-tg-key[href]:hover { filter: brightness(1.08); }
.ga-tg-key[aria-disabled="true"] { opacity: .65; }
.ga-tg-message :is(a, button, summary):focus-visible { outline: 2px solid var(--mud-palette-info); outline-offset: 2px; }

.ga-tg-caption {
    grid-row: 3;
    align-self: end;
    padding-inline: .75rem;
    color: var(--mud-palette-text-secondary);
    text-align: center;
    font-size: .6875rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}
