@import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap");

/* ── Design Tokens ──────────────────────────────────────────────────────── */
:root {
  --bg: #07090d;
  --surface: rgba(16, 22, 34, 0.55);
  --surface-hover: rgba(24, 32, 48, 0.65);
  --border: rgba(255, 255, 255, 0.06);
  --border-glow: rgba(100, 180, 255, 0.12);
  --text: #e4eaf2;
  --text-secondary: #8294ab;
  --muted: #5a6f87;

  --accent: #58b4ff;
  --accent-dim: #3d8fd4;
  --accent-glow: rgba(88, 180, 255, 0.35);
  --purple: #a78bfa;
  --purple-glow: rgba(167, 139, 250, 0.25);
  --teal: #2dd4bf;
  --teal-glow: rgba(45, 212, 191, 0.2);

  --user-bubble: rgba(30, 60, 90, 0.45);
  --assistant-bubble: rgba(18, 26, 40, 0.5);
  --danger: #f87171;
  --recording: #fbbf24;

  --glass-bg: rgba(14, 20, 32, 0.5);
  --glass-border: rgba(255, 255, 255, 0.07);
  --glass-blur: 20px;

  --aurora-1: rgba(30, 70, 110, 0.4);
  --aurora-2: rgba(60, 30, 90, 0.3);
  --aurora-3: rgba(20, 80, 70, 0.25);

  --orb-size: 160px;
  --orb-size-sm: 36px;

  --radius: 1rem;
  --radius-sm: 0.75rem;
  --radius-xs: 0.5rem;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

/* ── Aurora Background ──────────────────────────────────────────────────── */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 15% 80%, var(--aurora-3), transparent 60%),
    radial-gradient(ellipse 70% 45% at 85% 15%, var(--aurora-2), transparent 55%),
    radial-gradient(ellipse 100% 60% at 50% 0%, var(--aurora-1), transparent 65%);
  background-size: 200% 200%;
  animation: aurora 25s ease-in-out infinite alternate;
  pointer-events: none;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(circle at 50% 50%, transparent 30%, var(--bg) 70%);
  pointer-events: none;
}

@keyframes aurora {
  0%   { background-position: 0% 50%; }
  33%  { background-position: 60% 30%; }
  66%  { background-position: 30% 70%; }
  100% { background-position: 100% 50%; }
}

/* ── App Shell ──────────────────────────────────────────────────────────── */
.app {
  position: relative;
  z-index: 1;
  max-width: 44rem;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 1.25rem;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.header {
  position: relative;
  display: flex;
  align-items: center;
  padding: 1rem 0 0.75rem;
  border-bottom: 1px solid var(--glass-border);
  z-index: 5;
}

.title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.header-orb {
  width: var(--orb-size-sm);
  height: var(--orb-size-sm);
  border-radius: 50%;
  margin-right: 0.75rem;
  flex-shrink: 0;
  background: radial-gradient(circle at 35% 35%,
    rgba(88, 180, 255, 0.9),
    rgba(167, 139, 250, 0.5) 50%,
    rgba(45, 212, 191, 0.3) 80%,
    transparent 100%
  );
  box-shadow:
    0 0 20px var(--accent-glow),
    0 0 40px var(--purple-glow);
  animation: orb-idle 4s ease-in-out infinite;
  opacity: 0;
  transform: scale(0);
  transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.app.chat-active .header-orb {
  opacity: 1;
  transform: scale(1);
}

.header-orb.thinking {
  animation: orb-thinking 1.5s ease-in-out infinite;
  box-shadow:
    0 0 30px var(--accent-glow),
    0 0 60px var(--purple-glow),
    0 0 90px var(--teal-glow);
}

/* ── Landing Orb ────────────────────────────────────────────────────────── */
.orb-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 0 1.5rem;
  transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.app.chat-active .orb-container {
  padding: 0;
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

.orb {
  width: var(--orb-size);
  height: var(--orb-size);
  border-radius: 50%;
  position: relative;
  background: radial-gradient(circle at 30% 30%,
    rgba(88, 180, 255, 0.9),
    rgba(167, 139, 250, 0.55) 45%,
    rgba(45, 212, 191, 0.3) 75%,
    transparent 100%
  );
  box-shadow:
    0 0 60px var(--accent-glow),
    0 0 120px var(--purple-glow),
    0 0 180px var(--teal-glow),
    inset 0 0 40px rgba(88, 180, 255, 0.2);
  animation: orb-idle 4s ease-in-out infinite;
}

.orb::before {
  content: "";
  position: absolute;
  inset: -20%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(88, 180, 255, 0.08) 0%, transparent 70%);
  animation: orb-ring 6s ease-in-out infinite;
}

.orb.thinking {
  animation: orb-thinking 1.5s ease-in-out infinite;
  box-shadow:
    0 0 80px rgba(88, 180, 255, 0.5),
    0 0 160px rgba(167, 139, 250, 0.35),
    0 0 240px rgba(45, 212, 191, 0.2),
    inset 0 0 60px rgba(88, 180, 255, 0.4);
}

@keyframes orb-idle {
  0%, 100% {
    transform: scale(1);
    filter: brightness(1);
  }
  50% {
    transform: scale(1.05);
    filter: brightness(1.1);
  }
}

@keyframes orb-thinking {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25%  { transform: scale(1.1) rotate(2deg); }
  50%  { transform: scale(0.96); }
  75%  { transform: scale(1.08) rotate(-2deg); }
}

@keyframes orb-ring {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50%   { transform: scale(1.15); opacity: 0.2; }
}

.welcome-text {
  text-align: center;
  margin-top: 1.5rem;
  transition: opacity 0.6s ease;
}

.welcome-text h2 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--accent), var(--purple), var(--teal));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome-text p {
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 400;
}

