:root {
  --chatbox-bg-opacity: 0.9;
  --message-bg-opacity: 0.3;
  --primary-accent: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.5);
  --secondary-accent: #a855f7;
  --bg-dark: #0f172a;
  --glass-bg: rgba(15, 23, 42, 0.75);
  --glass-border: rgba(255, 255, 255, 0.1);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg-dark);
  font-family: var(--font-sans);
  color: var(--text-main);
}

.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-size: cover;
  background-position: center center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  opacity: var(--bg-image-opacity, 1);
  transition: opacity 0.3s ease;
  pointer-events: none;
}

canvas {
  position: fixed;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.chat-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 45%;
  max-width: 550px;
  min-width: 320px;
  min-height: 300px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px) saturate(180%);
  border-radius: 16px;
  padding: 0;
  color: var(--text-main);
  z-index: 9999;
  resize: both;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  cursor: default;
  touch-action: none;
  display: flex;
  flex-direction: column;
}

.chat-container:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.chat-container.dragging {
  user-select: none;
  cursor: grabbing;
}

.chat-container::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-top-color: transparent;
  border-left-color: transparent;
  background: radial-gradient(circle at 0 0, rgba(255, 255, 255, 0.35) 0, rgba(255, 255, 255, 0) 60%);
  opacity: 0.7;
  pointer-events: none;
}

.chat-container:hover::after {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.45);
  border-top-color: transparent;
  border-left-color: transparent;
}

.chat-container.offline-mode {
  box-shadow: 0 0 20px rgba(255, 105, 180, 0.5);
  border-color: rgba(255, 105, 180, 0.4);
  animation: pulse-glow 3s infinite ease-in-out;
  transition: box-shadow 0.5s ease-in-out, border-color 0.5s ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 15px rgba(255, 105, 180, 0.4); border-color: rgba(255, 105, 180, 0.3); }
  50% { box-shadow: 0 0 30px rgba(255, 105, 180, 0.7); border-color: rgba(255, 105, 180, 0.6); }
}

#chat-status-indicator {
  font-size: 10px;
  margin-left: 8px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(0, 255, 0, 0.2);
  color: #00ff00;
  display: none;
}

.offline-mode #chat-status-indicator {
  display: inline-block;
  background: rgba(255, 105, 180, 0.2);
  color: #ff69b4;
}

/* Chat Sidebar */
.chat-sidebar {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 300px;
  max-height: 500px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px) saturate(180%);
  border-radius: 16px;
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  transform: translateX(-20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.chat-sidebar.visible {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--glass-border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.chat-sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-sidebar-close,
.chat-sidebar-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1;
}

.chat-sidebar-close:hover,
.chat-sidebar-action-btn:hover {
  background: rgba(255,255,255,0.1);
}

.chat-sidebar-action-btn:hover {
  color: #ff69b4;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  max-height: 400px;
}

.chat-list-empty {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 20px;
}

.chat-list-item {
  display: flex;
  align-items: center;
  border-radius: 10px;
  margin-bottom: 4px;
}

.chat-list-item:hover {
  background: rgba(255,255,255,0.06);
}

.chat-list-item.active {
  background: rgba(255, 105, 180, 0.12);
  border: 1px solid rgba(255, 105, 180, 0.2);
}

.chat-list-item-content {
  flex: 1;
  padding: 10px 12px;
  cursor: pointer;
  min-width: 0;
}

.chat-list-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-list-item-meta {
  display: flex;
  gap: 8px;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.chat-list-item-preview {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-list-item-actions {
  display: flex;
  gap: 2px;
  padding-right: 8px;
  opacity: 0;
  transition: opacity 0.15s;
}

.chat-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1;
}

.chat-action-btn:hover {
  background: rgba(255,255,255,0.1);
}

.chat-action-delete:hover {
  background: rgba(255, 0, 0, 0.2);
}

.chat-list-item:hover .chat-list-item-actions {
  opacity: 1;
}

.chat-sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 16px;
  line-height: 1;
}

.chat-sidebar-toggle:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-main);
}

