:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: #101014;
  --panel-2: #171721;
  --panel-3: #20202c;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f5f5f7;
  --muted: #a4a4b0;
  --accent: #ff7bd5;
  --accent-2: #8f7cff;
  --success: #8fe8b8;
  --danger: #ff8a8a;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --safe-bottom: max(env(safe-area-inset-bottom), 18px);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(143, 124, 255, 0.16), transparent 28%),
    radial-gradient(circle at 80% 20%, rgba(255, 123, 213, 0.12), transparent 20%),
    var(--bg);
  color: var(--text);
}

body {
  overflow-x: hidden;
}

body.auth-pending > * {
  visibility: hidden;
}

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  max-width: 960px;
  margin: 0 auto;
  padding: 18px 16px calc(124px + var(--safe-bottom));
}

body.landing-mode .app-shell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-top: 24px;
  padding-bottom: calc(40px + var(--safe-bottom));
}

body.landing-mode .topbar,
body.landing-mode .status-strip,
body.landing-mode .chat-thread,
body.landing-mode .hero-card .eyebrow,
body.landing-mode .hero-copy,
body.landing-mode .role-grid,
body.landing-mode .suggestions,
body.landing-mode .composer-hint,
body.landing-mode .attachment-list,
body.landing-mode .attach-button {
  display: none !important;
}

body.landing-mode .page {
  gap: 0;
}

body.landing-mode .hero-card {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  text-align: center;
}

body.landing-mode .hero-card h1 {
  font-size: clamp(34px, 9vw, 58px);
}

body.landing-mode .composer-shell {
  position: static;
  padding: 18px 0 0;
  background: none;
}

body.landing-mode .composer {
  max-width: 760px;
  margin: 0 auto;
  padding-left: 18px;
}

.auth-shell {
  width: min(100%, 460px);
}

.auth-card {
  padding: 28px 24px;
  border: 1px solid var(--border);
  border-radius: 32px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 38%),
    rgba(10, 10, 14, 0.96);
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.auth-copy h1 {
  margin: 0 0 10px;
  font-size: clamp(30px, 8vw, 42px);
}

.auth-copy p:last-child {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.auth-form,
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-form {
  margin-top: 22px;
  gap: 14px;
}

.auth-form input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: none;
}

