@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&family=Space+Mono:wght@400;700&display=swap');

:root {
  --bg: #0a0a0c;
  --surface: #131318;
  --surface2: #1a1a22;
  --surface3: #22222e;
  --border: #2a2a3a;
  --border-hi: #3a3a55;
  --text: #e0e0e8;
  --text-dim: #7a7a8e;
  --accent: #00ff88;
  --accent-dim: #00cc6e;
  --accent-glow: rgba(0, 255, 136, 0.15);
  --pink: #ff3388;
  --cyan: #00ccff;
  --yellow: #ffcc00;
  --orange: #ff8800;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* HEADER */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.logo {
  font-family: 'Space Mono', monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
  display: flex; align-items: center; gap: 10px;
}

.logo-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  image-rendering: pixelated;
  clip-path: polygon(0 0, 75% 0, 100% 25%, 100% 100%, 25% 100%, 0 75%);
}

.header-actions {
  display: flex; gap: 8px;
}

.btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 700;
}
.btn-primary:hover { background: var(--accent-dim); }

/* LAYOUT */
.app-layout {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  flex: 1;
  min-height: 0;
}

/* PANELS */
.panel {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--surface);
}
.panel:last-child { border-right: none; border-left: 1px solid var(--border); }
.panel::-webkit-scrollbar { width: 4px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb { background: var(--border); }

.panel-section {
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}

details.panel-section > summary {
  list-style: none;
  list-style-type: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
  user-select: none;
  -webkit-user-select: none;
}
details.panel-section > summary:hover {
  background: rgba(255,255,255,0.03);
}
details.panel-section > summary::-webkit-details-marker {
  display: none;
}
details.panel-section > summary::marker {
  content: '';
  display: none;
}
details.panel-section > summary::after {
  content: '+';
  font-size: 14px;
  color: var(--text-dim);
  flex-shrink: 0;
  margin-left: 8px;
  line-height: 1;
}
details.panel-section[open] > summary::after {
  content: '−';
}
details.panel-section[open] {
  padding-bottom: 16px;
}
details.panel-section[open] > summary {
  margin-bottom: 16px;
}
.section-title {
  font-size: 9px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #fff;
  margin-bottom: 0;
}

/* CONTROLS */
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.control-label {
  font-size: 11px;
  color: var(--text-dim);
}
.control-value {
  font-size: 11px;
  color: var(--accent);
  min-width: 36px;
  text-align: right;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 3px;
  background: var(--surface3);
  border-radius: 0;
  outline: none;
  margin: 6px 0 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  background: var(--accent);
  cursor: pointer;
  border: none;
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px;
  background: var(--accent);
  cursor: pointer;
  border: none;
  border-radius: 0;
}

select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  width: 100%;
  padding: 7px 10px;
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  outline: none;
  margin-top: 4px;
}
select:focus { border-color: var(--accent); }

/* COLOR PALETTE */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  margin-top: 8px;
}
.palette-swatch {
  aspect-ratio: 1;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.1s;
  position: relative;
}
.palette-swatch:hover { transform: scale(1.2); z-index: 1; }
.palette-swatch.active { border-color: white; }

.palette-selector {
  display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px;
}
.palette-option {
  display: flex; gap: 2px; padding: 4px 6px;
  background: var(--surface3);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}
.palette-option:hover, .palette-option.active {
  border-color: var(--accent);
}
.palette-option .mini-swatch {
  width: 10px; height: 10px;
}

/* CANVAS AREA */
.canvas-area {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}
.canvas-toolbar .sep { width: 1px; height: 16px; background: var(--border); }

.canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background:
    linear-gradient(45deg, #0d0d12 25%, transparent 25%),
    linear-gradient(-45deg, #0d0d12 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #0d0d12 75%),
    linear-gradient(-45deg, transparent 75%, #0d0d12 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.canvas-wrapper {
  position: relative;
  display: flex;
  gap: 2px;
  align-items: flex-start;
}

canvas {
  image-rendering: pixelated;
  box-shadow: 0 0 60px rgba(0,0,0,0.5);
}
canvas.pannable { cursor: grab; }
canvas.pannable:active { cursor: grabbing; }
.hidden-ctrl { display: none; }

/* CURVE EDITOR */
.curve-editor {
  width: 100%;
  aspect-ratio: 1;
  margin-top: 6px;
  cursor: crosshair;
  border: 1px solid var(--border);
}
.curve-editor svg { display: block; width: 100%; height: 100%; }
.curve-point {
  cursor: grab;
  transition: r 0.1s;
}
.curve-point:hover { r: 7; }

.drop-zone {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10;
  cursor: pointer;
}
.drop-zone.has-image { display: none; }
.drop-zone-border {
  width: 300px; height: 200px;
  border: 2px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: all 0.2s;
}
.drop-zone-border:hover { border-color: var(--accent); }
.drop-icon {
  font-size: 32px;
  color: var(--text-dim);
}
.drop-text {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
}
.drop-sub {
  font-size: 10px;
  color: var(--border-hi);
}

/* TOGGLE */
.toggle-group {
  display: flex;
  border: 1px solid var(--border);
  margin-top: 4px;
}
.toggle-btn {
  flex: 1;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  padding: 6px 8px;
  background: var(--surface3);
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.toggle-btn:not(:last-child) { border-right: 1px solid var(--border); }
.toggle-btn.active { background: var(--accent); color: var(--bg); font-weight: 700; }

/* CHECKBOX */
.checkbox-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px; cursor: pointer;
  font-size: 11px; color: var(--text-dim);
}
.checkbox-row input { display: none; }
.check-box {
  width: 14px; height: 14px;
  border: 1px solid var(--border);
  background: var(--surface3);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.checkbox-row input:checked + .check-box { background: var(--accent); border-color: var(--accent); }
.checkbox-row input:checked + .check-box::after { content: '✓'; font-size: 10px; color: var(--bg); }

/* INFO */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.info-item {
  background: var(--surface3);
  padding: 8px 10px;
}
.info-label {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.info-value {
  font-size: 13px;
  color: var(--accent);
}

/* PRESETS */
.preset-list { display: flex; flex-direction: column; gap: 4px; }
.preset-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: var(--surface3);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}
.preset-item:hover { border-color: var(--accent); }
.preset-preview {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  image-rendering: pixelated;
}
.preset-name { font-size: 11px; }
.preset-desc { font-size: 9px; color: var(--text-dim); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.preset-save-load {
  display: flex; gap: 6px; margin-bottom: 8px;
}
.saved-preset-icon {
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 700; letter-spacing: 1px;
  color: var(--accent); background: var(--surface2);
}
.preset-item-actions {
  display: flex; gap: 2px; flex-shrink: 0;
}
.preset-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px; line-height: 1;
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  width: 22px; height: 22px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.preset-btn:hover { border-color: var(--accent); color: var(--text); }
.preset-btn-del:hover { border-color: var(--pink); color: var(--pink); }

/* VIEW TOGGLE */
.view-toggle {
  display: flex; gap: 4px;
}
.view-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  padding: 4px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  letter-spacing: 1px;
}
.view-btn.active { border-color: var(--accent); color: var(--accent); }

/* IMPORT PALETTE BUTTON */
.btn-import-pal {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  background: var(--surface3);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 1px;
  white-space: nowrap;
  margin-top: 4px;
}
.btn-import-pal:hover { border-color: var(--accent); color: var(--accent); }

/* CUSTOM PALETTE ENTRIES */
.custom-pal-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: var(--surface3);
  border: 1px solid var(--border);
  margin-bottom: 3px;
  font-size: 10px;
  color: var(--text-dim);
}
.custom-pal-entry .pal-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.custom-pal-entry .pal-count {
  font-size: 9px;
  color: var(--text-dim);
  margin: 0 8px;
}
.custom-pal-entry .pal-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
  font-family: 'JetBrains Mono', monospace;
}
.custom-pal-entry .pal-delete:hover { color: var(--pink); }

/* Responsive */
@media (max-width: 1100px) {
  .app-layout { grid-template-columns: 260px 1fr; }
  .panel:last-child { display: none; }
}
