:root {
  --bg:          #0d0d11;
  --surface:     #14141a;
  --surface-2:   #1c1c24;
  --surface-3:   #24242f;
  --border:      rgba(255,255,255,0.07);
  --border-hi:   rgba(255,255,255,0.13);
  --text:        #ededf2;
  --text-2:      #b0b0c0;
  --muted:       #68687a;
  --red:         #e84444;
  --red-dim:     #c93030;
  --red-glow:    rgba(232,68,68,0.22);
  --red-soft:    rgba(232,68,68,0.10);
  --green:       #3dba7e;
  --green-soft:  rgba(61,186,126,0.12);
  --amber:       #e8a030;
  --amber-soft:  rgba(232,160,48,0.12);
  --blue-soft:   rgba(100,140,255,0.12);
  --r-xl: 24px;
  --r-lg: 18px;
  --r-md: 14px;
  --r-sm: 10px;
  --ease: cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; height: 100%; }

body {
  height: 100%;
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, textarea { font: inherit; }
button { cursor: pointer; }

/* ── Page glow ─────────────────────────────────────────────────── */
.page-glow {
  position: fixed;
  pointer-events: none;
  border-radius: 50%;
  filter: blur(100px);
  opacity: .22;
  z-index: 0;
}
.page-glow-left  { width: 42rem; height: 42rem; top: -14rem; left: -14rem; background: var(--red); }
.page-glow-right { width: 36rem; height: 36rem; bottom: -10rem; right: -10rem; background: #5548cc; }

/* ── Shell ─────────────────────────────────────────────────────── */
.shell {
  position: relative;
  z-index: 1;
  width: min(1400px, 100vw);
  height: 100vh;
  display: grid;
  grid-template-columns: 300px 1fr;
}

/* ── Brand panel ───────────────────────────────────────────────── */
.brand-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  padding: 28px 22px;
  gap: 24px;
}

.eyebrow {
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

.seal-stage {
  position: relative;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  padding: 28px 20px;
  overflow: hidden;
}

.seal-halo {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 60%, var(--red-glow), transparent 65%);
}

.seal-logo {
  position: relative;
  width: min(100%, 200px);
  max-height: 240px;
  object-fit: contain;
  filter: drop-shadow(0 16px 32px rgba(232,68,68,.28));
  animation: floatSeal 6s ease-in-out infinite;
}

.seal-logo-fallback {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--red), #9b2020);
  display: grid;
  place-items: center;
  font-size: 36px;
  font-weight: 900;
  color: #fff;
  letter-spacing: -.02em;
  box-shadow: 0 0 40px var(--red-glow);
}

@keyframes floatSeal {
  0%,100% { transform: translateY(0)   scale(1); }
  50%      { transform: translateY(-7px) scale(1.02); }
}

.brand-copy h1 {
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: clamp(22px, 2.2vw, 26px);
  line-height: 1.2;
  color: var(--text);
}

.brand-copy p {
  margin-top: 8px;
  font-size: 13.5px;
  color: var(--text-2);
  line-height: 1.65;
}

.brand-stats {
  display: grid;
  gap: 10px;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.stat-icon { font-size: 18px; flex-shrink: 0; }

.stat-text strong {
  display: block;
  font-size: 13px;
  color: var(--text);
}
.stat-text span {
  font-size: 12px;
  color: var(--muted);
}

.brand-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Chat panel ────────────────────────────────────────────────── */
.chat-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(13,13,17,.85);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.section-kicker {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.chat-header h2 {
  font-family: "Noto Serif SC", serif;
  font-size: clamp(20px, 2vw, 26px);
  font-weight: 700;
  color: var(--text);
}

.status-cluster { display: flex; align-items: center; gap: 10px; }

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  transition: background .2s, color .2s;
}

.status-pill::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background .2s;
}

