:root {
  /* --- 1. Base Variables (Tokens) --- */
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  --focus-ring: 0 0 0 3px rgba(15, 118, 110, 0.3); /* Default Teal focus */
  
  /* Layout */
  --sidebar-width: 380px;
  --topbar-height: 64px;
  --statusbar-height: 32px;
}

/* Credits Footer */
.credits-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  opacity: 0.6;
}
.credits-footer:hover {
  opacity: 1;
  background: var(--bg-panel-alt);
}
.credits-icon {
  font-size: 1.5em;
  animation: pulse 2s infinite;
}
.credits-text {
  font-size: 0.85em;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}
.credits-sub {
  font-size: 0.8em;
  color: var(--text-secondary);
  font-weight: normal;
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 0.8; }
}

/* --- 2. Color Palettes --- */

/* 🎨 Palette 1 — Teal Pro (Default) */
body[data-theme="teal-light"] {
  --bg-app: #F8FAFC;
  --bg-panel: #FFFFFF;
  --bg-panel-alt: #F1F5F9;
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --border-subtle: #E2E8F0;
  --border-strong: #CBD5E1;
  
  --primary: #0F766E;
  --primary-hover: #115E59;
  --primary-contrast: #FFFFFF;
  --accent: #38BDF8;
  
  --danger: #EF4444;
  --success: #10B981;
  
  --focus-ring: 0 0 0 3px rgba(15, 118, 110, 0.3);
}

/* 🎨 Palette 2 — Deep Red / Charcoal */
body[data-theme="red-light"] {
  --bg-app: #FAFAFA;
  --bg-panel: #FFFFFF;
  --bg-panel-alt: #F3F4F6;
  --text-primary: #111827;
  --text-secondary: #4B5563;
  --border-subtle: #D1D5DB;
  --border-strong: #9CA3AF;
  
  --primary: #7F1D1D;
  --primary-hover: #991B1B;
  --primary-contrast: #FFFFFF;
  --accent: #F5DEB3;
  
  --danger: #DC2626;
  --success: #059669;

  --focus-ring: 0 0 0 3px rgba(127, 29, 29, 0.3);
}

/* 🎨 Palette 3 — Indigo / Orange */
body[data-theme="indigo-light"] {
  --bg-app: #F9FAFB;
  --bg-panel: #FFFFFF;
  --bg-panel-alt: #EEF2FF;
  --text-primary: #111827;
  --text-secondary: #4B5563;
  --border-subtle: #E5E7EB;
  --border-strong: #D1D5DB;
  
  --primary: #4338CA;
  --primary-hover: #3730A3;
  --primary-contrast: #FFFFFF;
  --accent: #F97316;
  
  --danger: #EF4444;
  --success: #10B981;

  --focus-ring: 0 0 0 3px rgba(67, 56, 202, 0.3);
}

/* 🌙 Dark Mode (Generic for all palettes, overriding backgrounds/text) */
body[data-mode="dark"] {
  --bg-app: #0F172A;
  --bg-panel: #020617;
  --bg-panel-alt: #1E293B;
  --text-primary: #E5E7EB;
  --text-secondary: #94A3B8;
  --border-subtle: #1E293B;
  --border-strong: #334155;
  
  --primary-contrast: #FFFFFF;
}

/* Dark mode tweaks per palette if needed for primary colors */
body[data-mode="dark"][data-theme="teal-light"] { --primary: #14B8A6; --primary-hover: #0D9488; }
body[data-mode="dark"][data-theme="red-light"] { --primary: #F87171; --primary-hover: #EF4444; }
body[data-mode="dark"][data-theme="indigo-light"] { --primary: #818CF8; --primary-hover: #6366F1; }


/* --- 3. Global Reset & Typography --- */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
  font-size: 14px;
}

/* --- 4. Layout Structure --- */
.app-container {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--statusbar-height));
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: all 0.3s ease;
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-header h1 {
  font-size: 1.25rem;
  font-weight: 800;
  margin: 0;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.025em;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* MAIN AREA */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--bg-app);
}

