/* ============================================
   DVC AI CHATBOT — MODERN DARK THEME v3.0
   Fully Responsive + PWA + Keyboard Fix
   promode × @dvc 2026
   ============================================ */

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --bg-hover: #21262d;
  --bg-input: #0d1117;
  --border-color: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #7c3aed;
  --accent-2: #3b82f6;
  --accent-3: #06b6d4;
  --gradient-main: linear-gradient(135deg, #7c3aed, #3b82f6, #06b6d4);
  --user-msg-bg: linear-gradient(135deg, #7c3aed, #5b21b6);
  --ai-msg-bg: #1c2128;
  --success: #238636;
  --danger: #da3633;
  --warning: #d29922;
  /* Dynamic viewport height — handles mobile keyboard */
  --dvh: 100vh;
  --dvh-sb: 100svh;
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eff2f5;
  --bg-hover: #e7ebef;
  --bg-input: #ffffff;
  --border-color: #d0d7de;
  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-muted: #8c959f;
  --ai-msg-bg: #f6f8fa;
}

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

/* ========== PWA: Prevent overscroll, hide browser chrome ========== */
html {
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  /* Dynamic viewport — works with keyboard open */
  height: var(--dvh-sb);
}

@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', 'Helvetica Neue', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: row;
  transition: background-color 0.3s ease, color 0.3s ease;
  /* Prevent rubber-banding on iOS */
  overscroll-behavior: none;
  position: fixed;
  width: 100%;
  height: 100%;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============ OFFLINE SCREEN ============ */
.offline-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0a0000 0%, #1a0505 50%, #2a1010 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
}

.offline-content {
  text-align: center;
  animation: fadeInUp 0.5s ease;
  max-width: 400px;
}

.offline-icon {
  font-size: 64px;
  margin-bottom: 16px;
  animation: pulse-icon 2s infinite;
}

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

.offline-screen h1 {
  font-size: clamp(24px, 5vw, 36px);
  color: #da3633;
  margin-bottom: 8px;
}

.offline-screen p {
  color: #8b949e;
  font-size: 14px;
}

.offline-footer {
  margin-top: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  font-size: 12px;
  color: #6e7681;
}

.offline-pulse {
  width: 8px;
  height: 8px;
  background: #da3633;
  border-radius: 50%;
  animation: pulse-dot 1.5s infinite;
}

/* ============ SETUP SCREEN ============ */
.setup-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.setup-card {
  max-width: 480px;
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: clamp(20px, 4vw, 32px);
  text-align: center;
  animation: fadeInUp 0.4s ease;
}

.setup-logo {
  font-size: 48px;
  margin-bottom: 10px;
  filter: drop-shadow(0 4px 12px rgba(124, 58, 237, 0.5));
}

.setup-card h1 {
  font-size: clamp(22px, 4vw, 28px);
  background: var(--gradient-main);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}

.setup-card p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 20px;
}

.setup-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

#setupApiKey,
#settingsNewKey {
  width: 100%;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
}

#setupApiKey:focus,
#settingsNewKey:focus {
  border-color: var(--accent);
}

.setup-show-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.setup-key-multi {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.multi-hint {
  font-size: 12px !important;
  color: var(--accent-2) !important;
  margin-bottom: 0 !important;
}

#setupMultiKeys,
#settingsMultiKeys {
  width: 100%;
  padding: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 12px;
  font-family: monospace;
  resize: vertical;
  min-height: 70px;
  outline: none;
}

.setup-save-btn {
  padding: 12px;
  background: var(--gradient-main);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.setup-save-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.4);
}

.setup-note {
  font-size: 11px !important;
  color: var(--text-muted) !important;
  text-align: center;
}

/* API Key Info Box — Setup & Settings */
.setup-key-info,
.key-info-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: 8px;
  text-align: left;
}

.key-info-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 6px 0;
}

.key-info-steps {
  margin: 0 0 8px 0;
  padding-left: 18px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.key-info-steps li {
  margin-bottom: 2px;
}

.key-info-steps a,
.key-info-box a {
  color: var(--accent);
  text-decoration: none;
}

.key-info-steps a:hover,
.key-info-box a:hover {
  text-decoration: underline;
}

.key-info-note {
  font-size: 11px;
  color: var(--text-muted);
  margin: 4px 0;
}

.key-info-note code {
  background: rgba(99, 102, 241, 0.15);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--accent);
}

/* ============ SIDEBAR ============ */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
  height: 100%;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.logo-icon {
  font-size: 28px;
  filter: drop-shadow(0 0 10px rgba(124, 58, 237, 0.5));
}

.logo-text {
  font-size: 22px;
  font-weight: 700;
  background: var(--gradient-main);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 1px;
}

