:root {
  --bg: #0d0f14;
  --bg-elevated: #17191f;
  --bg-input: #212327;
  --border: #2a2d35;
  --text: #ececec;
  --text-muted: #8b8f98;
  --accent: #4d6bfe;
  --accent-hover: #5a78ff;
  --accent-soft: rgba(77, 107, 254, 0.15);
  --user-bubble: #2a2d35;
  --sidebar-w: 280px;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-pill: 20px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;

  /* 提问页（明显放大） */
  --welcome-title-size: 28px;
  --welcome-mode-size: 16px;
  --welcome-input-size: 18px;
  --welcome-tool-size: 14px;
  --welcome-composer-max: 780px;

  /* 回答页（适度放大） */
  --chat-msg-size: 16px;
  --chat-input-size: 16px;
  --chat-tool-size: 13px;
  --chat-composer-max: 840px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

textarea {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin 0.25s ease, width 0.25s ease;
}

.sidebar.collapsed {
  width: 0;
  margin-left: calc(-1 * var(--sidebar-w));
  border: none;
  overflow: hidden;
}

.sidebar-restore {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 80;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(23, 25, 31, 0.9);
  color: var(--text);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transform: translateX(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.15s ease;
}

.sidebar-restore:hover {
  background: var(--bg-elevated);
}

.sidebar-restore.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.sidebar-restore span {
  font-size: 14px;
  white-space: nowrap;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
}

.sidebar-left-group {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sidebar-brand {
  font-family: "STXingkai", "华文行楷", "KaiTi", "楷体", cursive;
  font-size: 24px;
  line-height: 1;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: #9fd7ff;
  text-shadow: 0 0 12px rgba(104, 176, 255, 0.32);
  white-space: nowrap;
}

.sidebar-history {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.history-item {
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}

.history-item:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.main-header {
  display: none;
  padding: 12px 16px;
  justify-content: space-between;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--text);
  transition: background 0.15s;
}

.icon-btn:hover:not(:disabled) {
  background: var(--bg-elevated);
}

.icon-btn--circle {
  border: 1px solid var(--border);
  border-radius: 50%;
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Welcome / 提问页 */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px 56px;
  gap: 36px;
}

.welcome-brand {
  text-align: center;
}

.hero-brand {
  margin-bottom: 28px;
  text-align: center;
}

.hero-brand-name {
  font-family: "STXingkai", "华文行楷", "KaiTi", "楷体", cursive;
  font-size: 52px;
  line-height: 1.08;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: #9fd7ff;
  text-shadow: 0 0 18px rgba(104, 176, 255, 0.38), 0 12px 34px rgba(77, 107, 254, 0.26);
}

.hero-brand-subtitle {
  margin-top: 12px;
  font-size: 26px;
  line-height: 1.25;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: var(--text-muted);
}

.logo {
  margin-bottom: 20px;
}

.welcome .logo svg {
  width: 56px;
  height: 56px;
}

.welcome-title {
  margin: 0;
  font-size: var(--welcome-title-size);
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.35;
}

.mode-switch {
  display: inline-flex;
  background: var(--bg-elevated);
  border-radius: var(--radius-pill);
  padding: 6px;
  gap: 4px;
}

.mode-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font-size: var(--welcome-mode-size);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}

.welcome .mode-option svg {
  width: 18px;
  height: 18px;
}

.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-option--active,
.mode-option:has(input:checked) {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(77, 107, 254, 0.45);
}

/* Composer */
.composer {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.composer--welcome {
  max-width: var(--welcome-composer-max);
  padding: 18px 20px 14px;
  border-radius: 28px;
}

.composer--chat {
  max-width: var(--chat-composer-max);
  padding: 16px 18px 14px;
  border-radius: 26px;
}

.composer:focus-within {
  border-color: rgba(77, 107, 254, 0.5);
  box-shadow: 0 0 0 1px rgba(77, 107, 254, 0.2);
}

.composer-input {
  width: 100%;
  min-height: 28px;
  max-height: 220px;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding: 0;
}

.composer--welcome .composer-input {
  min-height: 36px;
  font-size: var(--welcome-input-size);
  line-height: 1.55;
}

.composer--chat .composer-input {
  min-height: 32px;
  font-size: var(--chat-input-size);
  line-height: 1.55;
}

.composer-input::placeholder {
  color: var(--text-muted);
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  gap: 8px;
}

.composer-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  transition: all 0.15s;
}

.composer--welcome .tool-btn {
  gap: 8px;
  padding: 8px 14px;
  font-size: var(--welcome-tool-size);
}

.composer--welcome .tool-btn svg {
  width: 18px;
  height: 18px;
}

.composer--chat .tool-btn {
  padding: 7px 13px;
  font-size: var(--chat-tool-size);
}

.composer--chat .tool-btn svg {
  width: 17px;
  height: 17px;
}

.tool-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.tool-btn--active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}

.composer--welcome .send-btn {
  width: 44px;
  height: 44px;
}

.composer--welcome .send-btn svg {
  width: 20px;
  height: 20px;
}

.composer--welcome .composer-actions .icon-btn {
  width: 40px;
  height: 40px;
}

.composer--welcome .composer-actions .icon-btn svg {
  width: 20px;
  height: 20px;
}

.composer--chat .send-btn {
  width: 40px;
  height: 40px;
}

.composer--chat .send-btn svg {
  width: 19px;
  height: 19px;
}

.composer--chat .composer-actions .icon-btn {
  width: 38px;
  height: 38px;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.send-btn.is-loading {
  pointer-events: none;
}

.send-btn.is-loading svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Chat view */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 20px;
  scroll-behavior: smooth;
}

.messages-inner {
  max-width: var(--chat-composer-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.message {
  display: flex;
  gap: 16px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
}

.message--user .message-avatar {
  background: var(--user-bubble);
  color: var(--text-muted);
}

.message--assistant .message-avatar {
  background: var(--accent-soft);
  color: var(--accent);
}

.message-body {
  flex: 1;
  min-width: 0;
  padding-top: 4px;
}

.message--user .message-content {
  background: var(--user-bubble);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: var(--chat-msg-size);
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.message--assistant .message-content {
  font-size: var(--chat-msg-size);
  line-height: 1.8;
  color: var(--text);
}

.message-content p {
  margin: 0 0 0.75em;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 1em 0 0.5em;
  font-weight: 600;
}

.message-content h1 {
  font-size: 1.25em;
}

.message-content h2,
.message-content h3 {
  font-size: 1.05em;
}

.message-content ul,
.message-content ol {
  margin: 0.5em 0;
  padding-left: 1.4em;
}

.message-content li {
  margin: 0.35em 0;
}

.message-content strong {
  color: #fff;
  font-weight: 600;
}

.message-content code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

.cite-ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  margin: 0 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  vertical-align: super;
  cursor: default;
}

.typewriter-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: blink 0.9s step-end infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.message-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 15px;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.message-error {
  color: #ff6b6b;
  font-size: 15px;
}

.references-panel {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.references-title {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.reference-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.reference-item {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}

.reference-item strong {
  color: var(--text);
  font-weight: 500;
}

.chat-footer {
  padding: 0 24px 24px;
  flex-shrink: 0;
}

.chat-footer .composer {
  margin: 0 auto;
}

.footer-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin: 12px 0 0;
  opacity: 0.7;
}

.mobile-only {
  display: none;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.is-visible {
  display: block;
}

body.sidebar-open {
  overflow: hidden;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    width: var(--sidebar-w);
    height: 100%;
    margin-left: 0;
    transform: translateX(0);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

  .sidebar.collapsed {
    width: var(--sidebar-w);
    margin-left: 0;
    transform: translateX(calc(-1 * var(--sidebar-w)));
    border-right: 1px solid var(--border);
    pointer-events: none;
  }

  .sidebar:not(.collapsed) {
    pointer-events: auto;
  }

  .sidebar-restore {
    display: none;
  }

  .main-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    z-index: 50;
    background: var(--bg);
  }

  .mobile-only {
    display: inline-flex;
  }

  .welcome-title {
    font-size: 22px;
  }

  .hero-brand-name {
    font-size: 42px;
    letter-spacing: 0.14em;
  }

  .hero-brand-subtitle {
    font-size: 21px;
    letter-spacing: 0.12em;
  }

  .welcome .mode-option {
    font-size: 15px;
    padding: 9px 16px;
  }

  .composer--welcome .composer-input {
    font-size: 17px;
  }

  .message--user .message-content,
  .message--assistant .message-content {
    font-size: 15px;
  }

  .mode-switch {
    flex-wrap: wrap;
    justify-content: center;
  }
}
