:root {
  --primary: #2d3748;
  --secondary: #4a5568;
  --accent: #6366f1;
  --light: #f7fafc;
  --bg-image: url('daylight_forest.png'); /* daytime forest for light mode */
  --bg-image-dark: url('occult_forest.png'); /* occult forest for dark mode */
  /* New variables for Dark Mode compatibility */
  --bg-container: rgba(45,55,72,0.05); /* 95% transparent container (very subtle overlay) */
  --text-color: var(--primary);
  --title-color: #f7fafc; /* force header title to appear like dark-mode (light) in light theme */
  --border-color: #e2e8f0;

  /* Shared sizing for send/mic buttons so both stay consistent across breakpoints */
  --send-w: 40px;
  --send-h: 40px;
}

body.dark-mode {
  --primary: #f7fafc; /* Light text color */
  --title-color: var(--primary); /* keep title color synced in dark mode */
  --secondary: #a0aec0; /* Lighter secondary elements color */
  --accent: #8b92f7; /* Adjusted accent */
  --light: #1a202c; /* Page Background */
  --bg-container: rgba(45,55,72,0.05); /* 95% transparent container for dark mode */
  --border-color: #4a5568; /* Dark mode border color */
  --bg-image: var(--bg-image-dark); /* switch to occult background in dark mode */
}

/* Custom Scrollbar Styles for Webkit browsers (Chrome, Safari, Edge) */
/* Thinner scrollbars for a sleeker look */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

/* Scrollbar Track (the background area) */
::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
}

/* Scrollbar Handle (the draggable part) */
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--accent), var(--primary));
  border-radius: 8px;
  min-height: 24px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
  background: var(--primary); /* Darker color on hover (adaptive) */
}

/* Firefox: use thin scrollbars and set colors where supported */
body,
.messages {
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: var(--accent) rgba(255,255,255,0.03); /* thumb track */
}

/* Add overlay canvas for three.js background (pointer-events none so page remains interactive) */
#three-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0; /* beneath UI which uses higher z-index values (modals are 1001) */
  pointer-events: none;
}

body {
  font-family: "Noto Sans", system-ui, -apple-system, sans-serif;
  margin: 0;
  padding: 0;
  /* subtle occult forest background with dark overlay for legibility */
  background: linear-gradient(rgba(8,10,12,0.65), rgba(8,10,12,0.65)), var(--bg-image);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--primary); /* Use primary for body text color */
  min-height: 100vh;
  display: flex;
  width: 100vw;
  overflow-x: hidden;
}

.chat-container {
  position: relative;
  z-index: 2;
  flex: 1;
  margin: 0;
  background: var(--bg-container); /* Use adaptive background */
  border-radius: 0;
  box-shadow: none;
  padding: 20px;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  height: 100vh;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 0px;
  padding-bottom: 0px;
  margin-top: 0px;
  padding-top: 0px;
  border-bottom: 1px solid var(--border-color); /* Use adaptive border */
  flex-shrink: 0;
}

.chat-header h3 { color: var(--title-color); margin: 0; font-weight:700; }

.omniakashica-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 6px;
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.message {
  display: flex;
  gap: 12px;
  animation: fadeIn 0.3s ease-out;
  margin-left: 35px; /* moved messages 35px to the right */
}

.message.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  flex-shrink: 0;
}

.message-content {
  background: var(--light); /* Use light background variable (which adapts) */
  padding: 12px 16px;
  border-radius: 12px;
  max-width: 70%;
  overflow-wrap: break-word;
  position: relative;
}

.message.user .message-content {
  background: var(--accent);
  color: white;
}

.copy-message-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.6;
  padding: 0px;
  transition: opacity 0.2s;
}

/* Speak (audio) button placed next to copy button */
.speak-message-btn {
  position: absolute;
  top: 4px;
  right: 36px; /* place to the left of the copy button */
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.6;
  padding: 0;
  transition: opacity 0.2s, transform 0.12s;
}

.speak-message-btn:hover,
.copy-message-btn:hover {
  opacity: 1;
  transform: translateY(-1px);
}

/* Ensure visibility for user messages (white icon) */
.message.user .copy-message-btn,
.message.user .speak-message-btn {
  color: white;
  opacity: 0.8;
}

.copy-message-btn:hover {
  opacity: 1;
}

.message.user .message-content .copy-message-btn {
  display: block;
  color: white;
  opacity: 0.7;
}

.message.user .message-content .copy-message-btn:hover {
  opacity: 1;
}