.new-chat-btn {
  width: 100%;
  padding: 12px 16px;
  background: var(--gradient-main);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.new-chat-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.4);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
}

.chat-history-item {
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
  margin-bottom: 4px;
  transition: all 0.2s ease;
  display: block;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

.chat-history-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chat-history-item.active {
  background: rgba(124, 58, 237, 0.15);
  border-left-color: var(--accent);
  color: var(--text-primary);
}

.settings-btn {
  width: 100%;
  padding: 10px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 8px;
  color: var(--accent-2);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.settings-btn:hover {
  background: rgba(59, 130, 246, 0.2);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.model-selector-wrap { display: flex; flex-direction: column; gap: 6px; }
.model-selector-wrap label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.model-select {
  width: 100%;
  padding: 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

.model-select:focus { border-color: var(--accent); }

.clear-all-btn {
  padding: 10px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.clear-all-btn:hover {
  background: rgba(218, 54, 51, 0.1);
  border-color: var(--danger);
  color: var(--danger);
}

.footer-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

.powered-by {
  background: var(--gradient-main);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 600;
}

/* ============ MAIN AREA ============ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  /* CRITICAL: flex column so messages + input share vertical space */
}

.topbar {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  z-index: 50;
}

.menu-toggle {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.menu-toggle:hover { background: var(--bg-hover); }

.topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse-dot 2s infinite;
  flex-shrink: 0;
}

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

.icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background 0.2s ease;
}

.icon-btn:hover { background: var(--bg-hover); }

/* ============ MESSAGES ============ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  /* KEYBOARD FIX: min-height 0 prevents flex from overflowing */
  min-height: 0;
}

.welcome-screen {
  max-width: 800px;
  margin: 20px auto;
  padding: 10px;
}

.welcome-logo {
  text-align: center;
  margin-bottom: 32px;
}

.welcome-logo-circle {
  width: 80px;
  height: 80px;
  background: var(--gradient-main);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin: 0 auto 16px;
  box-shadow: 0 8px 32px rgba(124, 58, 237, 0.35);
  animation: float 3s ease-in-out infinite;
}

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

.welcome-logo h1 {
  font-size: clamp(28px, 6vw, 42px);
  background: var(--gradient-main);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}

.welcome-logo p {
  color: var(--text-secondary);
  font-size: 14px;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.suggestion-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all 0.2s ease;
  text-align: left;
  color: inherit;
}

.suggestion-card:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.2);
}

.sg-icon { font-size: 24px; }
.sg-title { font-weight: 700; font-size: 14px; color: var(--text-primary); }
.sg-desc { font-size: 12px; color: var(--text-secondary); }

/* ============ DOWNLOAD APP SECTION ============ */
.download-app-section {
  margin-top: 24px;
}

.download-app-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  transition: border-color 0.3s ease;
}

.download-app-card:hover {
  border-color: var(--accent);
}

.download-app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.download-app-icon {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  flex-shrink: 0;
  object-fit: cover;
}

.download-app-info h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.download-app-info p {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
}

.download-app-features {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.download-feature {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-primary);
}

.df-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.download-app-actions {
  margin-bottom: 16px;
}

.download-app-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--gradient-main);
  color: #ffffff;
  text-decoration: none;
  border-radius: 12px;
  padding: 14px 24px;
  font-weight: 700;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.3);
  width: 100%;
  justify-content: center;
}

.download-app-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.4);
}

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

.dl-btn-icon {
  font-size: 22px;
}

