/* PixelLab – Editor Styles */
:root {
  --bg-dark: #1a1a2e;
  --bg-panel: #16213e;
  --bg-panel2: #0f3460;
  --accent: #e94560;
  --accent2: #f5a623;
  --text: #e0e0e0;
  --text-muted: #8892a4;
  --border: #2a3a5c;
  --tool-size: 44px;
  --panel-w: 220px;
  --layer-h: 52px;
  --radius: 8px;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* ── TOP BAR ── */
#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-panel);
  border-bottom: 2px solid var(--accent);
  z-index: 100;
  flex-shrink: 0;
}

#topbar .logo {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -1px;
  margin-right: 12px;
}

.menu-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.menu-btn:hover { background: var(--accent); border-color: var(--accent); }
.menu-btn svg { flex-shrink: 0; }

#topbar .spacer { flex: 1; }

#canvas-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 4px 10px;
  background: var(--bg-dark);
  border-radius: var(--radius);
}

/* Challenge badge in topbar */
#challenge-badge {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: linear-gradient(135deg, #f5a623, #e94560);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
#challenge-badge.active { display: flex; }

/* ── MAIN LAYOUT ── */
#workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── TOOL PANEL (left) ── */
#toolpanel {
  width: 60px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 2px;
  overflow: visible;  /* must not clip tooltips */
  flex-shrink: 0;
  z-index: 10;
}

.tool-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  gap: 2px;
}
.tool-group:last-child { border-bottom: none; }

.tool-btn {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  cursor: pointer;
  border: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  transition: all 0.15s;
  position: relative;
}
.tool-btn:hover { background: var(--bg-panel2); color: var(--text); }
.tool-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.tool-btn .tooltip {
  position: absolute;
  left: 54px;
  top: 50%;
  transform: translateY(-50%);
  background: #1a1a1a;
  color: #fff;
  font-size: 0.72rem;
  padding: 5px 10px;
  border-radius: 5px;
  white-space: nowrap;
  z-index: 9999;
  pointer-events: none;
  border: 1px solid #444;
  box-shadow: 0 3px 12px rgba(0,0,0,0.5);
  max-width: 260px;
  white-space: normal;
  line-height: 1.4;
  /* visible/opacity instead of display:none — no clipping, smooth */
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.15s, visibility 0.15s;
  transition-delay: 0.4s;  /* short delay so accidental hovers don't flash */
}
.tool-btn .tooltip::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-right-color: #1a1a1a;
  border-left: none;
}
.tool-btn:hover .tooltip {
  visibility: visible;
  opacity: 1;
}

/* Color swatches */
#color-section {
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#color-preview {
  position: relative;
  width: 38px;
  height: 38px;
  cursor: pointer;
}
#bg-color-swatch {
  position: absolute;
  width: 26px; height: 26px;
  right: 0; bottom: 0;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: #ffffff;
  cursor: pointer;
}
#fg-color-swatch {
  position: absolute;
  width: 26px; height: 26px;
  left: 0; top: 0;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: #000000;
  cursor: pointer;
  z-index: 1;
}
#fg-color-input, #bg-color-input { display: none; }

#swap-colors {
  font-size: 10px;
  cursor: pointer;
  color: var(--text-muted);
}
#swap-colors:hover { color: var(--accent); }

/* ── SHAPE SUBMENU ── */
.shape-opt {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  cursor: pointer;
  border-radius: 5px;
  color: var(--text);
  margin: 2px 0;
  transition: background 0.12s;
}
.shape-opt:hover { background: var(--accent); }
.shape-opt.active-shape { background: var(--accent); color: #fff; }

/* ── CANVAS AREA (center) ── */
#canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2a2a2a;
  overflow: auto;
  position: relative;
}

#canvas-area.drag-over::after {
  content: '📥 Bild hier ablegen';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #fff;
  background: rgba(64, 140, 255, 0.18);
  border: 2px dashed rgba(120, 170, 255, 0.9);
  pointer-events: none;
  z-index: 50;
}

#canvas-wrapper {
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

#canvas-stack {
  position: relative;
  display: block;
  /* width/height set by JS via style.width/height */
}

#canvas-stack canvas {
  position: absolute;
  top: 0; left: 0;
  image-rendering: pixelated;
}

#overlay-canvas {
  image-rendering: auto; /* marquee lines must not be pixelated */
}

#canvas-stack canvas:last-child {
  position: absolute; /* overlay sits on top like all other canvases */
}

#overlay-canvas {
  cursor: crosshair;
  z-index: 50;
}

/* Zoom controls */
#zoom-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  gap: 4px;
  z-index: 10;
}
.zoom-btn {
  width: 32px; height: 32px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.zoom-btn:hover { background: var(--accent); }
#zoom-label {
  padding: 0 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.75rem;
  display: flex; align-items: center;
  color: var(--text-muted);
  min-width: 52px; justify-content: center;
}

/* ── RIGHT PANEL (properties + layers) ── */
#rightpanel {
  width: var(--panel-w);
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--bg-panel2);
}
.panel-header:hover { color: var(--text); }

.panel-body { padding: 10px 12px; }

/* Tool options */
.opt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.opt-row label { flex: 1; }
.opt-row input[type=range] {
  flex: 1.5;
  accent-color: var(--accent);
  margin: 0 6px;
}
.opt-row .val { min-width: 28px; text-align: right; color: var(--text); }

.opt-row input[type=checkbox] { accent-color: var(--accent); }

.opt-row select {
  flex: 1.5;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 6px;
  font-size: 0.78rem;
  margin: 0 0 0 6px;
}

.opt-row input[type=color] {
  flex: 1.5;
  height: 26px;
  margin: 0 0 0 6px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

/* Layers */
#layers-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  position: relative;
}

