:root {
  --bg-1: #f8fbff;
  --bg-2: #eef6ff;
  --bg-3: #fdfcff;
  --line: rgba(75, 104, 140, 0.22);
  --text: #1f2f46;
  --dim: #5d7597;
  --accent: #16b79a;
  --accent-2: #3d8fff;
  --warn: #df5f5f;
  --user: rgba(72, 132, 222, 0.16);
  --assistant: rgba(32, 182, 148, 0.14);
  --think: rgba(255, 190, 93, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--text);
  font-family: "Manrope", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(1200px 800px at 10% -20%, rgba(61, 143, 255, 0.18), transparent 56%),
    radial-gradient(1000px 720px at 110% 10%, rgba(22, 183, 154, 0.16), transparent 58%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2) 50%, var(--bg-3));
}

.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(0deg, rgba(54, 81, 116, 0.03), rgba(54, 81, 116, 0.03) 1px, transparent 1px, transparent 4px),
    repeating-linear-gradient(90deg, rgba(54, 81, 116, 0.025), rgba(54, 81, 116, 0.025) 1px, transparent 1px, transparent 4px);
  mask-image: radial-gradient(circle at center, black 40%, transparent 95%);
}

.page {
  width: min(1100px, 94vw);
  margin: 20px auto 30px;
  display: grid;
  gap: 14px;
}

.glass {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.74), rgba(245, 251, 255, 0.82));
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(85, 121, 164, 0.16);
  backdrop-filter: blur(12px);
}

.topbar {
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.tag {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: #5380b8;
}

.topbar h1 {
  margin: 6px 0 6px;
  font-size: clamp(24px, 3.2vw, 38px);
  line-height: 1.05;
}

.sub {
  margin: 0;
  color: var(--dim);
  font-size: 14px;
}

.status-box {
  min-width: 160px;
  border: 1px solid rgba(98, 129, 163, 0.26);
  border-radius: 12px;
  padding: 9px 11px;
  font-size: 12px;
  color: var(--dim);
  background: rgba(255, 255, 255, 0.55);
  display: grid;
  gap: 4px;
}

.status-box strong {
  font-size: 13px;
  color: #128c74;
}

.control-bar {
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1.5fr 1fr auto auto;
  gap: 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--dim);
}

.model-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

#modelSelect {
  height: 40px;
}

#refreshModelsBtn {
  height: 40px;
  white-space: nowrap;
}

input,
select,
textarea,
button {
  font: inherit;
  color: var(--text);
}

input,
select,
textarea {
  border: 1px solid rgba(111, 140, 176, 0.34);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(22, 183, 154, 0.72);
  box-shadow: 0 0 0 3px rgba(22, 183, 154, 0.15);
}

.check-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  color: #395476;
}

.check-wrap input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

button {
  border: none;
  border-radius: 12px;
  height: 40px;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #ffffff;
}

button.ghost {
  border: 1px solid rgba(111, 140, 176, 0.36);
  background: rgba(255, 255, 255, 0.72);
  color: #2a4668;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-list {
  min-height: 56vh;
  max-height: 68vh;
  overflow: auto;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.session-tip {
  padding: 10px 12px;
  font-size: 12px;
  color: #516d90;
}

.msg {
  border: 1px solid rgba(105, 136, 173, 0.24);
  border-radius: 14px;
  padding: 11px 12px;
  max-width: min(90%, 860px);
}

.msg.user {
  justify-self: end;
  background: var(--user);
}

.msg.assistant {
  justify-self: start;
  background: var(--assistant);
}

.msg-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: #5d7fa7;
}

.msg-role {
  font-weight: 700;
  color: #284363;
}

.msg-time {
  font-family: "JetBrains Mono", monospace;
}

.md {
  line-height: 1.6;
  word-break: break-word;
}

.md > :first-child {
  margin-top: 0;
}

.md > :last-child {
  margin-bottom: 0;
}

.md pre {
  position: relative;
  overflow: auto;
  background: rgba(242, 248, 255, 0.9);
  border: 1px solid rgba(110, 141, 177, 0.24);
  border-radius: 10px;
  padding: 10px;
}

.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(111, 140, 176, 0.36);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: #2a4668;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.msg-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.msg-copy-btn {
  height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(111, 140, 176, 0.36);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.85);
  color: #2a4668;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.md code {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.think-wrap {
  margin-top: 9px;
  border: 1px dashed rgba(255, 191, 94, 0.5);
  border-radius: 10px;
  background: var(--think);
  padding: 8px;
}

.think-wrap summary {
  cursor: pointer;
  color: #8f6420;
  font-size: 12px;
}

.think-wrap .md {
  margin-top: 6px;
  color: #7a5b2a;
  font-size: 13px;
}

.answer-wrap {
  margin-top: 8px;
}

.composer {
  padding: 12px;
  display: grid;
  gap: 10px;
}

#promptInput {
  resize: vertical;
  min-height: 84px;
  max-height: 240px;
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.stream-tip {
  margin-right: auto;
  font-size: 12px;
  color: var(--dim);
}

@media (max-width: 860px) {
  .control-bar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .model-row {
    grid-template-columns: 1fr;
  }

  .chat-list {
    min-height: 52vh;
    max-height: 64vh;
  }

  .msg {
    max-width: 100%;
  }
}