.input-container {
  display: flex;
  gap: 12px;
  margin-top: auto;
  flex-shrink: 0;
}

/* New wrapper for the integrated input and button */
.input-wrapper {
    position: relative;
    flex: 1; /* Ensures the wrapper takes the available width */
}

.model-select {
  flex: 2;
  padding: 5px;
  margin-left: 10px;
}

textarea, #userInput {
  flex: 1;
  padding: 12px 60px 30px 12px; /* Adjusted padding: Right (60px) and Bottom (30px) for button clearance */
  border: 2px solid var(--border-color); /* Use adaptive border */
  /* Make the userInput background black with 85% opacity for clear contrast */
  background: rgba(0, 0, 0, 0.85);
  color: #ffffff; /* Force input text to white */
  border-radius: 8px;
  resize: none;
  font-family: inherit;
  font-size: 1rem;
  min-height: 60px;
  width: 100%; /* Ensure full width relative to wrapper */
  box-sizing: border-box;
}

/* Ensure the textarea placeholder text is white and fully visible across browsers */
textarea::placeholder { color: #ffffff; opacity: 1; }
textarea::-webkit-input-placeholder { color: #ffffff; opacity: 1; }
textarea:-ms-input-placeholder { color: #ffffff; opacity: 1; }

button {
  padding: 9px 9px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-weight: bold;
  transition: opacity 0.2s;
}

/* Style for the integrated send button - match mic-button visual style */
.send-button {
  position: absolute;
  bottom: 13px;
  right: 8px;
  width: var(--send-w);
  height: var(--send-h);
  /* Make the send button a perfect circle */
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  color: white;
  border: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  z-index: 11;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s, box-shadow 0.12s;
  touch-action: manipulation;
}

button:hover {
  opacity: 0.9;
}

.api-key-button {
  background: var(--accent);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  padding: 6px;
  cursor: pointer;
  margin-left: 8px;
  font-size: 16px;
}

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 1001;
  justify-content: center;
  align-items: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-container); /* Adaptive background */
  padding: 24px;
  border-radius: 12px;
  width: 90%;
  max-width: 400px;
  position: relative;
  color: var(--primary); /* Adaptive text color */
  border: 2px solid rgba(0, 180, 255, 0.95); /* neon-blue border */
  box-shadow: 0 8px 30px rgba(0,180,255,0.08), 0 2px 8px rgba(0,0,0,0.25);
  animation: pulse-neon 2.4s ease-in-out infinite;
}

/* Pulsing neon border effect for modal content */
@keyframes pulse-neon {
  0% {
    border-color: rgba(0,180,255,0.95);
    box-shadow: 0 8px 30px rgba(0,180,255,0.06), 0 2px 8px rgba(0,0,0,0.25);
    transform: translateY(0);
  }
  50% {
    border-color: rgba(0,220,255,1);
    box-shadow: 0 12px 48px rgba(0,220,255,0.18), 0 4px 12px rgba(0,0,0,0.25);
    transform: translateY(-2px);
  }
  100% {
    border-color: rgba(0,180,255,0.95);
    box-shadow: 0 8px 30px rgba(0,180,255,0.06), 0 2px 8px rgba(0,0,0,0.25);
    transform: translateY(0);
  }
}

/* Ensure modal headings are clearly visible (white) for the API key modal */
.modal-content h2 {
  color: #ffffff;
  margin-top: 0;
}

.close-modal {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--secondary);
}

.api-key-input {
  width: flex;
  padding: 8px;
  margin-top: 8px;
  border: 1px solid var(--secondary);
  border-radius: 4px;
  margin-bottom: 20px;
  background: var(--bg-container); /* Adaptive background */
  color: var(--primary); /* Adaptive text color */
}

