/* ─── Reset & Foundations ──────────────────────────────────── */

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

:root {
  --bg: #000000;
  --bg-near: #040608;
  --bg-active: #0a0e18;
  --particle-dim: #4a5568;
  --particle-bright: #8a9ab0;
  --blue-white: #c8d6ec;
  --orb-core: rgba(225, 232, 250, 0.5);
  --text: rgba(255, 255, 255, 0.88);
  --text-secondary: rgba(200, 210, 230, 0.5);
  --text-faint: rgba(200, 210, 230, 0.25);

  --font-display: 'Cormorant Garamond', 'Georgia', serif;
  --font-body: 'Outfit', system-ui, sans-serif;

  --orb-size: 32px;
  --orb-top: 15vh;
  --chat-top: calc(var(--orb-top) + var(--orb-size) + 40px);
  --input-height: 64px;
  --fade-height: 120px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 300;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Canvas (behind everything) ──────────────────────────── */

#particle-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* ─── Simon Label ─────────────────────────────────────────── */

#simon-label {
  position: fixed;
  top: max(20px, 3vh);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 13px;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--text-faint);
  pointer-events: none;
  user-select: none;
}

/* ─── Orb ─────────────────────────────────────────────────── */

#orb-container {
  position: fixed;
  top: var(--orb-top);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  pointer-events: none;
}

#orb {
  position: relative;
  width: var(--orb-size);
  height: var(--orb-size);
  transition: width 0.8s ease, height 0.8s ease;
}

.orb-core {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(
    circle at 50% 50%,
    var(--orb-core) 0%,
    rgba(200, 215, 240, 0.25) 30%,
    rgba(170, 190, 225, 0.08) 60%,
    transparent 80%
  );
  animation: orb-pulse 4s ease-in-out infinite;
}

.orb-glow {
  position: absolute;
  inset: -60%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(200, 214, 236, 0.12) 0%,
    rgba(200, 214, 236, 0.04) 40%,
    transparent 70%
  );
  animation: orb-pulse 4s ease-in-out infinite;
  animation-delay: -1s;
  transition: inset 0.8s ease, opacity 0.8s ease;
}

.orb-haze {
  position: absolute;
  inset: -150%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(200, 214, 236, 0.05) 0%,
    transparent 60%
  );
  animation: orb-pulse 6s ease-in-out infinite;
  animation-delay: -2s;
  transition: inset 0.8s ease, opacity 0.8s ease;
}

@keyframes orb-pulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}

/* Orb active state */
#orb.active {
  width: 44px;
  height: 44px;
}

#orb.active .orb-core {
  animation-duration: 1.5s;
  background: radial-gradient(
    circle at 50% 50%,
    rgba(225, 232, 250, 0.7) 0%,
    rgba(200, 215, 240, 0.4) 30%,
    rgba(170, 190, 225, 0.15) 60%,
    transparent 80%
  );
}

#orb.active .orb-glow {
  inset: -100%;
  animation-duration: 1.5s;
  background: radial-gradient(
    circle,
    rgba(200, 214, 236, 0.22) 0%,
    rgba(200, 214, 236, 0.08) 40%,
    transparent 70%
  );
}

#orb.active .orb-haze {
  inset: -250%;
  animation-duration: 2.5s;
  background: radial-gradient(
    circle,
    rgba(200, 214, 236, 0.1) 0%,
    transparent 60%
  );
}

/* ─── Chat Container ──────────────────────────────────────── */

#chat-container {
  position: fixed;
  top: var(--chat-top);
  bottom: calc(var(--input-height) + 16px);
  left: 0;
  right: 0;
  z-index: 5;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;

  /* Fade mask: top fades to transparent near orb zone */
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 0, 0, 0.3) 40px,
    rgba(0, 0, 0, 1) var(--fade-height),
    rgba(0, 0, 0, 1) 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 0, 0, 0.3) 40px,
    rgba(0, 0, 0, 1) var(--fade-height),
    rgba(0, 0, 0, 1) 100%
  );
}

#chat-container::-webkit-scrollbar {
  width: 4px;
}

#chat-container::-webkit-scrollbar-track {
  background: transparent;
}

#chat-container::-webkit-scrollbar-thumb {
  background: rgba(200, 214, 236, 0.1);
  border-radius: 2px;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px max(20px, 5vw) 12px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
  min-height: min-content;
}

/* ─── Messages ────────────────────────────────────────────── */

.message {
  opacity: 0;
  transform: translateY(8px);
  animation: msg-appear 0.4s ease forwards;
}

@keyframes msg-appear {
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  max-width: 85%;
  background: rgba(200, 214, 236, 0.06);
  border: 1px solid rgba(200, 214, 236, 0.08);
  border-radius: 18px 18px 4px 18px;
  padding: 10px 16px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
}

.message.assistant {
  align-self: flex-start;
  max-width: 92%;
  padding: 2px 0;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
}

.message.assistant p {
  margin-bottom: 0.6em;
}

.message.assistant p:last-child {
  margin-bottom: 0;
}

.message.assistant strong {
  font-weight: 500;
  color: rgba(255, 255, 255, 0.95);
}

.message.assistant em {
  color: var(--blue-white);
  font-style: italic;
}

.message.assistant ul, .message.assistant ol {
  margin: 0.4em 0 0.6em 1.2em;
}

.message.assistant li {
  margin-bottom: 0.25em;
}

.message.assistant code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.88em;
  background: rgba(200, 214, 236, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Tool activity indicator */
.tool-status {
  align-self: center;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 4px 0;
  opacity: 0;
  animation: msg-appear 0.3s ease forwards;
}

.tool-status .dot {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--particle-bright);
  margin-right: 6px;
  vertical-align: middle;
  animation: dot-pulse 1.2s ease-in-out infinite;
}

@keyframes dot-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* ─── Input ───────────────────────────────────────────────── */

#input-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: 12px max(16px, 5vw) max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

#input-form {
  max-width: 680px;
  margin: 0 auto;
}

.input-pill {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: rgba(200, 214, 236, 0.04);
  border: 1px solid rgba(200, 214, 236, 0.08);
  border-radius: 24px;
  padding: 8px 8px 8px 20px;
  transition: border-color 0.3s ease, background 0.3s ease;
}

.input-pill:focus-within {
  border-color: rgba(200, 214, 236, 0.18);
  background: rgba(200, 214, 236, 0.06);
}

#user-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 300;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  padding: 4px 0;
}

#user-input::placeholder {
  color: var(--text-secondary);
}

#send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(200, 214, 236, 0.08);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

#send-btn:hover {
  background: rgba(200, 214, 236, 0.14);
  color: var(--blue-white);
}

#send-btn:active {
  transform: scale(0.92);
}

#send-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ─── Welcome State ───────────────────────────────────────── */

#messages:empty::before {
  content: 'Ask about the Freiberg family — names, places, stories, connections.';
  display: block;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 300;
  padding-top: 30vh;
  letter-spacing: 0.01em;
}

/* ─── Responsive ──────────────────────────────────────────── */

@media (max-width: 600px) {
  :root {
    --orb-top: 10vh;
    --fade-height: 80px;
  }

  #messages {
    padding: 16px 16px 8px;
  }

  .message.user {
    max-width: 90%;
  }

  .message.assistant {
    max-width: 98%;
  }
}

@media (min-width: 1200px) {
  :root {
    --orb-top: 18vh;
  }
}

/* ─── Accessibility: reduced motion ───────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .orb-core, .orb-glow, .orb-haze {
    animation: none;
  }

  .message {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .tool-status .dot {
    animation: none;
    opacity: 0.6;
  }
}
