:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: 'IBM Plex Mono', 'Menlo', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Courier, monospace;

  /* -- Base Colors (Dark Theme) -- */
  --color-bg-app: #1e1e1e;
  --color-bg-panel-header: #252526;
  --color-bg-panel-body: #1e1e1e;
  --color-bg-activity-bar: #2c2c2e;
  --color-bg-side-panel: #252526;
  --color-bg-status-bar: #2c2c2e;
  
  --color-border: #3c3c3c;
  --color-border-active: #007acc;

  --color-text-primary: #cccccc;
  --color-text-secondary: #999999;
  --color-text-active: #ffffff;
  --color-text-inactive: #888888;
  
  --color-accent-blue: #3CDFFF;
  --color-accent-pink: #D153A1;
  --color-accent-red: #f44747;
  --color-accent-yellow: #ffd700;
  --color-accent-green: #4caf50;

  --input-bg: #3c3c3c;
  --input-border: #3c3c3c;
  --input-hover-border: #5a5a5a;
  --button-bg: #4a4a4a;
  --button-hover-bg: #5a5a5a;
}

/* -- Theme: Solarized Light -- */
body.theme-solarized-light {
  --color-bg-app: #fdf6e3;
  --color-bg-panel-header: #fdf6e3;
  --color-bg-panel-body: #eee8d5;
  --color-bg-activity-bar: #eee8d5;
  --color-bg-side-panel: #fdf6e3;
  --color-bg-status-bar: #eee8d5;
  
  --color-border: #93a1a1;
  --color-border-active: #268bd2;

  --color-text-primary: #586e75;
  --color-text-secondary: #839496;
  --color-text-active: #002b36;
  --color-text-inactive: #93a1a1;
  
  --color-accent-blue: #268bd2;
  --color-accent-pink: #d33682;
  --color-accent-red: #dc322f;
  --color-accent-yellow: #b58900;
  --color-accent-green: #859900;

  --input-bg: #eee8d5;
  --input-border: #93a1a1;
  --input-hover-border: #586e75;
  --button-bg: #eee8d5;
  --button-hover-bg: #fdf6e3;
}

/* -- Theme: Midnight Blue -- */
body.theme-midnight-blue {
  --color-bg-app: #0a192f;
  --color-bg-panel-header: #172a45;
  --color-bg-panel-body: #0a192f;
  --color-bg-activity-bar: #0a192f;
  --color-bg-side-panel: #172a45;
  --color-bg-status-bar: #0a192f;
  
  --color-border: #233554;
  --color-border-active: #64ffda;

  --color-text-primary: #ccd6f6;
  --color-text-secondary: #8892b0;
  --color-text-active: #64ffda;
  --color-text-inactive: #8892b0;
  
  --color-accent-blue: #57cbff;
  --color-accent-pink: #f57dff;
  --color-accent-red: #ff79c6;
  --color-accent-yellow: #f1fa8c;
  --color-accent-green: #50fa7b;

  --input-bg: #172a45;
  --input-border: #233554;
  --input-hover-border: #8892b0;
  --button-bg: #172a45;
  --button-hover-bg: #233554;
}

/* -- Theme: High Contrast -- */
body.theme-high-contrast {
  --color-bg-app: #000000;
  --color-bg-panel-header: #000000;
  --color-bg-panel-body: #000000;
  --color-bg-activity-bar: #000000;
  --color-bg-side-panel: #000000;
  --color-bg-status-bar: #000000;
  
  --color-border: #ffffff;
  --color-border-active: #f0ff00;

  --color-text-primary: #ffffff;
  --color-text-secondary: #eeeeee;
  --color-text-active: #f0ff00;
  --color-text-inactive: #bbbbbb;
  
  --color-accent-blue: #00aaff;
  --color-accent-pink: #ff00ff;
  --color-accent-red: #ff3333;
  --color-accent-yellow: #f0ff00;
  --color-accent-green: #00ff00;

  --input-bg: #000;
  --input-border: #fff;
  --input-hover-border: #f0ff00;
  --button-bg: #000;
  --button-hover-bg: #222;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  background-color: var(--color-bg-app);
  color: var(--color-text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}


/* 2. CORE APPLICATION LAYOUT */
.app-layout {
  display: flex;
  height: 100vh;
}

.activity-bar {
  flex: 0 0 50px;
  background-color: var(--color-bg-activity-bar);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 10px;
  gap: 8px;
  z-index: 100;
  transition: background-color 0.3s ease;
}

.main-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 3. ACTIVITY BAR STYLING */
.activity-item {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text-inactive);
  border-radius: 5px;
  position: relative;
  transition: all 0.2s ease;
}
.activity-item:hover {
  background-color: var(--input-bg);
  color: var(--color-text-active);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.activity-item.active {
  color: var(--color-accent-blue);
  background-color: rgba(60, 223, 255, 0.1);
}
.activity-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 70%;
  background-color: var(--color-accent-blue);
  border-radius: 0 2px 2px 0;
}
.activity-item svg {
  width: 24px;
  height: 24px;
  transition: transform 0.2s ease;
}
.activity-item:hover svg {
  transform: scale(1.1);
}
.activity-item span {
  display: none;
}

