:root {
  color-scheme: light;
  --paper: #f5f1e8;
  --sheet: #fbf8f1;
  --ink: #1b1a1a;
  --muted: #645d56;
  --line: #3a2c211e;
  --focus: #3e5589;
  --card-shadow: 0 22px 65px #43261518, 0 2px 8px #4326150a;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  isolation: isolate;
  background: var(--paper);
  color: var(--ink);
}

.atmosphere {
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 28% 32% at 83% 22%, #6b9e91b3, #91b4a170 42%, transparent 100%),
    radial-gradient(ellipse 30% 37% at 64% 8%, #6a8ac8d6, #9ab7e080 42%, transparent 100%),
    radial-gradient(ellipse 31% 38% at 10% 43%, #909a6eab, #b5b48e64 49%, transparent 100%),
    radial-gradient(ellipse 29% 32% at 26% 31%, #e49665c4, #eda3716e 42%, transparent 100%),
    radial-gradient(ellipse 30% 31% at 23% 98%, #777bc5bf, #afb4e280 42%, transparent 100%),
    radial-gradient(ellipse 36% 36% at 90% 95%, #b076b5b0, #dab0d283 43%, transparent 100%),
    radial-gradient(ellipse 34% 34% at 69% 92%, #f0896cd1, #ffb78b8a 43%, transparent 100%),
    var(--paper);
}

#paper-grain { display: block; width: 100%; height: 100%; opacity: .38; }
body:has(.is-thread) .atmosphere { opacity: .58; }

button, input, select, textarea { color: inherit; font: inherit; }
button { border: 0; border-radius: 11px; background: transparent; padding: 8px 12px; cursor: pointer; }
button:hover:not(:disabled) { background: #33231a0c; }
button:disabled { opacity: .48; cursor: default; }
a { color: inherit; }
button, a, textarea, input, select, summary { outline-offset: 4px; }
:focus-visible { outline: 2px solid var(--focus); }

.top {
  width: min(1140px, calc(100% - 2 * clamp(20px, 5.4vw, 90px)));
  min-height: 76px;
  margin-inline: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  text-decoration: none;
  white-space: nowrap;
  font-size: 1.04rem;
  font-weight: 750;
  letter-spacing: .015em;
}

.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 24% 20%, #ecb58c, transparent 53%),
              linear-gradient(137deg, #4266a5 16%, #4d7f8b 43%, #986597 69%, #e19773 98%);
  box-shadow: inset 0 0 0 1px #1c252d22;
}

nav, .controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
nav { font-size: .85rem; font-weight: 550; }
nav button { min-height: 40px; border-radius: 999px; }
nav #settings { padding-inline: 17px; }

main {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  align-content: center;
  padding: 26px clamp(16px, 4vw, 40px) min(10dvh, 110px);
}

main:has(.is-thread) { align-content: start; padding-block: 0 18px; }
.workspace { width: min(100%, 738px); min-width: 0; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.85rem, 5.3vw, 3.1rem); letter-spacing: -.045em; line-height: 1.23; font-weight: 800; }
h2 { font-size: 1.17rem; }
.start { margin-bottom: 26px; text-align: left; }
.start p { color: var(--muted); font-size: .95rem; line-height: 1.6; margin-top: 9px; }

.compose, .login {
  padding: clamp(22px, 4.2vw, 44px);
  border: 1px solid #fff9;
  border-radius: clamp(24px, 4vw, 36px);
  background: linear-gradient(139deg, #fffaf3ed, #fbf9f3ef 45%, #fbefe8ed);
  backdrop-filter: blur(20px);
  box-shadow: var(--card-shadow);
}

#question-form {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 8px 9px 8px 13px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: #ede7dfbf;
}

#question-form:focus-within { border-color: #53628b; box-shadow: 0 0 0 2px #53628b20; }
#question {
  display: block;
  width: 100%;
  min-height: 56px;
  max-height: 156px;
  padding: 9px 3px 4px;
  border: 0;
  outline: none;
  background: transparent;
  resize: vertical;
  line-height: 1.56;
}
#question::placeholder { color: var(--muted); }

.send, .primary, nav #settings { background: var(--ink); color: #fffaf3; }
.send:hover:not(:disabled), .primary:hover:not(:disabled), nav #settings:hover:not(:disabled) { background: #393435; }
.primary { min-height: 42px; padding-inline: 16px; }
.send { display: grid; place-items: center; min-width: 44px; min-height: 44px; border-radius: 12px; padding: 0; font-size: 1.48rem; }
.send span { transform: translateY(-1px); }
.send:hover span { transform: translate(1px, -2px); }

.compose-meta { display: flex; justify-content: space-between; margin-top: 8px; }
.model-pill, .suggestions button {
  min-height: 34px;
  border-radius: 999px;
  color: var(--muted);
  font-size: .82rem;
}
.model-pill { display: inline-flex; align-items: center; gap: 7px; padding-inline: 8px 10px; }
.model-pill::before { width: 7px; height: 7px; border-radius: 50%; background: #938a80; content: ""; }
.model-pill[data-ready="true"]::before { background: #40766a; }
.suggestions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 13px; padding-top: 14px; border-top: 1px solid var(--line); }
.suggestions button { border: 1px solid var(--line); padding-inline: 11px; text-align: left; }

.workspace.is-thread {
  width: min(100%, 870px);
  height: max(520px, calc(100dvh - 95px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.is-thread .compose { border-radius: 22px; padding: 12px 14px 6px; }
.is-thread .compose-meta { margin-top: 4px; }
.thread-head { display: flex; justify-content: flex-end; padding-block: 11px 8px; }
.thread-head button { min-height: 36px; border: 1px solid var(--line); border-radius: 999px; background: #faf7efc9; font-size: .87rem; }
.thread { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: 7px 7px 15px 1px; }
.exchange { display: grid; gap: 13px; margin-bottom: 22px; }
.exchange > div { padding: clamp(14px, 3vw, 22px); background: #fffbf4df; border: 1px solid #ffffff8c; border-radius: 20px; }
.question { justify-self: end; max-width: min(92%, 600px); background: #e7deefd9; border: 1px solid #fbf5ff8f; border-radius: 16px 16px 5px 16px; padding: 10px 14px; }
.question, .answer-text, .source-text, .note-copy { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.72; }
.answer-text { margin: 7px 0 12px; }
.answer-label { font-size: .8rem; color: var(--muted); font-weight: 690; }
.answer-footer { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 8px 16px; font-size: .83rem; color: var(--muted); }
.answer-footer button { padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px; }
.sources { flex: 1 1 230px; padding-top: 6px; min-width: 0; }
summary { cursor: pointer; }
.sources ul { margin: 8px 0 6px; padding-left: 20px; }
.sources li { margin: 0 0 12px; }
.source-text { margin-top: 4px; }

.error { color: #8c291f; max-width: 100%; margin: 10px 0 0; overflow-wrap: anywhere; font-size: .88rem; }
main > .error { background: #fff5ed; border: 1px solid #ad504044; border-radius: 11px; padding: 8px 13px; }
.login { width: min(100%, 418px); }
.login h1 { font-size: clamp(1.75rem, 5vw, 2.18rem); margin-bottom: 24px; }
.login .primary { width: 100%; margin-top: 4px; }
.fields { display: grid; gap: 13px; }
.fields label { display: grid; gap: 6px; font-size: .89rem; }
.fields input, .fields select, .fields textarea { width: 100%; min-height: 42px; background: #fffcf7; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; }
.fields textarea { resize: vertical; }
.fields > .primary { justify-self: start; }

dialog {
  width: min(558px, calc(100% - 28px));
  max-height: calc(100dvh - 34px);
  padding: 0;
  border: 1px solid #fff9;
  border-radius: 25px;
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 24px 70px #33251b3a;
}
dialog::backdrop { background: #28212b58; backdrop-filter: blur(5px); }
dialog header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); padding: 13px 20px; }
dialog header button { font-size: 1.4rem; line-height: 1; }
.dialog-body { padding: 18px 20px 21px; }
.controls > button:not(.primary) { border: 1px solid var(--line); min-height: 40px; }
.muted { font-size: .88rem; line-height: 1.6; color: var(--muted); }
#consent-copy { line-height: 1.6; }
#settings-state { margin-bottom: 13px; }
#settings-message { margin-top: 12px; font-size: .9rem; }
.settings-links { justify-content: space-between; margin-top: 17px; padding-top: 13px; border-top: 1px solid var(--line); font-size: .86rem; }
.items { display: grid; gap: 9px; margin-top: 13px; }
.items > button { text-align: left; border: 1px solid var(--line); overflow-wrap: anywhere; }
.note-item { padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.note-item summary { overflow-wrap: anywhere; }
.note-copy { margin: 8px 0; }
.note-item button { color: var(--muted); }
.sr-only { position: absolute; height: 1px; width: 1px; overflow: hidden; clip-path: inset(50%); }

@media (max-width: 520px) {
  .top { width: calc(100% - 32px); min-height: 58px; }
  .brand { font-size: .96rem; }
  .brand-mark { width: 21px; height: 21px; }
  nav { gap: 2px; }
  nav button { padding-inline: 8px; }
  nav #settings { padding-inline: 10px; }
  main { padding-bottom: 6dvh; }
  .start { margin-bottom: 19px; }
  .start p { max-width: 20em; font-size: .88rem; }
  #question { font-size: .92rem; }
  .workspace.is-thread { height: max(450px, calc(100dvh - 125px)); }
}
@media (max-width: 420px) {
  nav { width: 100%; justify-content: flex-end; }
  .suggestions button { max-width: 100%; }
}
