:root {
  color-scheme: light;
  --page: #f7f8fa;
  --surface: #fff;
  --surface-soft: #f0f2f6;
  --ink: #202433;
  --ink-soft: #656d7f;
  --ink-faint: #60697a;
  --line: #e4e7ee;
  --accent: #4959d6;
  --accent-hover: #3949c5;
  --on-accent: #fff;
  --accent-soft: #eaedff;
  --danger: #ba3a43;
  --shadow: 0 18px 50px rgb(34 45 80 / 8%);
  font-family: "DM Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #151821;
  --surface: #1d212c;
  --surface-soft: #262b38;
  --ink: #f1f2f7;
  --ink-soft: #b5bbca;
  --ink-faint: #8d95a6;
  --line: #343a49;
  --accent: #a7b0ff;
  --accent-hover: #bac1ff;
  --on-accent: #151821;
  --accent-soft: #292e4b;
  --danger: #ff9198;
  --shadow: 0 18px 50px rgb(0 0 0 / 22%);
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; background: var(--page); }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--page); color: var(--ink); }
button, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.app-shell { display: flex; min-height: 100vh; flex-direction: column; }

.topbar { width: min(100% - 64px, 1120px); height: 76px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: Manrope, "DM Sans", sans-serif; font-size: 18px; font-weight: 800; letter-spacing: -.7px; }
.brand-mark { display: grid; width: 31px; height: 31px; place-items: center; border-radius: 11px; background: #4959d6; color: #fff; font-family: Manrope, sans-serif; font-size: 22px; font-weight: 700; line-height: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.tools-link { padding: 9px 11px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--ink-soft); font-size: 12px; text-decoration: none; }
.tools-link:hover { color: var(--ink); background: var(--surface-soft); }
.language-control select { min-height: 38px; padding: 0 30px 0 11px; border: 1px solid var(--line); border-radius: 11px; appearance: none; background: var(--surface) url("/select-chevron.svg") no-repeat right 10px center; color: var(--ink-soft); cursor: pointer; font-size: 13px; }
.icon-button { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); cursor: pointer; transition: background .15s ease, border-color .15s ease; }
.icon-button:hover { background: var(--surface-soft); }
.icon-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.6; }

.main-content { display: flex; width: min(100% - 32px, 790px); flex: 1; flex-direction: column; align-self: center; justify-content: center; padding: 36px 0 24px; }
.welcome { margin: auto 0 38px; text-align: center; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 18px; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: #6e7bf0; box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent); }
h1 { margin: 0; font-family: Manrope, "DM Sans", sans-serif; font-size: clamp(34px, 6vw, 56px); font-weight: 700; letter-spacing: -2.5px; line-height: 1.1; }
.intro { max-width: 500px; margin: 17px auto 0; color: var(--ink-soft); font-size: 16px; line-height: 1.65; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 28px; }
.suggestion { display: inline-flex; min-height: 40px; align-items: center; gap: 8px; padding: 0 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink-soft); cursor: pointer; font-size: 12px; transition: color .15s ease, border-color .15s ease, transform .15s ease; }
.suggestion span:first-child { color: var(--accent); font-size: 14px; }
.suggestion:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); color: var(--ink); }

