/* ==========================================================================
   Zero UI — Dark Monolith Theme
   Minimal, cinematic, stark. The void IS the design.
   ========================================================================== */

:root {
  --bg: #050505;
  --text: #d0d0d0;
  --text-dim: #555;
  --input-border: rgba(255, 255, 255, 0.06);
  --input-border-focus: rgba(255, 255, 255, 0.14);
  --placeholder: rgba(255, 255, 255, 0.12);
  --glow-color: 80, 140, 255;
  --glow: rgba(var(--glow-color), 0.08);
  --glow-active: rgba(var(--glow-color), 0.18);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Syne', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---- App shell ---- */
#app {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  height: 100vh; /* fallback */
  transition: height 0.25s ease;
}

body.keyboard-open #app {
  justify-content: flex-start;
  padding-top: 60px;
}

/* ---- Background canvas (particles + grid) ---- */
#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ---- Ambient presence (breathing glow) ---- */
.ambient {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(var(--glow-color), 0.13) 0%, rgba(var(--glow-color), 0.04) 45%, transparent 70%);
  transform: translate(-50%, -50%) scale(1);
  pointer-events: none;
  will-change: opacity, transform;
  animation: breathe 8s ease-in-out infinite;
  z-index: 1;
  filter: blur(40px);
}

/* State: user is typing */
.ambient.listening {
  animation: breathe-listen 6s ease-in-out infinite;
}

/* State: waiting for AI */
.ambient.processing {
  animation: breathe-process 2s ease-in-out infinite;
}

/* State: AI is streaming */
.ambient.speaking {
  animation: breathe-speak 3s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.55; transform: translate(-50%, -50%) scale(1); }
  50%      { opacity: 0.9;  transform: translate(-50%, -50%) scale(1.08); }
}

@keyframes breathe-listen {
  0%, 100% { opacity: 0.65; transform: translate(-50%, -50%) scale(1); }
  50%      { opacity: 1;    transform: translate(-50%, -50%) scale(1.07); }
}

@keyframes breathe-process {
  0%, 100% { opacity: 0.5;  transform: translate(-50%, -50%) scale(0.97); }
  50%      { opacity: 1;    transform: translate(-50%, -50%) scale(1.1); }
}

@keyframes breathe-speak {
  0%, 100% { opacity: 0.75; transform: translate(-50%, -50%) scale(1); }
  50%      { opacity: 1;    transform: translate(-50%, -50%) scale(1.14); }
}

/* ---- Response area (centred text) ---- */
.response-area {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  max-width: 640px;
  width: 90%;
  max-height: 55vh;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 0 16px;
}

body.keyboard-open .response-area {
  margin-top: 40px;
  max-height: 40vh;
}

body.keyboard-open .ambient {
  top: 40%;
}

.response-area::-webkit-scrollbar {
  display: none;
}

.response-text {
  font-size: clamp(1.15rem, 2.6vw, 1.5rem);
  font-weight: 500;
  line-height: 1.8;
  letter-spacing: 0.02em;
  color: var(--text);
}

/* ---- Word-by-word reveal (welcome message) ---- */
.word {
  display: inline;
  opacity: 0;
  filter: blur(6px);
  animation: word-reveal 0.5s ease forwards;
}

@keyframes word-reveal {
  to {
    opacity: 1;
    filter: blur(0);
  }
}

/* ---- Token-by-token stream reveal ---- */
.token {
  opacity: 0;
  animation: token-fade 0.18s ease forwards;
}

@keyframes token-fade {
  to { opacity: 1; }
}

/* ---- Thinking indicator ---- */
.thinking {
  display: none;
  margin-top: 24px;
}

.thinking.active {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.thinking .dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  animation: dot-pulse 1.4s ease-in-out infinite;
}

.thinking .dot:nth-child(2) { animation-delay: 0.18s; }
.thinking .dot:nth-child(3) { animation-delay: 0.36s; }

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

/* ---- Input area ---- */
.input-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  padding: 24px 20px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.8s ease, transform 0.8s ease;
  pointer-events: none;
}

.input-area.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.chat-input {
  width: 100%;
  max-width: 480px;
  background: transparent;
  border: 1px solid var(--input-border);
  border-radius: 28px;
  padding: 15px 24px;
  font-family: 'Syne', system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text);
  outline: none;
  transition: border-color 0.35s ease;
  -webkit-appearance: none;
  appearance: none;
}

.chat-input::placeholder {
  color: var(--placeholder);
  font-weight: 300;
}

.chat-input:focus {
  border-color: var(--input-border-focus);
}

.chat-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---- Fade-out utility ---- */
.fade-out {
  transition: opacity 0.3s ease;
  opacity: 0;
}

/* ---- Mobile adjustments ---- */
@media (max-width: 600px) {
  .ambient {
    width: 420px;
    height: 420px;
  }

  .response-area {
    max-width: 100%;
    width: 94%;
    max-height: 50vh;
  }

  .response-text {
    font-size: 1.05rem;
    line-height: 1.75;
  }

  .chat-input {
    font-size: 1rem;
    padding: 14px 20px;
    max-width: 100%;
  }

  .input-area {
    padding: 16px 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ---- Landscape mobile (keyboard visible, tight space) ---- */
@media (max-height: 440px) {
  .response-area {
    max-height: 40vh;
  }

  .ambient {
    width: 280px;
    height: 280px;
  }
}
