:root {
  --bg-accent: #00e5ff;
  --text-accent: #030310;
  --surface-1: rgba(26, 26, 38, 0.4);
  --text-primary: #ffffff;
  --text-secondary: #8a8a9e;
  --border: rgba(0, 229, 255, 0.15);
  --bg-glow: radial-gradient(circle at 50% 50%, #15152a 0%, #07070f 100%);
}

body {
  color: var(--text-primary);
  font-family: 'Outfit', sans-serif;
  margin: 0;
  padding: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

#app-title {
  font-size: 18px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 4px;
  margin: 0 0 4px 0;
  text-align: center;
  background: linear-gradient(135deg, #ffffff 40%, #00e5ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#app-title .v-tag {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 1px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--bg-accent);
  text-transform: uppercase;
}

#rd {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  font-family: 'Outfit', sans-serif;
  width: 100%;
  max-width: 600px;
  background: rgba(18, 18, 28, 0.7);
  backdrop-filter: blur(12px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
  box-sizing: border-box;
}

/* Cybernetic HUD Corner Accents */
#rd::before {
  content: '';
  position: absolute;
  top: -1px; left: -1px; width: 12px; height: 12px;
  border-top: 2px solid var(--bg-accent);
  border-left: 2px solid var(--bg-accent);
  border-top-left-radius: 16px;
  pointer-events: none;
}

#rd::after {
  content: '';
  position: absolute;
  bottom: -1px; right: -1px; width: 12px; height: 12px;
  border-bottom: 2px solid var(--bg-accent);
  border-right: 2px solid var(--bg-accent);
  border-bottom-right-radius: 16px;
  pointer-events: none;
}

#rt {
  display: flex;
  gap: 20px;
  align-items: stretch;
}

#fp {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: rgba(8, 8, 12, 0.5);
  padding: 16px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

/* Settings Gear & Modal Panel styling */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

#test-excitement-btn,
#settings-btn {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 14px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#test-excitement-btn span,
#settings-btn span {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.65;
  transition: opacity 0.2s;
}

#test-excitement-btn svg,
#settings-btn svg {
  width: 14px;
  height: 14px;
  opacity: 0.8;
  transition: opacity 0.2s;
}

#test-excitement-btn:hover,
#settings-btn:hover {
  background: rgba(0, 229, 255, 0.08);
  border-color: var(--bg-accent);
  color: var(--bg-accent);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.2);
}

#test-excitement-btn:hover span,
#settings-btn:hover span {
  opacity: 0.95;
}

#test-excitement-btn:hover svg,
#settings-btn:hover svg {
  opacity: 1;
}

#settings-panel {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 18, 0.85);
  backdrop-filter: blur(16px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.3s ease;
  border-radius: 16px;
  border: 1px solid var(--border);
}

#settings-panel.hidden,
#confirm-delete-panel.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

.settings-content {
  background: rgba(20, 20, 30, 0.95);
  border: 1px solid var(--border);
  padding: 24px;
  border-radius: 14px;
  width: 85%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-content h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

#close-settings-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: all 0.2s;
}

#close-settings-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.password-wrapper input {
  width: 100%;
  padding-right: 32px !important;
  box-sizing: border-box;
}

#provider-select,
#model-input,
#endpoint-input,
#api-key-input {
  width: 100%;
  background: #08080c;
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.2s;
}

#provider-select:focus,
#model-input:focus,
#endpoint-input:focus,
#api-key-input:focus {
  border-color: var(--bg-accent);
}

#toggle-visibility-btn {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  transition: color 0.2s;
}

#toggle-visibility-btn:hover {
  color: var(--text-primary);
}

#toggle-visibility-btn svg.hidden {
  display: none;
}

#test-status-banner {
  font-size: 11px;
  padding: 8px 12px;
  border-radius: 6px;
  line-height: 1.4;
  font-weight: 500;
  word-break: break-word;
}

#test-status-banner.hidden {
  display: none;
}

#test-status-banner.success {
  background: rgba(104, 194, 78, 0.15);
  border: 1px solid #68c24e;
  color: #68c24e;
}

#test-status-banner.error {
  background: rgba(224, 78, 78, 0.15);
  border: 1px solid #e04e4e;
  color: #e04e4e;
}

