* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%; overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: auto;
  touch-action: none;
}
body {
  background: #111; display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  font-family: monospace; color: #ccc;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ── Toolbar: horizontal strip on mobile ── */
#toolbar {
  width: 100%; height: auto; min-height: 44px;
  background: rgba(20,20,20,.95);
  display: flex; flex-wrap: nowrap; flex-shrink: 0;
  gap: 3px; padding: 4px 6px;
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-bottom: 1px solid #333;
  order: 1;
}
#toolbar::-webkit-scrollbar { display: none; }

/* ── Canvas ── */
#game {
  flex: 1; display: block; cursor: crosshair;
  image-rendering: pixelated; image-rendering: crisp-edges;
  background: #000;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  width: 100%; height: 100%;
  order: 2;
}

/* ── HUD: bottom bar ── */
#hud {
  width: 100%; flex-shrink: 0;
  height: 44px; background: rgba(20,20,20,.9);
  display: flex; align-items: center; gap: 12px; padding: 0 10px;
  border-top: 1px solid #333; z-index: 10;
  order: 3;
}
#hud label { display: flex; align-items: center; gap: 6px; font-size: 12px; white-space: nowrap; }
#hud input[type=range] { width: 80px; }
#fps { font-size: 11px; color: #888; white-space: nowrap; }
#clear {
  background: #333; border: 1px solid #555; color: #ccc;
  padding: 6px 14px; border-radius: 3px; cursor: pointer; font-size: 11px;
  white-space: nowrap; flex-shrink: 0;
}
#clear:hover { background: #555; }

/* ── Element buttons ── */
.ebtn {
  flex-shrink: 0; min-width: 44px; height: 34px;
  border: 2px solid transparent;
  border-radius: 3px; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  font-size: 9px; color: #fff; text-shadow: 0 0 2px #000;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.ebtn.active { border-color: #fff; box-shadow: 0 0 6px #fff; }

/* ── Desktop (wide screen): sidebar layout ── */
@media (min-width: 600px) and (hover: hover) {
  body { flex-direction: row; padding: 0; }
  #toolbar {
    width: 100px; height: auto; min-height: unset;
    flex-wrap: wrap; align-content: flex-start;
    overflow-y: auto; overflow-x: hidden;
    border-bottom: none; border-right: 1px solid #333;
    order: 0;
  }
  #game { width: auto; height: auto; order: 1; }
  #hud {
    position: fixed; bottom: 0; left: 100px; right: 0;
    width: auto; height: 32px; order: 2;
  }
  .ebtn { min-width: 44px; height: 32px; }
  #clear { padding: 3px 10px; }
}
