﻿*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: #0f0f0f;
  color: #e0e0e0;
}

/* --- Loading / Error --- */
.loading-screen, .error-screen {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  background: #0f0f0f; z-index: 1000;
}
.loading-spinner {
  width: 32px; height: 32px; border: 3px solid #333;
  border-top-color: #47a0fb; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-screen p { color: #888; font-size: 14px; }

/* --- App Layout --- */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.editor { display: flex; flex-direction: column; height: 100vh; }

/* --- Top Bar --- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 16px;
  background: #1a1a1a; border-bottom: 1px solid #2a2a2a; flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 16px; font-weight: 700; color: #fff; letter-spacing: -0.02em; }
.topbar-center { flex: 1; display: flex; justify-content: center; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 24px; background: #2a2a2a; margin: 0 4px; }

/* --- Toolbar --- */
.toolbar { display: flex; align-items: center; gap: 4px; }
.tool-btn {
  border: 1px solid #333; background: #222; color: #888;
  border-radius: 6px; padding: 6px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all 100ms; line-height: 1; display: flex;
  align-items: center; justify-content: center; gap: 4px; white-space: nowrap;
}
.tool-btn:hover { background: #333; color: #fff; border-color: #555; }
.tool-btn.active { background: #47a0fb; color: #fff; border-color: #47a0fb; }
.tool-btn.danger { color: #E94560; }
.tool-btn.danger:hover { background: rgba(233,69,96,0.15); color: #ff6b7a; border-color: #E94560; }
.tool-btn svg { display: block; }

/* --- Content --- */
.content {
  display: flex; gap: 1px; flex: 1; min-height: 0; background: #1a1a1a;
}

/* --- Panels --- */
.panel {
  display: flex; flex-direction: column; background: #141414;
  overflow: hidden;
}
.panel-left { width: 220px; flex-shrink: 0; padding: 12px; gap: 12px; }
.panel-center { flex: 1; align-items: center; justify-content: center; padding: 12px; }
.panel-right { width: 220px; flex-shrink: 0; padding: 12px; gap: 12px; }
.panel-section { display: flex; flex-direction: column; gap: 8px; }
.section-title {
  font-size: 10px; font-weight: 700; color: #666;
  text-transform: uppercase; letter-spacing: 0.1em;
}

/* --- Canvas --- */
.canvas-wrap {
  display: flex; align-items: center; justify-content: center;
  flex: 1; min-height: 0; overflow: hidden; position: relative;
}
#canvas {
  image-rendering: pixelated; cursor: crosshair;
  max-width: 100%; max-height: 100%; object-fit: contain;
}

/* --- Color --- */
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="color"] {
  width: 36px; height: 36px; border: 1px solid #333; border-radius: 6px;
  background: #1a1a1a; padding: 2px; cursor: pointer; flex-shrink: 0;
}
.color-hex {
  display: flex; align-items: center; flex: 1;
  background: #1a1a1a; border: 1px solid #333; border-radius: 6px; padding: 0 8px;
}
.color-hex .hash { color: #666; font-size: 13px; }
.color-hex input {
  background: transparent; border: none; color: #e0e0e0; padding: 0 4px;
  height: 34px; font-size: 13px; font-family: 'Consolas', monospace; width: 100%;
  outline: none;
}

/* --- Palette --- */
.palette {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px;
}
.palette-swatch {
  width: 100%; aspect-ratio: 1; border-radius: 4px; border: 1px solid #333;
  cursor: pointer; transition: transform 80ms;
}
.palette-swatch:hover { transform: scale(1.15); z-index: 1; }
.palette-swatch.active { border-color: #47a0fb; box-shadow: 0 0 0 2px #47a0fb44; }

/* --- Buttons --- */
.btn-row { display: flex; gap: 4px; flex-wrap: wrap; }
.btn {
  border: none; background: #222; color: #e0e0e0; border-radius: 6px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background 100ms; line-height: 1;
}
.btn:hover { background: #333; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: #47a0fb; color: #fff; }
.btn.primary:hover { background: #5aafff; }

/* --- Status Bar --- */
.status-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 12px; background: #1a1a1a; border-top: 1px solid #2a2a2a;
  font-size: 11px; color: #666; width: 100%; flex-shrink: 0;
}

/* --- Preview --- */
.preview-mode-row { display: flex; gap: 4px; }
.preview-mode-row .tool-btn { flex: 1; text-align: center; padding: 5px 0; font-size: 11px; }
.preview-wrap {
  border-radius: 6px; border: 1px solid #2a2a2a; background: #0f0f0f;
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  min-height: 120px; position: relative;
}
#previewCanvas {
  width: 100%; max-width: 192px; image-rendering: pixelated; height: auto;
}
#preview3d { width: 100%; height: 100%; min-height: 160px; display: none; }

/* --- Popups --- */
.popup {
  position: fixed; inset: 0; z-index: 999;
  background: rgba(0,0,0,0.7); display: flex;
  align-items: center; justify-content: center;
}
.popup-inner {
  background: #1a1a1a; border: 1px solid #333; border-radius: 12px;
  padding: 24px 28px; min-width: 280px; max-width: 400px;
}
.popup-inner p { font-size: 14px; color: #e0e0e0; margin-bottom: 18px; line-height: 1.5; }
.popup-actions { display: flex; gap: 8px; justify-content: flex-end; }

.notif-popup {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  background: #2a4a7a; border: 1px solid #333; border-radius: 4px;
  padding: 0; min-width: 320px; max-width: 400px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.notif-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 14px 18px; gap: 12px;
}
.notif-inner span { font-size: 14px; font-weight: 700; color: #fff; flex: 1; }
.notif-close {
  width: 24px; height: 24px; border: none; background: transparent;
  color: #fff; font-size: 18px; cursor: pointer; border-radius: 3px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.notif-close:hover { background: rgba(255,255,255,0.15); }

@media (max-width: 860px) {
  .content { flex-direction: column; }
  .panel-left, .panel-right { width: 100%; max-height: 200px; }
  .topbar { flex-wrap: wrap; }
  .topbar-center { order: 3; flex-basis: 100%; justify-content: flex-start; }
}
