:root {
  color-scheme: light;
  --ink: #202e4d;
  --muted: #526582;
  --accent: #4b4cb4;
  --accent-dark: #38398e;
  --line: #d8e3f3;
  --paper: #fffffff0;
  --shadow: 0 20px 60px #45659c17, 0 2px 0 #ffffffcf inset;
  font: 16px/1.65 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 4% 7%, #d7f3ff 0%, transparent 50%),
    radial-gradient(ellipse at 91% 8%, #e9e5ff 0%, transparent 48%),
    radial-gradient(ellipse at 94% 86%, #eef1ff 0%, transparent 58%),
    #f5faff;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .54; cursor: default; }
:focus-visible { outline: 3px solid #5b78d1; outline-offset: 3px; }
h1, h2, p { margin: 0; }

.site-shell {
  width: min(100%, 70rem);
  margin: auto;
  padding: 0 clamp(1rem, 4vw, 2.75rem) max(1.25rem, env(safe-area-inset-bottom));
}

.topbar {
  min-height: 5.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid #d3e0f3;
}

.brand { display: flex; align-items: center; gap: .72rem; font-size: 1.23rem; font-weight: 730; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 2.38rem;
  height: 2.38rem;
  border: 1px solid #aebeea;
  border-radius: .83rem;
  background: linear-gradient(145deg, #fbfeff, #dce7ff 70%, #eae4ff);
  box-shadow: 0 2px 0 #cfdbf3, 0 5px 15px #7896d129;
  color: #4b59a6;
  font-size: 1.4rem;
  line-height: 1;
}

.loading { padding: 2.75rem .25rem; color: var(--muted); }

.welcome {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(21rem, 1fr);
  place-items: center stretch;
  gap: clamp(2rem, 6vw, 6rem);
  min-height: min(36rem, 77dvh);
  padding: 2.6rem clamp(0rem, 3vw, 2rem);
}

.welcome-intro { padding-bottom: 2.5rem; }
.welcome-intro h1 {
  font-size: clamp(3rem, 6.1vw, 5.5rem);
  font-weight: 780;
  line-height: 1.12;
  letter-spacing: -.08em;
}
.welcome-intro h1 span { color: #756ad0; }
.welcome-intro p { margin-top: 1.2rem; font-size: 1.1rem; color: var(--muted); }

.login-card, .chat-card {
  border: 1px solid var(--line);
  border-radius: 1.55rem;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.login-card { display: grid; gap: 1rem; padding: clamp(1.3rem, 3vw, 2.25rem); }
.login-card h2 { margin-bottom: .26rem; font-size: 1.53rem; }
.login-card .primary-button { margin-top: .25rem; }
.field { display: grid; gap: .35rem; min-width: 0; }
.field label { color: #405475; font-size: .93rem; font-weight: 640; }

input, select, textarea {
  width: 100%;
  min-height: 2.85rem;
  border: 1px solid #cbdaef;
  border-radius: .76rem;
  background: #f9fbff;
  color: var(--ink);
  padding: .55rem .77rem;
}
input:focus, select:focus, textarea:focus { border-color: #6f85cc; }
input::placeholder, textarea::placeholder { color: #627796; }
select { appearance: none; padding-right: 2rem; }
.select-field { position: relative; }
.select-field::after {
  content: "";
  position: absolute;
  pointer-events: none;
  right: .85rem;
  bottom: 1.28rem;
  width: .43rem;
  height: .43rem;
  transform: rotate(45deg);
  border: solid #546789;
  border-width: 0 2px 2px 0;
}

.primary-button, .quiet-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: .53rem 1rem;
  border-radius: .75rem;
  font-weight: 690;
  white-space: nowrap;
}
.primary-button {
  border: 1px solid var(--accent);
  color: #fff;
  background: linear-gradient(140deg, #5f59bf, var(--accent));
  box-shadow: 0 4px 10px #4c4cb42b;
}
.primary-button:hover:not(:disabled) { background: var(--accent-dark); }
.quiet-button {
  border: 1px solid #cdd9ed;
  background: #fafdff;
  color: #394e76;
  font-size: .9rem;
}
.quiet-button:hover:not(:disabled) { background: #eaf0ff; border-color: #a9bee5; }

.chat-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 32rem;
  height: calc(100vh - 7rem);
  height: calc(100dvh - 7rem);
  max-height: 65rem;
  margin-top: 1.25rem;
  overflow: hidden;
}
.chat-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1.1rem;
  padding: 1.12rem clamp(1rem, 3vw, 1.75rem);
  border-bottom: 1px solid #e2e9f5;
}
.chat-heading { display: flex; align-items: center; gap: 1rem; }
.chat-heading h1 { font-size: 1.5rem; }
.settings { display: grid; grid-template-columns: minmax(9rem, 1fr) minmax(7.5rem, .85fr); gap: .8rem; }
.conversation {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: clamp(1rem, 3vw, 2rem);
  scrollbar-color: #c4d2e8 transparent;
}
.conversation:focus-visible { outline-offset: -4px; }

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: .85rem;
  min-height: 100%;
  padding: 1rem 0;
  text-align: center;
}
.empty-mark { width: 3.32rem; height: 3.32rem; font-size: 1.85rem; border-radius: 1.1rem; }
.empty-state h2 { font-size: clamp(1.3rem, 4vw, 1.8rem); }
.suggestions { display: flex; justify-content: center; flex-wrap: wrap; gap: .48rem; margin-top: .1rem; }
.suggestions .quiet-button { min-height: 2.35rem; padding: .36rem .7rem; background: #f6f9ff; }

.messages { display: grid; gap: 1.35rem; width: min(100%, 49rem); margin: 0 auto; }
.message { justify-self: start; min-width: 0; max-width: 100%; width: 100%; }
.message.user { justify-self: end; width: auto; max-width: 83%; }
.message-label { display: block; margin: 0 0 .33rem .22rem; color: var(--muted); font-size: .84rem; font-weight: 680; }
.message.user .message-label { margin-left: 0; margin-right: .25rem; text-align: right; }
.message-body {
  padding: .72rem .95rem;
  border: 1px solid #e0e7f4;
  border-radius: .35rem 1rem 1rem 1rem;
  background: #f9fbff;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.user .message-body {
  border-color: #cfe0fc;
  border-radius: 1rem .35rem 1rem 1rem;
  background: #edf4ff;
}
.formatted { white-space: normal; }
.formatted > * { margin: 0; }
.formatted > * + * { margin-top: .72em; }
.formatted > p { white-space: pre-line; }
.formatted h2, .formatted h3, .formatted h4 { font-size: 1.05rem; }
.formatted ul, .formatted ol { padding-left: 1.3rem; }
.formatted a { color: #3f51a4; }
.formatted code { padding: .08rem .24rem; border-radius: .26rem; background: #e9eff9; }
.formatted pre {
  padding: .8rem;
  border-radius: .67rem;
  overflow-x: auto;
  color: #edf4ff;
  background: #253654;
  line-height: 1.5;
}
.formatted pre code { padding: 0; background: none; }

.composer { border-top: 1px solid #e2e9f5; padding: .85rem clamp(.75rem, 3vw, 1.75rem) .52rem; background: #ffffffdc; }
.compose-row { display: flex; align-items: end; gap: .65rem; max-width: 49rem; margin: auto; }
.compose-row textarea { flex: 1; min-width: 0; resize: none; }
.send, .stop { min-width: 4.3rem; }
.error { color: #a3313c; font-size: .91rem; overflow-wrap: anywhere; }
.composer .error, .reply-status { max-width: 49rem; margin: 0 auto; }
.composer .error { margin-bottom: .5rem; }
.reply-status { min-height: 1.25rem; margin-top: .24rem; font-size: .82rem; color: var(--muted); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 42rem) {
  .topbar { min-height: 4.25rem; }
  .welcome { grid-template-columns: 1fr; gap: 1.45rem; min-height: 0; padding: 3rem 0 2rem; }
  .welcome-intro { padding: 0; }
  .welcome-intro p { margin-top: .8rem; }
  .login-card { padding: 1.3rem; }
  .chat-card { margin-top: .72rem; min-height: 24rem; height: calc(100vh - 6.35rem); height: calc(100dvh - 6.35rem); }
  .chat-header { display: grid; gap: .63rem; padding: .72rem .72rem .85rem; }
  .chat-heading { justify-content: space-between; }
  .new-chat { min-height: 2.2rem; }
  .settings { grid-template-columns: minmax(0, 1fr) minmax(0, .82fr); gap: .55rem; }
  .conversation { padding: .8rem .72rem; }
  .compose-row { gap: .4rem; }
  .compose-row .primary-button, .compose-row .quiet-button { min-width: 3.8rem; padding-inline: .65rem; }
  .message.user { max-width: 92%; }
}
