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

:root {
  --bg: #121010;
  --bg-subtle: #1a1614;
  --surface: #1e1a18;
  --surface-hover: #262220;
  --border: #332e2b;
  --border-focus: #5a5350;
  --text: #ede8e4;
  --text-muted: #9e9590;
  --text-dim: #6b6260;
  --accent: #e8a838;
  --accent-hover: #d49530;
  --accent-glow: rgba(232, 168, 56, 0.15);
  --success: #6ee7a0;
  --brand-perplexity: #1CB0A8;
  --brand-chatgpt: #10a37f;
  --brand-claude: #D97706;
  --brand-gemini: #4285F4;
  --brand-grok: #1DA1F2;
  --brand-lechat: #FF7000;
  --user-bubble: #2a2420;
  --ai-bubble: #f5f0eb;
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  -webkit-font-smoothing: antialiased;
}

/* Atmospheric gradient mesh */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 30%, rgba(232, 168, 56, 0.04), transparent),
    radial-gradient(ellipse 60% 80% at 80% 70%, rgba(232, 168, 56, 0.03), transparent);
  pointer-events: none;
  z-index: 0;
}

/* Noise texture */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  opacity: 0.025;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* ── Chat container ── */
.chat-container {
  width: 100%;
  max-width: 640px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow:
    0 12px 50px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.03);
  position: relative;
  z-index: 1;
  animation: containerEntrance 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes containerEntrance {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Chat header ── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-header-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

.chat-header-status {
  font-size: 0.7rem;
  color: var(--success);
  letter-spacing: 0.02em;
}

.chat-header-dots {
  display: flex;
  gap: 4px;
}

.chat-header-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-dim);
}

/* ── Chat body ── */
.chat-body {
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 280px;
  overflow-y: auto;
  max-height: 80vh;
}

/* ── Message bubbles ── */
.message {
  display: flex;
  gap: 0.6rem;
  animation: messageIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.message.hidden {
  display: none;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* User messages — right aligned */
.message-user {
  justify-content: flex-end;
}

.message-bubble {
  max-width: 85%;
  padding: 0.75rem 1rem;
  line-height: 1.55;
  word-break: break-word;
}

.message-bubble-user {
  background: var(--user-bubble);
  border: 1px solid var(--border);
  border-radius: 16px 16px 4px 16px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text);
}

/* AI messages — left aligned with avatar */
.message-ai {
  align-items: flex-start;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-glow), rgba(232, 168, 56, 0.08));
  border: 1px solid rgba(232, 168, 56, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
}

.message-bubble-ai {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-radius: 16px 16px 16px 4px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: #1e1a18;
  min-width: 60px;
}

/* ── Input bar (bottom of chat) ── */
.input-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.55rem 0.85rem;
  margin-top: auto;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.input-bar.sent {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

.input-bar-text {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
  min-height: 1.5em;
  word-break: break-word;
  padding: 0.1rem 0;
}

/* ── Cursor ── */
.cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}

.cursor.hidden {
  display: none;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ── Send button ── */
.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: var(--border);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  transition: background 0.3s, color 0.3s, transform 0.15s;
  flex-shrink: 0;
}

.send-btn.active {
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
}

/* ── Thinking dots ── */
.thinking-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.5rem 0.25rem;
  transition: opacity 0.4s ease;
}

.thinking-dots.hidden {
  display: none;
}

.thinking-dots.fade-out {
  opacity: 0;
}

