:root {
  color-scheme: dark;
  --bg: #05141d;
  --bg-2: #0a2231;
  --panel: rgba(8, 30, 43, 0.72);
  --panel-border: rgba(125, 211, 252, 0.14);
  --text: #e9f6fb;
  --muted: #7fa6b8;
  --accent: #37c9c0;
  --accent-2: #7dd3fc;
  --ai-bubble: rgba(255, 255, 255, 0.055);
  --user-bubble: linear-gradient(135deg, #0f766e, #0e7490);
  --danger: #fca5a5;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

html {
  background: #05141d;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: transparent;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -2;
  display: grid;
  place-items: center;
  overflow: hidden;
  pointer-events: none;
  background: #05141d;
}

.backdrop img {
  display: block;
  width: min(100%, calc(100vh * 850 / 779));
  max-height: 100%;
  height: auto;
  object-fit: contain;
  filter: brightness(0.72) saturate(1.05);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 7%, #000 93%, transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0%, #000 7%, #000 93%, transparent 100%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(56, 189, 248, 0.1), transparent 60%),
    radial-gradient(900px 500px at 100% 10%, rgba(45, 212, 191, 0.06), transparent 55%),
    linear-gradient(
      180deg,
      rgba(5, 20, 29, 0.72) 0%,
      rgba(5, 20, 29, 0.18) 20%,
      rgba(5, 20, 29, 0) 42%,
      rgba(5, 20, 29, 0) 68%,
      rgba(5, 20, 29, 0.78) 92%,
      rgba(5, 20, 29, 0.94) 100%
    );
}

button,
textarea {
  font: inherit;
}

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

.chat-header {
  flex: none;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 6px 12px;
  background: linear-gradient(180deg, rgba(5, 20, 29, 0.92), rgba(5, 20, 29, 0.55) 70%, transparent);
  backdrop-filter: blur(10px);
}

.avatar {
  width: 56px;
  height: 56px;
  flex: none;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0;
  border-radius: 50%;
  font-size: 28px;
  background: radial-gradient(circle at 30% 25%, #0e7490, #083344);
  border: 1px solid rgba(125, 211, 252, 0.35);
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.18);
}

.avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 42%;
}

.avatar.small {
  width: 40px;
  height: 40px;
  font-size: 20px;
}

.titles {
  flex: 1;
  min-width: 0;
}

.titles h1 {
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.titles p {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0 0;
  overflow: hidden;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.titles p::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.8);
}

.clear {
  flex: none;
  margin-left: auto;
  padding: 7px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: 0.2s;
}

.clear:hover {
  color: var(--text);
  border-color: rgba(125, 211, 252, 0.35);
}

.log {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 4px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(
    180deg,
    rgba(5, 20, 29, 0) 0%,
    rgba(5, 20, 29, 0.12) 18%,
    rgba(5, 20, 29, 0.16) 50%,
    rgba(5, 20, 29, 0.12) 82%,
    rgba(5, 20, 29, 0) 100%
  );
}

.log::-webkit-scrollbar {
  width: 6px;
}

.log::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(125, 211, 252, 0.16);
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: pop 0.22s ease-out;
}

.msg.user {
  justify-content: flex-end;
}

.bubble {
  position: relative;
  max-width: 78%;
  padding: 11px 15px;
  border-radius: 20px 20px 20px 8px;
  background:
    radial-gradient(120% 90% at 12% 0%, rgba(125, 211, 252, 0.14), transparent 55%),
    linear-gradient(155deg, rgba(10, 52, 70, 0.84), rgba(6, 32, 47, 0.92));
  border: 1px solid rgba(125, 211, 252, 0.16);
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.ai .bubble::before,
.msg.user .bubble::before {
  content: "";
  position: absolute;
  bottom: 5px;
  width: 12px;
  height: 16px;
  clip-path: polygon(0 50%, 100% 0, 100% 100%);
}

.msg.ai .bubble::before {
  left: -7px;
  background: rgba(6, 32, 47, 0.92);
  transform: rotate(10deg);
}

.msg.user .bubble::before {
  right: -7px;
  background: #155e75;
  transform: rotate(-10deg) scaleX(-1);
}

.msg.user .bubble {
  border-radius: 20px 20px 8px 20px;
  background:
    radial-gradient(120% 90% at 88% 0%, rgba(125, 211, 252, 0.24), transparent 55%),
    linear-gradient(155deg, #0e7490, #155e75);
  border-color: rgba(125, 211, 252, 0.2);
  box-shadow:
    0 10px 30px rgba(8, 145, 178, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.bubble.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
}

.bubble.typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite;
}

.bubble.streaming::after {
  content: "▍";
  margin-left: 2px;
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
}

.notice {
  align-self: center;
  max-width: 90%;
  padding: 6px 12px;
  border: 1px solid rgba(252, 165, 165, 0.25);
  border-radius: 999px;
  background: rgba(127, 29, 29, 0.18);
  color: var(--danger);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  animation: pop 0.22s ease-out;
}

.composer {
  flex: none;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 4px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(5, 20, 29, 0.85) 30%);
}

.composer textarea {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
  min-height: 44px;
  max-height: 140px;
  padding: 11px 14px;
  resize: none;
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  outline: none;
  background: var(--panel);
  backdrop-filter: blur(12px);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.composer textarea:focus {
  border-color: rgba(125, 211, 252, 0.4);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.08);
}

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

.send {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(125, 211, 252, 0.25);
  border-radius: 50%;
  background: linear-gradient(135deg, #0e7490, #0f766e);
  color: #f0fdfa;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(14, 116, 144, 0.3);
  transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
}

.send:hover {
  transform: translateY(-1px);
}

.send:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.send svg {
  width: 20px;
  height: 20px;
}

.send .icon-stop {
  display: none;
}

.send.stop {
  background: linear-gradient(135deg, #7f1d1d, #991b1b);
  border-color: rgba(252, 165, 165, 0.3);
  box-shadow: 0 8px 24px rgba(127, 29, 29, 0.3);
}

.send.stop .icon-send {
  display: none;
}

.send.stop .icon-stop {
  display: block;
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 20, 29, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.gate[hidden] {
  display: none;
}

.gate-card {
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 28px 22px 22px;
  border: 1px solid rgba(125, 211, 252, 0.2);
  border-radius: 24px;
  background: linear-gradient(160deg, rgba(10, 52, 70, 0.94), rgba(6, 32, 47, 0.97));
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.gate-avatar {
  width: 88px;
  height: 88px;
  overflow: hidden;
  border: 1px solid rgba(125, 211, 252, 0.4);
  border-radius: 50%;
  box-shadow: 0 0 32px rgba(56, 189, 248, 0.2);
}

.gate-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 42%;
}

.gate-card h2 {
  margin: 4px 0 0;
  font-size: 20px;
}

.gate-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.gate-card input {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  outline: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 16px;
}

.gate-card input:focus {
  border-color: rgba(125, 211, 252, 0.45);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

.gate-card button {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, #0e7490, #0f766e);
  color: #f0fdfa;
  font-size: 15px;
  cursor: pointer;
}

.gate-card button:hover {
  filter: brightness(1.08);
}

.gate-error {
  min-height: 18px;
  color: var(--danger) !important;
  font-size: 12px;
}

@keyframes blink {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 480px) {
  .app {
    padding: 0 8px;
  }

  .bubble {
    max-width: 84%;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