/* ── Chat Area ──────────────────────────────────────────────────────────── */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}

.chat::-webkit-scrollbar {
  width: 4px;
}

.chat::-webkit-scrollbar-track {
  background: transparent;
}

.chat::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

/* ── Message Bubbles ────────────────────────────────────────────────────── */
.msg {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 0.9rem;
  animation: msg-enter 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes msg-enter {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.msg-user {
  align-self: flex-end;
  background: var(--user-bubble);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(88, 180, 255, 0.1);
  border-bottom-right-radius: 0.3rem;
}

.msg-assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-left: 2px solid rgba(88, 180, 255, 0.2);
  border-bottom-left-radius: 0.3rem;
}

.msg-system {
  align-self: center;
  max-width: 100%;
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 0.35rem 0.75rem;
  background: transparent;
  border: none;
}

.msg-error {
  border-color: rgba(248, 113, 113, 0.3) !important;
  border-left-color: rgba(248, 113, 113, 0.5) !important;
  color: #fca5a5;
}

.msg-meta {
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
}

/* ── Typewriter Cursor ──────────────────────────────────────────────────── */
.typewriter-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow), 0 0 16px var(--accent-glow);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: cursor-blink 0.7s step-end infinite;
  border-radius: 1px;
}

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

/* ── Composer ───────────────────────────────────────────────────────────── */
.composer {
  position: sticky;
  bottom: 0;
  padding: 0.75rem 0 1.25rem;
  z-index: 5;
}

.composer::before {
  content: "";
  position: absolute;
  inset: -2rem 0 0;
  background: linear-gradient(to top, var(--bg) 50%, transparent);
  z-index: -1;
  pointer-events: none;
}

.composer-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 0.35rem;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.composer-row:focus-within {
  border-color: rgba(88, 180, 255, 0.2);
  box-shadow: 0 0 24px rgba(88, 180, 255, 0.06);
}

.input-text {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
}

.input-text:focus {
  outline: none;
}

.input-text::placeholder {
  color: var(--muted);
}

.btn-send, .btn-mic {
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 500;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-send {
  padding: 0.55rem 1.1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #0a0f16;
  box-shadow: 0 0 16px rgba(88, 180, 255, 0.2);
}

.btn-send:hover {
  box-shadow: 0 0 24px rgba(88, 180, 255, 0.35);
  transform: translateY(-1px);
}

.btn-send:active {
  transform: translateY(0);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn-mic {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 0.75rem;
  background: transparent;
  color: var(--text-secondary);
  min-width: 4.25rem;
  justify-content: center;
}

.btn-mic:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.btn-mic[aria-pressed="true"] {
  color: var(--recording);
  background: rgba(251, 191, 36, 0.08);
}

.btn-mic-icon {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.2s;
}

.btn-mic[aria-pressed="true"] .btn-mic-icon {
  background: var(--recording);
  animation: pulse 1s ease-in-out infinite;
}

.btn-mic[aria-pressed="true"] .btn-mic-icon.waveform-active {
  display: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
}

/* ── Waveform Canvas ────────────────────────────────────────────────────── */
.waveform-canvas {
  display: none;
  width: 56px;
  height: 24px;
  border-radius: var(--radius-xs);
}

.btn-mic[aria-pressed="true"] .waveform-canvas {
  display: block;
}

/* ── Hint ───────────────────────────────────────────────────────────────── */
.hint {
  margin: 0.5rem 0 0;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
}

/* ── Suggestion Chips (persistent strip above composer) ─────────────────── */
.suggestions {
  padding: 0.35rem 0;
  overflow: hidden;
  mask-image: linear-gradient(to right, transparent, black 0.5rem, black calc(100% - 2rem), transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, black 0.5rem, black calc(100% - 2rem), transparent);
}

.suggestions-chips {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;          /* Firefox */
  -ms-overflow-style: none;       /* IE/Edge */
  padding-bottom: 0.25rem;
}

.suggestions-chips::-webkit-scrollbar {
  display: none;                  /* Chrome/Safari */
}

.chip {
  flex-shrink: 0;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--glass-border);
  border-radius: 2rem;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 450;
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.chip:hover {
  background: rgba(88, 180, 255, 0.08);
  border-color: rgba(88, 180, 255, 0.25);
  box-shadow: 0 0 20px rgba(88, 180, 255, 0.1);
  transform: translateY(-1px);
}

.chip:active {
  transform: translateY(0);
}

/* ── Tool Call Cards ────────────────────────────────────────────────────── */
.msg-tool {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-width: 85%;
  position: relative;
  overflow: hidden;
  animation: tool-slide 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.msg-tool::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.04), transparent);
  animation: shimmer 2s ease-in-out infinite;
}

