/* ========== Base Reset & Theme ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-dark: #0a0a1a;
  --bg-panel: #1a1a2e;
  --bg-section: #16213e;
  --accent: #0f3460;
  --highlight: #e94560;
  --success: #2ecc71;
  --warning: #f39c12;
  --text: #e0e0e0;
  --text-dim: #8899aa;
  --border: #2a2a4a;
  --radius: 6px;
}

html, body {
  width: 100%; height: 100%;
  background: var(--bg-dark);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  overflow: hidden;
  user-select: none;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--highlight); }

/* ========== Editor Layout ========== */
.editor-container {
  display: flex;
  width: 100vw; height: 100vh;
  min-width: 1100px; min-height: 600px;
}

.sidebar-left, .sidebar-right {
  width: 250px;
  min-width: 250px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-right {
  border-right: none;
  border-left: 1px solid var(--border);
}

.editor-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  position: relative;
  overflow: hidden;
  padding: 8px;
}

.editor-main canvas {
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  cursor: crosshair;
  max-width: 100%;
  max-height: 100%;
}

/* ========== Sidebar Sections ========== */
.sidebar-section {
  background: var(--bg-section);
  border-radius: var(--radius);
  padding: 10px;
  border: 1px solid var(--border);
}

.sidebar-section h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--highlight);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

/* ========== Block Palette ========== */
.block-palette {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.block-palette-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg-dark);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 11px;
  color: var(--text);
}
.block-palette-item:hover {
  border-color: var(--accent);
  background: var(--bg-panel);
}
.block-palette-item.selected {
  border-color: var(--highlight);
  background: rgba(233, 69, 96, 0.15);
  box-shadow: 0 0 8px rgba(233, 69, 96, 0.3);
}

.block-swatch {
  width: 18px; height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.2);
}

/* ========== Property Panel ========== */
.property-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 8px;
}
.property-row label {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ========== Inputs ========== */
input[type="text"], input[type="number"], select, textarea {
  background: var(--bg-dark);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
  border-color: var(--highlight);
}
select {
  cursor: pointer;
}
input[type="number"] {
  width: 60px;
}

/* Range Slider */
.slider-container {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.slider-container label {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 65px;
}
.slider-container .slider-value {
  font-size: 11px;
  color: var(--highlight);
  min-width: 24px;
  text-align: right;
}
input[type="range"] {
  -webkit-appearance: none;
  flex: 1;
  height: 4px;
  background: var(--bg-dark);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--highlight);
  border-radius: 50%;
  cursor: pointer;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  color: #fff;
  width: 100%;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.15); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--accent); }