.conversation { width: 100%; min-height: 150px; max-height: min(55vh, 570px); margin: auto 0 24px; overflow: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.conversation.hidden, .hidden { display: none !important; }
.message-list { display: flex; flex-direction: column; gap: 24px; padding: 8px 4px 18px; }
.message { display: flex; align-items: flex-start; gap: 13px; animation: rise-in .22s ease both; }
.message.user { justify-content: flex-end; }
.avatar { display: grid; width: 29px; height: 29px; flex: 0 0 29px; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-family: Manrope, sans-serif; font-size: 14px; font-weight: 800; }
.message.user .avatar { display: none; }
.message-content { max-width: min(86%, 650px); }
.message.user .message-content { padding: 13px 16px; border: 1px solid var(--line); border-radius: 18px 18px 5px 18px; background: var(--surface); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.message.assistant .message-content { min-width: 0; padding-top: 3px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.72; }
.message-label { margin: 0 0 7px; color: var(--ink-faint); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.message.assistant .message-text { min-height: 1.7em; }
.message.assistant .message-text > :first-child { margin-top: 0; }
.message.assistant .message-text > :last-child { margin-bottom: 0; }
.message.assistant .message-text p { margin: 0 0 12px; }
.message.assistant .message-text h2, .message.assistant .message-text h3, .message.assistant .message-text h4 { margin: 17px 0 8px; font-family: Manrope, "DM Sans", sans-serif; line-height: 1.35; }
.message.assistant .message-text h2 { font-size: 19px; }
.message.assistant .message-text h3 { font-size: 16px; }
.message.assistant .message-text h4 { font-size: 14px; }
.message.assistant .message-text ul, .message.assistant .message-text ol { margin: 7px 0 13px; padding-left: 23px; }
.message.assistant .message-text li { margin: 4px 0; padding-left: 2px; }
.message.assistant .message-text blockquote { margin: 10px 0; padding: 2px 0 2px 13px; border-left: 3px solid var(--line); color: var(--ink-soft); }
.message.assistant .message-text pre { max-width: 100%; margin: 10px 0 14px; padding: 14px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; }
.message.assistant .message-text :not(pre) > code { padding: 2px 5px; border-radius: 5px; background: var(--surface-soft); font: .9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.message.assistant .message-text a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.message-actions { display: flex; gap: 7px; margin-top: 11px; }
.message-action { display: inline-flex; min-height: 30px; align-items: center; gap: 6px; padding: 0 9px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--ink-faint); cursor: pointer; font-size: 11px; }
.message-action:hover { border-color: var(--line); color: var(--ink-soft); }
.message-action svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.6; }
.message-error { color: var(--danger); }
.typing-indicator { display: inline-flex; align-items: center; gap: 5px; height: 23px; }
.typing-indicator span { width: 5px; height: 5px; border-radius: 50%; background: var(--ink-faint); animation: pulse 1s infinite ease-in-out; }
.typing-indicator span:nth-child(2) { animation-delay: .12s; }
.typing-indicator span:nth-child(3) { animation-delay: .24s; }

.composer-wrap { position: sticky; bottom: 0; z-index: 2; width: 100%; margin-top: auto; padding: 0 0 7px; background: linear-gradient(transparent, var(--page) 14%); }
.beta-notice { margin: 0 8px 9px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); color: var(--ink-soft); font-size: 11px; line-height: 1.45; text-align: center; }
.ai-disclosure { margin: 0 8px 8px; color: var(--ink-soft); font-size: 11px; line-height: 1.45; text-align: center; }
.composer { padding: 15px 16px 12px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); transition: border-color .15s ease, box-shadow .15s ease; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 38%, var(--line)); box-shadow: 0 18px 50px rgb(34 45 80 / 10%), 0 0 0 3px color-mix(in srgb, var(--accent) 8%, transparent); }
.composer textarea { display: block; width: 100%; min-height: 30px; max-height: 180px; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 15px; line-height: 1.55; }
.composer textarea::placeholder { color: var(--ink-faint); }
.composer textarea:focus-visible { outline: none; }
.composer-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.composer-hint, .character-count { color: var(--ink-faint); font-size: 10px; }
.composer-actions { display: flex; align-items: center; gap: 12px; }
.send-button { display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; border: 0; border-radius: 13px; background: var(--accent); color: var(--on-accent); cursor: pointer; transition: background .15s ease, transform .15s ease; }
.send-button:hover:not(:disabled) { transform: translateY(-1px); background: var(--accent-hover); }
.send-button:disabled { opacity: .45; cursor: not-allowed; }
.send-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.stop-button { display: inline-flex; min-height: 36px; align-items: center; gap: 7px; padding: 0 11px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--ink-soft); cursor: pointer; font-size: 12px; }
.stop-button:hover { border-color: var(--danger); color: var(--danger); }
.stop-square { width: 9px; height: 9px; border-radius: 2px; background: currentColor; }
.privacy-note { margin: 11px 0 0; color: var(--ink-faint); font-size: 10px; text-align: center; }
.challenge-panel { display: grid; justify-items: center; gap: 5px; margin: 12px 0; padding: 12px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); text-align: center; }
.challenge-title, .challenge-help { margin: 0; }
.challenge-title { color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.challenge-help { color: var(--ink-faint); font-size: 11px; }
.history-dialog { width: min(540px, calc(100vw - 28px)); max-height: min(82dvh, 700px); padding: 22px; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.history-dialog::backdrop { background: rgb(18 22 34 / 42%); backdrop-filter: blur(3px); }
.history-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.history-dialog-header h2 { margin: 0; font-family: Manrope, "DM Sans", sans-serif; font-size: 20px; letter-spacing: -.5px; }
.history-consent { display: flex; align-items: center; gap: 10px; margin-top: 17px; font-size: 13px; font-weight: 650; cursor: pointer; }
.history-consent input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.history-info { margin: 7px 0 15px 27px; color: var(--ink-faint); font-size: 11px; line-height: 1.5; }
.history-empty { margin: 16px 0; color: var(--ink-faint); font-size: 12px; text-align: center; }
.history-list { display: flex; max-height: min(42dvh, 360px); flex-direction: column; gap: 6px; margin: 0; padding: 0; overflow: auto; list-style: none; }
.history-item { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.history-open { min-width: 0; flex: 1; overflow: hidden; border: 0; background: transparent; color: var(--ink); cursor: pointer; font-size: 12px; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.history-item-actions { display: flex; flex: 0 0 auto; gap: 3px; }
.history-item-action { min-height: 30px; padding: 0 7px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-faint); cursor: pointer; font-size: 10px; }
.history-item-action:hover { background: var(--surface-soft); color: var(--ink); }
.history-item-action.danger-text:hover { color: var(--danger); }
.history-status { min-height: 1.3em; margin: 11px 0 7px; color: var(--ink-soft); font-size: 11px; }
.history-dialog-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.secondary-button, .danger-button { min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; font-size: 11px; }
.secondary-button:hover { background: var(--surface-soft); }
.danger-button { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); color: var(--danger); }
.danger-button:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 7%, var(--surface)); }
.danger-button:disabled { opacity: .45; cursor: not-allowed; }
.screen-reader-status, .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }
.footer { width: min(100% - 32px, 790px); margin: 0 auto; padding: 10px 0 max(18px, env(safe-area-inset-bottom)); color: var(--ink-faint); font-size: 10px; text-align: center; }
.model-attributions { margin: 5px 0 0; }
.model-attributions a { color: var(--ink-faint); text-underline-offset: 2px; }

