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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ── Top Bar ──────────────────────────── */
#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: rgba(26, 26, 46, 0.95);
  backdrop-filter: blur(6px);
  z-index: 10;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

#top-bar button {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: #e0e0e0;
  font-size: 18px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#top-bar button:hover {
  background: rgba(255,255,255,0.16);
}

#top-bar button:active {
  background: rgba(255,255,255,0.24);
}

#btn-speed {
  font-size: 12px;
  font-weight: 700;
  width: auto;
  padding: 0 8px;
}

#entity-counter {
  flex: 1;
  font-size: 13px;
  text-align: center;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

/* ── Canvas ───────────────────────────── */
#canvas {
  position: fixed;
  top: 44px;
  left: 0;
  width: 100%;
  height: calc(100% - 124px);  /* 44px top-bar + 80px tray */
  cursor: crosshair;
  display: block;
}

/* ── Tray ─────────────────────────────── */
#tray {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: rgba(26, 26, 46, 0.95);
  backdrop-filter: blur(6px);
  border-top: 1px solid rgba(255,255,255,0.08);
  z-index: 10;
  display: flex;
  align-items: center;
}

#tray-scroll {
  display: flex;
  gap: 8px;
  padding: 0 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
  width: 100%;
  align-items: center;
}

#tray-scroll::-webkit-scrollbar {
  height: 4px;
}
#tray-scroll::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
}

.tray-btn {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  font-size: 30px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: rgba(255,255,255,0.06);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  position: relative;
}

.tray-btn:hover {
  background: rgba(255,255,255,0.12);
  transform: translateY(-2px);
}

.tray-btn.selected {
  background: rgba(99, 122, 255, 0.25);
  border-color: rgba(99, 122, 255, 0.6);
  box-shadow: 0 0 16px rgba(99, 122, 255, 0.3);
  transform: translateY(-3px);
}

.tray-btn.eraser {
  font-size: 26px;
}

.tray-btn .tool-label {
  position: absolute;
  bottom: -16px;
  font-size: 9px;
  opacity: 0.6;
  white-space: nowrap;
}