#test-status-banner.loading {
  background: rgba(138, 138, 158, 0.15);
  border: 1px solid var(--text-secondary);
  color: var(--text-primary);
}

.settings-note {
  font-size: 10px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.4;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 14px;
}

.settings-section:first-of-type {
  border-top: none;
  padding-top: 0;
}

.settings-section-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--cyan);
  opacity: 0.8;
  margin-bottom: 2px;
}

.settings-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.settings-row button {
  flex: 1;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 11px;
  transition: all 0.2s;
  text-align: center;
  box-sizing: border-box;
}

#test-key-btn {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 7px 12px;
}

#test-key-btn:hover {
  background: var(--border);
}

#save-settings-btn {
  background: var(--bg-accent);
  color: var(--text-accent);
}

#save-settings-btn:hover {
  opacity: 0.9;
}

.settings-row button.danger {
  background: transparent;
  border: 1px solid #e04e4e;
  color: #e04e4e;
  padding: 7px 12px;
}

.settings-row button.danger:hover {
  background: #e04e4e;
  color: #ffffff;
}

.settings-row button.danger-outline {
  background: transparent;
  border: 1px solid rgba(224, 78, 78, 0.4);
  color: rgba(224, 78, 78, 0.85);
  padding: 7px 12px;
}

.settings-row button.danger-outline:hover {
  border-color: #e04e4e;
  color: #ffffff;
  background: rgba(224, 78, 78, 0.08);
}

.settings-section.danger-section {
  border-top: 1px solid rgba(224, 78, 78, 0.15);
}

.danger-section .settings-section-title {
  color: #ff6b6b;
}

.wrap {
  position: relative;
  line-height: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: #050508;
  box-shadow: 
    inset 0 0 16px rgba(0, 229, 255, 0.12),
    inset 0 0 30px rgba(0, 0, 0, 0.85);
}

/* Horizontal scanline laser sweep crawling down the screen */
.wrap::before {
  content: '';
  position: absolute;
  top: 0; left: 0; width: 100%; height: 3px;
  background: rgba(0, 229, 255, 0.15);
  box-shadow: 0 0 6px rgba(0, 229, 255, 0.3);
  animation: scanline-scroll 6s linear infinite;
  pointer-events: none;
  z-index: 5;
}

/* Diagonal glass glare, screen curvature vignette, and phosphor scanline grille */
.wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: 
    radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.45) 100%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.15) 0px, rgba(0, 0, 0, 0.15) 1px, transparent 1px, transparent 2px),
    repeating-linear-gradient(90deg, rgba(0, 229, 255, 0.02) 0px, rgba(0, 229, 255, 0.02) 1px, transparent 1px, transparent 3px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0) 50%, rgba(0, 229, 255, 0.03) 100%);
  pointer-events: none;
  border-radius: 12px;
  z-index: 6;
  animation: crt-glow 0.15s infinite alternate;
}

@keyframes crt-glow {
  0% { opacity: 0.985; }
  100% { opacity: 1; }
}

@keyframes scanline-scroll {
  0% { transform: translateY(-3px); }
  100% { transform: translateY(190px); }
}

#fc {
  cursor: crosshair;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#sl {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: block;
}

#eb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #00e5ff;
  padding: 6px 16px;
  border: 1px solid rgba(0, 229, 255, 0.4);
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(0, 229, 255, 0.12), rgba(255, 0, 128, 0.12));
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.2);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
}

#eb:hover {
  transform: translateY(-1px) scale(1.05);
  border-color: #00e5ff;
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.6), inset 0 0 12px rgba(0, 229, 255, 0.2);
}

#emospan {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
  transition: all 0.2s ease;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

#emospan:hover {
  color: #ffffff;
  text-shadow: 0 0 10px #00e5ff;
}

.edot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #00e5ff;
  flex-shrink: 0;
  box-shadow: 0 0 8px #00e5ff;
  animation: status-pulse 2s infinite ease-in-out;
  transition: background 0.5s;
}

@keyframes status-pulse {
  0% { box-shadow: 0 0 4px #00e5ff; transform: scale(0.95); }
  50% { box-shadow: 0 0 12px #00e5ff; transform: scale(1.05); }
  100% { box-shadow: 0 0 4px #00e5ff; transform: scale(0.95); }
}

#cp {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#msgs {
  height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 6px;
  scroll-behavior: smooth;
}

#chat-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  align-self: flex-end;
  margin-bottom: 8px;
  width: 100%;
}

#clear-chat-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0 10px;
  height: 30px;
  border-radius: 8px;
  font-size: 9px;
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

#clear-chat-btn:hover {
  background: rgba(0, 229, 255, 0.08);
  border-color: var(--bg-accent);
  color: var(--text-primary);
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.15);
}