#layers-panel.drag-over {
  outline: 2px dashed rgba(120, 170, 255, 0.9);
  outline-offset: -2px;
  background: rgba(64, 140, 255, 0.08);
}

#layers-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  background: var(--bg-dark);
  transition: all 0.15s;
}
.layer-item:hover { border-color: var(--border); }
.layer-item.active { border-color: var(--accent); background: rgba(233,69,96,0.12); }

.layer-thumb {
  width: 36px; height: 28px;
  border-radius: 3px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  background: repeating-conic-gradient(#555 0% 25%, #333 0% 50%) 0 0 / 8px 8px;
  overflow: hidden;
  position: relative;
}
.layer-thumb canvas { width: 100%; height: 100%; }

.layer-info { flex: 1; min-width: 0; }
.layer-name {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
}
.layer-name:hover {
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-decoration-style: dotted;
}
.layer-name-input {
  background: var(--bg-panel2);
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--text);
  font-size: 0.78rem;
  width: 100%;
  padding: 1px 4px;
}
.layer-opacity-mini {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.layer-eye {
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 14px;
}
.layer-eye:hover { color: var(--text); }
.layer-eye.hidden { color: var(--border); }

#layers-toolbar {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
}
.layer-tool-btn {
  flex: 1;
  height: 28px;
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.layer-tool-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Layer opacity slider in right panel */
#layer-opacity-row { display: none; }
#layer-opacity-row.visible { display: flex; }

/* ── BOTTOM STATUS BAR ── */
#statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
  height: 26px;
  min-height: 26px;
  max-height: 26px;
  overflow: hidden;
  white-space: nowrap;
}
#status-pos, #status-color { font-variant-numeric: tabular-nums; }

/* ── MODAL OVERLAYS ── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  min-width: 340px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h2 { font-size: 1.1rem; margin-bottom: 16px; color: var(--text); }

.modal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 0.85rem;
}
.modal-row label { width: 120px; color: var(--text-muted); }
.modal-row input[type=number], .modal-row input[type=text], .modal-row select {
  flex: 1;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 0.85rem;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}
.btn-primary {
  padding: 8px 20px;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary {
  padding: 8px 20px;
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-secondary:hover { border-color: var(--text-muted); }

/* ── IMAGE ADJUSTMENTS MODAL ── */
#adjust-modal .adj-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.82rem;
}
#adjust-modal .adj-row label { width: 110px; color: var(--text-muted); }
#adjust-modal .adj-row input[type=range] { flex: 1; accent-color: var(--accent); }
#adjust-modal .adj-row .adj-val { width: 36px; text-align: right; font-variant-numeric: tabular-nums; }

/* ── CHALLENGE PANEL (slide-in) ── */
#challenge-panel {
  position: fixed;
  top: 0; right: -420px;
  width: 400px;
  height: 100vh;
  background: var(--bg-panel);
  border-left: 2px solid var(--accent);
  z-index: 200;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#challenge-panel.open { right: 0; }

#challenge-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--accent), #c0392b);
  font-weight: 700;
  font-size: 0.95rem;
}

#challenge-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.challenge-task-img {
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #111;
  margin-bottom: 12px;
}

.challenge-story {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 12px;
  line-height: 1.5;
  padding: 8px 12px;
  border-left: 3px solid var(--accent2);
  background: rgba(245,166,35,0.08);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.step-list { display: flex; flex-direction: column; gap: 8px; }

.step-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.83rem;
  background: var(--bg-dark);
  position: relative;
}
.step-item.done { border-color: #27ae60; background: rgba(39,174,96,0.08); }
.step-item.done::before {
  content: '✓';
  position: absolute; right: 10px; top: 10px;
  color: #27ae60; font-weight: 700;
}
.step-item.current { border-color: var(--accent2); background: rgba(245,166,35,0.1); }
.step-item.locked { opacity: 0.4; }

.step-number {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 3px;
}
.step-text { line-height: 1.4; }
.step-text code {
  display: inline-block;
  background: rgba(245,166,35,0.15);
  border: 1px solid rgba(245,166,35,0.3);
  border-radius: 4px;
  padding: 6px 10px;
  margin: 4px 0;
  font-family: 'Consolas', monospace;
  font-size: 0.85rem;
  color: var(--accent2);
  line-height: 1.6;
}

.hint-btn {
  margin-top: 8px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--accent2);
  border-radius: 4px;
  color: var(--accent2);
  font-size: 0.75rem;
  cursor: pointer;
}
.hint-btn:hover { background: rgba(245,166,35,0.15); }
.hint-text {
  display: none;
  margin-top: 6px;
  padding: 6px 8px;
  background: rgba(245,166,35,0.12);
  border-radius: 4px;
  font-size: 0.78rem;
  color: var(--accent2);
  line-height: 1.4;
}
.hint-text.shown { display: block; }

.step-btn {
  margin-top: 10px;
  width: 100%;
  padding: 8px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
}
.step-btn:hover { filter: brightness(1.1); }

/* Progress bar */
#challenge-progress {
  height: 4px;
  background: var(--border);
  flex-shrink: 0;
}
#challenge-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.4s ease;
}

/* Badge overlay */
#badge-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}
#badge-overlay.show { display: flex; }
#badge-overlay .badge-icon { font-size: 80px; animation: pop 0.4s ease; }
#badge-overlay h2 { font-size: 1.8rem; color: var(--accent2); }
#badge-overlay p { color: var(--text-muted); font-size: 0.9rem; }
@keyframes pop {
  0% { transform: scale(0.3); opacity: 0; }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Adjustments panel highlight ── */
.highlight-tool {
  animation: pulse 1.2s ease infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(233,69,96,0.6); }
  50% { box-shadow: 0 0 0 6px rgba(233,69,96,0); }
}
