@font-face {
    font-family: "Caveat";
    src: url('/fonts/Caveat-Variable.ttf') format('truetype');
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
}

html {
    box-sizing: border-box;
}

*,
*::before,
*::after {
    box-sizing: inherit;
}

[hidden] {
    display: none !important;
}

body {
    font-family: "Caveat", cursive;
    font-size: 24px;
    font-weight: 400;
    line-height: 1.25;
    color: #30363c;
    background-color: #f7f5f0;
    background-image:
        linear-gradient(rgba(247, 245, 240, 0.85), rgba(247, 245, 240, 0.85)),
        url('/images/dreamy-cats.png');
    background-size: auto, 960px 960px;
    background-position: 0 0, 0 0;
    background-repeat: repeat;
    background-attachment: fixed;
}

button,
input,
textarea {
    font: inherit;
}

h1 {
    margin: 16px 0 22px;
    font-size: 44px;
    line-height: 1.1;
}

.messages-and-users {
    display: none;
    width: 100%;
    max-width: 1032px;
    gap: 30px;
    margin-bottom: 20px;
}

.messages-list {
    flex: 1 1 800px;
    min-width: 0;
    height: 400px;
    border: 1px solid #bfc3c6;
    border-radius: 8px;
    background-color: #e3e5e7;
    background-image:
        linear-gradient(rgba(227, 229, 231, 0.86), rgba(227, 229, 231, 0.86)),
        url('/images/dreamy-rats.png');
    background-size: auto, 700px 700px;
    background-position: 0 0, 0 0;
    background-repeat: repeat;
    overflow-y: auto;
    overscroll-behavior-y: contain;
}

.users-list {
    width: 200px;
    height: 400px;
    box-sizing: border-box;
    padding: 16px;
    flex-shrink: 0;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid #c7c9cb;
    background-color: rgba(250, 249, 246, 0.94);
}

.users-title {
    margin: 0 0 16px;
    font-size: 26px;
}

.users-items {
    margin: 0;
    padding: 0;
    list-style: none;
}

.user-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 12px;
    overflow-wrap: anywhere;
}

.user-online-dot {
    flex: 0 0 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #16803c;
}

.users-status {
    color: #475467;
}

.controls {
    display: none;
    align-items: flex-end;
    width: 100%;
    max-width: 1032px;
    gap: 16px;
}

.send-status {
    color: #b42318;
}

.send-status.is-uploading {
    color: #42505e;
}

.attachment-picker {
    position: relative;
    flex: 0 0 52px;
}

.attachment-picker-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    z-index: 5;
    display: grid;
    gap: 6px;
    width: 180px;
    padding: 8px;
    border: 1px solid #d6c4c5;
    border-radius: 10px;
    background: #fcfaf7;
    box-shadow: 0 6px 20px rgba(48, 54, 60, 0.14);
}

.attachment-picker-menu button {
    width: 100%;
    text-align: left;
}

.attach-message,
.voice-message {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 52px;
    width: 52px;
    min-height: 52px;
    padding: 5px;
    border: 1px solid #b8a8ad;
    border-radius: 10px;
    background: #fcfaf7;
    cursor: pointer;
}

.attach-message span,
.voice-message span {
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
    font-size: 33px;
    line-height: 1;
}

.attach-message:disabled,
.voice-message:disabled,
.remove-attachment:disabled {
    opacity: 0.5;
    cursor: default;
}

.voice-message.is-recording {
    border-color: #ad3344;
    background: #f8e3e5;
    box-shadow: 0 0 0 3px rgba(173, 51, 68, .14);
}

.voice-recording {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    max-width: 1032px;
    margin: 8px 0;
    padding: 10px 12px;
    border: 1px solid #d6b6bb;
    border-radius: 10px;
    background: #fff6f4;
}

.voice-recording-caption {
    display: flex;
    flex: 1 1 190px;
    gap: 12px;
    align-items: center;
}

