/* Modern theme variables */
:root {
  --bg-app: #f8fafc;
  --bg-panel: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-glow: rgba(59, 130, 246, 0.15);
  --editor-bg: #ffffff;
  --editor-text: #0f172a;
  --caret-color: #3b82f6;
  --line-num-bg: #f8fafc;
  --line-num-text: #94a3b8;
  --line-num-border: #e2e8f0;
  
  /* Syntax Highlighting */
  --token-comment: #94a3b8;
  --token-punctuation: #64748b;
  --token-tag: #ec4899;
  --token-attr-name: #d97706;
  --token-attr-value: #059669;
  --token-string: #059669;
  --token-script: #7c3aed;
  --token-style: #2563eb;
}

.dark {
  --bg-app: #070a13;
  --bg-panel: #0f172a;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: #1e293b;
  --border-glow: rgba(96, 165, 250, 0.15);
  --editor-bg: #0f172a;
  --editor-text: #f1f5f9;
  --caret-color: #60a5fa;
  --line-num-bg: #070a13;
  --line-num-text: #475569;
  --line-num-border: #1e293b;

  /* Syntax Highlighting (Dark Theme) */
  --token-comment: #6b7280;
  --token-punctuation: #94a3b8;
  --token-tag: #f472b6;
  --token-attr-name: #fbbf24;
  --token-attr-value: #34d399;
  --token-string: #34d399;
  --token-script: #c084fc;
  --token-style: #60a5fa;
}

/* Base Styles */
body {
  font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  transition: background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1), color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

header, main, div, button, iframe, textarea {
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

/* Standardized Spac2 Brand Header */
.btn-back {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.04);
  border: 1.5px solid rgba(0, 0, 0, 0.22);
  color: #1f2937;
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  flex-shrink: 0;
  font-size: 18px;
}

.dark .btn-back {
  background: rgba(255, 255, 255, 0.07);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  color: #f4f4f5;
}

.btn-back:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #000000;
  transform: translateX(-2px);
  border-color: rgba(0, 0, 0, 0.45);
}

.dark .btn-back:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.42);
}

.btn-back:active {
  transform: scale(0.92);
  background: rgba(0, 0, 0, 0.12);
  border-color: rgba(0, 0, 0, 0.55);
  opacity: 0.85;
}

.dark .btn-back:active {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.6);
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  transition: opacity 0.15s ease;
  flex-shrink: 0;
}

.brand-link:hover {
  opacity: 0.92;
}

.brand-logo-card {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
  padding: 3.5px;
  box-sizing: border-box;
  transition: transform 0.2s ease;
}