@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

@media (max-width: 640px) {
  .topbar { width: calc(100% - 32px); height: 64px; }
  .main-content { width: calc(100% - 28px); min-height: calc(100svh - 112px); justify-content: flex-end; padding: 30px 0 14px; }
  .welcome { margin: auto 0 27px; }
  h1 { letter-spacing: -1.7px; }
  .intro { max-width: 340px; margin-top: 12px; font-size: 14px; }
  .eyebrow { margin-bottom: 14px; }
  .suggestions { gap: 8px; margin-top: 21px; }
  .suggestion { min-height: 37px; padding: 0 11px; font-size: 11px; }
  .suggestion:last-child { display: none; }
  .conversation { max-height: none; min-height: 100px; flex: 1; margin: 6px 0 14px; }
  .message-list { gap: 19px; }
  .message-content { max-width: 91%; }
  .composer-wrap { padding-bottom: max(5px, env(safe-area-inset-bottom)); }
  .composer { padding: 13px 13px 10px; border-radius: 17px; }
  .composer textarea { font-size: 16px; }
  .composer-hint { max-width: 175px; font-size: 9px; }
  .character-count { font-size: 9px; }
  .composer-actions { gap: 8px; }
  .history-dialog { padding: 17px; border-radius: 16px; }
  .history-item { align-items: flex-start; flex-direction: column; gap: 5px; }
  .history-item-actions { align-self: flex-end; }
  .secondary-button, .danger-button { min-height: 38px; }
  .footer { width: calc(100% - 28px); padding-top: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-delay: 0s !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
