/* ============================================
   Agent Smith — Matrix Theme
   Voice-first, mobile-first, single viewport
   ============================================ */

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

:root {
  --matrix-green: #00ff41;
  --matrix-dark: #003b00;
  --matrix-dim: #008f11;
  --bg: #000000;
  --text: #c8c8c8;
  --text-bright: #e0e0e0;
  --glow: rgba(0, 255, 65, 0.4);
  --panel-bg: rgba(0, 10, 0, 0.85);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

/* ---- Matrix Canvas ---- */
#matrix-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* ---- Splash Screen ---- */
.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
}

.splash-content {
  text-align: center;
  padding: 2rem;
}

.splash-icon {
  margin-bottom: 1.5rem;
}

.sunglasses-lg {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.lens-lg {
  width: 28px;
  height: 16px;
  background: var(--matrix-green);
  border-radius: 3px;
  box-shadow: 0 0 12px var(--glow);
}

.bridge-lg {
  width: 8px;
  height: 3px;
  background: var(--matrix-green);
  opacity: 0.6;
}

.splash-title {
  font-family: 'Courier New', monospace;
  font-size: 1.6rem;
  font-weight: bold;
  letter-spacing: 6px;
  color: var(--matrix-green);
  text-shadow: 0 0 16px var(--glow);
  margin-bottom: 0.4rem;
}

.splash-sub {
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  letter-spacing: 4px;
  color: var(--matrix-dim);
  margin-bottom: 2.5rem;
}

.enter-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 40px;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 3px;
  color: var(--matrix-green);
  background: transparent;
  border: 1px solid rgba(0, 255, 65, 0.3);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s;
}

.enter-btn:hover, .enter-btn:active {
  background: rgba(0, 255, 65, 0.08);
  box-shadow: 0 0 30px rgba(0, 255, 65, 0.15);
  border-color: rgba(0, 255, 65, 0.5);
}

.enter-mic-icon {
  width: 36px;
  height: 36px;
  animation: gentlePulse 2s ease-in-out infinite;
}

@keyframes gentlePulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.hidden {
  display: none !important;
}

/* ---- Main App ---- */
.app {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}

/* ---- Agent Header ---- */
.agent-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top, 12px));
  background: rgba(0, 5, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(0, 255, 65, 0.15);
  flex-shrink: 0;
}

.agent-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sunglasses {
  display: flex;
  align-items: center;
  gap: 2px;
}

.lens {
  width: 12px;
  height: 8px;
  background: var(--matrix-green);
  border-radius: 2px;
  opacity: 0.9;
  box-shadow: 0 0 6px var(--glow);
}

.bridge {
  width: 4px;
  height: 2px;
  background: var(--matrix-green);
  opacity: 0.6;
}

.agent-name {
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 3px;
  color: var(--matrix-green);
  text-shadow: 0 0 8px var(--glow);
  flex: 1;
}

.agent-status {
  font-size: 0.7rem;
  color: var(--matrix-dim);
  font-family: 'Courier New', monospace;
  letter-spacing: 1px;
  transition: color 0.3s;
}

.agent-status.speaking {
  color: var(--matrix-green);
  text-shadow: 0 0 6px var(--glow);
}

.agent-status.listening {
  color: #44ff77;
}

/* ---- Chat Area ---- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  mask-image: linear-gradient(to bottom, transparent 0%, black 3%, black 97%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 3%, black 97%, transparent 100%);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.5;
  animation: msgIn 0.3s ease-out;
  word-wrap: break-word;
}

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

.msg.smith {
  align-self: flex-start;
  background: var(--panel-bg);
  color: var(--matrix-green);
  border: 1px solid rgba(0, 255, 65, 0.15);
  border-bottom-left-radius: 4px;
  font-family: 'Courier New', monospace;
  text-shadow: 0 0 4px rgba(0, 255, 65, 0.2);
}

.msg.user {
  align-self: flex-end;
  background: rgba(0, 255, 65, 0.1);
  color: var(--text-bright);
  border: 1px solid rgba(0, 255, 65, 0.1);
  border-bottom-right-radius: 4px;
}

.interim-preview {
  align-self: flex-end;
  max-width: 85%;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  color: rgba(200, 200, 200, 0.5);
  background: rgba(0, 255, 65, 0.05);
  border: 1px dashed rgba(0, 255, 65, 0.1);
  font-style: italic;
}

.thinking {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--panel-bg);
  border: 1px solid rgba(0, 255, 65, 0.15);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}

.thinking span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--matrix-green);
  animation: thinkPulse 1.2s ease-in-out infinite;
}

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

@keyframes thinkPulse {
  0%, 60%, 100% { opacity: 0.2; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* ---- Email Panel (non-blocking floating card) ---- */
.email-panel {
  flex-shrink: 0;
  padding: 0 12px 8px;
  z-index: 20;
  animation: slideUp 0.4s ease-out;
}

.email-panel-inner {
  position: relative;
  background: rgba(0, 8, 0, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 255, 65, 0.3);
  border-radius: 12px;
  padding: 14px 16px;
}

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