/* 4. MAIN VIEW PANELS (HEADER, CONTENT, FOOTER) */
.main-header {
  flex: 0 0 auto;
  padding: 8px 20px;
  background-color: var(--color-bg-panel-body);
  border-bottom: 1px solid var(--color-border);
  transition: background-color 0.3s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.main-header h1 {
  font-size: 1.2rem;
  font-weight: 500;
  background: linear-gradient(135deg, var(--color-accent-blue), var(--color-accent-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.content-area {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.main-footer {
  flex: 0 0 24px;
  background-color: var(--color-bg-status-bar);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  transition: background-color 0.3s ease;
}

.page {
  display: none;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.page.active {
  display: flex;
  flex-direction: column;
  opacity: 1;
}

/* Allow scrolling on content-heavy pages */
#settings-page.active,
#api-guide-page.active {
  overflow-y: auto;
  justify-content: flex-start;
}

/* 5. STUDIO / DASHBOARD LAYOUT */
#dashboard-page.page.active {
  display: flex;
  flex-direction: column;
}
.studio-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.editor-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  z-index: 1;
}
.side-panel {
  flex: 0 0 320px;
  border-left: 1px solid var(--color-border);
  background-color: var(--color-bg-side-panel);
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease;
}
.bottom-panel {
  flex: 0 0 200px;
  max-height: 40%;
  border-top: 1px solid var(--color-border);
  background-color: var(--color-bg-panel-header);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color 0.3s ease;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
}

/* 6. EDITOR PANEL COMPONENTS */
.editor-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background-color: var(--color-bg-panel-header);
  border-bottom: 1px solid var(--color-border);
  transition: background-color 0.3s ease;
}
.editor-instance {
  flex: 1;
  overflow: hidden;
  position: relative;
  border-radius: 0 0 8px 8px;
}

/* 7. SIDE PANEL COMPONENTS (PREVIEW) */
.preview-controls {
  padding: 12px;
  display: flex;
  gap: 10px;
  border-bottom: 1px solid var(--color-border);
  background-color: var(--color-bg-panel-header);
  transition: background-color 0.3s ease;
}
.preview-squares-container {
  flex: 1;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
  transition: all 0.3s ease;
}
.preview-squares-container.active {
  display: flex;
  animation: fadeInScale 0.3s ease-out;
}
.preview-squares {
  display: grid;
  grid-template-columns: repeat(4, 40px);
  grid-template-rows: repeat(4, 40px);
  gap: 15px;
}
.square {
  width: 40px;
  height: 40px;
  background-color: var(--color-accent-pink);
  border-radius: 8px;
  box-shadow: 0 0 15px rgba(209, 83, 161, 0.7);
  transition: all 0.2s ease;
}

/* Individual LED placement for "square without corners" layout */
#square1 { grid-area: 1 / 2; }
#square2 { grid-area: 1 / 3; }
#square3 { grid-area: 2 / 1; }
#square4 { grid-area: 2 / 4; }
#square5 { grid-area: 3 / 1; }
#square6 { grid-area: 3 / 4; }
#square7 { grid-area: 4 / 2; }
#square8 { grid-area: 4 / 3; }

/* 8. BOTTOM PANEL COMPONENTS (ERROR LOG) */
.bottom-panel .panel-header {
  padding: 8px 12px;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
  cursor: ns-resize;
  background: linear-gradient(135deg, var(--color-bg-panel-header), var(--color-bg-panel-body));
  transition: all 0.3s ease;
  position: relative;
  user-select: none;
}
.bottom-panel .panel-header::after {
  content: '⋯⋯⋯';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-inactive);
  font-size: 0.7rem;
  letter-spacing: 2px;
  opacity: 0.6;
  transition: opacity 0.2s ease;
}
.bottom-panel .panel-header:hover {
  background: var(--color-bg-panel-body);
  color: var(--color-text-primary);
}
.bottom-panel .panel-header:hover::after {
  opacity: 1;
  color: var(--color-text-primary);
}
.error-log {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 8px;
  background: var(--color-bg-app);
  transition: background-color 0.3s ease;
}
.error-log ul {
  list-style: none;
}
.error-log li {
  padding: 6px 8px;
  margin-bottom: 4px;
  white-space: pre-wrap;
  border-radius: 4px;
  border-left: 3px solid transparent;
  transition: all 0.2s ease;
}
.error-log li:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateX(4px);
}
.error-log li.error-message {
  color: var(--color-accent-red);
  border-left-color: var(--color-accent-red);
  background: rgba(244, 71, 71, 0.1);
}
.error-log li.warning-message {
  color: var(--color-accent-yellow);
  border-left-color: var(--color-accent-yellow);
  background: rgba(255, 215, 0, 0.1);
}