.voice-timer {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.selected-attachment:has(.voice-preview) {
    flex-wrap: wrap;
}

.voice-preview,
.attachment-audio {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: 54px;
}

.voice-player {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    gap: 0 8px;
    width: 260px;
    max-width: 100%;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid #d6c4c5;
    border-radius: 18px;
    background: rgba(255, 253, 249, 0.92);
}

.voice-player audio {
    display: none !important;
}

.voice-player-toggle {
    grid-row: 1 / 3;
    width: 40px;
    min-height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    color: #65414a;
    background: #f1e5df;
    font: 18px/1 system-ui, sans-serif;
    cursor: pointer;
}

.voice-player-seek {
    display: block;
    grid-column: 2;
    width: 100%;
    min-width: 0;
    min-height: 36px;
    height: 24px;
    margin: 0;
    padding: 0;
    accent-color: #65414a;
    cursor: pointer;
}

.voice-player-seek:disabled {
    opacity: 0.5;
    cursor: default;
}

.voice-player-time {
    grid-column: 2;
    min-width: 0;
    font-size: 16px;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: #56606a;
}

.voice-player-status {
    grid-column: 1 / -1;
    min-width: 0;
    margin-top: 5px;
    font-size: 17px;
    line-height: 1.2;
    color: #b42318;
}

.voice-player-toggle:focus-visible,
.voice-player-seek:focus-visible {
    outline: 3px solid #b8a8ad;
    outline-offset: 2px;
}

.selected-attachment.selected-voice {
    flex-wrap: nowrap;
}

.selected-voice .voice-player {
    flex: 1 1 auto;
    width: auto;
}

.voice-preview {
    flex: 1 1 230px;
    min-width: min(230px, 100%);
}

.attachment-selection {
    width: 100%;
    max-width: 1032px;
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 1px solid #d6c4c5;
    border-radius: 10px;
    background: rgba(255, 253, 249, 0.96);
}

.selected-attachments {
    max-height: 150px;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    list-style: none;
}

.selected-attachment {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.selected-attachment + .selected-attachment {
    margin-top: 5px;
}

.selected-attachment-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
}

.selected-attachment-size,
.attachment-size {
    color: #56606a;
    font-size: 19px;
    white-space: nowrap;
}

.remove-attachment {
    flex: 0 0 44px;
    width: 44px;
    min-height: 44px;
    padding: 2px;
    border: 1px solid #d6c4c5;
    border-radius: 8px;
    color: #65414a;
    background: #fcfaf7;
    font: 28px/1 system-ui, sans-serif;
    cursor: pointer;
}

.attachment-hint {
    margin: 7px 0 0;
    color: #56606a;
    font-size: 19px;
}

.message-attachments {
    display: grid;
    gap: 10px;
    min-width: 0;
    margin-top: 8px;
}

.message-attachment {
    min-width: 0;
}

.attachment-preview {
    position: relative;
    display: block;
    width: var(--photo-inline-size, 262px);
    max-width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border: 1px solid #c7c9cb;
    border-radius: 8px;
    background: #e3e5e7;
}

.attachment-preview img {
    display: block;
    width: 100%;
    height: auto;
}

.attachment-preview.is-loaded,
.attachment-preview.is-unavailable {
    aspect-ratio: auto;
}

.attachment-preview.is-unavailable {
    width: 262px;
    min-height: 120px;
}

.attachment-preview-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    color: #56606a;
    text-align: center;
    font-size: 21px;
}

.attachment-download {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 3px 8px;
    max-width: 100%;
    padding: 5px 0;
    color: #65414a;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.attachment-name {
    min-width: 0;
    overflow-wrap: anywhere;
}

.attachment-viewer {
    width: min(94vw, 900px);
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    max-height: calc(100svh - 24px);
    padding: 14px;
    border: 1px solid #b8a8ad;
    border-radius: 12px;
    color: #30363c;
    background: #fcfaf7;
}

.attachment-viewer[open] {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
}

.attachment-viewer::backdrop {
    background: rgba(35, 38, 42, 0.78);
}