.status-pill[data-state="thinking"]::before { background: #648cff; box-shadow: 0 0 6px #648cff; }
.status-pill[data-state="thinking"]         { color: #9ab0ff; background: var(--blue-soft); }
.status-pill[data-state="success"]::before  { background: var(--green); }
.status-pill[data-state="success"]          { color: var(--green); background: var(--green-soft); }
.status-pill[data-state="error"]::before    { background: var(--red); }
.status-pill[data-state="error"]            { color: #ff8080; background: var(--red-soft); }
.status-pill[data-state="listening"]::before{ background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.status-pill[data-state="listening"]        { color: var(--amber); background: var(--amber-soft); }

/* prompt chips */
.prompt-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.prompt-chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  transition: border-color .15s var(--ease), background .15s var(--ease), color .15s var(--ease);
}

.prompt-chip:hover {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--text);
}

/* conversation */
.conversation {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.conversation::-webkit-scrollbar { width: 4px; }
.conversation::-webkit-scrollbar-track { background: transparent; }
.conversation::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 99px; }

.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  max-width: 860px;
  animation: riseIn 220ms var(--ease);
}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user {
  flex-direction: row-reverse;
  margin-left: auto;
  max-width: 72%;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.avatar-assistant {
  background: linear-gradient(135deg, #3a1a1a, #5a2020);
  color: var(--red);
  border: 1px solid rgba(232,68,68,.2);
  font-size: 16px;
}

.avatar-user {
  background: linear-gradient(135deg, var(--red-dim), var(--red));
  color: #fff;
}

.bubble {
  border-radius: var(--r-lg);
  padding: 14px 18px;
  border: 1px solid var(--border);
  word-break: break-word;
  overflow-wrap: anywhere;
}

.bubble-assistant {
  background: var(--surface);
  border-color: var(--border);
}

.bubble-user {
  background: linear-gradient(135deg, var(--red-dim) 0%, var(--red) 100%);
  border-color: transparent;
  color: #fff;
}

/* Markdown inside bubbles */
.markdown-body { color: inherit; }
.bubble-assistant .markdown-body { color: var(--text); }
.bubble-user     .markdown-body { color: #fff; }

.markdown-body h1,.markdown-body h2,.markdown-body h3 {
  margin: .65em 0 .3em;
  font-weight: 700;
  line-height: 1.3;
}
.markdown-body h1 { font-size: 1.12em; }
.markdown-body h2 { font-size: 1.04em; }
.markdown-body h3 { font-size: .97em; color: var(--text-2); }
.bubble-user .markdown-body h3 { color: rgba(255,255,255,.8); }

.markdown-body p  { margin: .35em 0; }
.markdown-body ul,.markdown-body ol { margin: .3em 0; padding-left: 1.4em; }
.markdown-body li { margin: .18em 0; }

.markdown-body strong { font-weight: 700; }
.markdown-body em     { font-style: italic; opacity: .85; }

.markdown-body blockquote {
  border-left: 2px solid var(--red);
  padding: .2em .8em;
  margin: .4em 0;
  opacity: .75;
  font-style: italic;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: .55em 0;
  font-size: .88em;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border-hi);
  padding: .3em .7em;
  text-align: left;
}
.markdown-body th {
  background: var(--surface-2);
  font-weight: 700;
  color: var(--text);
}
.markdown-body tr:nth-child(even) { background: rgba(255,255,255,.03); }

.markdown-body code {
  background: var(--surface-3);
  border-radius: 5px;
  padding: .1em .36em;
  font-family: "Fira Code", "SF Mono", monospace;
  font-size: .87em;
  color: #c0c8ff;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: .65em 0;
}

/* cursor */
.typing-cursor::after {
  content: "▋";
  animation: blink .65s step-end infinite;
  color: var(--red);
}
@keyframes blink { 50% { opacity: 0; } }

/* sources */
.sources-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.source-tag {
  font-size: 11.5px;
  padding: .2em .6em;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Composer ──────────────────────────────────────────────────── */
.composer {
  flex-shrink: 0;
  padding: 16px 28px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.composer-label {
  display: none;
}

.composer-shell {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 14px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color .18s var(--ease);
}

.composer-shell:focus-within {
  border-color: rgba(232,68,68,.4);
  box-shadow: 0 0 0 3px var(--red-soft);
}

textarea {
  flex: 1;
  resize: none;
  min-height: 26px;
  max-height: 160px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  line-height: 1.7;
  font-size: 15px;
}

textarea::placeholder { color: var(--muted); }

.composer-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.ghost-button, .primary-button {
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  transition: opacity .15s, transform .12s, background .15s;
}

.ghost-button {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-2);
}
.ghost-button:hover { background: var(--surface-3); color: var(--text); }

.primary-button {
  background: var(--red);
  color: #fff;
  border-color: var(--red-dim);
  box-shadow: 0 4px 18px var(--red-glow);
}
.primary-button:hover  { opacity: .9; transform: translateY(-1px); }
.primary-button:active { transform: translateY(0); }

.ghost-button:disabled, .primary-button:disabled {
  opacity: .38;
  cursor: not-allowed;
  transform: none !important;
}

.composer-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ── Auth Overlay ──────────────────────────────────────────────── */
#authOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 8, 12, 0.92);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-xl);
  padding: 40px 36px;
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  box-shadow: 0 32px 80px rgba(0,0,0,.6), 0 0 0 1px rgba(232,68,68,.1);
}

.auth-logo {
  font-size: 48px;
  line-height: 1;
  filter: drop-shadow(0 4px 16px rgba(232,68,68,.4));
}

.auth-card h2 {
  font-family: "Noto Serif SC", serif;
  font-size: 22px;
  color: var(--text);
  margin: 0;
}

.auth-card > p {
  font-size: 14px;
  color: var(--text-2);
  margin: 0;
  line-height: 1.6;
}

.auth-input-row {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
}

.auth-input-row input {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-hi);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-family: "Fira Code", "SF Mono", monospace;
  letter-spacing: .06em;
  outline: none;
  transition: border-color .15s;
}
.auth-input-row input:focus { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.auth-input-row input::placeholder { color: var(--muted); letter-spacing: normal; }

.auth-error {
  font-size: 13px;
  color: #ff7070;
  min-height: 18px;
  margin: 0;
}

.auth-hint {
  font-size: 12.5px;
  color: var(--muted);
  margin: 0;
}

/* ── Quota badge ───────────────────────────────────────────────── */
.quota-badge {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12.5px;
  color: var(--text-2);
}

.quota-badge:not(:empty) { display: inline-flex; }
.quota-badge[data-low="true"] { border-color: rgba(232,160,48,.4); color: var(--amber); background: var(--amber-soft); }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .brand-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 16px 20px;
    gap: 16px;
  }

  .seal-stage { width: 64px; height: 64px; padding: 10px; border-radius: 14px; flex-shrink: 0; }
  .seal-logo  { width: 44px; max-height: 44px; }
  .seal-halo  { display: none; }
  .brand-copy h1 { font-size: 18px; }
  .brand-copy p  { display: none; }
  .brand-stats   { display: none; }
  .brand-footer  { display: none; }

  .chat-panel { min-height: 90vh; }
}

@media (max-width: 640px) {
  .chat-header  { padding: 14px 16px 12px; }
  .prompt-row   { padding: 10px 16px; gap: 6px; }
  .conversation { padding: 16px 16px 8px; }
  .composer     { padding: 12px 16px 16px; }

  .message.user { max-width: 88%; }

  .chat-header h2 { font-size: 18px; }
  .prompt-chip    { font-size: 12px; padding: 6px 12px; }
}