.thinking-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6b6260;
  animation: dotPulse 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dotPulse {
  0%, 80%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ── Snarky message (inside AI bubble) ── */
.snarky-message {
  padding: 0.25rem 0;
}

.snarky-message.hidden {
  display: none;
}

.snarky-title {
  font-family: var(--font-body);
  font-size: clamp(1.2rem, 3.5vw, 1.5rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
  color: #1e1a18;
  animation: punchlineReveal 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.snarky-subtitle {
  font-size: 0.9rem;
  font-style: italic;
  color: #6b6260;
  animation: subtitleReveal 0.5s ease 0.2s both;
}

@keyframes punchlineReveal {
  0% {
    opacity: 0;
    transform: scale(0.85);
    filter: blur(4px);
  }
  60% {
    opacity: 1;
    transform: scale(1.04);
    filter: blur(0px);
  }
  100% {
    opacity: 1;
    transform: scale(1);
    filter: blur(0px);
  }
}

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

/* Brief flash on the AI bubble when punchline hits */
@keyframes bubbleFlash {
  0% { border-color: var(--border); }
  30% { border-color: var(--accent); box-shadow: 0 0 20px rgba(232, 168, 56, 0.25); }
  100% { border-color: var(--border); box-shadow: none; }
}

.message-bubble-ai.reveal {
  animation: bubbleFlash 0.8s ease-out;
}


/* ── AI buttons ── */
.ai-buttons {
  max-width: 640px;
  width: 100%;
  margin: 0.75rem auto 0;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
}

.ai-buttons.hidden {
  display: none;
}

.ai-btn {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  text-align: left;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.15s ease;
  animation: aiBtnFadeIn 0.25s ease both;
}

.ai-btn:nth-child(2) { animation-delay: 40ms; }
.ai-btn:nth-child(3) { animation-delay: 80ms; }
.ai-btn:nth-child(4) { animation-delay: 120ms; }
.ai-btn:nth-child(5) { animation-delay: 160ms; }
.ai-btn:nth-child(6) { animation-delay: 200ms; }
.ai-btn:nth-child(7) { animation-delay: 240ms; }

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

.ai-btn:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  border-color: var(--accent);
}

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

.ai-btn-logo {
  color: var(--text-dim);
  flex-shrink: 0;
  transition: color 0.25s;
}

.ai-btn-primary {
  border-color: var(--accent);
  background: var(--bg-subtle, #1a1614);
  box-shadow: 0 0 12px var(--accent-glow);
}

.ai-btn-primary .ai-btn-logo {
  color: var(--accent);
}

.ai-btn-copy {
  grid-column: 1 / -1;
  justify-content: center;
  background: var(--bg);
  border-style: dashed;
  color: var(--text-muted);
}

/* ── Toast ── */
.toast {
  position: fixed;
  top: 2rem;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: fit-content;
  min-width: 280px;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  animation: fadeInDown 0.3s ease;
  z-index: 100;
}

.toast.hidden {
  display: none;
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
}

.toast-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.toast-icon.hidden {
  display: none;
}

.toast-icon svg {
  width: 24px;
  height: 24px;
}

.toast-text {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
}

.toast-cancel {
  background: rgba(232, 168, 56, 0.08);
  border: 1px solid var(--border-focus);
  border-radius: 8px;
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.35rem 0.85rem;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s;
}

.toast-cancel.hidden {
  display: none;
}

.toast-cancel:hover {
  border-color: var(--accent);
  background: rgba(232, 168, 56, 0.15);
}

.toast-progress {
  height: 3px;
  background: var(--border);
}

.toast-progress.hidden {
  display: none;
}

.toast-progress-bar {
  height: 100%;
  transform-origin: left;
  animation: progressShrink 3s linear forwards;
}

@keyframes progressShrink {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* Toast brand colors via data-ai attribute */
.toast[data-ai="p"] .toast-progress-bar { background: var(--brand-perplexity); }
.toast[data-ai="g"] .toast-progress-bar { background: var(--brand-chatgpt); }
.toast[data-ai="c"] .toast-progress-bar { background: var(--brand-claude); }
.toast[data-ai="m"] .toast-progress-bar { background: var(--brand-gemini); }
.toast[data-ai="k"] .toast-progress-bar { background: var(--brand-grok); }
.toast[data-ai="l"] .toast-progress-bar { background: var(--brand-lechat); }

.toast[data-ai="p"] .toast-icon,
.toast[data-ai="p"] .toast-text { color: var(--brand-perplexity); }
.toast[data-ai="g"] .toast-icon,
.toast[data-ai="g"] .toast-text { color: var(--brand-chatgpt); }
.toast[data-ai="c"] .toast-icon,
.toast[data-ai="c"] .toast-text { color: var(--brand-claude); }
.toast[data-ai="m"] .toast-icon,
.toast[data-ai="m"] .toast-text { color: var(--brand-gemini); }
.toast[data-ai="k"] .toast-icon,
.toast[data-ai="k"] .toast-text { color: var(--brand-grok); }
.toast[data-ai="l"] .toast-icon,
.toast[data-ai="l"] .toast-text { color: var(--brand-lechat); }


@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Drag affordance (desktop only) ── */
@media (pointer: fine) {
  .chat-header {
    cursor: grab;
  }

  .chat-container:hover:not(.dragging) {
    box-shadow:
      0 14px 55px rgba(0, 0, 0, 0.55),
      0 0 0 1px rgba(255, 255, 255, 0.04);
  }

  .chat-container.dragging {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    opacity: 0.97;
    z-index: 10;
  }

  .chat-container.dragging .chat-header {
    cursor: grabbing;
  }

  .ai-buttons:not(.hidden) {
    cursor: grab;
  }

  .ai-buttons:hover:not(.dragging):not(.hidden) {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  }

  .ai-buttons.dragging {
    cursor: grabbing;
    opacity: 0.97;
    z-index: 10;
  }

  .toast:not(.hidden) {
    cursor: grab;
  }

  .toast.dragging {
    cursor: grabbing;
    z-index: 110;
  }
}

/* Prevent text selection during drag */
.is-dragging,
.is-dragging * {
  user-select: none !important;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  body {
    padding: 0.5rem;
    align-items: flex-start;
    padding-top: 1rem;
    padding-bottom: env(safe-area-inset-bottom, 0.5rem);
  }

  .chat-container {
    border-radius: 14px;
    max-width: 100%;
  }

  .chat-header {
    padding: 10px 14px;
  }

  .chat-header-avatar {
    width: 28px;
    height: 28px;
  }

  .chat-header-avatar svg {
    width: 13px;
    height: 13px;
  }

  .chat-body {
    padding: 1rem 0.75rem;
    gap: 0.6rem;
    min-height: 240px;
  }

  .message-bubble {
    max-width: 92%;
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
  }

  .message-avatar {
    width: 26px;
    height: 26px;
  }

  .message-avatar svg {
    width: 13px;
    height: 13px;
  }

  .input-bar {
    padding: 0.5rem 0.75rem;
  }

  .input-bar-text {
    font-size: 0.85rem;
  }

  .ai-buttons {
    grid-template-columns: 1fr;
    padding: 0 0.5rem;
  }

  .ai-btn {
    padding: 0.7rem 0.85rem;
    min-height: 44px;
  }

  .ai-btn-copy {
    grid-column: auto;
  }

  .toast {
    top: 1rem;
    min-width: auto;
    max-width: calc(100% - 2rem);
  }
}

/* Extra small screens (iPhone SE, etc.) */
@media (max-width: 380px) {
  .chat-header-title {
    font-size: 0.8rem;
  }

  .chat-header-status {
    font-size: 0.65rem;
  }

  .snarky-title {
    font-size: 1.05rem;
  }

  .snarky-subtitle {
    font-size: 0.8rem;
  }
}

/* Hide tooltips on touch devices */
@media (hover: none) {
  .tooltip {
    display: none;
  }
}