/* 9. GENERAL UI COMPONENTS */
button {
  font-family: var(--font-sans);
  background-color: var(--button-bg);
  color: var(--color-text-primary);
  border: 1px solid transparent;
  padding: 6px 14px;
  font-size: 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transition: left 0.5s ease;
}
button:hover {
  background-color: var(--button-hover-bg);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
button:hover::before {
  left: 100%;
}
button:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#run-btn {
  background: linear-gradient(135deg, var(--color-accent-green), #45a049);
  color: white;
  border-color: var(--color-accent-green);
  flex-grow: 1;
  font-weight: 500;
}
#run-btn:hover {
  background: linear-gradient(135deg, #45a049, var(--color-accent-green));
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}
#stop-btn {
  background: linear-gradient(135deg, var(--color-accent-red), #d32f2f);
  color: white;
  border-color: var(--color-accent-red);
  flex-grow: 1;
  font-weight: 500;
}
#stop-btn:hover {
  background: linear-gradient(135deg, #d32f2f, var(--color-accent-red));
  box-shadow: 0 4px 12px rgba(244, 71, 71, 0.4);
}

.filename-input,
select {
  background-color: var(--input-bg);
  color: var(--color-text-primary);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  width: 150px;
  transition: all 0.2s ease;
}
.filename-input:focus,
select:focus {
  outline: none;
  border-color: var(--color-border-active);
  box-shadow: 0 0 0 3px rgba(60, 223, 255, 0.1);
  transform: translateY(-1px);
}

/* 10. SETTINGS & API GUIDE PAGES */
.settings-container, .api-guide-container {
  padding: 32px;
  max-width: 900px;
  margin: 20px auto;
  border-radius: 12px;
  height: fit-content;
  transition: all 0.3s ease;
}
.settings-container:hover, .api-guide-container:hover {

}
.settings-container h2, .api-guide-container h1 {
  font-size: 2rem;
  color: var(--color-accent-blue);
  border-bottom: 2px solid var(--color-accent-blue);
  padding-bottom: 12px;
  margin-bottom: 32px;
  position: relative;
}
.settings-container h2::after, .api-guide-container h1::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 60px;
  height: 2px;
  background: var(--color-accent-pink);
  border-radius: 1px;
}
.api-guide-container h1 {
  text-transform: none;
  letter-spacing: normal;
}
.api-guide-container h2 {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-top: 40px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 10px;
  transition: color 0.3s ease;
}
.api-guide-container h3 {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--color-accent-pink);
  margin-top: 28px;
  margin-bottom: 16px;
  transition: color 0.3s ease;
}
.api-guide-container p {
  line-height: 1.8;
  margin-bottom: 16px;
  color: var(--color-text-secondary);
  transition: color 0.3s ease;
}
.api-guide-container code {
  font-family: var(--font-mono);
  background-color: var(--color-bg-app);
  color: #85FFBD;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
.api-guide-container pre {
  background-color: var(--color-bg-app);
  padding: 20px;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 20px;
  border: 1px solid var(--color-border);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}
.api-guide-container pre:hover {
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.15);
}