#msgs::-webkit-scrollbar,
#db-logs::-webkit-scrollbar {
  width: 5px;
}

#msgs::-webkit-scrollbar-track,
#db-logs::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.01);
}

#msgs::-webkit-scrollbar-thumb,
#db-logs::-webkit-scrollbar-thumb {
  background: rgba(0, 229, 255, 0.15);
  border-radius: 4px;
}

#msgs::-webkit-scrollbar-thumb:hover,
#db-logs::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 229, 255, 0.4);
}

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

.um {
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 85%;
  align-self: flex-end;
  background: linear-gradient(135deg, #0088cc 0%, #00e5ff 100%);
  color: #030310;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 229, 255, 0.15);
  animation: slide-up 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.rm {
  padding: 10px 14px;
  border-radius: 16px 16px 16px 4px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 85%;
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: slide-up 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

#ir {
  display: flex;
  gap: 10px;
  align-items: center;
}

#qi {
  flex: 1;
  background: rgba(8, 8, 12, 0.6);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  transition: all 0.3s ease;
}

#qi:focus {
  outline: none;
  border-color: var(--bg-accent);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.15);
  background: rgba(8, 8, 12, 0.9);
}

#send-btn {
  background: var(--bg-accent);
  color: var(--text-accent);
  border: none;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 229, 255, 0.2);
}

#send-btn:hover {
  opacity: 0.95;
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.4);
  transform: translateY(-1px);
}

#stop-btn {
  background: rgba(255, 59, 48, 0.1);
  color: #ff6b6b;
  border: 1px solid rgba(255, 59, 48, 0.3);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(255, 59, 48, 0.05);
  box-sizing: border-box;
}

#stop-btn:hover:not(:disabled) {
  background: rgba(255, 59, 48, 0.2);
  border-color: rgba(255, 59, 48, 0.6);
  color: #ff8181;
  box-shadow: 0 0 12px rgba(255, 59, 48, 0.2);
  transform: scale(1.05);
}

#stop-btn:disabled {
  opacity: 0.25;
  pointer-events: none;
  cursor: default;
  background: rgba(255, 255, 255, 0.02);
  border-color: var(--border);
  color: var(--text-secondary);
}

#sg {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.sgb {
  font-size: 11px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 20px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sgb:hover {
  background: rgba(0, 229, 255, 0.06);
  border-color: var(--bg-accent);
  color: var(--text-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 229, 255, 0.15);
}

@keyframes tpls {
  0% { opacity: 0.3; }
  100% { opacity: 1; }
}

.tdots {
  display: inline-block;
  animation: tpls 0.65s infinite alternate;
  letter-spacing: 2px;
  margin-left: 8px;
}

@keyframes rcurb {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.rcur {
  display: inline-block;
  animation: rcurb 0.8s step-end infinite;
  color: var(--text-secondary);
  font-weight: 400;
}

#api-status-footer {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 20px;
  box-sizing: border-box;
  transition: all 0.3s ease;
}

#api-status-footer.api-status-active {
  color: #00ff66;
  border-color: rgba(0, 255, 102, 0.3);
  background: rgba(0, 255, 102, 0.06);
  box-shadow: 0 0 10px rgba(0, 255, 102, 0.1);
}

#api-status-footer.api-status-offline {
  color: var(--text-secondary);
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.02);
}

/* Delete All & Clear Chat Confirmation Modal Overlays */
#confirm-clear-panel,
#confirm-delete-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(5, 5, 8, 0.85);
  backdrop-filter: blur(12px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

#confirm-clear-panel.hidden,
#confirm-delete-panel.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

.confirm-clear-content,
.confirm-delete-content {
  background: rgba(20, 20, 30, 0.95);
  border: 1px solid rgba(255, 59, 48, 0.3);
  border-radius: 16px;
  width: 340px;
  max-width: 90%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255, 59, 48, 0.1);
}

