:root {
  --bg: #eef1fb;
  --bg-glow-1: #c7d2fe;
  --bg-glow-2: #e0e7ff;
  --card: #ffffff;
  --text: #1a1d29;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-2: #818cf8;
  --bot-bubble: #f1f2f8;
  --user-bubble-from: #6366f1;
  --user-bubble-to: #4338ca;
  --user-text: #ffffff;
  --border: #e5e7eb;
  --code-bg: #1e2130;
  --code-text: #e8eaf0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d14;
    --bg-glow-1: #312e81;
    --bg-glow-2: #1e1b4b;
    --card: #161822;
    --text: #e8eaf0;
    --muted: #9aa0ad;
    --accent: #818cf8;
    --accent-2: #a5b4fc;
    --bot-bubble: #202331;
    --user-bubble-from: #6366f1;
    --user-bubble-to: #4338ca;
    --user-text: #ffffff;
    --border: #2a2e3a;
    --code-bg: #0e1018;
    --code-text: #e8eaf0;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 10%, var(--bg-glow-1) 0%, transparent 45%),
    radial-gradient(circle at 85% 90%, var(--bg-glow-2) 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 16px;
}

.chat-card {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  height: 640px;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(30, 27, 75, 0.18), 0 2px 8px rgba(30, 27, 75, 0.06);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(79, 70, 229, 0.06), transparent);
}

.header-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.chat-header h1 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.2px;
}

.subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.logo {
  position: relative;
  flex-shrink: 0;
}

.logo svg {
  display: block;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

.status-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--card);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

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

.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.45;
  font-size: 14px;
  white-space: pre-wrap;
  animation: msg-in 0.2s ease-out;
}

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

.msg a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-word;
}

.msg.user a {
  color: #ffffff;
}

.msg.bot,
.msg.user {
  position: relative;
  padding-right: 30px;
}

.msg.bot {
  background: var(--bot-bubble);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.msg.user {
  background: linear-gradient(135deg, var(--user-bubble-from), var(--user-bubble-to));
  color: var(--user-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.msg-copy-btn {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: currentColor;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.12s ease, background 0.12s ease;
}

.msg.bot:hover .msg-copy-btn,
.msg.user:hover .msg-copy-btn {
  opacity: 0.55;
}

.msg-copy-btn:hover {
  opacity: 1 !important;
  background: rgba(127, 127, 127, 0.18);
}

.msg-copy-btn.copied {
  opacity: 1 !important;
  color: #22c55e;
}

.msg.muted {
  color: var(--muted);
  font-size: 11.5px;
  align-self: center;
  background: none;
  padding: 0 4px;
}

.code-wrapper {
  position: relative;
  margin: 6px 0;
}

.msg pre {
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--code-bg);
  color: var(--code-text);
  overflow-x: auto;
  font-size: 13px;
}

.msg pre code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  white-space: pre;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: #e8eaf0;
  cursor: pointer;
  transition: background 0.15s ease;
}

.copy-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.msg.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  box-shadow: none;
}

.spinner {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

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

.chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--card);
}

#chat-input {
  flex: 1;
  padding: 11px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

#chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18);
}

.chat-form button {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.chat-form button:hover {
  transform: scale(1.05);
}

.chat-form button:active {
  transform: scale(0.96);
}

.site-footer {
  display: flex;
  justify-content: center;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.site-footer .footer-logo {
  display: block;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.site-footer a:hover .footer-logo {
  opacity: 1;
}

@media (hover: none) {
  .msg-copy-btn {
    opacity: 0.45;
    width: 26px;
    height: 26px;
  }
}

@media (max-width: 600px) {
  body {
    padding: 0;
  }

  .chat-card {
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border: none;
    border-radius: 0;
  }

  #chat-input {
    font-size: 16px;
  }

  .chat-form {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .chat-header {
    padding-top: calc(18px + env(safe-area-inset-top));
  }

  .msg {
    max-width: 88%;
  }
}
