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

/* CSS Variables for consistent theming */
:root {
  /* Backgrounds */
  --bg-app: #111827;
  --bg-panel: #1f2937;
  --bg-surface: #374151;
  --bg-surface-hover: #4b5563;
  --bg-danger: #7f1d3a;

  /* Borders */
  --border-default: #374151;
  --border-hover: #6b7280;
  --border-focus: #6366f1;
  --border-canvas: #ffffff;

  /* Text colors */
  --text-title: #d1d5db;
  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --text-muted: #9ca3af;
  --text-selected: #ffffff;
  --text-unselected: #9ca3af;
  --text-danger: #f87171;

  /* Interactive states */
  --accent-primary: #6366f1;
  --accent-hover: #5855eb;

  /* Add action colors */
  --add-action: #16a34a;
  --add-action-hover: #047857;

  /* Border radius */
  --radius-textbox: 2px;
  --radius-slider: 3px;
  --radius-button: 4px;
  --radius-surface: 6px;
  --radius-toggle: 12px;

  /* Typography */
  --font-mono: 'Monaco', monospace;
  --font-sans: 'Segoe UI', Arial, sans-serif;
}

body {
  padding: 0;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
}

/* Layout */
.app-container {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  height: 100vh;
  gap: 1px;
  background: var(--border-default);
}

/* Common panel styles */
.control-panel,
.palette-panel {
  padding: 20px 10px;
  background: var(--bg-panel);
  display: flex;
  gap: 24px;
  flex-direction: column;
}

.control-panel {
  border-right: 1px solid var(--border-default);
  overflow-y: auto;
}

.palette-panel {
  border-left: 1px solid var(--border-default);
  overflow-y: hidden;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.canvas-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 30px 30px 40px;
  background: var(--bg-app);
}

/* Common heading styles */
h2,
.app-title {
  color: var(--text-primary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

h2 {
  font-size: 14px;
}

.app-title {
  color: var(--text-title);
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 32px;
  text-transform: none;
  font-variant: small-caps;
}

/* Common label styles */
.control-label,
.toggle-label,
h3 {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.control-label,
h3 {
  display: block;
  margin-bottom: 8px;
}

/* Common interactive elements */
.segmented-control,
.dropdown-control,
.color-item {
  background: var(--bg-surface);
  border: 1px solid var(--bg-surface-hover);
  border-radius: var(--radius-surface);
  transition: all 0.2s ease;
}

.segmented-control {
  display: flex;
  padding: 2px;
  gap: 2px;
}

.dropdown-control {
  color: var(--text-secondary);
  font-size: 12px;
  padding: 8px 12px;
  cursor: pointer;
  outline: none;
}

.dropdown-control:hover {
  border-color: var(--border-hover);
}

.dropdown-control:focus {
  border-color: var(--border-focus);
}

.color-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px;
}

.color-item:hover {
  background: var(--bg-surface-hover);
}

.color-item.newly-added {
  animation: newItemHighlight 3s ease-out;
}

@keyframes newItemHighlight {
  0% {
    box-shadow: inset 0 0 50px var(--add-action);
  }

  100% {
    box-shadow: inset 0 0 0px var(--add-action);
  }
}

.closest-color-item {
  box-shadow: inset 0 0 0 4px var(--accent-primary);
  background: var(--bg-surface);
}

.closest-color-item:hover {
  box-shadow: inset 0 0 0 4px var(--accent-hover);
  background: var(--bg-surface-hover);
}

.highlighted-color-item {
  background: var(--accent-primary);
}

.highlighted-color-item:hover {
  background: var(--accent-hover);
}

/* Button styles */
.radio-button,
.color-delete-btn,
.add-color-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
  padding: 8px 10px;
  border-radius: var(--radius-button);
  color: var(--text-unselected);

  transition-property: color, background, border;
  transition-duration: 0.15s;
  transition-timing-function: ease;
}

.radio-button {
  flex: 1;
}

.add-color-btn {
  background: var(--add-action);
  color: var(--text-primary);
  visibility: hidden;
  padding: 0px;
  font-size: 18px;
  width: 24px;
  height: 24px;
}

.radio-button input {
  display: none;
}

.radio-button:hover {
  color: var(--text-secondary);
  background: var(--bg-surface-hover);
}

.add-color-btn:hover {
  background: var(--add-action-hover);
  color: var(--text-secondary);
}

.radio-button:has(input:checked) {
  background: var(--accent-primary);
  color: var(--text-selected);
}

.radio-button:has(input:checked):hover {
  background: var(--accent-hover);
}

.color-delete-btn {
  transform: scale(1.5);
  align-self: center;
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 4px;
}

.color-delete-btn:hover {
  background: var(--bg-danger);
  color: var(--text-danger);
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 4px;
}

.axis-sliders-3d .slider-container {
  padding-bottom: 6px;
}

/* Range slider track container */
.range-slider-track {
  position: relative;
  flex: 1;
  height: 20px;
  cursor: pointer;
}

/* Range slider track background */
.range-slider-background {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--bg-surface-hover);
  border-radius: var(--radius-slider);
  transform: translateY(-50%);
}

/* Range slider active range */
.range-slider-active {
  position: absolute;
  top: 50%;
  height: 6px;
  background: var(--accent-primary);
  border-radius: var(--radius-slider);
  transform: translateY(-50%);
}

/* Range slider thumbs */
.range-slider-thumb {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  background: var(--accent-primary);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  cursor: grab;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  z-index: 2;
}