.dl-btn-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.dl-btn-main {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.dl-btn-sub {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.85;
  line-height: 1.4;
}

.download-app-note {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

/* FB/Messenger warning banner */
.fb-warning-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: linear-gradient(135deg, rgba(255, 193, 7, 0.15), rgba(255, 152, 0, 0.1));
  border: 1px solid rgba(255, 193, 7, 0.4);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.fb-warn-icon {
  font-size: 22px;
  flex-shrink: 0;
}
.fb-warning-banner strong {
  color: #ffc107;
  font-size: 13px;
  display: block;
  margin-bottom: 4px;
}
.fb-warning-banner p {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

/* Open in Browser button (FB/Messenger escape) */
.open-browser-btn {
  display: none;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #1877f2, #0d65d9);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  padding: 14px 24px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 16px rgba(24, 119, 242, 0.3);
  font-family: inherit;
}
.open-browser-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(24, 119, 242, 0.4);
}
.open-browser-btn:active {
  transform: translateY(0);
}

/* ============ /DOWNLOAD APP SECTION ============ */

.message-row {
  max-width: 800px;
  margin: 0 auto 16px;
  display: flex;
  gap: 10px;
  animation: fadeInUp 0.3s ease;
}

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

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

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.message-row.user .avatar {
  background: var(--gradient-main);
  color: white;
}

.message-row.ai .avatar {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
}

.message-bubble {
  max-width: calc(100% - 52px);
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 14px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message-row.user .message-bubble {
  background: var(--user-msg-bg);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-row.ai .message-bubble {
  background: var(--ai-msg-bg);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

.message-bubble pre {
  background: #0d1117;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
}

.message-bubble pre code {
  background: none;
  padding: 0;
  color: #e6edf3;
}

.message-bubble code {
  background: rgba(110, 118, 129, 0.3);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
}

.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite;
}

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

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-6px); opacity: 1; }
}

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

.error-bubble {
  background: rgba(218, 54, 51, 0.1) !important;
  border-color: var(--danger) !important;
  color: var(--danger) !important;
}

/* ============ INPUT AREA — CRITICAL FOR KEYBOARD ============ */
.input-area {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.input-wrapper {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 22px;
  padding: 8px 12px;
  transition: border-color 0.2s ease;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

#userInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  padding: 4px 0;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient-main);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.input-footer {
  max-width: 800px;
  margin: 6px auto 0;
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
}

.key-status {
  color: var(--success);
  font-weight: 600;
}

.user-badge {
  background: rgba(124, 58, 237, 0.15);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 16px;
  font-weight: 700;
  font-size: 9px;
  letter-spacing: 0.5px;
  border: 1px solid rgba(124, 58, 237, 0.3);
  white-space: nowrap;
}

/* ============ SETTINGS MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: fadeInUp 0.3s ease;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: 18px;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { color: var(--danger); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-field {
  margin-bottom: 14px;
}

.modal-field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.modal-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.saved-keys-list {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  max-height: 180px;
  overflow-y: auto;
  font-family: monospace;
  font-size: 12px;
}

.saved-keys-list .key-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 8px;
  border-radius: 6px;
  margin-bottom: 3px;
}

.saved-keys-list .key-item:hover {
  background: var(--bg-hover);
}

.key-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 14px;
}

/* ============ OVERLAY ============ */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

.overlay.show { display: block; }

/* =============================================
   RESPONSIVE — TABLET & MOBILE
   ============================================= */

/* Tablet: sidebar becomes overlay */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    margin-left: -300px;
    transition: margin-left 0.3s ease;
    z-index: 200;
    width: 280px;
  }

  .sidebar.show {
    margin-left: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }

  .menu-toggle {
    display: flex;
  }
}

/* Mobile: tighter spacing, bigger touch targets */
@media (max-width: 480px) {
  .sidebar {
    width: 100%;
    min-width: 100%;
    margin-left: -100%;
  }

  .sidebar.show {
    margin-left: 0;
  }

  .topbar {
    padding: 10px 12px;
  }

  .topbar-title {
    font-size: 14px;
  }

  .messages {
    padding: 14px 10px;
  }

  .message-row {
    margin-bottom: 12px;
  }

  .avatar {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }

  .message-bubble {
    max-width: calc(100% - 44px);
    padding: 10px 14px;
    font-size: 14px;
    border-radius: 12px;
  }

  .suggestion-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .suggestion-card {
    padding: 14px;
  }

  .welcome-logo-circle {
    width: 64px;
    height: 64px;
    font-size: 32px;
  }

  .input-area {
    padding: 10px 12px;
  }

  .input-wrapper {
    padding: 6px 10px;
    border-radius: 20px;
  }

  #userInput {
    font-size: 16px; /* Prevent iOS zoom on input focus */
    max-height: 80px;
  }

  .input-footer {
    flex-direction: row;
    justify-content: space-between;
    font-size: 9px;
    gap: 4px;
    flex-wrap: wrap;
  }

  .modal-card {
    max-height: 90vh;
  }
}

/* Very small screens (320px width) */
@media (max-width: 350px) {
  .message-bubble {
    font-size: 13px;
    padding: 8px 12px;
  }

  .welcome-logo h1 {
    font-size: 24px;
  }
}

/* Landscape mode on phones */
@media (max-height: 500px) and (orientation: landscape) {
  .welcome-screen {
    margin: 10px auto;
  }

  .welcome-logo {
    margin-bottom: 16px;
  }

  .welcome-logo-circle {
    width: 48px;
    height: 48px;
    font-size: 24px;
  }

  .welcome-logo h1 {
    font-size: 20px;
  }
}

/* Safe areas for phones with notches (iPhone, etc.) */
@supports (padding-top: env(safe-area-inset-top)) {
  .topbar {
    padding-top: calc(12px + env(safe-area-inset-top));
  }

  .input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .sidebar {
    padding-top: env(safe-area-inset-top);
  }
}

/* ============ PWA: standalone mode (when launched from home screen) ============ */
@media (display-mode: standalone) {
  .topbar {
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
  }

  .input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
}

