:root {
    --bg: #f7f1e8;
    --bg-accent: #eadfcf;
    --surface: rgba(255, 252, 247, 0.92);
    --surface-strong: #fffaf2;
    --line: rgba(60, 43, 27, 0.12);
    --text: #2d2117;
    --muted: #79624d;
    --primary: #9a3412;
    --primary-strong: #7c2d12;
    --bubble-own: #f4b183;
    --bubble-other: #fff3df;
    --danger: #c2410c;
    --shadow: 0 18px 40px rgba(64, 41, 18, 0.14);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top right, rgba(154, 52, 18, 0.16), transparent 28%),
        radial-gradient(circle at bottom left, rgba(120, 53, 15, 0.12), transparent 22%),
        linear-gradient(180deg, var(--bg), var(--bg-accent));
    color: var(--text);
    overflow-x: hidden;
}

button,
input,
textarea {
    font: inherit;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 16px;
}

body.chat-active {
    overflow: hidden;
}

body.modal-open {
    overflow: hidden;
}

body.chat-active .app-shell {
    min-height: 100dvh;
    padding: 0;
    display: block;
}

.card,
.chat-screen {
    width: min(100%, 560px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 28px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.login-card {
    padding: 28px 22px;
}

.brand,
.stack,
.composer,
.chat-screen {
    display: grid;
    gap: 16px;
}

.chat-screen {
    min-height: calc(100vh - 32px);
    padding: 16px;
    grid-template-rows: auto 1fr auto;
    overflow: hidden;
}

body.chat-active .chat-screen {
    position: fixed;
    inset: 0;
    width: min(100%, 560px);
    min-height: 100dvh;
    height: 100dvh;
    margin-inline: auto;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 0;
    border-left: 0;
    border-right: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

.eyebrow {
    margin: 0 0 6px;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

h1,
h2 {
    margin: 0;
}

.supporting {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.headline-preview {
    display: grid;
    gap: 12px;
}

.headline-item {
    padding: 14px 16px;
    border-radius: 18px;
    background: rgba(255, 250, 242, 0.82);
    border: 1px solid rgba(60, 43, 27, 0.08);
}

.headline-item h2 {
    margin: 0;
    font-size: 1rem;
    line-height: 1.35;
}

.headline-kicker {
    margin: 0 0 6px;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary-strong);
}

.field,
.composer-field {
    display: grid;
    gap: 8px;
}

.field span {
    font-size: 0.94rem;
    color: var(--muted);
}

input,
textarea {
    width: 100%;
    border: 1px solid rgba(60, 43, 27, 0.15);
    border-radius: 18px;
    padding: 14px 16px;
    background: var(--surface-strong);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

input:focus,
textarea:focus {
    border-color: rgba(154, 52, 18, 0.55);
    transform: translateY(-1px);
}

textarea {
    min-height: 52px;
    max-height: 160px;
    resize: vertical;
}

.primary-button,
.icon-button {
    border: 0;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s ease;
}

.primary-button {
    padding: 14px 18px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: #fff9f2;
    font-weight: 600;
}

.send-button {
    min-width: 52px;
    padding: 0;
    min-height: 45px;
}

.send-button svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.primary-button:active,
.icon-button:active {
    transform: scale(0.98);
}

.icon-button {
    width: 46px;
    height: 46px;
    display: inline-grid;
    place-items: center;
    border-radius: 14px;
    background: rgba(154, 52, 18, 0.09);
    color: var(--danger);
}

.icon-button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.presence-indicator {
    display: inline-grid;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    align-items: center;
    justify-content: end;
    gap: 6px;
    min-height: 18px;
    width: max-content;
    flex: 0 0 auto;
    overflow: visible;
}

.presence-dot {
    width: 10px;
    height: 10px;
    display: block;
    border-radius: 999px;
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14);
}

.message-list {
    display: grid;
    align-content: start;
    gap: 12px;
    overflow-y: auto;
    padding: 8px 2px;
    min-height: 0;
}

.message-bubble {
    justify-self: start;
    max-width: 85%;
    padding: 12px 14px;
    border-radius: 20px 20px 20px 6px;
    background: var(--bubble-other);
    border: 1px solid rgba(60, 43, 27, 0.08);
}

.message-bubble.own {
    justify-self: end;
    border-radius: 20px 20px 6px 20px;
    background: var(--bubble-own);
}

.message-meta {
    margin: 0 0 6px;
    font-size: 0.78rem;
    color: rgba(45, 33, 23, 0.72);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.message-meta span {
    color: rgba(45, 33, 23, 0.56);
}

.message-body {
    margin: 0;
    white-space: normal;
    line-height: 1.45;
    word-break: break-word;
}

.message-image-link {
    display: block;
    margin-bottom: 10px;
}

.message-image {
    width: 100%;
    max-width: 260px;
    max-height: 340px;
    object-fit: cover;
    border-radius: 16px;
    border: 1px solid rgba(60, 43, 27, 0.08);
    background: rgba(255, 255, 255, 0.55);
}

.composer {
    grid-template-columns: 1fr;
    align-items: end;
    gap: 0;
}

.composer-shell {
    display: grid;
    gap: 8px;
    margin: 0 -16px -16px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    padding-bottom: 0;
    background: linear-gradient(180deg, rgba(247, 241, 232, 0), rgba(255, 250, 242, 0.96) 24%, rgba(255, 250, 242, 0.98));
    border-top: 1px solid rgba(60, 43, 27, 0.08);
}

.composer-tools {
    display: grid;
    gap: 12px;
}

.composer-row {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    align-items: end;
    gap: 10px;
}

.composer-field {
    min-width: 0;
}

.composer-field textarea {
    min-height: 45px;
    resize: none;
    padding: 10px 5px 0;
}

.emoji-strip {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
}

.emoji-strip::-webkit-scrollbar {
    display: none;
}

.emoji-button,
.image-picker,
.composer-icon-button {
    border: 1px solid rgba(60, 43, 27, 0.14);
    background: rgba(255, 250, 242, 0.88);
    border-radius: 14px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.emoji-button {
    font-size: 1.2rem;
}

.emoji-button:active,
.image-picker:active,
.composer-icon-button:active {
    transform: scale(0.98);
}

.composer-icon-button {
    width: 48px;
    padding: 0;
    font-size: 1.2rem;
    color: var(--text);
}

.image-picker {
    color: var(--text);
    padding: 0;
}

.image-picker svg,
.composer-icon-button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.selected-image {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
    word-break: break-word;
}

.send-status {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 0.72rem;
    text-align: right;
}

.send-button:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.image-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
}

.image-modal-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(14, 10, 7, 0.78);
    cursor: pointer;
}

.image-modal-panel {
    position: relative;
    z-index: 1;
    width: min(100%, 760px);
    max-height: calc(100dvh - 40px);
    display: grid;
    justify-items: center;
    gap: 12px;
}

.image-modal-preview {
    max-width: 100%;
    max-height: calc(100dvh - 96px);
    border-radius: 18px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.34);
    background: #fff;
}

.image-modal-close {
    justify-self: end;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    color: #2d2117;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}

.feedback {
    margin: 0;
    color: var(--danger);
    font-size: 0.92rem;
}

.chat-feedback {
    text-align: center;
}

.is-hidden {
    display: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

@media (max-width: 640px) {
    .app-shell {
        padding: 0;
    }

    .chat-screen,
    .login-card {
        width: 100%;
        min-height: 100vh;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
    }

    body.chat-active .chat-screen {
        left: 0;
        transform: none;
    }

    .login-card {
        display: grid;
        align-content: center;
    }

    .composer-row {
        grid-template-columns: 44px 44px minmax(0, 1fr) auto;
        gap: 8px;
    }

    .message-image {
        max-width: 100%;
    }
}