.auth-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.auth-submit {
  width: 100%;
  justify-content: center;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.brand-pill {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(16, 16, 20, 0.76);
  backdrop-filter: blur(18px);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 700;
}

.brand-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-copy strong {
  font-size: 15px;
}

.brand-copy span {
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(16, 16, 20, 0.9);
  color: var(--text);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-lines,
.icon-lines::before,
.icon-lines::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  content: "";
}

.icon-lines::before {
  transform: translateY(-6px);
}

.icon-lines::after {
  transform: translateY(4px);
}

.page {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero-card,
.status-card,
.message,
.composer,
.drawer,
.attachment-pill {
  border: 1px solid var(--border);
}

.hero-card {
  padding: 24px 20px;
  border-radius: 32px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 35%),
    rgba(10, 10, 14, 0.94);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 10px;
  color: #9f92ff;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-card h1 {
  margin: 0;
  font-size: clamp(30px, 8vw, 52px);
  line-height: 1.06;
}

.hero-copy {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.65;
  font-size: 15px;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.role-card {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.role-card strong {
  display: block;
  font-size: 15px;
  margin-bottom: 6px;
}

.role-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.role-card .role-tag {
  display: inline-flex;
  margin-top: 10px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(143, 124, 255, 0.14);
  color: #c6bcff;
  font-size: 12px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.suggestion-chip,
.secondary-button,
.primary-button {
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
}

.suggestion-chip {
  padding: 10px 14px;
  font-size: 13px;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.status-card {
  min-height: 88px;
  padding: 14px;
  border-radius: 20px;
  background: rgba(15, 15, 20, 0.9);
}

.status-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.status-card strong {
  font-size: 15px;
  line-height: 1.4;
}

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 12px;
}

.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 16px;
  border-radius: 24px;
  background: rgba(16, 16, 20, 0.95);
}

.message.user {
  background: linear-gradient(135deg, rgba(143, 124, 255, 0.18), rgba(255, 123, 213, 0.12));
}

.message-avatar {
  flex: 0 0 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 700;
}

.message-body {
  min-width: 0;
  flex: 1;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.message-meta strong {
  font-size: 14px;
}

.message-time {
  color: var(--muted);
  font-size: 12px;
}

.message-content {
  color: #f1f1f5;
  line-height: 1.72;
  font-size: 15px;
  word-break: break-word;
}

.message-content p {
  margin: 0 0 12px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content ul,
.message-content ol {
  margin: 0 0 12px 20px;
}

.message-content code,
.prompt-preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.message-content pre {
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 16px;
  overflow-x: auto;
  background: rgba(255, 255, 255, 0.04);
}

.message-content img {
  width: 100%;
  max-width: 280px;
  display: block;
  border-radius: 16px;
  margin-top: 10px;
  border: 1px solid var(--border);
}

.message-content .attachment-meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.message.loading .message-content::after {
  content: "思考中...";
  color: var(--muted);
}

.composer-shell {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 16px calc(var(--safe-bottom) + 8px);
  background: linear-gradient(180deg, rgba(5, 5, 5, 0), rgba(5, 5, 5, 0.96) 24%);
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.attachment-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(16, 16, 20, 0.92);
}

.attachment-pill img {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 10px;
}

.attachment-pill button {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 28px;
  background: rgba(36, 36, 44, 0.95);
  backdrop-filter: blur(24px);
}

.attach-button,
.send-button {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  color: var(--text);
}

.attach-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.attach-button svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.send-button {
  min-width: 62px;
  padding: 11px 14px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  font-weight: 600;
}

#messageInput {
  flex: 1;
  resize: none;
  border: 0;
  outline: none;
  min-height: 40px;
  max-height: 180px;
  padding: 10px 0;
  color: var(--text);
  background: transparent;
}

#messageInput::placeholder {
  color: #838393;
}

.composer-hint {
  margin: 8px 10px 0;
  color: var(--muted);
  font-size: 12px;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: min(560px, 100%);
  height: 100vh;
  padding: 18px;
  background: rgba(9, 9, 12, 0.98);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.drawer-header h2,
.drawer-section h3 {
  margin: 0;
}

.close-button {
  width: 38px;
  height: 38px;
}

.close-button span {
  font-size: 28px;
  line-height: 1;
}

.drawer-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-right: 2px;
}

.drawer-section {
  padding: 16px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.drawer-role-list,
.source-list,
.session-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.drawer-item {
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.drawer-item.active {
  border-color: rgba(143, 124, 255, 0.55);
  background: rgba(143, 124, 255, 0.12);
}

.drawer-item strong {
  display: block;
  margin-bottom: 6px;
}

.drawer-item p,
.drawer-item small {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.drawer-item small {
  display: block;
  margin-top: 8px;
}

.session-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.session-main {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 0;
  background: none;
  text-align: left;
  color: inherit;
}

.session-title {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}

.session-snippet {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  line-clamp: 2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.session-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
}

.session-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ghost-button {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
}

.prompt-preview {
  margin: 12px 0 0;
  max-height: 320px;
  overflow: auto;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  color: #d8d8e0;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 12px;
}

.settings-form,
.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-form {
  gap: 14px;
}

.settings-form input,
.settings-form textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: none;
}

.settings-actions,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.secondary-button,
.primary-button {
  padding: 10px 16px;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border-color: transparent;
  color: #fff;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(104px + var(--safe-bottom));
  z-index: 40;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(18, 18, 24, 0.95);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 13px;
}

@media (max-width: 720px) {
  .status-strip,
  .role-grid {
    grid-template-columns: 1fr;
  }

  .hero-card {
    padding: 22px 18px;
  }

  .message-meta {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (min-width: 721px) {
  .app-shell {
    padding-left: 24px;
    padding-right: 24px;
  }

  .hero-card {
    padding: 30px 28px;
  }

  .chat-thread {
    max-width: 820px;
  }
}
