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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #0d1117;
  color: #e6edf3;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── TOOLBAR ── */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  flex-wrap: wrap;
  flex-shrink: 0;
  min-height: 50px;
}
.logo { font-weight: 700; font-size: 15px; color: #58a6ff; margin-right: 4px; }
.sep { width: 1px; height: 26px; background: #30363d; margin: 0 2px; }
#terrain-info { font-size: 12px; color: #8b949e; }
#terrain-info strong { color: #e6edf3; }

button {
  background: #21262d;
  color: #e6edf3;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
  white-space: nowrap;
}
button:hover { background: #30363d; border-color: #8b949e; }
button.active { background: #1f6feb; border-color: #388bfd; color: #fff; }
button.danger { color: #f85149; border-color: #f85149; }
button.danger:hover { background: rgba(248,81,73,0.15); }

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

/* ── SIDEBAR ── */
#sidebar {
  width: 196px;
  min-width: 196px;
  background: #161b22;
  border-right: 1px solid #30363d;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#sidebar-header {
  padding: 10px 12px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid #30363d;
  flex-shrink: 0;
}
#sidebar-scroll { flex: 1; overflow-y: auto; }
#area-list { padding: 6px; }
#sidebar-stats {
  padding: 10px 12px;
  border-top: 1px solid #30363d;
  font-size: 12px;
  color: #8b949e;
  line-height: 1.9;
  flex-shrink: 0;
}
#sidebar-stats strong { color: #e6edf3; }

.area-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}
.area-item:hover { background: rgba(255,255,255,0.05); }
.area-item.selected { background: rgba(31,111,235,0.2); }
.area-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.area-name-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── FURNITURE PALETTE ── */
.sidebar-section-header {
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-top: 1px solid #30363d;
  margin-top: 4px;
}
#furniture-palette { padding: 0 6px 8px; }
.furn-group { margin-bottom: 2px; }
.furn-category {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: #c9d1d9;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.furn-category:hover { background: rgba(88,166,255,0.1); color: #58a6ff; }
.furn-category.open  { color: #58a6ff; }
.furn-arrow { font-size: 9px; transition: transform 0.2s; }
.furn-category.open .furn-arrow { transform: rotate(90deg); }
.furn-items { padding: 0 4px 4px; }
.furn-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: #0d1117;
  border: 1px solid #30363d;
  color: #c9d1d9;
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  margin-bottom: 3px;
  transition: all 0.1s;
  text-align: left;
}
.furn-btn:hover { background: #161b22; border-color: #58a6ff; color: #e6edf3; }
.furn-btn span { font-size: 10px; color: #8b949e; font-weight: normal; }

/* ── OBJECT PANEL ── */
#obj-panel {
  position: absolute;
  top: 12px; right: 12px;
  width: 210px;
  background: #161b22;
  border: 1px solid #388bfd;
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
#obj-panel h3 {
  font-size: 11px;
  font-weight: 600;
  color: #58a6ff;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}
#obj-panel-name {
  font-size: 13px;
  color: #e6edf3;
  margin-bottom: 12px;
  padding: 6px 8px;
  background: #0d1117;
  border-radius: 6px;
}

/* ── CANVAS ── */
#canvas-wrap { flex: 1; position: relative; overflow: hidden; background: #0d1117; }
canvas { display: block; }

/* ── PANEL ── */
#panel {
  position: absolute;
  top: 12px; right: 12px;
  width: 210px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
#panel h3 {
  font-size: 11px;
  font-weight: 600;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}
#panel > label {
  display: block;
  font-size: 11px;
  color: #8b949e;
  margin-bottom: 4px;
}
#area-name-input {
  width: 100%;
  background: #0d1117;
  border: 1px solid #30363d;
  color: #e6edf3;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  margin-bottom: 10px;
}
#area-name-input:focus { outline: none; border-color: #388bfd; }
.toggle-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; }
.toggle {
  width: 32px; height: 18px;
  background: #21262d;
  border-radius: 100px;
  border: 1px solid #30363d;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #8b949e;
  transition: transform 0.2s, background 0.2s;
}
.toggle.on { background: #1f6feb; border-color: #388bfd; }
.toggle.on::after { transform: translateX(14px); background: #fff; }
.toggle-label { font-size: 13px; }
.color-grid { display: grid; grid-template-columns: repeat(6,1fr); gap: 5px; margin-bottom: 10px; }
.color-swatch { width: 100%; aspect-ratio: 1; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: transform 0.1s; }
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: #fff; transform: scale(1.1); }
#panel-size { font-size: 12px; color: #8b949e; margin-bottom: 10px; padding: 6px 8px; background: #0d1117; border-radius: 6px; }

/* ── INFO BAR ── */
#info-bar {
  position: absolute;
  bottom: 12px; left: 50%;
  transform: translateX(-50%);
  background: rgba(22,27,34,0.92);
  border: 1px solid #30363d;
  border-radius: 100px;
  padding: 5px 14px;
  font-size: 12px;
  color: #8b949e;
  pointer-events: none;
  white-space: nowrap;
}

/* ── DIALOG ── */
dialog {
  background: #161b22;
  color: #e6edf3;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 24px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog h2 { font-size: 16px; margin-bottom: 6px; }
dialog p { font-size: 13px; color: #8b949e; margin-bottom: 20px; line-height: 1.5; }
.field-row { display: flex; gap: 12px; margin-bottom: 16px; }
.field { flex: 1; }
.field label { display: block; font-size: 12px; color: #8b949e; margin-bottom: 5px; }
.field input {
  width: 100%;
  background: #0d1117;
  border: 1px solid #30363d;
  color: #e6edf3;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
}
.field input:focus { outline: none; border-color: #388bfd; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.btn-primary { background: #1f6feb; border-color: #388bfd; color: #fff; }
.btn-primary:hover { background: #388bfd; }