.attachment-viewer-heading {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.attachment-viewer-name {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-size: 23px;
    line-height: 1.15;
    max-height: 2.3em;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.close-attachment-viewer {
    flex: 0 0 auto;
    min-height: 44px;
    white-space: nowrap;
}

.attachment-viewer-image {
    display: block;
    flex: 1 1 auto;
    -webkit-touch-callout: default;
    -webkit-user-select: auto;
    user-select: auto;
    min-height: 0;
    max-height: 70vh;
    max-height: 70svh;
    height: min(65vh, 700px);
    height: min(65svh, 700px);
    width: 100%;
    object-fit: contain;
}

.attachment-viewer-status {
    flex-shrink: 0;
    margin: 0;
    color: #56606a;
}

.attachment-viewer-actions {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    max-height: 35svh;
    overflow-y: auto;
}

.attachment-viewer-download {
    min-height: 44px;
}

.photo-save-status,
.photo-save-hint {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
    color: #56606a;
}

.new-message {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 52px;
    max-height: 160px;
    padding: 10px 12px;
    border: 1px solid #bfc3c6;
    border-radius: 10px;
    resize: vertical;
    color: #30363c;
    background-color: rgba(255, 253, 249, 0.96);
}

.send-message {
    flex: 0 0 auto;
    min-height: 52px;
    padding: 10px 16px;
    border: 1px solid #65414a;
    border-radius: 10px;
    color: #fff;
    background-color: #65414a;
    cursor: pointer;
}

.send-message:disabled {
    opacity: 0.5;
    cursor: default;
}

.new-message:focus-visible,
.send-message:focus-visible,
.attach-message:focus-visible,
.voice-message:focus-visible,
.remove-attachment:focus-visible,
.attachment-preview:focus-visible,
.attachment-download:focus-visible {
    outline: 3px solid #b8a8ad;
    outline-offset: 2px;
}

.message-item {
    width: fit-content;
    max-width: 78%;
    box-sizing: border-box;
    margin: 14px 20px;
    padding: 10px 14px;
    border: 1px solid rgba(130, 139, 146, 0.22);
    border-radius: 14px 14px 14px 4px;
    background-color: rgba(255, 253, 249, 0.9);
    box-shadow: 0 2px 6px rgba(48, 54, 60, 0.04);
}

.message-item.message-own {
    margin-left: auto;
    margin-right: 20px;
    border-color: #d6c4c5;
    border-radius: 14px 14px 4px 14px;
    background-color: rgba(246, 233, 224, 0.96);
}

.message-item.message-other {
    margin-left: 20px;
    margin-right: auto;
}

.message-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-page .message-item:focus-visible,
.chat-page .message-quote:focus-visible {
    outline: 3px solid #b8a8ad;
    outline-offset: 2px;
}

.chat-page .message-item.is-selected {
    border-color: #8f6573;
    box-shadow: 0 0 0 2px rgba(143, 101, 115, .2);
}

.chat-page .message-item {
    scroll-margin-block: 20px;
}

.chat-page .message-actions,
.chat-page .reply-compose {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    min-width: 0;
    margin-bottom: 6px;
    padding: 5px 8px;
    border: 1px solid #d6c4c5;
    border-radius: 10px;
    background: rgba(255, 253, 249, .96);
}

.chat-page .message-selection-status {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
}

.chat-page .message-actions .secondary-button {
    flex: 0 0 auto;
    padding: 5px 8px;
    font-size: 17px;
}

.chat-page .message-delete {
    color: #a12e3e;
}

.chat-page .reply-compose {
    border-left: 3px solid #8f6573;
}

.reply-compose-content {
    flex: 1 1 auto;
    min-width: 0;
}

.reply-compose-name,
.reply-compose-text,
.message-quote-name,
.message-quote-text {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-compose-name,
.message-quote-name {
    color: #65414a;
    font-size: 17px;
}

.reply-compose-text {
    font-size: 18px;
}

.chat-page .cancel-reply,
.chat-page .cancel-message-selection {
    flex: 0 0 44px;
    width: 44px;
    padding: 4px;
    font: 24px/1 system-ui, sans-serif;
}

.message-quote {
    display: block;
    width: 100%;
    min-width: 0;
    margin: 5px 0 7px;
    padding: 5px 8px;
    border: 0;
    border-left: 3px solid #b8a8ad;
    border-radius: 4px;
    color: #475467;
    background: rgba(227, 229, 231, .5);
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.message-quote-text {
    font-size: 17px;
}

.message-quote:disabled {
    cursor: default;
    opacity: .8;
}

.chat-page .send-actions {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: center;
    align-self: flex-end;
    gap: 4px;
}

.message-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: flex-start;
    gap: 4px 12px;
    margin-bottom: 4px;
    font-size: 20px;
    line-height: 1.15;
}

.message-own .message-header {
    justify-content: flex-end;
}

.datetime {
    flex-shrink: 0;
    color: #42505e;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.username {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    max-width: 100%;
    min-width: 0;
    font-weight: 700;
    color: #65414a;
}

.author-name,
.participant-name {
    min-width: 0;
    overflow-wrap: anywhere;
}

.rat-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
    font-size: 1.05em;
    line-height: 1.2;
    vertical-align: -0.06em;
}

.auth-panel {
    width: 470px;
    max-width: 100%;
    box-sizing: border-box;
    padding: 24px;
    margin-bottom: 30px;
    border: 1px solid #c7c9cb;
    border-radius: 12px;
    background-color: rgba(250, 249, 246, 0.96);
    box-shadow: 0 6px 24px rgba(48, 54, 60, 0.06);
}

.auth-panel h2 {
    margin: 0 0 12px;
    font-size: 30px;
}

.auth-panel p {
    margin: 0 0 12px;
    line-height: 1.5;
}

.auth-example {
    color: #42505e;
}

.auth-form {
    display: grid;
    gap: 12px;
    margin-top: 20px;
}

.auth-form label {
    font-weight: bold;
}

.auth-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid #bfc3c6;
    border-radius: 6px;
    font: inherit;
    color: #30363c;
    background-color: #fff;
}

.auth-input[aria-invalid="true"] {
    border-color: #b42318;
}

.auth-input:focus-visible,
.auth-submit:focus-visible {
    outline: 3px solid #b8a8ad;
    outline-offset: 2px;
}

.auth-submit {
    justify-self: start;
    padding: 10px 18px;
    border: 1px solid #65414a;
    border-radius: 6px;
    font: inherit;
    color: #fff;
    background-color: #65414a;
    cursor: pointer;
}

.auth-submit:disabled {
    opacity: 0.6;
    cursor: wait;
}

.auth-panel .auth-error {
    margin: 0;
    color: #b42318;
}

.access-code {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid #bfc3c6;
    border-radius: 6px;
    color: #30363c;
    background: #fff;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 17px;
}

.form-note {
    color: #56606a;
    font-size: 20px;
}

.auth-panel .form-note {
    margin: 0;
}

.secondary-button,
.button-link {
    min-height: 44px;
    padding: 7px 12px;
    border: 1px solid #b8a8ad;
    border-radius: 8px;
    color: #65414a;
    background: #fcfaf7;
    cursor: pointer;
}

.button-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.secondary-button:disabled {
    opacity: 0.5;
    cursor: default;
}

.access-code:focus-visible,
.secondary-button:focus-visible,
.button-link:focus-visible,
summary:focus-visible {
    outline: 3px solid #b8a8ad;
    outline-offset: 2px;
}

.install-guide {
    max-width: 1032px;
    margin-bottom: 12px;
    color: #65414a;
}

.install-guide summary {
    width: fit-content;
    min-height: 36px;
    cursor: pointer;
    font-size: 22px;
}

.install-guide p {
    max-width: 650px;
    margin: 8px 0;
    color: #475467;
    font-size: 22px;
}

.chat-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    width: 100%;
    max-width: 1032px;
    margin-bottom: 12px;
}