/* Ensure the placeholder in the API key input is white and fully visible */
.api-key-input::placeholder { color: #ffffff; opacity: 1; }
.api-key-input::-webkit-input-placeholder { color: #ffffff; opacity: 1; }
.api-key-input:-ms-input-placeholder { color: #ffffff; opacity: 1; }

.modal-buttons {
  display: flex;
  justify-content: center; /* Center the buttons */
  gap: 10px; /* Space between buttons */
}

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

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px;
  background: var(--light); /* Adaptive background */
  border-radius: 12px;
  width: fit-content;
}

.dot {
  width: 8px;
  height: 8px;
  background: var(--secondary);
  border-radius: 50%;
  animation: bounce 1.4s infinite;
}

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

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.floating-keyboard-btn {
  position: fixed;
  top: calc(50vh + 130px); /* swapped with dark mode position */
  left: 20px; /* Moved to left */
  right: unset; /* Ensure right is unset */
  width: 34px; /* reduced size */
  height: 34px; /* reduced size */
  background: rgba(0,0,0,0.7); /* black with 70% opacity */
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.2s, background 0.2s;
  opacity: 1;
}

.floating-keyboard-btn:hover {
  transform: scale(1.1);
  background: var(--primary);
  opacity: 1.0;
}

.input-popup {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--bg-container); /* Adaptive background */
  box-shadow: 0 -4px 6px rgba(0,0,0,0.1);
  z-index: 1001;
  padding: 2px;
  animation: slideUp 0.3s ease-out;
}

.input-popup.active {
  display: block;
}

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

.floating-settings-btn {
  position: fixed;
  top: calc(50vh - 120px);  /* New position: 170 - 50 = 120 */
  left: 20px; /* Moved to left */
  right: unset;
  width: 34px; /* reduced size */
  height: 34px; /* reduced size */
  background: rgba(0,0,0,0.7); /* black with 70% opacity */
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.2s, background 0.2s;
  opacity: 1;
}

.floating-settings-btn:hover {
  transform: scale(1.1);
  background: var(--primary);
  opacity: 1.0;
}

.settings-container {
  max-width: 500px;
  margin: 0 auto;
}

.settings-option {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
}

.settings-option label {
  flex: 1;
}

.settings-option input[type="range"] {
  flex: 2;
}

.settings-option input[type="number"] {
  width: 80px;
  padding: 5px;
  background: var(--bg-container); /* Adaptive background for input */
  color: var(--primary); /* Adaptive text color for input */
  border: 1px solid var(--border-color);
}

.floating-clear-history-btn {
  position: fixed;
  top: calc(50vh - 70px);  /* New position: 120 - 50 = 70 */
  left: 20px; /* Moved to left */
  right: unset;
  width: 34px; /* reduced size */
  height: 34px; /* reduced size */
  background: rgba(0,0,0,0.7); /* black with 70% opacity */
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.2s, background 0.2s;
  opacity: 1;
}

.floating-clear-history-btn:hover {
  transform: scale(1.1);
  background: var(--primary);
  opacity: 1.0;
}

.floating-export-history-btn {
  position: fixed;
  top: calc(50vh - 20px);  /* New position: 70 - 50 = 20 */
  left: 20px; /* Moved to left */
  right: unset;
  width: 34px; /* reduced size */
  height: 34px; /* reduced size */
  background: rgba(0,0,0,0.7); /* black with 70% opacity */
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.2s, background 0.2s;
  opacity: 1;
}

.floating-export-history-btn:hover {
  transform: scale(1.1);
  background: var(--primary);
  opacity: 1.0;
}

/* New Home button */
.floating-home-btn {
  position: fixed;
  top: calc(50vh + 30px); /* New position: -20 + 50 = 30 */
  left: 20px; /* Moved to left */
  right: unset;
  width: 34px; /* reduced size */
  height: 34px; /* reduced size */
  background: rgba(0,0,0,0.7); /* black with 70% opacity */
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.2s, background 0.2s;
  opacity: 1;
}

.floating-home-btn:hover {
  transform: scale(1.1);
  background: var(--primary);
  opacity: 1.0;
}

.floating-api-key-btn {
  position: fixed;
  top: calc(50vh + 80px);  /* New position: 30 + 50 = 80 */
  left: 20px; /* Moved to left */
  right: unset;
  width: 34px; /* reduced size */
  height: 34px; /* reduced size */
  background: rgba(0,0,0,0.7); /* black with 70% opacity */
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.2s, background 0.2s;
  opacity: 1;
}

.floating-api-key-btn:hover {
  transform: scale(1.1);
  background: var(--primary);
  opacity: 1.0;
}

/* NEW Dark Mode button */
.floating-dark-mode-btn {
  position: fixed;
  top: calc(50vh - 170px);  /* swapped with keyboard position */
  left: 20px; /* Moved to left */
  right: unset;
  width: 34px; /* reduced size */
  height: 34px; /* reduced size */
  background: rgba(0,0,0,0.7); /* black with 70% opacity */
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.2s, background 0.2s;
  opacity: 1;
}

.floating-dark-mode-btn:hover {
  transform: scale(1.1);
  background: var(--primary);
  opacity: 1.0;
}

@media (max-width: 600px) {
  body {
    font-size: 14px; /* Slightly smaller base font size for mobile */
  }

  .chat-container {
    padding: 10px; /* Reduce padding on smaller screens */
  }

  .chat-header {
    flex-direction: row; /* Revert to row for better compact layout */
    justify-content: space-between; /* Spread out items */
    align-items: center;
  }

  .chat-header h1 {
    font-size: 1.2rem; /* Smaller header text */
    margin: 0;
  }

  .chat-header h3 {
    font-size: 1.2rem; /* Smaller header text */
    margin: 0;
  }

  .messages {
    padding: 5px; /* Reduce padding */
    gap: 10px; /* Tighter message spacing */
  }

  .message-content {
    max-width: 85%; /* Allow slightly wider messages */
    font-size: 0.9rem; /* Slightly smaller message text */
  }

  .input-container {
    flex-direction: row; /* Keep input and button in one row */
    align-items: stretch; /* Stretch items to same height */
  }

  textarea {
    flex: 1;
    min-height: 50px; /* Slightly shorter input */
    padding: 8px; /* Reduce padding */
  }

  button {
    padding: 8px; /* Slightly smaller buttons */
    font-size: 0.9rem;
  }

  .modal-content {
    width: 95%;
    max-width: 95%;
    margin: 0 10px;
    padding: 15px; /* Reduce modal padding */
  }

  .modal-buttons {
    flex-direction: column; /* Stack modal buttons vertically on mobile */
    gap: 8px;
  }

  .input-container {
    flex-direction: column;
  }

  .input-popup .input-container {
    gap: 10px;
  }

  .input-popup textarea {
    width: 100%;
    min-height: 100px;
    padding: 12px 60px 30px 12px; /* Ensure clearance is maintained on mobile */
    color: #ffffff; /* Ensure popup textarea text is white on mobile */
  }

  .input-popup button {
    width: 100%;
  }
  
  /* Ensure the absolutely positioned button retains its natural size on mobile */
  .input-popup .send-button {
    width: auto;
  }

  .model-select {
    width: 100%;
    margin-left: 0;
  }

  .settings-option {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .settings-option label {
    width: 100%;
  }

  .settings-option input[type="range"],
  .settings-option input[type="number"] {
    width: 100%;
  }
  
  /* Ensure save settings button is full width on mobile */
  .settings-container button {
    width: 100%;
    margin-top: 10px;
  }
  
  .floating-keyboard-btn,
  .floating-settings-btn,
  .floating-clear-history-btn,
  .floating-export-history-btn,
  .floating-home-btn, /* New: Add mobile styling for home button */
  .floating-api-key-btn,
  .floating-dark-mode-btn {
    width: 28px; /* reduced mobile size */
    height: 28px; /* reduced mobile size */
    font-size: 16px; /* adjusted font */
    left: 10px;
  }
  
  /* Reposition floating buttons to center vertically on mobile */
  /* Using 32px size and 42px center-to-center distance */
  
  .floating-keyboard-btn {
    top: calc(50vh - 142px);
    bottom: unset;
  }
  
  .floating-settings-btn {
    top: calc(50vh - 100px);
    bottom: unset;
  }

  .floating-clear-history-btn {
    top: calc(50vh - 58px);
    bottom: unset;
  }

  .floating-export-history-btn {
    top: calc(50vh - 16px);
    bottom: unset;
  }

  .floating-home-btn {
    top: calc(50vh + 26px);
    bottom: unset;
  }

  .floating-api-key-btn {
    top: calc(50vh + 68px); 
    bottom: unset;
  }
  
  /* NEW Dark Mode button mobile position */
  .floating-dark-mode-btn {
    top: calc(50vh + 110px); 
    bottom: unset;
  }
}

@media (max-width: 900px) {
  /* mobile / small tablet adjustments */
  .chat-container {
    padding: 12px;
    height: 100vh;
    box-sizing: border-box;
  }

  .messages { gap: 10px; padding: 8px; }

  textarea {
    padding: 12px 72px 40px 12px; /* extra right padding for large touch send button */
    min-height: 84px;
    font-size: 1rem;
  }

  .input-popup .input-container { padding: 8px 12px; }

  /* Make floating buttons slightly larger for touch targets and align left stacked centered vertically */
  .floating-keyboard-btn,
  .floating-settings-btn,
  .floating-clear-history-btn,
  .floating-export-history-btn,
  .floating-home-btn,
  .floating-api-key-btn,
  .floating-dark-mode-btn {
    width: 38px;
    height: 38px;
    font-size: 18px;
    left: 12px;
  }

  /* Compact vertical spacing using consistent step (swapped keyboard & dark-mode) */
  .floating-keyboard-btn { top: calc(50vh + 132px); }
  .floating-settings-btn { top: calc(50vh - 88px); }
  .floating-clear-history-btn { top: calc(50vh - 44px); }
  .floating-export-history-btn { top: calc(50vh - 0px); }
  .floating-home-btn { top: calc(50vh + 44px); }
  .floating-api-key-btn { top: calc(50vh + 88px); }
  .floating-dark-mode-btn { top: calc(50vh - 132px); }
}

@media (max-width: 420px) {
  /* Very small screens: full-width send button inside input bar, larger tap target */
  .input-wrapper { position: relative; }
  .send-button {
    position: absolute;
    bottom: 13px;
    right: 8px;
    /* Make mobile send button respect the circular sizing variables and be a circle */
    padding: 0;
    width: var(--send-w);
    height: var(--send-h);
    border-radius: 50%;
    font-size: 16px;
    touch-action: manipulation;
  }

  .input-popup .send-button {
    /* Use slightly larger mobile variables but keep circular form */
    --send-w: 52px;
    --send-h: 52px;
    width: var(--send-w);
    height: var(--send-h);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
  }

  /* Ensure messages have comfortable line-height and spacing */
  .message-content { font-size: 15px; line-height: 1.4; padding: 12px 16px; }
  .avatar { width: 36px; height: 36px; font-size: 14px; }

  /* Keep modals full-screen friendly */
  .modal-content { width: 94%; max-width: 420px; padding: 16px; }
}

@media (max-height: 600px) {
  .chat-container {
    height: 100vh;
    overflow-y: auto; /* Allow scrolling if content is too tall */
  }
}

/* Microphone button placed above send-button inside .input-wrapper */
.mic-button {
  position: absolute;
  bottom: 58px; /* above the send-button which is at bottom:13px */
  right: 8px;
  width: var(--send-w);
  height: var(--send-h);
  /* Make mic a perfect circle and use same sizing variables as send button */
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  color: white;
  border: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  z-index: 11;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s, box-shadow 0.12s;
  touch-action: manipulation;
}

/* Mobile override: stack mic above send inside the input bar (vertical buttons) */
@media (max-width: 600px) {
  /* Keep input container horizontal so popup layout remains consistent */
  .input-container {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  /* Use a two-column grid: textarea on the left, a narrow column on the right for stacked buttons */
  .input-wrapper {
    display: grid;
    grid-template-columns: 1fr var(--send-w);
    grid-template-rows: auto auto;
    gap: 8px;
    width: 100%;
    align-items: center;
  }

  /* Make the textarea span both rows of the left column so it remains tall while buttons stack */
  .input-wrapper textarea {
    grid-column: 1 / 2;
    grid-row: 1 / 3;
    position: relative;
    flex: none;
    padding-right: 12px;
    width: 100%;
    box-sizing: border-box;
  }

  /* Place mic above send by assigning explicit grid positions */
  .input-wrapper .mic-button {
    grid-column: 2;
    grid-row: 1;
    position: relative;
    bottom: unset;
    right: unset;
    width: var(--send-w);
    height: var(--send-h);
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .input-wrapper .send-button {
    grid-column: 2;
    grid-row: 2;
    position: relative;
    bottom: unset;
    right: unset;
    width: var(--send-w);
    height: var(--send-h);
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Slightly increase touch targets on very small phones while maintaining stacked layout */
  @media (max-width: 420px) {
    .input-wrapper {
      grid-template-columns: 1fr 52px;
      grid-template-rows: auto auto;
    }
    .input-wrapper .send-button,
    .input-wrapper .mic-button {
      --send-w: 52px;
      --send-h: 52px;
      width: var(--send-w);
      height: var(--send-h);
    }
  }
}

/* Align mic size to the send button on very small screens */
@media (max-width: 420px) {
  /* ensure the send button uses the larger mobile touch size (keep perfect circle) */
  .input-popup .send-button {
    --send-w: 52px;
    --send-h: 52px;
    width: var(--send-w);
    height: var(--send-h);
  }

  .mic-button {
    width: var(--send-w);
    height: var(--send-h);
    bottom: 66px; /* keep vertical spacing */
    right: 8px;
  }
}

/* Listening state */
.mic-button.listening {
  background: rgba(255,92,92,0.95);
  box-shadow: 0 6px 18px rgba(255,92,92,0.18);
  transform: scale(1.05);
}