:root {
    color-scheme: light;
    --ink: #1a1d2e;
    --muted: #535873;
    --primary: #514bd9;
    --surface: #f0f2f8;
    --border: #d9ddec;
    --white: #fff;
    --error: #a62941;
    font: 15px/1.6 system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--surface); color: var(--ink); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .7; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
h1, h2, p { margin: 0; }

.app {
    max-width: 1040px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: #f7f8fc;
    border-inline: 1px solid var(--border);
}

.topbar, .brand, .chat-actions { display: flex; align-items: center; }
.topbar {
    justify-content: space-between;
    gap: 12px;
    padding: 16px clamp(16px, 4vw, 40px);
    background: var(--white);
    border-bottom: 1px solid var(--border);
}
.brand { gap: 11px; }
.brand-icon, .message-avatar {
    display: grid;
    place-items: center;
    flex: none;
    background: #e7e8ff;
    color: #453dcc;
    font-weight: 650;
}
.brand-icon { width: 42px; height: 42px; border-radius: 12px; }
.brand-icon svg { width: 24px; height: 24px; }
.brand h1 { font-size: 18px; line-height: 1.3; font-weight: 680; }
.brand p { color: var(--muted); font-size: 12px; }
.chat-actions { gap: 8px; }

.primary, .secondary {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 600;
    white-space: nowrap;
}
.primary { color: var(--white); background: var(--primary); }
.primary:hover:not(:disabled) { background: #443dc5; }
.secondary { background: var(--white); border-color: var(--border); color: var(--ink); }
.secondary:hover:not(:disabled) { background: var(--surface); }

.access-panel {
    flex: 1;
    min-height: 0;
    padding: 24px 16px;
    display: flex;
    overflow: auto;
}
.access-card {
    width: min(100%, 420px);
    margin: auto;
    padding: clamp(20px, 5vw, 32px);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 8px 28px rgb(26 29 46 / 7%);
}
.eyebrow { color: #453dcc; font-size: 13px; font-weight: 650; }
.access-card h2 { margin-top: 4px; font-size: 25px; }
.access-description { color: var(--muted); margin: 6px 0 22px; }
.access-card label { display: block; font-weight: 600; margin-bottom: 6px; }
.access-card input, .access-card button { width: 100%; }
.access-card button { margin-top: 14px; }
.access-card input, .composer textarea {
    min-width: 0;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--ink);
    background: #fafaff;
}
.error, .composer-footer .error { margin-top: 10px; color: var(--error); }

.chat-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.messages, .composer-wrap { width: min(100%, 790px); margin-inline: auto; }
.messages { display: grid; gap: 20px; padding: 26px clamp(14px, 4vw, 28px); }
.message-row { display: flex; align-items: flex-start; gap: 9px; }
.message-row.user { flex-direction: row-reverse; }
.message-avatar { width: 32px; height: 32px; border-radius: 50%; font-size: 12px; }
.message-body { min-width: 0; max-width: min(84%, 65ch); }
.message-author { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.user .message-author { text-align: right; }
.bubble {
    padding: 10px 14px;
    border-radius: 4px 15px 15px 15px;
    background: var(--white);
    border: 1px solid var(--border);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.user .bubble { color: var(--white); background: var(--primary); border-color: var(--primary); border-radius: 15px 4px 15px 15px; }
.composer-wrap { padding: 12px clamp(14px, 4vw, 28px) max(14px, env(safe-area-inset-bottom)); }
.composer { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; resize: vertical; max-height: 25vh; }
.composer-footer { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.composer-footer .error { margin-top: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.no-script { padding: 16px; color: var(--error); }

@media (max-width: 520px) {
    .app { border: 0; }
    .topbar { padding-block: 12px; }
    .brand h1 { font-size: 16px; }
    .brand-icon { width: 36px; height: 36px; }
    .chat-actions button { padding-inline: 9px; font-size: 13px; }
    .keyboard-hint { display: none; }
    .access-card input, .composer textarea { font-size: 16px; }
}