.dark .brand-logo-card {
  background: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.brand-link:hover .brand-logo-card {
  transform: scale(1.04);
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
  display: block;
}

.brand-text {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  line-height: 1;
  white-space: nowrap;
}

.brand-name {
  font-weight: 800;
  font-size: 19px;
  color: #111827;
  letter-spacing: -0.025em;
  line-height: 1;
}

.dark .brand-name {
  color: #ffffff;
}

.brand-divider {
  font-size: 14px;
  font-weight: 300;
  color: #9ca3af;
  opacity: 0.7;
  user-select: none;
}

.dark .brand-divider {
  color: #52525b;
  opacity: 0.85;
}

.brand-app {
  font-size: 14px;
  font-weight: 600;
  color: #4b5563;
  letter-spacing: -0.01em;
  line-height: 1;
}

.dark .brand-app {
  color: #a1a1aa;
}

@media (max-width: 640px) {
  .btn-back {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 16px;
  }
  .brand-logo-card {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    padding: 3px;
  }
  .brand-name {
    font-size: 17px;
  }
  .brand-app {
    font-size: 13px;
  }
}

/* CodeMirror VS Code Style Editor */
.CodeMirror {
  font-family: 'Roboto Mono', 'Fira Code', Consolas, 'Courier New', monospace !important;
  font-size: 13.5px !important;
  line-height: 1.65 !important;
  height: 100% !important;
  width: 100% !important;
  background-color: var(--editor-bg) !important;
  color: var(--editor-text) !important;
  border: none !important;
}

/* VS Code Gutter & Line Numbers */
.CodeMirror-gutters {
  background-color: var(--line-num-bg) !important;
  border-right: 1px solid var(--line-num-border) !important;
  padding-right: 2px !important;
  width: auto !important;
}

.CodeMirror-linenumber {
  color: var(--line-num-text) !important;
  padding: 0 10px 0 8px !important;
  font-size: 12.5px !important;
  font-family: 'Roboto Mono', Consolas, monospace !important;
  text-align: right !important;
  opacity: 0.65;
  transition: color 0.15s ease, opacity 0.15s ease;
}

/* Active Line Number Highlight (VS Code Style) */
.CodeMirror-activeline .CodeMirror-linenumber {
  color: var(--text-main) !important;
  opacity: 1 !important;
  font-weight: 700 !important;
}

/* VS Code Active Line Border / Background */
.CodeMirror-activeline-background {
  background-color: rgba(0, 0, 0, 0.02) !important;
  border-top: 1px solid rgba(0, 0, 0, 0.04);
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.dark .CodeMirror-activeline-background {
  background-color: rgba(255, 255, 255, 0.025) !important;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* VS Code Code Folding Gutter Icons */
.CodeMirror-foldgutter {
  width: 16px;
  cursor: pointer;
}

.CodeMirror-foldgutter-open,
.CodeMirror-foldgutter-folded {
  font-size: 11px;
  text-align: center;
  line-height: 1.65;
}

.CodeMirror-foldgutter-open:after {
  content: "▾";
  color: var(--line-num-text);
  opacity: 0.5;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.CodeMirror-foldgutter:hover .CodeMirror-foldgutter-open:after {
  opacity: 1;
  color: var(--text-main);
}

.CodeMirror-foldgutter-folded:after {
  content: "▸";
  color: #3b82f6;
  font-weight: bold;
}

.CodeMirror-foldmarker {
  background-color: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  border-radius: 4px;
  padding: 0 5px;
  margin: 0 3px;
  font-family: sans-serif;
  font-size: 11px;
  font-weight: bold;
  border: 1px solid rgba(59, 130, 246, 0.3);
  cursor: pointer;
}

/* Cursor & Selection */
.CodeMirror-cursor {
  border-left: 2px solid var(--caret-color) !important;
}

.CodeMirror-selected {
  background-color: rgba(59, 130, 246, 0.22) !important;
}

.CodeMirror-focused .CodeMirror-selected {
  background-color: rgba(59, 130, 246, 0.28) !important;
}

.CodeMirror-matchingbracket {
  color: #3b82f6 !important;
  font-weight: 700 !important;
  background-color: rgba(59, 130, 246, 0.15) !important;
  border-radius: 2px;
  outline: 1px solid rgba(59, 130, 246, 0.4);
}

.CodeMirror-placeholder {
  color: #94a3b8 !important;
  font-style: italic !important;
  opacity: 0.7 !important;
}

.dark .CodeMirror-placeholder {
  color: #64748b !important;
}

/* VS Code Standard Syntax Tokens */
.cm-tag { color: #f43f5e !important; font-weight: 600 !important; }
.dark .cm-tag { color: #f472b6 !important; font-weight: 600 !important; }
.cm-attribute { color: #d97706 !important; }
.dark .cm-attribute { color: #fbbf24 !important; }
.cm-string { color: #059669 !important; }
.dark .cm-string { color: #34d399 !important; }
.cm-string-2 { color: #059669 !important; }
.dark .cm-string-2 { color: #34d399 !important; }
.cm-comment { color: #6b7280 !important; font-style: italic !important; }
.dark .cm-comment { color: #64748b !important; font-style: italic !important; }
.cm-bracket { color: #94a3b8 !important; }
.cm-qualifier { color: #8b5cf6 !important; }
.cm-property { color: #0284c7 !important; }
.dark .cm-property { color: #38bdf8 !important; }
.cm-keyword { color: #8b5cf6 !important; font-weight: 600 !important; }
.dark .cm-keyword { color: #c084fc !important; font-weight: 600 !important; }
.cm-atom { color: #6366f1 !important; }
.cm-number { color: #f59e0b !important; }
.cm-def { color: #06b6d4 !important; }
.cm-variable { color: var(--editor-text) !important; }
.cm-variable-2 { color: #3b82f6 !important; }

/* CodeMirror Autocomplete / Show Hint Popup with Rich Search */
.CodeMirror-hints {
  position: absolute !important;
  z-index: 1000 !important;
  background: var(--bg-panel) !important;
  border: 1px solid var(--border) !important;
  border-radius: 14px !important;
  padding: 6px !important;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.2), 0 8px 16px -4px rgba(0, 0, 0, 0.1) !important;
  font-family: 'Roboto Mono', monospace !important;
  font-size: 12.5px !important;
  max-height: 280px !important;
  min-width: 280px !important;
  max-width: 420px !important;
  backdrop-filter: blur(16px) !important;
  overflow-y: auto !important;
}

.CodeMirror-hint {
  padding: 7px 10px !important;
  border-radius: 9px !important;
  color: var(--text-main) !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 10px !important;
  transition: all 0.12s ease !important;
  margin-bottom: 2px !important;
}

.CodeMirror-hint:hover {
  background: rgba(59, 130, 246, 0.1) !important;
}

li.CodeMirror-hint-active {
  background: #3b82f6 !important;
  color: #ffffff !important;
}

.hint-title-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hint-match-highlight {
  color: #3b82f6;
  font-weight: 700;
  text-decoration: underline;
}

li.CodeMirror-hint-active .hint-match-highlight {
  color: #ffffff;
}

.hint-type-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-muted);
  flex-shrink: 0;
}

.dark .hint-type-badge {
  background: rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
}

li.CodeMirror-hint-active .hint-type-badge {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* Snippets Modal Cards Styling */
.snippet-card {
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.snippet-card:hover {
  transform: translateY(-2px);
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: 0 10px 25px -5px rgba(99, 102, 241, 0.1);
}

.dark .snippet-card:hover {
  border-color: rgba(129, 140, 248, 0.4);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

.scrollbar-none::-webkit-scrollbar {
  display: none;
}
.scrollbar-none {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Modern Clean Canvas & Device Simulator */
.preview-container {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--bg-app);
  background-image: radial-gradient(rgba(148, 163, 184, 0.25) 1px, transparent 1px);
  background-size: 16px 16px;
  height: 100%;
  width: 100%;
  overflow: hidden;
  transition: all 0.3s ease;
}

.dark .preview-container {
  background-image: radial-gradient(rgba(51, 65, 85, 0.4) 1px, transparent 1px);
}

.preview-wrapper {
  background: #ffffff;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1), height 0.35s cubic-bezier(0.4, 0, 0.2, 1), border-radius 0.3s ease, box-shadow 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Desktop Mode */
.device-desktop {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.05);
}

/* Tablet Mode (iPad Pro style) */
.device-tablet {
  width: 768px;
  max-width: 100%;
  height: 94%;
  border-radius: 20px;
  border: 3px solid #334155;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* Mobile Mode (iPhone style) */
.device-mobile {
  width: 375px;
  max-width: 100%;
  height: 94%;
  border-radius: 24px;
  border: 3px solid #1e293b;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.dark .device-tablet {
  border-color: #475569;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.7);
}

.dark .device-mobile {
  border-color: #334155;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.8);
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background-color: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 12px 18px;
  border-radius: 14px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateY(20px);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  opacity: 0.3;
  border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-main);
}