.msg-tool.tool-complete::after {
  animation: none;
  opacity: 0;
}

@keyframes tool-slide {
  from { transform: translateX(-16px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.tool-spinner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
  font-size: 0;
  position: relative;
  z-index: 1;
}

.tool-spinner.tool-done {
  animation: tool-check 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
  border-color: var(--teal);
  color: var(--teal);
  font-size: 0.6rem;
  font-weight: 700;
}

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

@keyframes tool-check {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.tool-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  z-index: 1;
}

/* ── Metadata Panel ─────────────────────────────────────────────────────── */
.msg-metadata {
  align-self: flex-start;
  max-width: 85%;
  margin-top: -0.15rem;
}

.metadata-toggle {
  background: none;
  border: none;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.65rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius-xs);
  opacity: 0.6;
  transition: opacity 0.2s;
}

.metadata-toggle::before {
  content: "\25B6 ";
  font-size: 0.45rem;
  vertical-align: middle;
}

.metadata-toggle.open::before {
  content: "\25BC ";
}

.metadata-toggle:hover {
  opacity: 1;
}

.metadata-details {
  margin-top: 0.25rem;
  padding: 0.5rem 0.65rem;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xs);
  animation: msg-enter 0.3s ease both;
}

.metadata-table {
  border-collapse: collapse;
  font-size: 0.7rem;
  font-family: "JetBrains Mono", monospace;
}

.metadata-key {
  color: var(--muted);
  padding: 0.12rem 0.75rem 0.12rem 0;
  white-space: nowrap;
}

.metadata-val {
  color: var(--text-secondary);
  padding: 0.12rem 0;
}

/* ── Access Gate Overlay ────────────────────────────────────────────────── */
.gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 9, 13, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  animation: gate-fade-in 0.6s ease both;
}

@keyframes gate-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.gate-overlay.gate-unlocked {
  animation: gate-fade-out 0.5s ease both;
  pointer-events: none;
}

@keyframes gate-fade-out {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(1.05); }
}

.gate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 2.5rem 2rem;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 1.25rem;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5), 0 0 60px rgba(88, 180, 255, 0.06);
  max-width: 22rem;
  width: 90vw;
}

.gate-orb {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin-bottom: 1.25rem;
  background: radial-gradient(circle at 30% 30%,
    rgba(88, 180, 255, 0.9),
    rgba(167, 139, 250, 0.55) 50%,
    rgba(45, 212, 191, 0.3) 80%,
    transparent 100%
  );
  box-shadow:
    0 0 40px var(--accent-glow),
    0 0 80px var(--purple-glow);
  animation: orb-idle 4s ease-in-out infinite;
}

.gate-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.gate-subtitle {
  margin: 0.4rem 0 1.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.gate-form {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.gate-input {
  flex: 1;
  min-width: 0;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.gate-input:focus {
  outline: none;
  border-color: rgba(88, 180, 255, 0.3);
  box-shadow: 0 0 16px rgba(88, 180, 255, 0.1);
}

.gate-input::placeholder {
  color: var(--muted);
}

.gate-btn {
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #0a0f16;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 0 16px rgba(88, 180, 255, 0.2);
}

.gate-btn:hover {
  box-shadow: 0 0 24px rgba(88, 180, 255, 0.35);
  transform: translateY(-1px);
}

.gate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.gate-error {
  margin: 0.75rem 0 0;
  font-size: 0.8rem;
  color: var(--danger);
  text-align: center;
  min-height: 1.2em;
}

.gate-input.gate-shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%  { transform: translateX(-6px); }
  40%  { transform: translateX(6px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(4px); }
}

/* ── Accessibility ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  :root {
    --orb-size: 110px;
  }

  .app {
    padding: 0 0.75rem;
  }

  .orb-container {
    padding: 2.5rem 0 1rem;
  }

  .welcome-text h2 {
    font-size: 1.4rem;
  }

  .msg {
    max-width: 92%;
  }

  .chip {
    font-size: 0.7rem;
    padding: 0.35rem 0.65rem;
  }
}