.new-chat-btn {
  background: none;
  border: none;
  color: #ff69b4;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  margin-left: auto;
}

.new-chat-btn:hover {
  background: rgba(255, 105, 180, 0.15);
}

.regenerate-title-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1;
}

.regenerate-title-btn:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-main);
}

#chatTitle {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header {
  height: 40px;
  background: rgba(255, 255, 255, 0.03);
  cursor: grab;
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
  user-select: none;
  gap: 8px;
}

.chat-header span:first-child {
  display: flex;
  align-items: center;
  gap: 8px;
}

.go-online-btn {
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 10px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.05);
  color: #ff69b4;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.go-online-btn:hover {
  background: rgba(255,255,255,0.15);
}

.offline-mode .go-online-btn {
  display: inline-flex;
}

.chat-header:active {
  cursor: grabbing;
}

.chat-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px;
}

.chat-history {
  overflow-y: auto;
  margin-bottom: 10px;
  padding: 10px;
  flex: 1;
  min-height: 100px;
}

.message {
  margin: 12px 0;
  padding: 10px 14px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  position: relative;
  max-width: 85%;
  animation: message-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  line-height: 1.5;
  font-size: 14px;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.message-actions {
  position: absolute;
  bottom: -15px;
  right: 4px;
  display: none;
  gap: 4px;
  background: rgba(30, 30, 30, 0.8);
  padding: 4px;
  border-radius: 6px;
  z-index: 10;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.message:hover .message-actions {
  display: flex;
}

.message-action-btn {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: none;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.message-action-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.message-action-btn.delete-msg:hover {
  background: rgba(255, 68, 68, 0.6);
}

.message-action-btn.tts-play:hover {
  background: rgba(0, 123, 255, 0.6);
}

/* On user messages, align actions to the left if preferred, 
   but user asked for "bottom right of each chat message box" */
.user-message .message-actions {
  right: 4px;
}

.user-message {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.4), rgba(168, 85, 247, 0.4));
  align-self: flex-end;
  border-bottom-right-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
}

.model-message {
  background: rgba(255, 255, 255, 0.08);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: #f1f5f9;
}

.message-original-text {
  font-weight: normal;
}

.sentence-chunk {
  transition: background-color 0.3s ease, color 0.3s ease;
  padding: 0 2px;
  border-radius: 2px;
}

.sentence-highlight {
  background-color: rgba(255, 255, 0, 0.2);
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

.retry-tts-btn {
  background: rgba(255, 165, 0, 0.3);
  border: 1px solid rgba(255, 165, 0, 0.5);
  color: #ffcc00;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
  width: fit-content;
}

.retry-tts-btn:hover {
  background: rgba(255, 165, 0, 0.5);
}

.message-transliteration-text {
  font-style: italic;
  font-size: 0.9em;
  color: #ccc;
  margin-top: 3px;
}

.message-translation-text {
  font-size: 0.9em;
  color: #b0e0e6;
  margin-top: 3px;
  padding-left: 10px;
  border-left: 2px solid #b0e0e6;
}

/* Streaming message styles */
.streaming-message {
  opacity: 0.9;
}

.streaming-message .message-original-text {
  font-style: italic;
}

.streaming-message .message-actions button {
  cursor: default;
}

/* Cursor animation for streaming text */
.streaming-text::after {
  content: '▋';
  animation: blink 1s infinite;
  color: #888;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.summary-cutoff-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 25px 0;
  position: relative;
  opacity: 0.7;
  pointer-events: none;
  user-select: none;
}

.summary-cutoff-marker::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  z-index: 1;
}

.summary-cutoff-marker span {
  background: #2d2d2d;
  padding: 4px 12px;
  font-size: 10px;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 2;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.chat-input {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex-shrink: 0;
}

.chat-input input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
  color: white;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input input:focus {
  border-color: var(--primary-accent);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.chat-input button {
  padding: 0 20px;
  border: none;
  border-radius: 12px;
  background: var(--primary-accent);
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.1s, filter 0.2s;
}

.chat-input button:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.chat-input button:active {
  transform: translateY(0);
}

#resetChatBtn {
  background-color: #dc3545;
}

#resetChatBtn:hover {
  background-color: #c82333;
}

.chat-input button:hover {
  background: #0056b3;
}

.chat-input-status-bar {
  display: none;
  background: rgba(99, 102, 241, 0.15);
  padding: 8px 12px;
  border-radius: 12px 12px 0 0;
  font-size: 0.8em;
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}

.chat-input-status-bar .queue-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-input-status-bar #queueLengthText {
  font-weight: bold;
  color: var(--primary-accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.queued-messages-list {
  max-height: 100px;
  overflow-y: auto;
  font-size: 0.85em;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.queue-item {
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 10px;
  border-radius: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.clear-queue-chat-btn {
  background: rgba(244, 63, 94, 0.15);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.2);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75em;
  cursor: pointer;
  width: fit-content;
  align-self: flex-end;
  transition: all 0.2s;
}

.clear-queue-chat-btn:hover {
  background: rgba(244, 63, 94, 0.3);
  transform: translateY(-1px);
}

.typing-indicator {
  font-style: italic;
  color: #aaa;
  margin-top: 5px;
  display: none;
}

.mic-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: none;
  border-radius: 5px;
  background: #333;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
  z-index: 1;
}

.mic-button:hover { background: #444; }
.mic-button.active { background: #c62828; }

.mic-button svg { pointer-events: none; }

.settings-button {
  position: fixed;
  top: 24px;
  right: 24px;
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  color: white;
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  cursor: pointer;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.settings-button:hover {
  background: var(--primary-accent);
  transform: rotate(45deg);
  box-shadow: 0 0 15px var(--primary-glow);
  border-color: rgba(255, 255, 255, 0.3);
}

.settings-button:hover {
  background: rgba(60, 60, 60, 0.9);
}

.settings-panel {
  position: fixed;
  top: 80px;
  right: 24px;
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(160%);
  border-radius: 20px;
  padding: 24px;
  color: var(--text-main);
  z-index: 10000;
  width: 340px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  display: none;
  scroll-behavior: smooth;
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.settings-search-container {
  position: sticky;
  top: -20px;
  margin: -20px -20px 15px -20px;
  padding: 15px 20px;
  background: rgba(45, 45, 45, 0.98);
  backdrop-filter: blur(5px);
  z-index: 10;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
}

.settings-search-input {
  width: 100%;
  padding: 10px 35px 10px 12px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: white;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.settings-search-input:focus {
  border-color: #007bff;
  background: rgba(0, 0, 0, 0.5);
}

.settings-search-container .search-icon {
  position: absolute;
  right: 32px;
  color: #888;
  pointer-events: none;
}

.settings-panel.visible {
  display: block;
}

.settings-main-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-category-label {
  margin-top: 10px;
  margin-bottom: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 4px 2px;
  opacity: 0.9;
}

.settings-menu-item {
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 2px;
}

/* Make touching settings items share flat borders so they read as sections */
.settings-menu-item:not(:first-child) {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.settings-menu-item:not(:last-child) {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.settings-menu-item:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateX(4px);
}

.settings-menu-item:active {
  transform: scale(0.98);
}

.settings-menu-item .icon {
  margin-right: 12px;
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.settings-menu-item .chevron {
  margin-left: auto;
  color: #888;
  font-size: 18px;
}

/* Flattened Search View */
.settings-panel.searching .settings-main-menu {
  display: none !important;
}

.settings-panel.searching .settings-submenu {
  display: block !important;
  padding: 0;
  border-bottom: none;
}

.settings-panel.searching .submenu-header {
  display: none !important;
}

.settings-panel.searching .settings-item {
  display: none !important;
}

.settings-panel.searching .settings-item.search-match {
  display: block !important;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.settings-panel.searching .settings-submenu::before {
  content: attr(data-category-name);
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  color: #007bff;
  letter-spacing: 1px;
  margin: 15px 0 5px 0;
  padding-left: 4px;
}

/* Only show category heading if it contains a match */
.settings-panel.searching .settings-submenu:not(:has(.search-match)) {
  display: none !important;
}

.no-results {
  text-align: center;
  padding: 40px 20px;
  color: #888;
  font-style: italic;
}

.settings-submenu {
  display: none;
}

.settings-submenu.active {
  display: block;
}

.submenu-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.submenu-header h3 {
  margin: 0;
  font-size: 16px;
  color: #eee;
}

.back-button {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  transition: background 0.2s;
}

.back-button:hover {
  background: rgba(255, 255, 255, 0.2);
}

.settings-item {
  margin-bottom: 15px;
}

/* Links section inside settings */
.links-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.link-item {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
  font-size: 13px;
}

.link-item:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateX(2px);
}

.link-icon {
  width: 22px;
  text-align: center;
  margin-right: 8px;
  font-size: 16px;
}

.link-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-item label {
  display: block;
  margin-bottom: 5px;
}

.settings-item input[type="range"] {
  width: 100%;
}

.settings-item input[type="checkbox"] {
  margin-right: 10px;
  vertical-align: middle;
}

.settings-item .settings-select,
.settings-item .settings-textarea {
  width: 100%;
  padding: 8px;
  background-color: #333;
  color: white;
  border: 1px solid #555;
  border-radius: 4px;
  box-sizing: border-box;
  font-family: inherit;
}

.settings-item .settings-textarea {
  height: 120px;
  resize: vertical;
  margin-bottom: 8px;
}

.value-display {
  font-size: 14px;
  color: #aaa;
  margin-top: 5px;
}

.nowtime {
  position: absolute;
  top: 15px;
  left: 15px;
  background: rgba(0, 0, 0, 0.7);
  padding: 15px 25px;
  border-radius: 20px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 9998;
  transform: translateZ(0);
  transition: all 0.3s ease;
  display: none;
}

.nowtime.visible {
  display: block;
}

.nowtime:hover {
  background: rgba(0, 0, 0, 0.8);
  transform: translateY(-2px) translateZ(0);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}

#time {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Inter', sans-serif;
  font-size: 48px;
  font-weight: 700;
  color: white;
  letter-spacing: 2px;
  margin: 0;
  line-height: 1;
}

#colon {
  animation: blink 1s infinite;
  opacity: 1;
  margin: 0 5px;
}

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

.debug-panel {
  position: fixed;
  top: 80px;
  left: 24px;
  width: 380px;
  height: 380px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(12px);
  color: #4ade80;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  border-radius: 16px;
  z-index: 9999;
  display: none;
  resize: both;
  border: 1px solid rgba(74, 222, 128, 0.2);
  overflow: hidden;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.debug-header {
  height: 30px;
  flex-shrink: 0;
  background: rgba(40, 40, 40, 0.9);
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 0 12px;
  font-size: 11px;
  color: #00ff00;
  border-bottom: 1px solid rgba(0, 255, 0, 0.2);
  user-select: none;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.debug-header:active {
  cursor: grabbing;
}

.debug-header-title {
  flex: 1;
}

.debug-header-buttons {
  display: flex;
  gap: 4px;
}

.debug-header-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #ccc;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  padding: 0;
}

.debug-header-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.debug-close-btn:hover {
  background: rgba(255, 80, 80, 0.5);
  color: #fff;
}

.debug-content {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.debug-panel.visible {
  display: flex;
}



.debug-log {
  margin: 5px 0;
  font-size: 12px;
  white-space: pre-wrap;
}

.debug-log.error {
  color: #ff4444;
}

.debug-log.warn {
  color: #ffbb33;
}

.debug-log.info {
  color: #33b5e5;
}

/* Navigation controls now live inside the Settings panel */
.navigation-controls {
  display: none; /* hidden until the checkbox enables it */
  grid-template-areas:
    ". up ."
    "left zoom-in right"
    "left zoom-out right"
    ". down .";
  gap: 6px;
}

.navigation-controls.visible {
  display: grid;
}

.navigation-controls button {
  background: rgba(45, 45, 45, 0.8);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  width: 40px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Keep grid areas so UIManager/app_init logic remains intact */
#zoomInBtn { grid-area: zoom-in; }
#zoomOutBtn { grid-area: zoom-out; }
#moveUpBtn { grid-area: up; }
#moveDownBtn { grid-area: down; }
#moveLeftBtn { grid-area: left; }
#moveRightBtn { grid-area: right; }

/* Model selector styles for settings panel */
.settings-panel .model-selector-selected {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.3s;
  display: flex;
  align-items: center;
}

.settings-panel .model-selector-selected:hover {
  background: rgba(255, 255, 255, 0.2);
}

.settings-panel .model-selector-selected-img {
  width: 24px;
  height: 24px;
  object-fit: cover;
  border-radius: 50%;
  margin-right: 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.settings-panel .model-selector-selected-name {
  flex-grow: 1;
  color: #eee;
  font-size: 14px;
}

.settings-panel .model-selector-arrow {
  margin-left: 8px;
  color: #ccc;
  transition: transform 0.3s;
  font-size: 12px;
}

.settings-panel .model-selector-selected.open .model-selector-arrow {
  transform: rotate(180deg);
}

.settings-panel .model-selector-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  background: rgba(55, 55, 55, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  max-height: 150px;
  overflow-y: auto;
  z-index: 10001;
  display: none;
  list-style: none;
  padding: 0;
  margin: 2px 0 0 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.settings-panel .model-selector-dropdown li {
  display: flex;
  align-items: center;
  padding: 8px;
  cursor: pointer;
  transition: background 0.2s;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-panel .model-selector-dropdown li:last-child {
  border-bottom: none;
}

.settings-panel .model-selector-dropdown li:hover {
  background: rgba(255, 255, 255, 0.15);
}

.settings-panel .model-selector-option-img {
  width: 24px;
  height: 24px;
  object-fit: cover;
  border-radius: 50%;
  margin-right: 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.settings-panel .model-selector-dropdown li span {
  color: #eee;
  font-size: 14px;
}

.button-row {
  display: flex;
  gap: 10px;
}

.button-row button {
  flex: 1;
}

.reset-button {
  background-color: #6c757d !important;
}

.reset-button:hover {
  background-color: #5a6268 !important;
}

/* Hide the old separate containers */
.radio-container,
.model-selector-container,
.language-display-settings-container {
  display: none !important;
}

.radio-controls-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.05);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.radio-controls-inline .radio-toggle-button {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.radio-controls-inline .radio-icon {
  width: 18px;
  height: 18px;
}

.volume-control-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-grow: 1;
}

.volume-control-inline .volume-icon {
  width: 16px;
  height: 16px;
  color: #ccc;
  flex-shrink: 0;
}

.volume-control-inline #radioVolumeSlider {
  flex-grow: 1;
  height: 6px;
  min-width: 80px;
}

.volume-icon {
  width: 20px;
  height: 20px;
  color: #ccc;
}

#radioVolumeSlider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  opacity: 0.9;
  transition: opacity .2s;
  border-radius: 4px;
  cursor: pointer;
}

#radioVolumeSlider:hover {
  opacity: 1;
}

#radioVolumeSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: #007bff;
  border-radius: 50%;
  cursor: pointer;
  margin-top: -5px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#radioVolumeSlider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #007bff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#radioVolumeSlider::-ms-thumb {
  width: 18px;
  height: 18px;
  background: #007bff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.hidden {
  display: none;
}

.tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  z-index: 10002;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.tutorial-overlay.visible {
  display: flex;
}

.tutorial-modal {
  background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
  color: #fff;
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  padding: 0;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.tutorial-modal h3 {
  margin: 0;
  padding: 24px;
  font-size: 22px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
}

.tutorial-controls {
  display: flex;
  padding: 16px 24px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  justify-content: flex-end;
}

.tutorial-controls button {
  background: #007bff;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.tutorial-controls button:hover {
  background: #0056b3;
  transform: translateY(-1px);
}

.tutorial-controls #tutorialPrevBtn,
.tutorial-controls #tutorialNextBtn {
  display: none;
}

#tutorialBody {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  line-height: 1.7;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}

::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

#tutorialBody h4 {
  margin: 24px 0 12px 0;
  font-size: 18px;
  color: #4da3ff;
  border-bottom: 1px solid rgba(77, 163, 255, 0.2);
  padding-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#tutorialBody h4:first-child {
  margin-top: 0;
}



.settings-tutorial-content {
  padding: 0;
  color: #eee;
}

.tutorial-step-card {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: all 0.2s ease;
}

.tutorial-step-card:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
}

.tutorial-step-card h4, 
.settings-tutorial-content h4 {
  margin: 0 0 8px 0;
  font-size: 15px;
  color: #4da3ff;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.settings-tutorial-content h4:first-child {
  margin-top: 0;
}

.settings-tutorial-content p {
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
  color: #bbb;
}

.tutorial-details-section {
  margin-top: 24px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.tutorial-details-section h4 {
  font-size: 14px;
  color: #88c0ff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 16px 0 8px 0;
}

.tutorial-details-section h4:first-child {
  margin-top: 0;
}

.tutorial-details-section p {
  font-size: 12px;
  color: #999;
  margin-bottom: 12px;
}

#bgLibrary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}

#bgLibrary img {
  width: 100%; height: 64px; object-fit: cover; border-radius: 6px; cursor: pointer; border: 1px solid rgba(255,255,255,0.15);
}

#bgLibrary img.selected { outline: 3px solid #007bff; outline-offset: 0; }

/* Fullscreen viewer */
.bg-viewer-overlay{position:fixed;inset:0;background:rgba(0,0,0,0.9);display:none;z-index:10003;align-items:center;justify-content:center}
.bg-viewer-overlay.visible{display:flex}
.bg-viewer-overlay img{max-width:92vw;max-height:92vh;border-radius:8px;box-shadow:0 10px 40px rgba(0,0,0,0.6)}
.bg-viewer-close{position:absolute;top:16px;right:20px;background:#333;color:#fff;border:none;border-radius:6px;padding:6px 10px;cursor:pointer}
.bg-viewer-nav{position:absolute;top:50%;transform:translateY(-50%);background:#333;color:#fff;border:none;border-radius:6px;padding:10px 14px;cursor:pointer}
.bg-viewer-nav.prev{left:20px}
.bg-viewer-nav.next{right:20px}
.bg-viewer-counter{position:absolute;bottom:16px;left:50%;transform:translateX(-50%);color:#ddd;font-size:12px;background:rgba(255,255,255,0.08);padding:4px 8px;border-radius:6px}



#customModelInfo .custom-model-info{display:flex;gap:10px;align-items:center;background:rgba(255,255,255,0.05);padding:8px;border-radius:8px;border:1px solid rgba(255,255,255,0.1)}
#customModelInfo img{width:40px;height:40px;object-fit:cover;border-radius:6px;border:1px solid rgba(255,255,255,0.2)}
#customModelInfo .meta{flex:1;min-width:0}
#customModelInfo .meta .name{color:#eee;font-size:14px;font-weight:600}
#customModelInfo .meta .url{color:#9ecbff;font-size:12px;word-break:break-all}
#customModelInfo .remove-btn{background:#dc3545;border:none;color:#fff;border-radius:6px;padding:6px 10px;cursor:pointer}
#customModelInfo .remove-btn:hover{background:#c82333}

.bg-fit-group { display:flex; flex-wrap: wrap; gap:6px }
.bg-fit-group button{background:#333;color:#fff;border:1px solid #555;border-radius:6px;padding:6px 10px;cursor:pointer}
.bg-fit-group button.active{background:#007bff;border-color:#007bff}

.model-gallery-overlay{position:fixed;inset:0;background:rgba(0,0,0,0.9);display:none;z-index:10020;overflow:auto}
.model-gallery-overlay.visible{display:block}
.model-gallery-close{position:fixed;top:16px;right:20px;background:#333;color:#fff;border:none;border-radius:6px;padding:6px 10px;cursor:pointer}
.model-gallery-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:16px;padding:80px 24px 24px}
.model-card {
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.model-card:hover {
  transform: translateY(-8px);
  border-color: var(--primary-accent);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
  background: rgba(255, 255, 255, 0.06);
}
.model-card:hover{transform:translateY(-2px);border-color:rgba(255,255,255,0.25)}
.model-thumb{width:100%;height:220px;object-fit:cover;background:#000}
.model-name{padding:10px 12px;color:#eee;font-size:14px;text-align:center}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
  .chat-container {
    width: calc(100% - 20px) !important;
    left: 10px !important;
    bottom: 10px !important;
    transform: none !important; /* Force reset layout to mobile default */
    max-width: none;
    min-width: 0;
    height: 40vh;
    padding: 10px;
    padding-top: 25px;
    box-sizing: border-box;
  }

  .chat-header {
    height: 24px;
    font-size: 10px;
    gap: 4px;
  }

  .chat-sidebar {
    width: calc(100% - 20px);
    left: 10px;
    bottom: 10px;
  }

  .chat-list-item-actions {
    opacity: 1;
  }

  .chat-content {
    margin-top: 20px;
    height: calc(100% - 20px);
  }

  .chat-history {
    padding: 5px;
  }

  .message {
    margin: 10px 0;
    font-size: 14px;
    padding-bottom: 24px; /* Ensure space for overlapping action buttons */
  }

  .user-message {
    margin-left: 5%;
  }

  .model-message {
    margin-right: 5%;
  }

  .message-actions {
    display: flex; /* Always show on mobile since there is no hover */
    bottom: -10px;
    opacity: 1;
    transform: scale(0.85);
    right: 0px;
    padding: 2px;
  }

  .settings-panel {
    width: calc(100% - 20px) !important;
    right: 10px !important;
    left: 10px !important;
    top: 65px !important;
    transform: none !important;
    max-height: calc(100vh - 80px);
    box-sizing: border-box;
    padding: 15px;
  }

  .settings-item .settings-select, 
  .settings-item .settings-textarea {
    font-size: 16px; /* Prevent iOS zoom on focus */
  }

  .debug-panel {
    width: calc(100% - 20px) !important;
    left: 10px !important;
    top: 65px !important;
    transform: none !important;
    height: 50vh;
  }

  .nowtime {
    padding: 6px 10px;
    top: 8px;
    left: 8px;
    border-radius: 12px;
  }

  #time {
    font-size: 24px;
  }

  .settings-button {
    top: 8px;
    right: 8px;
    width: 44px;
    height: 44px;
  }

  .mic-button, .chat-input button {
    padding: 8px 10px;
    font-size: 13px;
  }

  .radio-controls-inline {
    flex-direction: column;
    align-items: stretch;
  }

  .volume-control-inline {
    width: 100%;
    margin-top: 8px;
  }

  .bg-fit-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
  }

  .bg-fit-group button {
    padding: 6px 4px;
    font-size: 11px;
    text-align: center;
  }

  #bgLibrary {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Landscape Mobile Tweaks */
@media (max-width: 900px) and (orientation: landscape) {
  .chat-container {
    width: 40%;
    height: 60vh;
  }
  
  .settings-panel {
    width: 300px;
  }
}