:root {
  --brand-300: #a5b4fc;
  --brand-400: #818cf8;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --surface-100: #f8fafc;
  --surface-200: #e2e8f0;
  --surface-300: #cbd5e1;
  --surface-400: #94a3b8;
  --surface-500: #94a3b8;
  --surface-600: #7c8ba1;
  --surface-900: #0f172a;
  --workbench-bg: #0a0a0f;
  --workbench-panel: #131318;
  --workbench-panelLight: #1a1a22;
  --workbench-border: #2a2a35;
  --workbench-borderLight: #3a3a45;
  --gradient-brand: linear-gradient(135deg, #6366f1, #8b5cf6);
  --radius-sm: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-panel: 0.75rem;
  --shadow-panel: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-glow: 0 0 12px rgba(99, 102, 241, 0.4);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  max-width: 100%;
  min-height: 100vh;
  margin: 0;
  background-color: var(--workbench-bg);
  color: var(--surface-100);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

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

::-webkit-scrollbar-track {
  background: var(--workbench-panel);
}

::-webkit-scrollbar-thumb {
  background: var(--workbench-borderLight);
  border-radius: 5px;
  border: 2px solid var(--workbench-panel);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--surface-400);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--workbench-borderLight) var(--workbench-panel);
}

::selection {
  background-color: rgba(99, 102, 241, 0.3);
  color: #ffffff;
}

:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: 2px;
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
span,
a,
label,
li {
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

img,
video,
canvas,
iframe {
  max-width: 100%;
  height: auto;
  display: block;
}

.hidden {
  display: none !important;
}

/* === Components, Animations & UX Defenses === */

.glass-morphism {
  background: rgba(19, 19, 24, 0.75);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
.btn-toolbar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  background-color: transparent;
  border: 1px solid transparent;
  color: var(--surface-300);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}
.btn-toolbar:hover {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: var(--workbench-borderLight);
  color: #ffffff;
}
.btn-toolbar:active {
  transform: scale(0.95);
  background-color: rgba(255, 255, 255, 0.08);
}
.btn-toolbar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, transparent 60%);
  opacity: 0;
  transform: scale(0);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
.btn-toolbar:active::after {
  opacity: 1;
  transform: scale(1.5);
  transition: 0s;
}
.btn-primary-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  background-image: var(--gradient-brand);
  border: 1px solid rgba(99, 102, 241, 0.5);
  color: #ffffff;
  font-weight: 600;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}
.btn-primary-sm:hover {
  background-image: linear-gradient(135deg, #818cf8, #a78bfa);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.5);
  transform: translateY(-1px);
}
.btn-primary-sm:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 1px 4px rgba(99, 102, 241, 0.3);
}
.btn-primary-sm::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.2), transparent 40%);
  transform: translateX(-100%);
  transition: transform 0.5s;
  pointer-events: none;
}
.btn-primary-sm:hover::after {
  transform: translateX(100%);
}
.tab-button {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}
.tab-button:hover {
  background-color: rgba(255, 255, 255, 0.03);
}
.tab-button:active {
  transform: scale(0.98);
}
.tab-button.tab-active {
  color: #ffffff;
}
.tab-button.tab-active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--brand-500);
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.8);
  border-radius: 2px;
}
.shadow-glow {
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.5), 0 0 32px rgba(139, 92, 246, 0.3);
}
.bg-gradient-brand {
  background-image: var(--gradient-brand);
}
.rounded-panel {
  border-radius: var(--radius-panel);
}
@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes scale-bounce {
  0% { transform: scale(0.9); opacity: 0; }
  50% { transform: scale(1.02); opacity: 1; }
  70% { transform: scale(0.98); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(99, 102, 241, 0.4); }
  50% { box-shadow: 0 0 20px rgba(99, 102, 241, 0.8); }
}
@keyframes spin-slow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--workbench-panelLight) 25%, var(--workbench-borderLight) 50%, var(--workbench-panelLight) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}
.animate-fade-in {
  animation: fade-in 0.3s ease-out both;
}
.animate-slide-up {
  animation: slide-up 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.animate-scale-bounce {
  animation: scale-bounce 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.animate-pulse-glow {
  animation: pulse-glow 2s ease-in-out infinite;
}
.animate-spin-slow {
  animation: spin-slow 2s linear infinite;
}
.dark .btn-toolbar {
  background-color: transparent;
}
.dark .tab-button:hover {
  background-color: rgba(255, 255, 255, 0.05);
}
.dark .glass-morphism {
  background: rgba(10, 10, 15, 0.8);
  border-color: rgba(255, 255, 255, 0.06);
}
.dark .shadow-glow {
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.6), 0 0 40px rgba(139, 92, 246, 0.4);
}
.overlay,
.modal-backdrop,
.drawer,
.toast-container,
.popover,
.dropdown-menu,
.context-menu {
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}
.overlay.active,
.modal-backdrop.active,
.drawer.active,
.toast-container.active,
.popover.active,
.dropdown-menu.active,
.context-menu.active {
  pointer-events: auto;
  visibility: visible;
  opacity: 1;
  transition: opacity 0.25s ease, visibility 0s;
}
[hidden],
.hidden {
  display: none !important;
}
[aria-hidden="true"] {
  pointer-events: none;
}
.bg-elements,
.background-layer {
  z-index: 1;
}
.sticky-header,
.app-header,
.sticky-sidebar,
.side-panel {
  z-index: 20;
}
.floating-button,
.fab,
.floating-toolbar {
  z-index: 30;
}
.overlay,
.modal-backdrop {
  z-index: 40;
}
.dialog,
.modal,
.popup {
  z-index: 45;
}
.toast,
.notification,
.tooltip,
.popover[data-position="top"] {
  z-index: 9999 !important;
}
button,
[role="button"],
a,
select,
input[type="checkbox"],
input[type="radio"],
label[for],
.interactive {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:disabled,
[role="button"][aria-disabled="true"],
a[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.5;
  pointer-events: none;
}
button:active:not(:disabled),
[role="button"]:active:not([aria-disabled="true"]),
a:active:not([aria-disabled="true"]) {
  transform: scale(0.98);
}
button:hover:not(:disabled),
[role="button"]:hover:not([aria-disabled="true"]),
a:hover:not([aria-disabled="true"]) {
  filter: brightness(1.05);
}
button:focus-visible,
[role="button"]:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
#brand-icon {
  position: relative;
  overflow: hidden;
}
#brand-icon::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.6), transparent 60%);
  pointer-events: none;
}
#reference-preview {
  background-image: linear-gradient(45deg, var(--workbench-borderLight) 25%, transparent 25%, transparent 75%, var(--workbench-borderLight) 75%),
    linear-gradient(45deg, var(--workbench-borderLight) 25%, transparent 25%, transparent 75%, var(--workbench-borderLight) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  background-color: var(--surface-900);
}
#badge-dot {
  animation: pulse-glow 1.5s ease-in-out infinite;
}
@media (max-width: 640px) {
  .btn-toolbar {
    padding: 0.5rem;
  }
  .btn-primary-sm {
    padding: 0.5rem 0.75rem;
  }
}