.account-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
    font-weight: 700;
}

.notification-settings {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    color: #56606a;
    font-size: 20px;
}

.access-name {
    font-weight: 700;
}

.access-error,
.owner-status.is-error {
    color: #b42318;
}

.owner-page {
    max-width: 1050px;
}

.owner-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.owner-heading h2 {
    margin: 0;
}

.owner-card {
    margin: 16px 0;
    padding: 20px;
    border: 1px solid #c7c9cb;
    border-radius: 12px;
    background: rgba(250, 249, 246, 0.96);
}

.owner-card h2,
.owner-card p {
    margin: 0 0 12px;
}

.owner-card .auth-form {
    max-width: 650px;
}

.created-code {
    display: grid;
    gap: 12px;
    margin-top: 24px;
    max-width: 650px;
}

.created-code .secondary-button {
    justify-self: start;
}

.member-list {
    padding: 0;
    list-style: none;
}

.member-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    overflow-wrap: anywhere;
}

.member-card > div:first-child {
    min-width: 0;
}

.member-card .member-state {
    margin: 4px 0 0;
    color: #56606a;
    font-size: 20px;
}

.member-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.member-approve {
    border-color: #47785b;
    color: #28583c;
}

.member-revoke {
    border-color: #c8a5a1;
}

@media (max-width: 760px), (max-width: 1000px) and (max-height: 500px) {
    body {
        margin: 0;
        padding: 12px;
        padding-top: max(12px, env(safe-area-inset-top));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        padding-left: max(12px, env(safe-area-inset-left));
        background-size: auto, 680px 680px;
        background-attachment: scroll;
    }

    h1 {
        margin: 0 0 12px;
        font-size: 38px;
    }

    .auth-panel {
        margin-bottom: 0;
        padding: 20px;
    }

    .auth-submit {
        width: 100%;
        min-height: 48px;
    }

    .messages-and-users {
        flex-direction: column;
        gap: 12px;
        margin-bottom: 12px;
    }

    .messages-list {
        flex: 0 0 auto;
        width: 100%;
        height: max(220px, calc(100vh - 260px));
        height: max(220px, calc(100svh - 260px));
        background-size: auto, 500px 500px;
    }

    .users-list {
        order: -1;
        width: 100%;
        height: auto;
        padding: 10px 12px;
    }

    .users-title {
        margin: 0 0 4px;
        font-size: 22px;
    }

    .users-items {
        display: flex;
        gap: 16px;
        overflow-x: auto;
        padding-bottom: 4px;
    }

    .user-item {
        flex: 0 0 auto;
        max-width: 260px;
        margin: 0;
        gap: 6px;
        white-space: nowrap;
    }

    .participant-name {
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .users-status {
        margin: 0;
    }

    .controls {
        gap: 8px;
    }

    .new-message {
        resize: none;
    }

    .send-message {
        padding: 10px 12px;
    }

    .message-item {
        max-width: 88%;
        margin: 10px 12px;
        padding: 9px 12px;
    }

    .message-item.message-own {
        margin-right: 12px;
    }

    .message-item.message-other {
        margin-left: 12px;
    }

    .message-header {
        gap: 3px 8px;
    }

    .send-status {
        margin: 8px 0 0;
    }

    body.chat-ready {
        display: flex;
        flex-direction: column;
        height: 100vh;
        height: 100svh;
    }

    .chat-ready > h1,
    .chat-ready > .install-guide,
    .chat-ready > .chat-toolbar,
    .chat-ready > .attachment-selection,
    .chat-ready > .voice-recording,
    .chat-ready > .controls,
    .chat-ready > .send-status {
        flex-shrink: 0;
    }

    .chat-ready .messages-and-users {
        flex: 1 0 260px;
        min-height: 260px;
    }

    .chat-ready .messages-list {
        flex: 1 1 auto;
        min-height: 160px;
        height: 0;
    }

    .notification-settings {
        order: 3;
        flex-basis: 100%;
    }

    .owner-card {
        padding: 16px;
    }
}

@media (max-width: 360px) {
    .chat-ready .controls {
        display: grid !important;
        grid-template-columns: 52px 52px minmax(0, 1fr);
    }

    .controls .new-message {
        grid-column: 1 / -1;
        grid-row: 1;
        width: 100%;
    }

    .voice-recording-caption {
        flex-basis: 100%;
    }
}

@media (max-width: 1000px) and (max-height: 500px) {
    .messages-list {
        height: max(160px, calc(100vh - 230px));
        height: max(160px, calc(100svh - 230px));
    }

    h1 {
        font-size: 30px;
        margin-bottom: 8px;
    }
}

/* The chat fills the available screen; owner and access management keep their layout. */
body.chat-page {
    margin: 0;
    padding: 12px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
    font-size: 20px;
}

body.chat-page.chat-ready {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

.chat-page .app-header {
    position: relative;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 12px;
    min-height: 38px;
    margin-bottom: 6px;
    padding-right: 44px;
}

.chat-page .app-header h1 {
    flex: 0 0 auto;
    margin: 0;
    font-size: 34px;
    white-space: nowrap;
}

.chat-page .install-guide {
    min-width: 0;
    margin: 0;
}

.chat-page .install-guide summary {
    min-height: 32px;
    padding: 5px 0;
    font-size: 16px;
    line-height: 1.2;
    white-space: nowrap;
}

.chat-page .install-guide-content {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 30;
    max-width: 650px;
    max-height: 60vh;
    max-height: 60dvh;
    overflow-y: auto;
    padding: 12px 14px;
    border: 1px solid #c7c9cb;
    border-radius: 10px;
    background: #fcfaf7;
    box-shadow: 0 6px 20px rgba(48, 54, 60, 0.14);
}

.chat-page .install-guide p {
    margin: 0 0 8px;
    font-size: 18px;
    line-height: 1.3;
}

.chat-page .install-guide p:last-child {
    margin-bottom: 0;
}

.chat-page .chat-toolbar {
    flex-shrink: 0;
    align-items: center;
    gap: 4px 10px;
    min-height: 32px;
    max-width: none;
    margin-bottom: 6px;
}

.chat-page .account-name {
    flex: 0 1 auto;
    font-size: 20px;
    line-height: 1.15;
}

.chat-page .notification-settings {
    display: contents;
    font-size: 16px;
}

.chat-page .notification-toggle {
    position: relative;
    flex: 0 1 auto;
    min-height: 32px;
    padding: 4px 8px;
    font-size: 16px;
    line-height: 1.15;
}

.chat-page .notification-toggle::after {
    position: absolute;
    inset: -6px 0;
    content: "";
}

.chat-page .notification-status {
    flex: 1 0 100%;
    min-width: 0;
    font-size: 16px;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.chat-page .chat-toolbar .chat-sign-out {
    position: fixed;
    top: max(6px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    z-index: 40;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 12px;
    border: 0;
    background: transparent;
}

.chat-page .chat-sign-out:hover,
.chat-page .chat-sign-out:focus-visible {
    background: rgba(246, 233, 224, 0.9);
}

.chat-page .app-update-notice {
    flex-shrink: 0;
    width: calc(100% - 48px);
    max-width: none;
    margin: 0 48px 6px 0;
    padding: 8px 12px;
    font-size: 18px;
}

.chat-page .messages-and-users {
    max-width: none;
    gap: 12px;
    margin-bottom: 8px;
}

.chat-page.chat-ready .messages-and-users {
    flex: 1 1 0;
    min-height: 0;
}

.chat-page.chat-ready .messages-list {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
}

.chat-page .users-list {
    flex: 0 0 158px;
    align-self: flex-start;
    width: 158px;
    height: auto;
    max-height: 180px;
    padding: 10px;
    font-size: 18px;
}

.chat-page .users-title {
    margin: 0 0 8px;
    font-size: 20px;
}

.chat-page .user-item {
    gap: 5px;
    margin-bottom: 8px;
}

.chat-page .users-status {
    font-size: 17px;
}

.chat-page .message-item {
    margin-top: 9px;
    margin-bottom: 9px;
    padding: 8px 10px;
}

.chat-page .message-header {
    font-size: 17px;
}

.chat-page .form-note,
.chat-page .attachment-hint,
.chat-page .selected-attachment-size,
.chat-page .attachment-size {
    font-size: 17px;
}

.chat-page .attachment-selection,
.chat-page .voice-recording,
.chat-page .controls {
    flex-shrink: 0;
    max-width: none;
}

.chat-page.chat-ready .controls {
    display: flex !important;
    align-items: flex-end;
    gap: 6px;
}

.chat-page .message-tools {
    display: flex;
    flex: 0 0 44px;
    flex-direction: column;
    gap: 4px;
    width: 44px;
}

.chat-page .message-tools .attachment-picker {
    display: flex;
    flex: 0 0 auto;
    width: 44px;
}

.chat-page .attach-message,
.chat-page .voice-message {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 5px;
}

.chat-page .attach-message span,
.chat-page .voice-message span {
    font-size: 26px;
}

.chat-page .new-message {
    flex: 1 1 auto;
    width: auto;
    min-height: 92px;
    max-height: 150px;
    padding: 8px 10px;
    font-size: 20px;
}

.chat-page .send-message {
    position: relative;
    flex: 0 0 auto;
    min-height: 38px;
    padding: 6px 9px;
    font-size: 18px;
}

.chat-page .send-message::after {
    position: absolute;
    inset: -3px 0;
    content: "";
}

.chat-page .send-status {
    flex-shrink: 0;
    max-height: 50px;
    overflow-y: auto;
    margin: 5px 0 0;
    font-size: 17px;
    line-height: 1.2;
}

@media (max-width: 760px), (max-width: 1000px) and (max-height: 500px) {
    .chat-page .app-header {
        gap: 10px;
    }

    .chat-page .messages-and-users {
        gap: 6px;
    }

    .chat-page.chat-ready .messages-list {
        height: 0;
    }

    .chat-page .users-list {
        display: flex;
        flex: 0 0 auto;
        align-items: center;
        gap: 8px;
        width: 100%;
        min-height: 36px;
        max-height: 48px;
        padding: 6px 8px;
        overflow: hidden;
    }

    .chat-page .users-title {
        flex: 0 0 auto;
        margin: 0;
        font-size: 18px;
        line-height: 1;
        white-space: nowrap;
    }

    .chat-page .users-items {
        display: flex;
        flex: 1 1 auto;
        align-items: center;
        gap: 12px;
        min-width: 0;
        max-height: 30px;
        padding: 0;
        scrollbar-width: thin;
    }

    .chat-page .users-items:empty {
        display: none;
    }

    .chat-page .user-item {
        align-items: center;
        max-width: 205px;
        margin: 0;
        font-size: 17px;
        line-height: 1.1;
    }

    .chat-page .participant-name {
        max-width: 175px;
    }

    .chat-page .user-online-dot {
        flex-basis: 5px;
        width: 5px;
        height: 5px;
    }

    .chat-page .users-status {
        min-width: 0;
        margin: 0;
        font-size: 16px;
    }

    .chat-page .message-item {
        max-width: 90%;
        margin-left: 10px;
        margin-right: 10px;
    }

    .chat-page .message-item.message-own {
        margin-left: auto;
    }

    .chat-page .message-item.message-other {
        margin-right: auto;
    }
}

@media (max-height: 500px) {
    .chat-page .app-header {
        min-height: 32px;
        margin-bottom: 4px;
    }

    .chat-page .app-header h1 {
        font-size: 30px;
    }

    .chat-page .new-message {
        min-height: 92px;
    }

    .chat-page .selected-attachments {
        max-height: 90px;
    }
}

/* Keep tiny image files usable without letting names stretch normal media. */
.chat-page .message-media-fit {
    min-width: 104px;
}

/* Names, captions and quotes cannot stretch a photo or circle bubble. */
.chat-page .message-media-fit > .message-header,
.chat-page .message-media-fit > .message-text,
.chat-page .message-media-fit > .message-quote {
    contain: inline-size;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.chat-page .message-media-fit .message-attachments {
    grid-template-columns: minmax(0, 1fr);
}

.chat-page .message-media-fit .message-attachment {
    width: fit-content;
    max-width: 100%;
}

.chat-page .message-media-fit .message-quote-name,
.chat-page .message-media-fit .message-quote-text {
    overflow: visible;
    overflow-wrap: anywhere;
    text-overflow: clip;
    white-space: normal;
}

.chat-page .message-media-fit .circle-player {
    width: 220px;
    max-width: 100%;
}