/* TOP BAR */
.top-bar {
  height: var(--topbar-height);
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 10;
}

.top-bar-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* WORKSPACE (3D + 2D) */
.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.view-panel {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view-3d {
  flex: 1.2; /* Larger 3D view */
  background: radial-gradient(circle at center, var(--bg-panel-alt) 0%, var(--bg-app) 100%);
}

.view-2d {
  flex: 0.8;
  background-color: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
  background-image: radial-gradient(var(--border-strong) 1px, transparent 1px);
  background-size: 20px 20px;
}

.view-overlay-toolbar {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 10;
}

/* STATUS BAR */
.status-bar {
  height: var(--statusbar-height);
  background-color: var(--bg-panel);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  user-select: none;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-item::after {
  content: '|';
  color: var(--border-subtle);
  margin-left: 12px;
}
.status-item:last-child::after { content: none; }

/* --- 5. UI Components --- */

/* CARDS in Sidebar */
.ui-card {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, border-color 0.2s;
}
.ui-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.ui-card-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ui-card-title i { font-size: 1rem; color: var(--primary); }

/* INPUTS & CONTROLS */
.control-group {
  margin-bottom: 1rem;
}
.control-group:last-child { margin-bottom: 0; }

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.value-badge {
  font-family: 'Inter', monospace;
  background-color: var(--bg-panel-alt);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
}

/* Custom Range Slider */
input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
  cursor: pointer;
  margin: 10px 0;
}
input[type=range]:focus { outline: none; }
input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 6px;
  background: var(--bg-panel-alt);
  border-radius: 3px;
  border: 1px solid var(--border-subtle);
}
input[type=range]::-webkit-slider-thumb {
  height: 18px;
  width: 18px;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 2px solid var(--primary);
  box-shadow: var(--shadow-sm);
  margin-top: -7px;
  -webkit-appearance: none;
  transition: transform 0.1s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.1); background: var(--primary); border-color: var(--bg-panel); }

/* Number Input */
input[type=number], select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background-color: var(--bg-panel-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s;
}
input[type=number]:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
  background-color: var(--bg-panel);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.btn-primary {
  background-color: var(--primary);
  color: var(--primary-contrast);
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  box-shadow: var(--shadow-md);
}
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  background-color: var(--bg-panel);
  border-color: var(--border-subtle);
  color: var(--text-secondary);
}
.btn-secondary:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
  background-color: var(--bg-panel-alt);
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background-color: var(--bg-panel-alt);
  color: var(--text-primary);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--bg-panel-alt);
  border: 1px solid var(--border-subtle);
  transition: .4s;
  border-radius: 24px;
}
.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-secondary);
  transition: .4s;
  border-radius: 50%;
}
input:checked + .toggle-slider {
  background-color: var(--primary);
  border-color: var(--primary);
}
input:checked + .toggle-slider:before {
  transform: translateX(20px);
  background-color: #fff;
}

/* Tabs */
.tabs-nav {
  display: flex;
  background-color: var(--bg-panel-alt);
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
}
.tab-link {
  flex: 1;
  text-align: center;
  padding: 8px 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  border: none;
  background: transparent;
}
.tab-link.active {
  background-color: var(--bg-panel);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

/* Tab Content Visibility */
.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}
.tab-content.active {
  display: block;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Tooltip */
[data-tooltip] {
  position: relative;
}
/* Tooltip styles removed - handled by JS */
/* [data-tooltip]:hover::after { ... } */

/* Utilities */
.hidden { display: none !important; }
.flex-row { display: flex; gap: 10px; align-items: center; }
.w-full { width: 100%; }
.mt-4 { margin-top: 1rem; }

/* SVG Preview */
.svg-container {
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}
#svgPreview {
  width: 100%;
  height: 100%;
}
#svgPreview path {
  stroke: var(--text-primary);
  stroke-width: 1;
  fill: none;
  vector-effect: non-scaling-stroke;
}