.confirm-clear-content h3,
.confirm-delete-content h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  color: #ff3b30;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.confirm-clear-warning,
.confirm-delete-warning,
.confirm-delete-body {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

#confirm-delete-list {
  background: rgba(8, 8, 12, 0.6);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
}

.confirm-delete-item {
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
}

.confirm-delete-item .masked-key {
  color: #ff3b30;
}

.confirm-clear-actions,
.confirm-delete-actions {
  display: flex;
  gap: 10px;
}

.confirm-clear-actions button,
.confirm-delete-actions button {
  flex: 1;
  padding: 8px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  box-sizing: border-box;
}

#confirm-clear-proceed-btn,
#confirm-delete-proceed-btn {
  background: #ff3b30;
  color: #ffffff;
  font-weight: 600;
  border: none;
}

#confirm-clear-proceed-btn:hover,
#confirm-delete-proceed-btn:hover {
  background: #e0352b;
}

#confirm-clear-cancel-btn,
#confirm-delete-cancel-btn {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

#confirm-clear-cancel-btn:hover,
#confirm-delete-cancel-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

/* Debug Button Header Action */
#debug-btn {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-sizing: border-box;
}

#debug-btn:hover {
  background: rgba(0, 229, 255, 0.08);
  border-color: var(--bg-accent);
  color: var(--bg-accent);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.2);
}

/* Developer Debug Panel Sidebar */
#debug-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: calc(50vw - 320px);
  min-width: 280px;
  height: 100vh;
  box-sizing: border-box;
  background: rgba(18, 18, 28, 0.85);
  backdrop-filter: blur(16px);
  border-left: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  z-index: 900;
  overflow-y: auto;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.6);
  font-family: 'JetBrains Mono', monospace;
}

#debug-panel.hidden {
  display: none;
}

.debug-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  width: 100%;
}

#close-debug-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: all 0.2s;
  margin-right: -4px;
}

#close-debug-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

#debug-panel h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--bg-accent);
  font-family: 'Outfit', sans-serif;
}

.debug-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.debug-section.flex-grow {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.debug-section h4 {
  margin: 0 0 8px 0;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-family: 'Outfit', sans-serif;
}

.debug-logs-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  width: 100%;
}

.debug-logs-header h4 {
  margin: 0 !important;
}

#clear-logs-btn {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 9px;
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
}

#clear-logs-btn:hover {
  background: rgba(0, 229, 255, 0.08);
  border-color: var(--bg-accent);
  color: var(--bg-accent);
}

.debug-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 11px;
}

.debug-val {
  color: var(--bg-accent);
  font-weight: 600;
}

#db-flags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.debug-flag {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 9px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-secondary);
  opacity: 0.3;
  transition: all 0.2s ease;
  background: rgba(255, 255, 255, 0.01);
}

.debug-flag.active {
  opacity: 1;
  color: #030310;
  background: var(--bg-accent);
  border-color: var(--bg-accent);
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.3);
}

#db-logs {
  flex-grow: 1;
  overflow-y: auto;
  border: 1px solid var(--border);
  background: rgba(5, 5, 8, 0.6);
  padding: 10px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 180px;
}

.debug-log-entry {
  font-size: 10px;
  line-height: 1.4;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.04);
  padding-bottom: 6px;
  word-break: break-all;
  white-space: pre-wrap;
}

.debug-log-time {
  color: var(--text-secondary);
  margin-right: 6px;
}

.debug-log-msg {
  color: var(--text-primary);
}

/* Responsive Mobile Layout Adjustments */
@media (max-width: 680px) {
  body {
    padding: 10px;
    align-items: flex-start;
  }
  
  #rd {
    padding: 16px;
    margin: 0;
    width: 100%;
    border-radius: 12px;
  }
  
  #rd::before {
    border-top-left-radius: 12px;
  }
  
  #rd::after {
    border-bottom-right-radius: 12px;
  }
  
  #rt {
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }
  
  #fp {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 8px;
  }
  
  #cp {
    width: 100%;
  }
  
  #top-bar {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    flex-wrap: nowrap;
    gap: 6px;
  }
  
  #api-status-footer {
    padding: 6px 10px;
    font-size: 8.5px;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
  }
  
  #api-status-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90px;
  }
  
  #settings-btn span {
    display: none;
  }
  
  #settings-btn {
    padding: 6px;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    justify-content: center;
    box-sizing: border-box;
    flex-shrink: 0;
  }
  
  #debug-btn {
    padding: 6px 10px;
    font-size: 8.5px;
    flex-shrink: 0;
  }
  
  #debug-panel {
    width: 80vw;
    min-width: 260px;
    padding: 16px;
    gap: 16px;
    z-index: 3000;
  }
  
  #stop-btn {
    margin-bottom: 6px;
  }
  
  #msgs {
    height: 200px; /* Conserve vertical screen real estate on mobile devices */
  }
}