.email-dismiss {
  position: absolute;
  top: 6px;
  right: 10px;
  background: none;
  border: none;
  color: var(--matrix-dim);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  transition: color 0.2s;
}

.email-dismiss:hover, .email-dismiss:active {
  color: var(--matrix-green);
}

.email-title {
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  color: var(--matrix-green);
  text-shadow: 0 0 10px var(--glow);
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.email-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.email-input, .phone-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: 'Courier New', monospace;
  color: var(--matrix-green);
  background: rgba(0, 20, 0, 0.6);
  border: 1px solid rgba(0, 255, 65, 0.25);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.email-input:focus, .phone-input:focus {
  border-color: var(--matrix-green);
  box-shadow: 0 0 12px rgba(0, 255, 65, 0.2);
}

.email-input::placeholder, .phone-input::placeholder {
  color: rgba(0, 255, 65, 0.3);
}

.email-submit {
  width: 100%;
  padding: 12px;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  font-weight: bold;
  letter-spacing: 3px;
  color: #000;
  background: var(--matrix-green);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  text-transform: uppercase;
}

.email-submit:hover, .email-submit:active {
  box-shadow: 0 0 24px var(--glow);
  background: #33ff66;
}

.confirmed-msg {
  font-family: 'Courier New', monospace;
  color: var(--matrix-green);
  font-size: 0.95rem;
  text-shadow: 0 0 10px var(--glow);
  padding: 12px;
  letter-spacing: 1px;
  text-align: center;
}

/* ---- Input Area ---- */
.input-area {
  padding: 8px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background: rgba(0, 5, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid rgba(0, 255, 65, 0.1);
  flex-shrink: 0;
}

/* Voice Controls */
.voice-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: relative;
}

.voice-status {
  font-family: 'Courier New', monospace;
  font-size: 0.7rem;
  letter-spacing: 2px;
  color: var(--matrix-dim);
  min-height: 1em;
  transition: color 0.3s;
}

.voice-status.active {
  color: var(--matrix-green);
  text-shadow: 0 0 6px var(--glow);
}

/* Large mic button */
.mic-btn-lg {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(0, 255, 65, 0.3);
  background: rgba(0, 20, 0, 0.4);
  color: var(--matrix-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.3s;
}

.mic-btn-lg svg {
  width: 28px;
  height: 28px;
  position: relative;
  z-index: 2;
}

.mic-btn-lg.listening {
  border-color: var(--matrix-green);
  color: var(--matrix-green);
  background: rgba(0, 40, 0, 0.5);
  box-shadow: 0 0 20px rgba(0, 255, 65, 0.2);
}

.mic-btn-lg.thinking {
  border-color: #ffaa00;
  color: #ffaa00;
  background: rgba(40, 30, 0, 0.4);
}

.mic-btn-lg.speaking {
  border-color: rgba(0, 255, 65, 0.2);
  color: rgba(0, 255, 65, 0.3);
  background: rgba(0, 10, 0, 0.3);
}

/* Mic pulse rings */
.mic-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--matrix-green);
  opacity: 0;
  pointer-events: none;
}

.mic-btn-lg.listening .mic-ring {
  animation: ringPulse 2s ease-out infinite;
}

.mic-btn-lg.listening .mic-ring-2 {
  animation: ringPulse 2s ease-out infinite 0.5s;
}

@keyframes ringPulse {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* Text toggle (keyboard icon) */
.text-toggle {
  position: absolute;
  right: 16px;
  bottom: 0;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: rgba(0, 255, 65, 0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.text-toggle:hover, .text-toggle:active {
  color: rgba(0, 255, 65, 0.6);
}

.text-toggle svg {
  width: 22px;
  height: 22px;
}

/* Text Controls */
.text-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.voice-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(0, 255, 65, 0.3);
  background: rgba(0, 20, 0, 0.4);
  color: var(--matrix-green);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.voice-toggle svg {
  width: 20px;
  height: 20px;
}

.text-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  background: rgba(0, 20, 0, 0.5);
  border: 1px solid rgba(0, 255, 65, 0.2);
  border-radius: 24px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.text-input-wrap:focus-within {
  border-color: rgba(0, 255, 65, 0.5);
}

.text-input {
  flex: 1;
  padding: 12px 16px;
  font-size: 0.95rem;
  color: var(--text-bright);
  background: transparent;
  border: none;
  outline: none;
  font-family: inherit;
}

.text-input::placeholder {
  color: rgba(200, 200, 200, 0.3);
}

.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--matrix-green);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.send-btn:hover, .send-btn:active {
  opacity: 1;
}

.send-btn svg {
  width: 20px;
  height: 20px;
}

/* ---- Responsive ---- */
@media (min-width: 600px) {
  .chat-area {
    padding: 24px;
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
  }

  .input-area {
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
  }

  .agent-header {
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
  }

  .email-panel {
    max-width: 420px;
    margin: 0 auto;
  }
}

/* ---- Scrollbar (desktop) ---- */
.chat-area::-webkit-scrollbar {
  width: 4px;
}

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

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