/* ============ PRINT HIDE ============ */
@media print {
  body { display: none; }
}

/* =============================================
   OUTPUT/DOWNLOAD BOX + CODE BLOCKS
   ============================================= */

.code-block-wrapper {
  position: relative;
  margin: 12px 0;
  border-radius: 8px;
  overflow: visible;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #161b22;
  border: 1px solid var(--border-color);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 6px 12px;
  gap: 8px;
}

.code-block-lang {
  font-size: 11px;
  color: var(--accent-2);
  font-weight: 600;
  font-family: monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.code-block-actions {
  display: flex;
  gap: 6px;
}

.code-action-btn {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: var(--accent-2);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.code-action-btn:hover {
  background: rgba(59, 130, 246, 0.25);
  transform: translateY(-1px);
}

.code-action-btn.copied,
.code-action-btn.downloaded {
  background: rgba(35, 134, 54, 0.2);
  border-color: rgba(35, 134, 54, 0.4);
  color: #238636;
}

.message-bubble .code-block-wrapper pre {
  margin-top: 0;
  border-radius: 0 0 8px 8px !important;
}

/* Output panel for generated files */
.output-panel {
  margin: 10px 0 4px;
  padding: 10px 12px;
  background: rgba(35, 134, 54, 0.08);
  border: 1px dashed rgba(35, 134, 54, 0.3);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.output-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  min-width: 0;
}

.output-file-icon { font-size: 16px; }
.output-filename {
  color: var(--success);
  font-family: monospace;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.output-filesize { color: var(--text-muted); font-size: 10px; }

.output-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.download-output-btn {
  background: linear-gradient(135deg, #238636, #2ea043);
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.download-output-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(46, 160, 67, 0.4);
}

.copy-output-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.copy-output-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Image output preview in AI message */
.ai-image-output {
  max-width: 300px;
  max-height: 250px;
  border-radius: 8px;
  margin: 8px 0;
  border: 1px solid var(--border-color);
  cursor: zoom-in;
}

/* =============================================
   VIDEO EMBED & MEDIA STYLES
   ============================================= */

.video-embed {
  margin: 12px 0;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  background: #000;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 60vh;
}

/* Fullscreen button for video */
.video-fs-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  background: rgba(0,0,0,0.65);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.2s;
}
.video-fs-btn:hover { background: rgba(0,0,0,0.85); }

/* Fullscreen mode — landscape-ready */
.video-embed:fullscreen,
.video-embed:-webkit-full-screen {
  width: 100vw !important;
  height: 100vh !important;
  max-height: none !important;
  aspect-ratio: unset !important;
  border-radius: 0 !important;
  z-index: 99999;
}
.video-embed:fullscreen iframe,
.video-embed:fullscreen video,
.video-embed:-webkit-full-screen iframe,
.video-embed:-webkit-full-screen video {
  width: 100% !important;
  height: 100% !important;
  min-height: unset !important;
}
/* Auto-rotate hint for phones */
@media (orientation: portrait) and (max-width: 600px) {
  .video-embed {
    min-height: 220px;
  }
}
@media (orientation: landscape) and (max-width: 900px) {
  .video-embed {
    min-height: unset;
    aspect-ratio: 16/9;
  }
}

.video-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.video-embed iframe-loader {
  display: block;
  width: 100%;
  height: 100%;
}

.play-overlay:hover {
  background: rgba(0,0,0,0.45) !important;
}

.play-overlay:hover div {
  transform: scale(1.08);
  box-shadow: 0 0 30px rgba(255,0,0,0.5);
}

.play-overlay div {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Search image cards */
.search-image {
  margin: 10px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  max-width: 340px;
  background: var(--bg-secondary);
}

.search-image img {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: opacity 0.2s;
}

.search-image img:hover {
  opacity: 0.92;
}

.search-image figcaption {
  padding: 6px 10px;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

/* Markdown image inline (from ![alt](url)) */
.md-image {
  margin: 8px 0;
}

.md-image img {
  max-width: 300px;
  max-height: 240px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  cursor: pointer;
}

.md-image img:hover {
  opacity: 0.92;
}

/* Temp search messages (searching indicator) */
.temp-msg {
  opacity: 0.75;
  font-style: italic;
}

.temp-msg .message-bubble {
  border-style: dashed;
}

/* ============ MODEL HINT (welcome screen only) ============ */
.model-hint {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 560px;
  margin: 18px auto;
  padding: 14px 16px;
  background: rgba(124, 58, 237, 0.08);
  border: 1px dashed rgba(124, 58, 237, 0.35);
  border-radius: 14px;
  animation: fadeInUp 0.6s ease 0.2s backwards;
}

.model-hint-icon {
  font-size: 24px;
  flex-shrink: 0;
  line-height: 1.2;
}

.model-hint-text {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
}

.model-hint-text strong {
  color: var(--accent);
  font-weight: 600;
}

.model-hint-highlight {
  color: var(--accent);
  font-weight: 600;
}

/* Hide hint when user starts chatting */
.model-hint.hidden,
.welcome-screen.active .model-hint {
  display: none;
}

/* Mobile hint */
@media (max-width: 480px) {
  .model-hint {
    margin: 12px auto;
    padding: 12px 14px;
    font-size: 12px;
  }
  .model-hint-icon { font-size: 20px; }
  .model-hint-text { font-size: 12px; }
}

/* Very small screens */
@media (max-width: 350px) {
  .model-hint { padding: 10px; font-size: 11px; }
}

/* Mobile tweaks */
@media (max-width: 480px) {
  .output-filename { max-width: 120px; }
  .code-block-header { padding: 5px 8px; }
  .code-action-btn { font-size: 10px; padding: 3px 6px; }
  .search-image { max-width: 100%; }
  /* Video BIGGER on phones — medium-large, easy to tap */
  .video-embed {
    margin: 10px -4px;
    border-radius: 10px;
    aspect-ratio: auto;
    min-height: 240px;
    max-height: none;
  }
  .video-embed iframe,
  .video-embed video {
    min-height: 240px;
    height: auto;
  }
}

/* =============================================
   ABOUT MODAL
   ============================================= */
.about-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: fadeInUp 0.3s ease;
}

.about-header {
  background: var(--gradient-main);
  border-radius: 16px 16px 0 0;
}

.about-header h2 { color: white !important; }
.about-header .modal-close { color: rgba(255,255,255,0.8) !important; }
.about-header .modal-close:hover { color: white !important; }

.about-body {
  padding: 0 !important;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Hero */
.about-hero {
  text-align: center;
  padding: 28px 20px 20px;
  background: linear-gradient(180deg, rgba(124,58,237,0.08) 0%, transparent 100%);
}

.about-avatar {
  font-size: 60px;
  margin-bottom: 10px;
  filter: drop-shadow(0 4px 12px rgba(124, 58, 237, 0.4));
}

.about-name {
  font-size: 28px;
  font-weight: 800;
  background: var(--gradient-main);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}

.about-title {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 12px;
}

.about-divider {
  width: 60px;
  height: 3px;
  background: var(--gradient-main);
  margin: 0 auto;
  border-radius: 2px;
}

/* Message */
.about-message {
  padding: 20px 24px;
}

.about-greeting {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.about-message p {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.about-message p:last-child { margin-bottom: 0; }
.about-message p.about-closing {
  margin-top: 8px;
  text-align: right;
  color: var(--text-primary);
}
.about-message strong {
  color: var(--accent);
  font-weight: 700;
}

/* Donation */
.donation-section {
  padding: 20px 24px;
  background: rgba(35, 134, 54, 0.05);
  border-top: 1px solid var(--border-color);
}

.donation-section h3 {
  font-size: 16px;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.donation-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.donation-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.donation-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}

.dc-icon { font-size: 24px; margin-bottom: 4px; }
.dc-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.dc-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-2);
  font-family: monospace;
  margin-bottom: 8px;
  word-break: break-all;
}

.copy-donation-btn {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: var(--accent-2);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.copy-donation-btn:hover {
  background: rgba(59, 130, 246, 0.25);
}

/* Connect */
.connect-section {
  padding: 20px 24px;
  border-top: 1px solid var(--border-color);
}

.connect-section h3 {
  font-size: 16px;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.facebook-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(24, 119, 242, 0.08);
  border: 1px solid rgba(24, 119, 242, 0.25);
  border-radius: 10px;
  color: #1877f2;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.facebook-link:hover {
  background: rgba(24, 119, 242, 0.15);
  transform: translateY(-1px);
}

.fb-handle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

/* Footer */
.about-footer {
  padding: 20px 24px;
  text-align: center;
  border-top: 1px solid var(--border-color);
}

.about-quote {
  font-style: italic;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.about-signature {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 14px;
}

.about-powered {
  font-size: 10px;
  color: var(--text-muted);
}

.about-btn {
  width: 100%;
  padding: 10px;
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid rgba(124, 58, 237, 0.3);
  border-radius: 8px;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.about-btn:hover {
  background: rgba(124, 58, 237, 0.2);
}

/* Mobile about */
@media (max-width: 480px) {
  .about-card { max-width: 100%; border-radius: 12px; }
  .about-avatar { font-size: 48px; }
  .about-name { font-size: 22px; }
  .about-message { padding: 16px; }
  .about-message p { font-size: 13px; }
  .donation-cards { grid-template-columns: 1fr; }
}

/* ============ AUTO-INJECTED SEARCH IMAGE GALLERY ============ */
.search-gallery {
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(124, 58, 237, 0.25);
  border-radius: 14px;
  padding: 10px;
  max-width: min(560px, 92%);
}

.gallery-header {
  font-size: 12px;
  font-weight: 600;
  color: #b8a8e8;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.gallery-count {
  background: rgba(124, 58, 237, 0.3);
  color: #d4c4f7;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.gallery-card {
  border-radius: 10px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease;
}

.gallery-card:hover {
  transform: translateY(-2px);
}

.gallery-card a {
  display: block;
  text-decoration: none;
}

.gallery-card img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  display: block;
}

.gallery-caption {
  display: block;
  font-size: 10px;
  color: #a99cc9;
  padding: 4px 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mobile gallery */
@media (max-width: 480px) {
  .search-gallery { max-width: 100%; padding: 8px; }
  .gallery-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .gallery-card img { height: 75px; }
}

/* ============ RESPONSIVE MEDIA — FIT ALL DEVICES ============ */

/* Tablet & below: bigger video + code */
@media (max-width: 768px) {
  .video-embed {
    max-width: 100%;
    border-radius: 10px;
    aspect-ratio: auto;
    min-height: 280px;
    max-height: none;
  }
  .video-embed iframe,
  .video-embed video {
    min-height: 280px;
  }

  .message-bubble pre {
    font-size: 12px;
    padding: 10px;
    margin: 8px 0;
  }

  .code-block-header {
    padding: 6px 10px;
  }

  .search-image {
    max-width: 100%;
  }

  .search-image img {
    max-height: 200px;
  }
}

/* Mobile: full-width media, bigger touch targets */
@media (max-width: 480px) {
  .video-embed {
    border-radius: 8px;
    margin: 8px 0;
  }

  .video-embed iframe,
  .video-embed iframe-loader {
    width: 100%;
    height: 100%;
  }

  .play-overlay div {
    width: 54px !important;
    height: 38px !important;
  }

  .search-image img {
    max-height: 180px;
  }

  .md-image img {
    max-width: 100%;
    max-height: 180px;
    width: auto;
  }

  .gallery-card img {
    height: 70px;
  }

  .output-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .output-actions {
    justify-content: flex-end;
  }

  .download-output-btn,
  .copy-output-btn {
    padding: 8px 12px;
    font-size: 11px;
    min-height: 32px;
  }

  .code-block-wrapper pre {
    font-size: 11.5px;
  }

  /* Horizontal scroll for wide tables */
  .message-bubble table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* Very small screens */
@media (max-width: 350px) {
  .gallery-grid { grid-template-columns: repeat(2, 1fr); }
  .gallery-card img { height: 60px; }
}

/* Download section — mobile */
@media (max-width: 768px) {
  .download-app-section { margin-top: 16px; }
  .download-app-card { padding: 18px; border-radius: 14px; }
  .download-app-header { gap: 12px; margin-bottom: 16px; }
  .download-app-icon { width: 52px; height: 52px; border-radius: 12px; }
  .download-app-info h2 { font-size: 15px; }
  .download-app-info p { font-size: 12px; }
  .download-app-features { grid-template-columns: 1fr; gap: 8px; margin-bottom: 14px; }
  .download-feature { font-size: 12px; gap: 6px; }
  .df-icon { font-size: 14px; }
  .download-app-btn { padding: 12px 20px; gap: 10px; }
  .dl-btn-main { font-size: 13px; }
  .dl-btn-sub { font-size: 10px; }
  .download-app-note { font-size: 11px; }
  .fb-warning-banner { padding: 10px 12px; gap: 8px; }
  .fb-warn-icon { font-size: 18px; }
  .open-browser-btn { padding: 12px 20px; }
}

/* Landscape phones — keep input visible */
@media (max-height: 500px) and (orientation: landscape) {
  .messages { padding: 8px 16px; }
  .welcome-screen { padding: 20px; }
  .welcome-logo-circle { width: 48px; height: 48px; font-size: 24px; }
  .suggestion-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .suggestion-card { padding: 8px; }
  .sg-desc { display: none; }
}

/* =============================================
   AIBOT ICON — 3D BOUNCE v7.0
   promode × @dvc 2026
   ============================================= */

/* Sidebar logo icon — gentle slow low bounce */
.logo-icon-img {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  object-fit: cover;
  animation: iconBounceGentle 3.2s ease-in-out infinite;
  filter: drop-shadow(0 4px 8px rgba(124, 58, 237, 0.45));
}

/* Setup screen logo — gentle bounce */
.setup-logo-img {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  object-fit: cover;
  margin-bottom: 12px;
  animation: iconBounceGentle 3.4s ease-in-out infinite;
  filter: drop-shadow(0 6px 16px rgba(124, 58, 237, 0.55));
}

/* Welcome screen logo — THE MAKULIT TUMBLING ICON */
.welcome-logo-img {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  object-fit: cover;
  display: block;
  margin: 0 auto 16px;
  box-shadow: 0 12px 40px rgba(124, 58, 237, 0.45), 0 4px 14px rgba(59, 130, 246, 0.3);
  animation: iconMakulitTumble 5s ease-in-out infinite;
}

/* Gentle low bounce — sidebar & setup icons */
@keyframes iconBounceGentle {
  0%, 100% {
    transform: translateY(0) scale(1, 1);
  }
  30% {
    transform: translateY(-6px) scale(0.97, 1.03);
  }
  50% {
    transform: translateY(-9px) scale(0.96, 1.04);
  }
  70% {
    transform: translateY(-4px) scale(0.98, 1.02);
  }
  85% {
    transform: translateY(0) scale(1.04, 0.96);
  }
  92% {
    transform: translateY(0) scale(0.98, 1.02);
  }
}

/* MAKULIT TUMBLE — low hops + 360 spin + wobble + head shake */
@keyframes iconMakulitTumble {
  /* Resting */
  0% {
    transform: translateY(0) rotate(0deg) scale(1, 1);
  }
  /* Small hop up + tilt right */
  10% {
    transform: translateY(-12px) rotate(12deg) scale(0.97, 1.03);
  }
  /* Peak of first hop + more tilt */
  18% {
    transform: translateY(-16px) rotate(18deg) scale(0.95, 1.05);
  }
  /* Land first hop — squash */
  28% {
    transform: translateY(0) rotate(0deg) scale(1.08, 0.9);
  }
  32% {
    transform: translateY(0) rotate(0deg) scale(1, 1);
  }
  /* BIG HOP — full 360 spin while in air! */
  38% {
    transform: translateY(-8px) rotate(120deg) scale(0.95, 1.05);
  }
  48% {
    transform: translateY(-18px) rotate(270deg) scale(0.93, 1.07);
  }
  /* Landing from 360 — squash */
  58% {
    transform: translateY(0) rotate(360deg) scale(1.1, 0.88);
  }
  62% {
    transform: translateY(0) rotate(360deg) scale(1, 1);
  }
  /* Wobble left-right-left — head shake "no" */
  66% {
    transform: translateY(-4px) rotate(-15deg) scale(1.02, 0.98);
  }
  72% {
    transform: translateY(-6px) rotate(15deg) scale(1.02, 0.98);
  }
  78% {
    transform: translateY(-4px) rotate(-10deg) scale(1.01, 0.99);
  }
  82% {
    transform: translateY(-2px) rotate(6deg) scale(1.01, 0.99);
  }
  /* Settle down */
  88% {
    transform: translateY(0) rotate(0deg) scale(1.04, 0.96);
  }
  94% {
    transform: translateY(0) rotate(0deg) scale(0.98, 1.02);
  }
  100% {
    transform: translateY(0) rotate(0deg) scale(1, 1);
  }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .logo-icon-img,
  .setup-logo-img,
  .welcome-logo-img {
    animation: none;
  }
}

/* =============================================
   WEATHER EFFECT LAYER — RAIN / CLOUDS / THUNDER
   Dark mode = rain + clouds + lightning every 10s
   Light mode = drifting blue clouds every 10s
   Layer sits BEHIND all UI — pointer-events none
   ============================================= */

.weather-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

/* Make sure app UI stacks above weather layer.
   NOTE: .sidebar keeps its original z-index:100, .overlay stays 99,
   modal-overlay 9999, offline 10000 — do NOT change them here. */
.main {
  position: relative;
  z-index: 1;
}

/* ---------- CLOUDS ---------- */
.weather-clouds {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.cloud-puff {
  position: absolute;
  background: radial-gradient(circle at 30% 70%, #ffffff 0%, #e8eef7 45%, transparent 70%),
              radial-gradient(circle at 65% 60%, #ffffff 0%, #dfe9f5 50%, transparent 72%);
  border-radius: 50%;
  opacity: 0;
  will-change: transform, opacity;
  filter: blur(0.4px);
}

.cloud-puff.drifting {
  opacity: 1;
  transition: opacity 2s ease;
}

.dark-theme-cloud {
  background: radial-gradient(circle at 30% 70%, #4a5568 0%, #2d3748 45%, transparent 70%),
              radial-gradient(circle at 65% 60%, #3d4859 0%, #1a202c 50%, transparent 72%);
}

.light-theme-cloud-blue {
  background: radial-gradient(circle at 30% 70%, rgba(147, 197, 253, 0.85) 0%, rgba(96, 165, 250, 0.55) 45%, transparent 70%),
              radial-gradient(circle at 65% 60%, rgba(191, 219, 254, 0.9) 0%, rgba(147, 197, 253, 0.6) 50%, transparent 72%);
}

/* Cloud drift animations */
@keyframes cloudDriftRight {
  from { transform: translateX(-30vw); }
  to   { transform: translateX(115vw); }
}

@keyframes cloudDriftLeft {
  from { transform: translateX(115vw); }
  to   { transform: translateX(-30vw); }
}

/* ---------- RAIN (dark mode) ---------- */
.weather-rain {
  position: absolute;
  inset: 0;
  display: none;
}

.rain-drop {
  position: absolute;
  top: -5%;
  width: 2px;
  height: 68px;
  background: linear-gradient(to bottom, rgba(174, 194, 224, 0), rgba(174, 194, 224, 0.75));
  border-radius: 2px;
  will-change: transform;
  animation: rainFall 0.9s linear forwards;
}

.rain-drop.heavy {
  width: 2.5px;
  height: 90px;
  background: linear-gradient(to bottom, rgba(140, 170, 210, 0), rgba(140, 170, 210, 0.85));
}

@keyframes rainFall {
  from { transform: translateY(-10vh) translateX(0); }
  to   { transform: translateY(115vh) translateX(-6vw); }
}

.rain-splash {
  position: absolute;
  bottom: 4%;
  width: 6px;
  height: 6px;
  border: 1.5px solid rgba(174, 194, 224, 0.6);
  border-radius: 50%;
  opacity: 0;
  animation: splashGrow 0.6s ease-out forwards;
}

@keyframes splashGrow {
  0%   { transform: scale(0.2); opacity: 0.8; }
  100% { transform: scale(2.6); opacity: 0; }
}

/* ---------- LIGHTNING / THUNDER (dark mode) ---------- */
.weather-lightning {
  position: absolute;
  inset: 0;
  display: none;
}

.lightning-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 60% 45% at 50% 0%,
      rgba(255, 255, 255, 0.95) 0%,
      rgba(190, 200, 255, 0.55) 30%,
      rgba(120, 120, 200, 0.22) 60%,
      transparent 80%);
  opacity: 0;
}

.lightning-flash.flash-1 {
  animation: thunderFlash1 0.9s ease-out forwards;
}

.lightning-flash.flash-2 {
  animation: thunderFlash2 1.4s ease-out forwards;
}

@keyframes thunderFlash1 {
  0%   { opacity: 0; }
  8%   { opacity: 1; }
  18%  { opacity: 0.15; }
  30%  { opacity: 0.85; }
  55%  { opacity: 0.1; }
  65%  { opacity: 0.45; }
  100% { opacity: 0; }
}

@keyframes thunderFlash2 {
  0%   { opacity: 0; }
  6%   { opacity: 1; }
  14%  { opacity: 0.1; }
  22%  { opacity: 0.9; }
  40%  { opacity: 0.05; }
  52%  { opacity: 0.6; }
  70%  { opacity: 0; }
}

/* Lightning bolt shape */
.lightning-bolt {
  position: absolute;
  top: 6%;
  width: 34px;
  height: 150px;
  opacity: 0;
  background: linear-gradient(160deg,
      rgba(255, 255, 240, 0) 0%,
      rgba(255, 255, 230, 1) 18%,
      rgba(255, 245, 150, 0.95) 45%,
      rgba(255, 255, 240, 0.9) 70%,
      rgba(255, 255, 200, 0) 100%);
  clip-path: polygon(62% 0%, 20% 44%, 44% 44%, 30% 74%, 82% 30%, 54% 30%, 78% 0%);
  filter: drop-shadow(0 0 14px rgba(255, 250, 180, 0.95)) drop-shadow(0 0 34px rgba(200, 200, 255, 0.6));
}

.lightning-bolt.strike {
  animation: boltStrike 0.75s ease-out forwards;
}

@keyframes boltStrike {
  0%   { opacity: 0; transform: scale(0.7) translateY(-20px); }
  10%  { opacity: 1; transform: scale(1.02) translateY(0); }
  22%  { opacity: 0.2; }
  32%  { opacity: 0.95; }
  55%  { opacity: 0.1; }
  68%  { opacity: 0.55; }
  100% { opacity: 0; }
}

/* ---------- LIGHT MODE BLUE SKY TINT (subtle) ---------- */
html[data-theme="light"] .weather-layer {
  background: linear-gradient(180deg, rgba(186, 225, 255, 0.16) 0%, rgba(219, 240, 255, 0.10) 40%, transparent 75%);
}

/* ---------- PERFORMANCE: pause when tab hidden ---------- */
.weather-layer.paused * {
  animation-play-state: paused !important;
}
