/* PixelKlotz — Dark Theme */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-panel: #1e1e3a;
  --bg-input: #2a2a4a;
  --bg-hover: #2e2e5a;
  --bg-active: #3a3a6a;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0c0;
  --text-muted: #707090;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --border: #333366;
  --border-light: #444488;
  --grid-line: #333;
  --checker-light: #2a2a40;
  --checker-dark: #222238;
  --radius: 4px;
  --panel-gap: 8px;
  --header-height: 44px;
  --sidebar-width: 200px;
  --statusbar-height: 24px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Consolas', 'Menlo', monospace;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-primary);
}

/* Header */
#header {
  display: flex;
  align-items: center;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  gap: 16px;
  user-select: none;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
}

.header-right {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.header-btn {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 12px;
  cursor: pointer;
  font-size: 12px;
}
.header-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

/* Tab Bar */
.tab-bar {
  display: flex;
  gap: 2px;
}

.tab {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover {
  color: var(--text-primary);
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Main Layout */
#main {
  display: flex;
  height: calc(100% - var(--header-height) - var(--statusbar-height));
}

/* Sidebars */
#sidebar-left, #sidebar-right {
  width: var(--sidebar-width);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--panel-gap);
  padding: var(--panel-gap);
  flex-shrink: 0;
}
#sidebar-right {
  border-right: none;
  border-left: 1px solid var(--border);
}

/* Panels */
.panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}

.panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Tool Buttons */
.tool-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
}

.tool-btn {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  cursor: pointer;
  font-size: 16px;
  text-align: center;
  transition: background 0.15s;
}
.tool-btn:hover {
  background: var(--bg-hover);
}
.tool-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.tool-icon {
  pointer-events: none;
}

/* Shape Grid */
.shape-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

.shape-btn {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shape-btn:hover {
  background: var(--bg-hover);
}
.shape-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}
.shape-btn canvas {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Grid Options */
.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.num-input {
  width: 50px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 4px;
  font-size: 12px;
  text-align: center;
}

.small-btn {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 11px;
  margin-top: 4px;
  width: 100%;
}
.small-btn:hover {
  background: var(--bg-hover);
}

.tiny-btn {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 6px;
  cursor: pointer;
  font-size: 10px;
}
.tiny-btn:hover {
  background: var(--bg-hover);
}

/* Palette */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

.palette-swatch {
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  position: relative;
}
.palette-swatch:hover {
  border-color: var(--text-secondary);
}
.palette-swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 1px var(--accent);
}
.palette-swatch .swatch-index {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 8px;
  color: rgba(255,255,255,0.6);
  text-shadow: 0 0 2px #000;
  pointer-events: none;
}

.color-edit {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

#color-picker {
  width: 32px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0;
  background: transparent;
}

.color-hex {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

/* Depth Selector */
.depth-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

.depth-btn {
  aspect-ratio: 1;
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.depth-btn:hover {
  border-color: var(--text-secondary);
}
.depth-btn.active {
  border-color: var(--accent);
  background: var(--bg-active);
}

.depth-auto {
  margin-top: 8px;
}
.depth-auto h4 {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.depth-auto .small-btn {
  margin-top: 3px;
}

/* Workspace */
#workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
}

.tab-content {
  display: none;
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
}
.tab-content.active {
  display: block;
}

/* Canvas editors fill workspace */
#canvas-editor, #depth-editor {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* Preview container */
#preview-container {
  width: 100%;
  height: 100%;
}
#preview-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Export Panel */
.export-panel {
  padding: 24px;
  overflow-y: auto;
  height: 100%;
}

.export-section {
  margin-bottom: 20px;
}

.export-section h3 {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.export-btn {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}
.export-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.export-btn .format {
  font-size: 16px;
  font-weight: 700;
  display: block;
  margin-bottom: 4px;
}
.export-btn .desc {
  font-size: 10px;
  color: var(--text-muted);
}

.export-options {
  margin-top: 12px;
}
.export-options label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

/* Status Bar */
#statusbar {
  height: var(--statusbar-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-muted);
  user-select: none;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 300px;
  max-width: 500px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 14px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 16px;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-btn {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 16px;
  cursor: pointer;
  font-size: 12px;
}
.modal-btn:hover {
  background: var(--bg-hover);
}
.modal-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.modal-btn.primary:hover {
  background: var(--accent-hover);
}

/* Info text */
.info-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}
