/* ===== 远航娱乐 · 主黑辅金 ===== */

:root {
  --bg: #0a0a0a;
  --bg-alt: #141414;
  --bg-elev: #1a1a1a;
  --ink: #f5f1e6;
  --ink-muted: #8a8478;
  --accent: #d4af37;
  --accent-deep: #b8941f;
  --accent-soft: rgba(212, 175, 55, 0.14);
  --on-accent: #0a0a0a;
  --agent-bubble: #1a1a1a;
  --agent-border: rgba(212, 175, 55, 0.18);
  --conn-bar-bg: #d4af37;
  --hairline: rgba(212, 175, 55, 0.1);

  --radius: 18px;
  --radius-tail: 6px;
  --radius-img: 14px;

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Spline Sans", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  position: relative;
}

/* 顶部背景加一道极淡金色光晕，强化黑金氛围 */
.app::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 220px;
  background: radial-gradient(
    ellipse at top,
    rgba(212, 175, 55, 0.08) 0%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
}

/* ---------- Top bar ---------- */
.topbar {
  height: 56px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: var(--bg);
  border-bottom: 1px solid var(--hairline);
  z-index: 5;
  position: relative;
  animation: fade-up 0.45s ease-out 0.2s both;
}

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-optical-sizing: auto;
  font-size: 22px;
  letter-spacing: 0.02em;
  color: var(--accent);
  line-height: 1;
  text-shadow: 0 0 18px rgba(212, 175, 55, 0.25);
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.18);
  animation: pulse 2.6s ease-in-out infinite;
}

.status-text {
  font-size: 13px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}

/* ---------- Connection bar ---------- */
.conn-bar {
  background: var(--conn-bar-bg);
  color: var(--on-accent);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  letter-spacing: 0.04em;
  padding: 0 16px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease, padding 0.25s ease;
  flex: 0 0 auto;
}

.conn-bar.show {
  max-height: 44px;
  padding: 9px 16px;
}

/* ---------- Messages ---------- */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 26px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  position: relative;
  z-index: 1;
}

.messages.is-empty {
  justify-content: center;
}

.messages::-webkit-scrollbar {
  width: 8px;
}
.messages::-webkit-scrollbar-thumb {
  background: rgba(212, 175, 55, 0.22);
  border-radius: 4px;
}
.messages::-webkit-scrollbar-track {
  background: transparent;
}
.messages {
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 175, 55, 0.22) transparent;
}

/* ---------- Welcome opening (cover) ---------- */
.welcome {
  text-align: center;
  padding: 24px 12px 8px;
  animation: fade-up 0.55s ease-out 0.3s both;
}

.welcome-eyebrow {
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 14px;
  opacity: 0.85;
}

.welcome-title {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 400;
  font-size: clamp(26px, 5.4vw, 38px);
  line-height: 1.2;
  letter-spacing: -0.018em;
  color: var(--ink);
  max-width: 22ch;
  margin: 0 auto;
}

/* ---------- Message rows ---------- */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  animation: msg-in 0.28s ease-out both;
}

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

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

.msg.system {
  align-items: center;
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg.visitor .bubble {
  background: var(--accent);
  color: var(--on-accent);
  border-bottom-right-radius: var(--radius-tail);
  box-shadow: 0 2px 12px rgba(212, 175, 55, 0.18);
}

.msg.agent .bubble {
  background: var(--agent-bubble);
  color: var(--ink);
  border: 1px solid var(--agent-border);
  border-bottom-left-radius: var(--radius-tail);
}

/* image bubbles keep the same radius as text bubbles, with 4px inner padding */
.msg.image .bubble {
  padding: 4px;
  display: flex;
  flex-direction: column;
  background: var(--agent-bubble);
}

.msg.image.visitor .bubble {
  background: var(--accent);
}

.msg.image .bubble img {
  display: block;
  max-width: min(260px, 60vw);
  max-height: 300px;
  width: auto;
  height: auto;
  border-radius: var(--radius-img);
  object-fit: cover;
}

.msg.image .caption {
  padding: 5px 9px 7px;
  font-size: 14px;
  line-height: 1.45;
}

.msg.image .bubble:has(img:not([src])) {
  min-height: 80px;
  min-width: 120px;
}

.time {
  font-size: 11px;
  color: var(--ink-muted);
  margin: 4px 6px 0;
  opacity: 0.75;
  letter-spacing: 0.02em;
}

/* system messages: centered, small, muted, no bubble */
.system-text {
  font-size: 12.5px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  text-align: center;
  padding: 4px 14px;
  line-height: 1.5;
}

/* failed state */
.msg.failed .bubble {
  opacity: 0.55;
}
.fail-tag {
  font-size: 11px;
  color: var(--accent);
  margin: 4px 6px 0;
  letter-spacing: 0.02em;
}

/* ---------- Typing indicator ----------
   关键修复：默认 display:none，避免 [hidden] 属性被 display:flex 覆盖导致一直显示。
   用 .is-visible 类显式控制可见性。
*/
.typing {
  display: none;
  justify-content: flex-start;
}

.typing.is-visible {
  display: flex;
  animation: msg-in 0.28s ease-out both;
}

.typing-bubble {
  background: var(--agent-bubble);
  border: 1px solid var(--agent-border);
  border-radius: var(--radius);
  border-bottom-left-radius: var(--radius-tail);
  padding: 13px 15px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-bubble .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-bubble .dot:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-bubble .dot:nth-child(3) {
  animation-delay: 0.3s;
}

/* ---------- Composer ---------- */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--hairline);
  animation: fade-up 0.45s ease-out 0.5s both;
  position: relative;
  z-index: 1;
}

.input {
  flex: 1 1 auto;
  resize: none;
  border: none;
  background: var(--bg-alt);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  max-height: 120px;
  padding: 11px 14px;
  border-radius: 14px;
  outline: none;
  border: 1px solid transparent;
  transition: border-color 0.18s ease;
}

.input:focus {
  border-color: var(--agent-border);
}

.input::placeholder {
  color: var(--ink-muted);
  opacity: 0.7;
}

.input:disabled {
  color: var(--ink-muted);
  cursor: not-allowed;
  opacity: 0.6;
}

.icon-btn,
.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease,
    opacity 0.18s ease;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-muted);
}

.icon-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: transparent;
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
}

.send-btn:hover {
  background: var(--accent-deep);
  transform: scale(1.05);
}

.send-btn:active {
  transform: scale(0.97);
}

.send-btn:disabled {
  cursor: not-allowed;
  transform: none;
}

.send-btn.idle {
  opacity: 0.45;
}
.send-btn.idle:hover {
  background: var(--accent);
  transform: none;
}

.send-icon,
.spinner {
  display: block;
}

.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(10, 10, 10, 0.35);
  border-top-color: var(--on-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.send-btn.loading .send-icon {
  display: none;
}
.send-btn.loading .spinner {
  display: block;
}

/* ---------- Animations ---------- */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.18);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(212, 175, 55, 0.06);
  }
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .topbar {
    height: 52px;
    padding: 0 16px;
  }
  .brand {
    font-size: 20px;
  }
  .messages {
    padding: 18px 14px 12px;
    gap: 12px;
  }
  .bubble {
    max-width: 78%;
    font-size: 14.5px;
  }
  .composer {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    gap: 8px;
  }
  .welcome {
    padding: 16px 8px 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
