:root { color-scheme: dark; --panel-h: 124px; }

html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  overflow: hidden; background: #1a2a1a;
  touch-action: none; overscroll-behavior: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}

canvas { display: block; position: absolute; inset: 0; touch-action: none; }

#hud {
  position: fixed; top: env(safe-area-inset-top, 8px); left: 8px;
  color: #e6f0e6; font: 12px/1.3 -apple-system, system-ui, sans-serif;
  background: rgba(0,0,0,0.45); padding: 6px 10px; border-radius: 6px;
  pointer-events: none; z-index: 2;
}

#deselect {
  position: fixed;
  bottom: calc(var(--panel-h) + env(safe-area-inset-bottom, 8px) + 8px);
  right: 12px;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0,0,0,0.55); color: #d6ecf3;
  border: 1px solid rgba(77,208,225,0.6);
  font: 20px/1 -apple-system, system-ui, sans-serif;
  display: flex; align-items: center; justify-content: center;
  z-index: 4; -webkit-tap-highlight-color: transparent;
}
#deselect[hidden] { display: none; }
#deselect:active { background: rgba(77,208,225,0.25); }

/* Bottom build panel */
#buildPanel {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 8px 10px calc(env(safe-area-inset-bottom, 8px) + 8px);
  background: linear-gradient(180deg, rgba(10,16,26,0.65), rgba(8,14,24,0.92));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(77,208,225,0.35);
  box-shadow: 0 -4px 18px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.05);
  display: flex; flex-direction: column; gap: 6px;
  z-index: 3;
}
.panelHeader {
  display: flex; align-items: center; gap: 8px; height: 24px;
  color: #d6ecf3; font: 600 12px/1 -apple-system, system-ui, sans-serif;
}
.backBtn {
  background: rgba(77,208,225,0.12);
  color: #d6ecf3;
  border: 1px solid rgba(77,208,225,0.5);
  border-radius: 6px;
  width: 30px; height: 24px;
  font: 16px/1 -apple-system, system-ui, sans-serif;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.backBtn:active { background: rgba(77,208,225,0.25); }
.backBtn[hidden] { display: none; }
.panelTitle { letter-spacing: 1px; text-transform: uppercase; opacity: 0.85; }
.panelSub { margin-left: auto; opacity: 0.7; font-weight: 400; font-size: 11px; }
.panelGrid {
  display: flex; gap: 8px;
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px 2px 4px;
}
.panelGrid::-webkit-scrollbar { display: none; }
.itemBtn {
  flex: 0 0 auto;
  width: 72px; height: 80px;
  background: linear-gradient(180deg, rgba(72,110,158,0.32), rgba(22,32,48,0.6));
  border: 1px solid rgba(77,208,225,0.32);
  border-radius: 10px;
  color: #e8f3fb;
  font: 600 10px/1.1 -apple-system, system-ui, sans-serif;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 4px 4px 6px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  position: relative; overflow: hidden;
  transition: transform 0.08s ease, border-color 0.15s, box-shadow 0.15s;
}
.itemBtn:active { transform: scale(0.96); }
.itemBtn[disabled] {
  opacity: 0.42; cursor: default;
  border-color: rgba(140,150,170,0.25);
}
.itemBtn.selected {
  border-color: #4dd0e1;
  box-shadow: 0 0 0 2px rgba(77,208,225,0.35), inset 0 0 14px rgba(77,208,225,0.18);
}
.itemBtn .icon {
  width: 56px; height: 56px; margin-bottom: 2px;
  display: flex; align-items: center; justify-content: center;
  background-position: center; background-size: contain; background-repeat: no-repeat;
  font-size: 30px;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,0.5));
}
.itemBtn .label {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%; text-align: center; letter-spacing: 0.2px;
}
.itemBtn .emptyBadge {
  position: absolute; top: 4px; right: 4px;
  font: 600 8px/1 -apple-system, system-ui, sans-serif;
  letter-spacing: 0.5px;
  color: #d6ecf3; background: rgba(0,0,0,0.45);
  padding: 2px 4px; border-radius: 3px;
  opacity: 0.7;
}
.itemBtn .countBadge {
  position: absolute; top: 4px; right: 4px;
  min-width: 18px; height: 18px; padding: 0 4px;
  font: 700 10px/18px -apple-system, system-ui, sans-serif;
  text-align: center;
  color: #082;
  background: #4dd0e1;
  border-radius: 9px;
  box-shadow: 0 0 6px rgba(77,208,225,0.6);
}
