html, body {
    width: 100%;
    height: 100%;
    height: var(--app-height, 100dvh);
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    display: flex;
    flex-direction: column;
}

/* ---- Timer ---- */
.page-timer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    color: var(--danger-text);
    border: 1px solid var(--danger);
    border-radius: 2px;
    padding: 0.3rem 0.7rem;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    background: var(--danger-soft);
    z-index: 25;
    white-space: nowrap;
}

/* ---- Chat container ---- */
.chat-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(65px + 1rem) 1rem 4rem;
    overflow: hidden;
}

#chat-container {
    display: flex;
    flex-direction: column;
    width: min(420px, 100%);
    height: min(620px, calc(var(--app-height, 100dvh) - 8rem));
    background: var(--bg-panel);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 3px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(26, 29, 34, 0.06);
    transition: background 0.3s ease, border-color 0.3s ease;
}

#chat-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 0.88rem;
    min-height: 52px;
    flex-shrink: 0;
}

.chat-session-id {
    margin-left: auto;
    font-size: 0.68rem;
    color: var(--ink-dim);
    font-weight: 400;
    white-space: nowrap;
    letter-spacing: 0.04em;
}

/* ---- Messages ---- */
#messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 3px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg-wrap { display: flex; }
.msg-user-wrap { justify-content: flex-end; }
.msg-supporter-wrap { justify-content: flex-start; }

.msg-user, .msg-supporter {
    max-width: 78%;
    padding: 0.55rem 0.8rem;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.msg-user {
    background: var(--user-bubble);
    color: var(--user-bubble-ink);
    border-bottom-right-radius: 3px;
}

.msg-supporter {
    background: var(--peer-bubble);
    color: var(--peer-bubble-ink);
    border-bottom-left-radius: 3px;
}

.msg-label {
    display: block;
    font-size: 0.62rem;
    font-weight: 500;
    opacity: 0.7;
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.msg-text { margin: 0; }

.msg-time {
    display: block;
    font-size: 0.6rem;
    opacity: 0.5;
    margin-top: 4px;
    text-align: right;
    letter-spacing: 0.04em;
}

.msg-system-wrap {
    display: flex;
    justify-content: center;
    margin: 0.25rem 0;
}

.msg-system-text {
    font-size: 0.7rem;
    color: var(--ink-dim);
    background: var(--input-bg);
    padding: 0.25rem 0.75rem;
    border-radius: 2px;
    text-align: center;
    letter-spacing: 0.04em;
}

/* ---- Typing bubble ---- */
.typing-bubble {
    display: none;
    padding: 0 0.9rem 0.55rem;
    justify-content: flex-start;
    flex-shrink: 0;
}
.typing-bubble.visible { display: flex; }

.typing-bubble-inner {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 48px;
    padding: 0.55rem 0.75rem;
    background: var(--peer-bubble);
    border-radius: 12px;
    border-bottom-left-radius: 3px;
}

.typing-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--ink-dim);
    animation: typing-bounce 1.1s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes typing-bounce {
    0%, 75%, 100% { transform: translateY(0); opacity: 0.45; }
    35% { transform: translateY(-4px); opacity: 1; }
}

/* ---- Chat input ---- */
#chat-form {
    display: flex;
    gap: 0.45rem;
    padding: 0.65rem 0.85rem max(0.8rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#chat-form input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 0.55rem 0.8rem;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--ink);
    font-size: 0.85rem;
    line-height: 1.25;
    outline: none;
    transition: border-color 0.2s;
}
#chat-form input[type="text"]:focus { border-color: var(--accent); }
#chat-form input[type="text"]::placeholder { color: var(--ink-dim); }

#chat-form button {
    padding: 0.55rem 0.9rem;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 3px;
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: opacity 0.2s;
    white-space: nowrap;
}
#chat-form button:hover { opacity: 0.85; }

@media (max-width: 520px) {
    .page-timer { top: 0.75rem; width: calc(100% - 1.5rem); text-align: center; justify-content: center; }
    .chat-wrapper { padding: calc(55px + 0.75rem) 0.75rem 3rem; }
    #chat-container { width: 100%; height: calc(var(--app-height, 100dvh) - 7rem); max-height: none; }
    .chat-session-id { display: none; }
    .msg-user, .msg-supporter { max-width: 86%; }
    #messages { padding: 0.8rem; }
    #chat-form { gap: 0.4rem; }
    #chat-form button { padding-inline: 0.75rem; }
}