.range-slider-thumb:hover {
  background: var(--accent-hover);
}

.slider-display-value {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  width: 55px;
}

/* Toggle styles */
.toggle-checkbox {
  display: none;
}

.control-label:has(.toggle-checkbox) {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin-bottom: 0;
  position: relative;
}

.control-label:has(.toggle-checkbox):hover .toggle-label {
  color: var(--text-secondary);
}

.toggle-label {
  transition: color 0.2s ease;
}

.control-label:has(.toggle-checkbox)::before {
  content: '';
  width: 40px;
  height: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--bg-surface-hover);
  border-radius: var(--radius-toggle);
  position: relative;
  flex-shrink: 0;

  transition-property: color, border;
  transition-duration: 0.15s;
  transition-timing-function: ease;
}

.control-label:has(.toggle-checkbox)::after {
  content: '';
  width: 16px;
  height: 16px;
  background: var(--text-unselected);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 2px;
  transform: translateY(-50%);
  transition: background, left 0.2s ease;
}

.control-label:has(.toggle-checkbox:checked)::before {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.control-label:has(.toggle-checkbox:checked)::after {
  left: 22px;
  background: var(--text-selected);
}

.control-label:has(.toggle-checkbox:checked) .toggle-label {
  color: var(--text-selected);
}

.highlight-mode-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.highlight-mode-container label {
  margin: 0px;
}

/* Color elements */
.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-button);
  border: 1px solid var(--bg-surface-hover);
  flex-shrink: 0;
  transition: opacity 0.2s ease;
  position: relative;
  background-color: transparent;
  --show-indicator: 0.5;
}

.color-swatch.has-color {
  --show-indicator: 0;
  background-color: var(--swatch-color);
}

.color-swatch::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  background: var(--text-muted);
  border: 1px solid var(--bg-surface-hover);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: var(--show-indicator);
  transition: opacity 0.2s ease;
}

.color-values {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  flex: 1;
}

.color-value {
  display: flex;
  gap: 6px;
  line-height: 1.4em;
  min-height: 1.4em;
}

.color-data {
  color: var(--text-secondary);
}

.color-item-info {
  flex: 1;
  min-width: 0;
}

.color-item .color-name {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 2px;
}

.color-name.editable {
  outline: none;
}

.color-name.editable:hover,
.color-name.editable:focus {
  background: var(--bg-surface);
  outline: 1px solid var(--border-focus);
  border-radius: var(--radius-textbox);
  outline-offset: 2px;
}

.palette-select-container {
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: center;
}

.count-current {
  color: var(--text-secondary);
}

.count-max {
  color: var(--text-muted);
}

.palette-section {
  /* Required so palette-color-list can scroll */
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.palette-color-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.canvas-container {
  position: relative;
  display: inline-block;
}

.canvas-container canvas {
  filter: drop-shadow(0 0 2px var(--border-canvas));
}

/* Selection indicator */
.selection-indicator {
  position: absolute;
  /* Center the indicator on the click point */
  transform: translate(-50%, -50%);
}

.selection-indicator::before {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.3);
  display: flex;
  z-index: 1000;
  animation: selectionPulse .5s ease-in-out;
}

@keyframes selectionPulse {

  0% {
    transform: scale(0);
    opacity: 0;
  }

  25%,
  100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.2);
  }
}

/* Axis labels and tick marks */
.axis-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  white-space: nowrap;
  font-size: 10px;
  z-index: 10;
}

.axis-title,
.tick-mark {
  position: absolute;
}

.x-axis {
  top: 100%;
}

.y-axis {
  right: 100%;
}

.axis-title.x-axis {
  left: 50%;
  transform: translate(-50%, -50%) translate(2px, 20px);
}

.axis-title.y-axis {
  top: 50%;
  transform: rotate(-90deg) translate(50%, -50%) translate(8px, -25px);
  transform-origin: right;
}

.tick-mark.x-axis {
  transform: translateX(-50%) translateX(3px);
}

.tick-mark.y-axis {
  transform: translateY(-50%) translateX(-5px);
}

.tick-mark.theta-axis {
  transform: translate(-50%, -50%);
}

.tick-mark.axis-title.theta-axis {
  transform: translateY(-50%) translateX(-10px);
}

/* Add feedback for command-click */
.add-feedback {
  position: absolute;
  /* Center the indicator on the click point */
  transform: translate(-50%, -50%);
}

.add-feedback::before {
  content: "+";
  width: 24px;
  height: 24px;
  background: var(--add-action);
  color: var(--text-primary);
  border: 0.5px solid var(--border-default);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: addFeedback 0.8s ease-out;
}

@keyframes addFeedback {
  0% {
    transform: scale(0);
    opacity: 1;
  }

  30% {
    transform: scale(1.2);
    opacity: 1;
  }

  100% {
    transform: scale(0.8);
    opacity: 0;
  }
}

/* Responsive Design */
@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    height: auto;
    min-height: 100vh;
  }

  .control-panel,
  .palette-panel,
  .canvas-panel {
    border: none;
  }

  .canvas-panel {
    order: 2;
  }

  .palette-panel {
    order: 3;
  }

  .app-title {
    font-size: 24px;
    margin-bottom: 24px;
  }
}

@media (max-width: 768px) {

  .control-panel,
  .palette-panel {
    padding: 16px;
  }

  .app-title {
    font-size: 22px;
    margin-bottom: 20px;
  }
}