/* Screen Jitter Jolt/Glitch Vibration */
@keyframes glitch-shake {
  0% { transform: translate(0, 0) skew(0deg); }
  10% { transform: translate(-3px, 1px) skew(-1deg); }
  20% { transform: translate(2px, -1px) skew(1deg); }
  30% { transform: translate(-1px, 2px) skew(0deg); }
  40% { transform: translate(3px, -2px) skew(-2deg); }
  50% { transform: translate(-2px, 1px) skew(2deg); }
  60% { transform: translate(2px, 2px) skew(-1deg); }
  70% { transform: translate(-2px, -2px) skew(0deg); }
  80% { transform: translate(3px, 1px) skew(1deg); }
  90% { transform: translate(-3px, -1px) skew(-1deg); }
  100% { transform: translate(0, 0) skew(0deg); }
}

.monitor-glitch {
  animation: glitch-shake 0.15s infinite linear;
}

/* Glitch Confirmation Box - Neon Cyan Theme */
#glitch-confirm {
  margin-top: 10px;
  padding: 8px 12px;
  border: 1px solid #00e5ff;
  background: rgba(0, 229, 255, 0.04);
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.2), inset 0 0 10px rgba(0, 229, 255, 0.1);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-sizing: border-box;
  animation: fade-in 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

#glitch-confirm.hidden {
  display: none !important;
}

.glitch-confirm-text {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #00e5ff;
  text-shadow: 0 0 5px rgba(0, 229, 255, 0.4);
  font-weight: 600;
  text-align: center;
}

.glitch-confirm-buttons {
  display: flex;
  gap: 8px;
}

#glitch-yes, #glitch-no {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 14px;
  font-size: 9px;
  border-radius: 12px;
  cursor: pointer;
  text-transform: uppercase;
  font-weight: 600;
  transition: all 0.2s ease;
  box-sizing: border-box;
}

#glitch-yes {
  background: rgba(0, 229, 255, 0.08);
  border-color: #00e5ff;
  color: #00e5ff;
  text-shadow: 0 0 5px rgba(0, 229, 255, 0.5);
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.1);
}

#glitch-yes:hover {
  background: #00e5ff;
  color: #000;
  border-color: #00e5ff;
  text-shadow: none;
  box-shadow: 0 0 12px #00e5ff;
}

#glitch-no:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.25);
}

/* CRT Power Off Collapse Animation */
@keyframes crt-power-off {
  0% {
    transform: scale(1, 1);
    filter: brightness(1) contrast(1) saturate(1);
    opacity: 1;
  }
  30% {
    transform: scale(1, 0.015); /* Collapse vertically to a horizontal line */
    filter: brightness(3) contrast(1.5) saturate(0.5);
    opacity: 1;
  }
  65% {
    transform: scale(0.015, 0.015); /* Shrink line horizontally to a single dot */
    filter: brightness(8) contrast(2);
    opacity: 1;
  }
  100% {
    transform: scale(0.015, 0.015);
    filter: brightness(10);
    opacity: 0; /* Fade out dot */
  }
}

.crt-off {
  animation: crt-power-off 0.45s cubic-bezier(0.25, 1, 0.5, 1) forwards;
  pointer-events: none;
}

/* CRT Power On Flash/Expansion Animation */
@keyframes crt-power-on {
  0% {
    transform: scale(0.015, 0.015);
    filter: brightness(10);
    opacity: 0;
  }
  30% {
    transform: scale(1, 0.015);
    filter: brightness(4) contrast(1.5);
    opacity: 1;
  }
  70% {
    transform: scale(1, 1);
    filter: brightness(1.5) contrast(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(1, 1);
    filter: brightness(1) contrast(1);
    opacity: 1;
  }
}

.crt-on {
  animation: crt-power-on 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