.setting-item {
  background-color: var(--color-bg-panel-body);
  padding: 24px;
  border-radius: 8px;
  margin-bottom: 20px;
  border: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}
.setting-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(135deg, var(--color-accent-blue), var(--color-accent-pink));
  transform: scaleY(0);
  transition: transform 0.3s ease;
}
.setting-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border-color: var(--color-accent-blue);
}
.setting-item:hover::before {
  transform: scaleY(1);
}
.setting-item-info h3 {
  font-size: 1.25rem;
  color: var(--color-text-primary);
  margin-bottom: 8px;
  transition: color 0.3s ease;
}
.setting-item-info p {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  transition: color 0.3s ease;
}

/* 11. CODEMIRROR THEME OVERRIDES & STYLING */
.editor-instance .CodeMirror {
  border-radius: 0;
  background: var(--color-bg-app);
  transition: background-color 0.3s ease;
}
.CodeMirror-gutters {
  background: var(--color-bg-app);
  border-right: 1px solid var(--color-border);
  transition: all 0.3s ease;
}
.CodeMirror .line-error {
  background-color: rgba(255, 0, 0, 0.15) !important;
  animation: errorPulse 2s ease-in-out infinite;
}
.CodeMirror-gutters .error-gutter {
  width: 16px;
  text-align: center;
  color: var(--color-accent-red);
  cursor: pointer;
  padding-top: 2px;
  transition: all 0.2s ease;
}
.CodeMirror-gutters .error-gutter:hover {
  transform: scale(1.2);
  text-shadow: 0 0 8px var(--color-accent-red);
}
.CodeMirror .line-warning {
  background-color: rgba(255, 215, 0, 0.1) !important;
  animation: warningPulse 3s ease-in-out infinite;
}
.CodeMirror-gutters .warning-gutter {
  width: 16px;
  text-align: center;
  color: var(--color-accent-yellow);
  cursor: default;
  padding-top: 2px;
  transition: all 0.2s ease;
}
.CodeMirror-gutters .warning-gutter:hover {
  transform: scale(1.1);
  text-shadow: 0 0 6px var(--color-accent-yellow);
}

/* Autocomplete Box */
.CodeMirror-hints {
  background-color: var(--color-bg-side-panel) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2) !important;
  padding: 8px !important;
  font-family: var(--font-sans) !important;
  backdrop-filter: blur(10px);
}
.CodeMirror-hint {
  padding: 8px 12px !important;
  margin: 2px 0 !important;
  font-size: 0.9rem !important;
  color: var(--color-text-primary) !important;
  border-radius: 4px !important;
  transition: all 0.2s ease !important;
}
.CodeMirror-hint:hover {
  background-color: rgba(60, 223, 255, 0.1) !important;
  transform: translateX(4px) !important;
}
.CodeMirror-hint-active {
  background-color: var(--color-accent-blue) !important;
  color: #ffffff !important;
  transform: translateX(4px) !important;
}

/* Remove original preview button and related styles */
.preview-btn {
  display: none;
}

/* 12. ANIMATIONS & KEYFRAMES */
@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes errorPulse {
  0%, 100% { background-color: rgba(255, 0, 0, 0.15); }
  50% { background-color: rgba(255, 0, 0, 0.25); }
}

@keyframes warningPulse {
  0%, 100% { background-color: rgba(255, 215, 0, 0.1); }
  50% { background-color: rgba(255, 215, 0, 0.2); }
}

/* 13. RESPONSIVE DESIGN */
@media (max-width: 768px) {
  .studio-layout {
    flex-direction: column;
  }
  .side-panel {
    flex: 0 0 200px;
    border-left: none;
    border-top: 1px solid var(--color-border);
  }
  .settings-container, .api-guide-container {
    margin: 10px;
    padding: 20px;
  }
} 