*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --thread-bg: #ffffff;
  --user-bubble-bg: #dbeafe;
  --user-bubble-text: #1e3a5f;
  --card-bg: #f8f9fa;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-light: #eef2ff;
  --ink: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --input-bg: #ffffff;
  --danger: #dc2626;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 780px;
  margin: 0 auto;
  background: var(--thread-bg);
  box-shadow: var(--shadow-md);
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--thread-bg);
  flex-shrink: 0;
  z-index: 10;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
  text-decoration: none;
}

.header-brand svg {
  color: var(--accent);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  font-family: var(--font);
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.user-chip strong {
  color: var(--ink);
}

/* ── Thread ── */
.thread {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.thread:empty::after {
  content: "描述你的想法，即可开始生成图片";
  display: block;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin-top: 80px;
}

/* ── Messages ── */
.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-user {
  align-items: flex-end;
}

.msg-assistant {
  align-items: flex-start;
}

.bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}

.msg-user .bubble {
  background: var(--user-bubble-bg);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}

/* ── Image card ── */
.img-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-sm);
}

.img-card-body {
  position: relative;
}

.img-card img {
  display: block;
  width: 100%;
  height: auto;
  opacity: 0;
  transition: opacity .3s ease;
}

.img-card img.loaded {
  opacity: 1;
}

.img-card-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  gap: 8px;
}

.btn-download {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font);
  transition: all .15s;
}

.btn-download:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Skeleton loader ── */
.skeleton-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  max-width: 480px;
  width: 100%;
}

.skeleton-img {
  width: 100%;
  background: #e9ecef;
  position: relative;
  overflow: hidden;
}

/* aspect ratios driven by JS via inline style */
.skeleton-img::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 0%,
    rgba(255,255,255,.55) 45%,
    rgba(255,255,255,.7) 50%,
    rgba(255,255,255,.55) 55%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.skeleton-text {
  height: 12px;
  border-radius: 6px;
  background: #dde0e4;
  flex: 1;
}

.skeleton-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.skeleton-dot:nth-child(2) { animation-delay: .2s; }
.skeleton-dot:nth-child(3) { animation-delay: .4s; }

@keyframes pulse {
  0%, 100% { opacity: .3; }
  50%       { opacity: 1; }
}

.skeleton-label {
  font-size: 12px;
  color: var(--muted);
  margin-left: 4px;
}

/* ── Error message ── */
.msg-error {
  align-items: flex-start;
}

.error-bubble {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--danger);
  max-width: 75%;
}

/* ── Settings bar ── */
.settings-bar {
  border-top: 1px solid var(--border);
  background: var(--thread-bg);
  flex-shrink: 0;
  overflow: hidden;
  transition: max-height .2s ease;
  max-height: 0;
}

.settings-bar.open {
  max-height: 80px;
}

.settings-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  flex-wrap: wrap;
}

.settings-label {
  font-size: 12px;
  color: var(--muted);
  margin-right: 2px;
}

.settings-select {
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--ink);
  font-family: var(--font);
  cursor: pointer;
  outline: none;
  transition: border-color .15s;
}

.settings-select:focus {
  border-color: var(--accent);
}

/* ── Input area ── */
.input-area {
  border-top: 1px solid var(--border);
  padding: 12px 16px 14px;
  background: var(--thread-bg);
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 12px;
  transition: border-color .15s;
}

.input-row:focus-within {
  border-color: var(--accent);
}

.btn-attach {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color .15s;
}

.btn-attach:hover { color: var(--accent); }

.input-file { display: none; }

.prompt-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: transparent;
  color: var(--ink);
  max-height: 140px;
  overflow-y: auto;
  padding: 2px 0;
}

.prompt-input::placeholder { color: #adb5bd; }

.input-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.btn-settings {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color .15s;
  font-size: 11px;
}

.btn-settings:hover, .btn-settings.active { color: var(--accent); }

.btn-send {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s;
  flex-shrink: 0;
}

.btn-send:hover:not(:disabled) { background: var(--accent-hover); }

.btn-send:disabled {
  background: #c7d2fe;
  cursor: not-allowed;
}

/* image preview chip */
.image-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-light);
  border: 1px solid #c7d2fe;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 6px;
}

.image-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--accent);
  padding: 0;
  display: flex;
  line-height: 1;
  font-size: 14px;
}

/* ── Auth Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--thread-bg);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.modal h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--ink);
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 5px;
}

.form-group input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color .15s;
  color: var(--ink);
}

.form-group input:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  font-family: var(--font);
  transition: background .15s;
}

.btn-primary:hover { background: var(--accent-hover); }

.modal-switch {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 16px;
}

.modal-switch a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}

.modal-error {
  font-size: 13px;
  color: var(--danger);
  margin-top: 8px;
  text-align: center;
  min-height: 18px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1f2937;
  color: #fff;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .thread { padding: 16px 12px 12px; }
  .input-area { padding: 10px 12px 12px; }
  .settings-inner { padding: 8px 12px; }
  .bubble, .error-bubble { max-width: 90%; }
  .img-card, .skeleton-card { max-width: 100%; }
  .modal { padding: 24px 20px; }
}