.btn-danger  { background: var(--highlight); }
.btn-success { background: var(--success); }
.btn-warning { background: var(--warning); color: #111; }
.btn-export {
  background: linear-gradient(135deg, var(--highlight), #c0392b);
  font-size: 14px;
  padding: 10px 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 15px rgba(233, 69, 96, 0.3);
}
.btn-export:hover {
  box-shadow: 0 6px 20px rgba(233, 69, 96, 0.5);
}
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-group { display: flex; gap: 4px; }

/* ========== Drop Zone ========== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 11px;
  transition: all 0.2s ease;
  cursor: pointer;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--highlight);
  background: rgba(233, 69, 96, 0.05);
  color: var(--text);
}
.drop-zone .icon { font-size: 20px; }

.bg-preview {
  max-width: 100%;
  max-height: 80px;
  border-radius: 4px;
  border: 1px solid var(--border);
  margin-top: 6px;
  object-fit: contain;
}

/* ========== Tool Buttons ========== */
.tool-buttons {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.tool-button {
  padding: 5px 10px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.tool-button:hover { border-color: var(--accent); }
.tool-button.active {
  border-color: var(--highlight);
  background: rgba(233, 69, 96, 0.15);
  color: var(--highlight);
}

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s;
}
.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.modal-header h2 { font-size: 16px; color: var(--highlight); }
.modal-close {
  background: var(--highlight);
  border: none;
  color: #fff;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.modal-close:hover { transform: scale(1.1); }

.modal-game-info {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
  font-size: 13px;
}
.modal-game-info span { color: var(--text-dim); }
.modal-game-info strong { color: var(--highlight); margin-left: 4px; }

/* ========== Status Bar ========== */
.status-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 24px;
  background: var(--bg-section);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 16px;
  font-size: 11px;
  color: var(--text-dim);
}
.status-bar span { display: flex; align-items: center; gap: 3px; }

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-section);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 2000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========== Animations ========== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ========== Tab Navigation ========== */
.tab-nav { display:flex; gap:2px; margin-bottom:8px; }
.tab-btn { flex:1; padding:6px 4px; background:var(--bg-dark); border:1px solid var(--border); border-bottom:none; border-radius:4px 4px 0 0; color:var(--text-dim); font-size:10px; cursor:pointer; text-align:center; transition:all .15s; }
.tab-btn:hover { color:var(--text); background:var(--bg-section); }
.tab-btn.active { color:var(--highlight); background:var(--bg-section); border-color:var(--highlight); font-weight:600; }
.tab-content { display:none; }
.tab-content.active { display:block; }

/* ========== Stage List ========== */
.stage-list { display:flex; flex-direction:column; gap:3px; max-height:200px; overflow-y:auto; }
.stage-item { display:flex; align-items:center; gap:6px; padding:6px 8px; background:var(--bg-dark); border:1px solid transparent; border-radius:4px; cursor:pointer; font-size:11px; transition:all .15s; }
.stage-item:hover { border-color:var(--accent); }
.stage-item.active { border-color:var(--highlight); background:rgba(233,69,96,0.1); }
.stage-item .stage-num { color:var(--highlight); font-weight:700; min-width:20px; }
.stage-item .stage-name { flex:1; color:var(--text); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.stage-item .stage-blocks { color:var(--text-dim); font-size:10px; }
.stage-item .stage-actions { display:flex; gap:2px; }
.stage-item .stage-actions button { background:none; border:none; color:var(--text-dim); cursor:pointer; font-size:12px; padding:2px; }
.stage-item .stage-actions button:hover { color:var(--highlight); }

/* ========== Block Palette Extensions ========== */
.block-palette { max-height:280px; overflow-y:auto; }
.block-palette-item .block-effect { font-size:8px; color:var(--text-dim); display:block; margin-top:1px; }

/* ========== Editor Toolbar ========== */
.editor-toolbar { display:flex; align-items:center; gap:4px; padding:4px 8px; background:var(--bg-section); border:1px solid var(--border); border-radius:var(--radius); margin-bottom:6px; width:100%; max-width:810px; flex-wrap:wrap; }
.editor-toolbar .tool-separator { width:1px; height:20px; background:var(--border); margin:0 4px; }
.toolbar-btn { padding:4px 8px; background:var(--bg-dark); border:1px solid var(--border); border-radius:4px; color:var(--text-dim); font-size:11px; cursor:pointer; transition:all .15s; display:flex; align-items:center; gap:3px; }
.toolbar-btn:hover { border-color:var(--accent); color:var(--text); }
.toolbar-btn.active { border-color:var(--highlight); color:var(--highlight); background:rgba(233,69,96,0.1); }
.toolbar-btn .icon { font-size:13px; }

/* ========== Minimap ========== */
.minimap-container { position:relative; margin-top:6px; }
.minimap { border:1px solid var(--border); border-radius:3px; background:var(--bg-dark); width:100%; aspect-ratio:4/3; image-rendering:pixelated; }
.minimap-viewport { position:absolute; border:1px solid var(--highlight); pointer-events:none; }

/* ========== Template Panel ========== */
.template-grid { display:grid; grid-template-columns:1fr 1fr; gap:4px; }
.template-item { padding:8px 6px; background:var(--bg-dark); border:1px solid var(--border); border-radius:4px; cursor:pointer; text-align:center; font-size:10px; color:var(--text-dim); transition:all .15s; }
.template-item:hover { border-color:var(--accent); color:var(--text); }
.template-item .icon { display:block; font-size:18px; margin-bottom:3px; }

/* ========== Shortcut Help Modal ========== */
.shortcut-modal { max-width:400px; }
.shortcut-list { display:flex; flex-direction:column; gap:4px; }
.shortcut-row { display:flex; justify-content:space-between; align-items:center; padding:4px 0; border-bottom:1px solid var(--border); font-size:12px; }
.shortcut-key { background:var(--bg-dark); border:1px solid var(--border); border-radius:3px; padding:2px 6px; font-family:monospace; font-size:11px; color:var(--highlight); }

/* ========== Game Settings Panel ========== */
.game-settings { display:flex; flex-direction:column; gap:8px; }
.setting-group { padding:8px; background:var(--bg-dark); border-radius:4px; border:1px solid var(--border); }
.setting-group label { display:block; font-size:10px; color:var(--text-dim); margin-bottom:4px; text-transform:uppercase; letter-spacing:0.5px; }
.difficulty-select { display:flex; gap:4px; }
.difficulty-btn { flex:1; padding:6px; border:1px solid var(--border); background:var(--bg-section); border-radius:4px; color:var(--text-dim); font-size:11px; cursor:pointer; text-align:center; transition:all .15s; }
.difficulty-btn:hover { border-color:var(--accent); }
.difficulty-btn.active { border-color:var(--highlight); color:var(--highlight); background:rgba(233,69,96,0.1); }

/* ========== Progress Overlay ========== */
.progress-overlay { position:fixed; inset:0; background:rgba(0,0,0,0.7); display:flex; align-items:center; justify-content:center; z-index:1500; }
.progress-box { background:var(--bg-panel); border:1px solid var(--border); border-radius:10px; padding:24px 32px; text-align:center; min-width:300px; }
.progress-bar { height:6px; background:var(--bg-dark); border-radius:3px; overflow:hidden; margin-top:12px; }
.progress-bar-fill { height:100%; background:linear-gradient(90deg, var(--highlight), #FF6B6B); border-radius:3px; transition:width .3s; }
.progress-text { font-size:12px; color:var(--text-dim); margin-top:8px; }

/* ========== Context Menu ========== */
.context-menu { position:fixed; background:var(--bg-panel); border:1px solid var(--border); border-radius:var(--radius); padding:4px 0; min-width:160px; z-index:1100; box-shadow:0 8px 24px rgba(0,0,0,0.5); animation:fadeIn .1s; }
.context-menu-item { padding:6px 12px; font-size:12px; color:var(--text); cursor:pointer; display:flex; align-items:center; gap:6px; transition:background .1s; }
.context-menu-item:hover { background:var(--accent); }
.context-menu-item.danger { color:#E74C3C; }
.context-menu-separator { height:1px; background:var(--border); margin:3px 0; }

/* ========== Item Badge ========== */
select option.item-option { padding:4px; }
.item-badge { display:inline-flex; align-items:center; gap:4px; padding:2px 6px; border-radius:10px; font-size:10px; }
.item-badge .dot { width:8px; height:8px; border-radius:50%; display:inline-block; }

/* ========== Selection Box ========== */
.selection-box { position:absolute; border:1px dashed var(--highlight); background:rgba(233,69,96,0.1); pointer-events:none; z-index:10; }

/* ========== Toast Extensions ========== */
.toast.success { border-color:var(--success); }
.toast.error { border-color:#E74C3C; }
.toast.warning { border-color:var(--warning); }

/* ========== Background Layer List ========== */
.bg-layer-list { display:flex; flex-direction:column; gap:4px; max-height:200px; overflow-y:auto; }
.bg-layer-item { display:flex; align-items:center; gap:6px; padding:6px 8px; background:var(--bg-dark); border:1px solid var(--border); border-radius:4px; font-size:11px; }

/* ========== Responsive ========== */
@media (max-width: 1200px) {
  .editor-container { min-width:auto; flex-direction:column; }
  .sidebar-left, .sidebar-right { width:100%; min-width:auto; max-height:200px; flex-direction:row; flex-wrap:wrap; overflow-x:auto; border:none; border-bottom:1px solid var(--border); }
  .editor-main { order:-1; }
  .editor-main canvas { max-height:50vh; }
}

/* ========== Sidebar Scrollbar ========== */
.sidebar-left::-webkit-scrollbar, .sidebar-right::-webkit-scrollbar { width:4px; }

/* ========== Additional Animations ========== */
@keyframes slideUp { from { transform:translateY(10px); opacity:0; } to { transform:translateY(0); opacity:1; } }
@keyframes pulse { 0%,100% { transform:scale(1); } 50% { transform:scale(1.05); } }
.btn-export { animation: pulse 2s infinite; }
.btn-export:hover { animation: none; }
