body, html {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100%;
  background: #000; /* pure black background */
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  color: #fff; /* white text */
}

canvas { display: block; }

/* Panel */
#controlPanel {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 280px;
  max-height: calc(100% - 32px);
  background: #111; /* slightly lighter black for panel */
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  z-index: 10;
  overflow: hidden;
  border: 1px solid #222; /* dark border */
  box-sizing: border-box;
}
#zoomPanel {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 280px;
  max-height: calc(100% - 32px);
  background: #111;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  z-index: 10;
  overflow: hidden;
  border: 1px solid #222;
  box-sizing: border-box;
}
#selectionPanel {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: fit-content;
  max-width: 380px;
  max-height: 340px;
  background: #111;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  z-index: 11;
  overflow: hidden;
  border: 1px solid #222;
  box-sizing: border-box;
}
#selectionPanel.collapsed { max-height:60px !important; height:auto; overflow:visible; width:fit-content !important; }
#selectionPanel.collapsed .panel-body { display:none !important; }
/* Consistent collapse behavior for all panels */
#controlPanel.collapsed { max-height:60px !important; height:auto; overflow:visible; width:220px !important; }
#controlPanel.collapsed .panel-body { display:none !important; }
#zoomPanel.collapsed { max-height:60px !important; height:auto; overflow:visible; width:220px !important; }
#zoomPanel.collapsed .panel-body { display:none !important; }
#typeList .type-item {display:flex;align-items:center;justify-content:space-between;padding:6px 8px;background:#1a1a1a;border:1px solid #222;border-radius:8px;font-size:12px;margin-top:6px;cursor:pointer;transition:background .15s ease,border-color .15s ease;}
#typeList .type-item:hover {background:#222;}
#typeList .type-item.active {background:#2d2d2d;border-color:#444;}
#typeList .type-color {width:14px;height:14px;border-radius:4px;border:1px solid #555;margin-right:8px;flex-shrink:0;}
#typeList .type-name {flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
#typeList .type-count {font-size:10px;color:#aaa;margin-left:6px;}
.floating-props .panel-header button {background:#222;border:1px solid #333;border-radius:50%;width:28px;height:28px;display:flex;align-items:center;justify-content:center;font-size:14px;transition:all .2s ease;cursor:pointer;color:#fff;}
.floating-props .panel-header button:hover {background:#333;transform:scale(1.1);} .floating-props .panel-header button:active {transform:scale(.95);} 
#selectionPanel .panel-header {display:flex;align-items:center;justify-content:space-between;padding:12px 16px;font-weight:600;font-size:14px;cursor:move;background:#111;color:#fff;}
#selectionPanel .panel-header button {background:#222;border:1px solid #333;border-radius:50%;width:28px;height:28px;display:flex;align-items:center;justify-content:center;font-size:14px;transition:all .2s ease;cursor:pointer;color:#fff;}
#selectionPanel .panel-header button:hover {background:#333;transform:scale(1.1);}#selectionPanel .panel-header button:active {transform:scale(0.95);}
#selectionPanel .panel-body {padding:14px;overflow-y:auto;scrollbar-width:thin;scrollbar-color:#555 #111;}

/* Lasso overlay path */
.lasso-path { position:fixed; top:0; left:0; pointer-events:none; z-index:12; }
.lasso-path canvas { position:absolute; top:0; left:0; }
/* Zoom panel header/button styles mirror control panel */
#zoomPanel .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: move;
  background: #111;
  color: #fff;
}
#zoomPanel .panel-header button {
  background: #222;
  border: 1px solid #333;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s ease;
  cursor: pointer;
  color: #fff;
}
#zoomPanel .panel-header button:hover { background:#333; transform:scale(1.1); }
#zoomPanel .panel-header button:active { transform:scale(0.95); }
#zoomPanel .panel-body {
  padding: 14px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #555 #111;
  max-height: 560px;
}
.stat-line { font-size:12px; color:#ddd; }

/* Panel Header */
#controlPanel .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: move;
  background: #111;
  color: #fff;
}

#controlPanel .panel-header button {
  background: #222;
  border: 1px solid #333;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s ease;
  cursor: pointer;
  color: #fff;
}

#controlPanel .panel-header button:hover {
  background: #333;
  transform: scale(1.1);
}

#controlPanel .panel-header button:active {
  transform: scale(0.95);
}

/* Panel Body */
#controlPanel .panel-body {
  padding: 14px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #555 #111;
  max-height: 560px; /* fixed interior height to avoid overwhelming page */
}

#controlPanel::-webkit-scrollbar { width: 8px; }
#controlPanel::-webkit-scrollbar-track { background:#111; }
#controlPanel::-webkit-scrollbar-thumb { background:#555; border-radius:4px; }

/* Sections */
.section {
  margin-top: 14px;
  padding: 12px;
  background: #1a1a1a;
  border-radius: 12px;
  position: relative;
  border: 1px solid #222;
}
.section.collapsible { padding-top:32px; }
.section.collapsible .collapse-toggle {
  position:absolute;
  top:8px; right:10px;
  background:#fff;
  color:#000;
  border:none;
  border-radius:12px;
  font-size:11px;
  padding:6px 10px;
  cursor:pointer;
  display:flex;
  align-items:center;
  gap:6px;
  box-shadow:0 2px 4px rgba(0,0,0,0.3);
  transition:background .15s ease, transform .15s ease;
}
.section.collapsible .collapse-toggle:hover { background:#ddd; transform:translateY(-1px); }
.section.collapsible .collapse-toggle:active { background:#bbb; transform:translateY(1px); }
.section.collapsible.collapsed .section-body { display:none; }
.section.collapsible .collapse-toggle::after { content:'▼'; font-size:10px; transition:transform .2s ease; }
.section.collapsible.collapsed .collapse-toggle::after { transform:rotate(-90deg); }

.section::before {
  content: attr(data-section);
  position: absolute;
  top: -9px;
  left: 12px;
  font-size: 10px;
  font-weight: 600;
  background: #111;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  padding: 0 4px;
}

/* Controls */
.control-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.control-label {
  font-size: 12px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  color: #fff;
}

/* Flat slider (no bulb) */
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: #333;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  appearance: none;
  width: 0;
  height: 0;
  background: transparent;
  cursor: pointer;
  box-shadow: none;
}

input[type=range]::-moz-range-thumb {
  width: 0;
  height: 0;
  background: transparent;
  border: none;
}
/* Tutorial system */
.tutorial-target { position:relative; }
.tutorial-tooltip { animation: tut-pop .28s cubic-bezier(.3,1.4,.4,1); }
@keyframes tut-pop { 0%{ transform:scale(.85) translateY(6px); opacity:0; } 100%{ transform:scale(1) translateY(0); opacity:1; } }

/* Styled select to look like buttons */
#qualitySelect, .pill-select {
  appearance: none;
  -webkit-appearance: none;
  appearance: none;
  -moz-appearance: none;
  width: 100%;
  background: #fff;
  color: #000;
  border: none;
  border-radius: 12px;
  padding: 8px 36px 8px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  line-height: 1.2;
  position: relative;
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
#qualitySelect:hover, .pill-select:hover {
  background: #ddd;
  transform: translateY(-1px);
}
#qualitySelect:active, .pill-select:active {
  background: #bbb;
  transform: translateY(1px);
}
#qualitySelect:focus-visible, .pill-select:focus-visible {
  outline: 2px solid #888;
  outline-offset: 2px;
}
/* Custom arrow */
#qualitySelect {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px 14px;
}
/* Dark theme consistency when body toggles (optional if theme-light class exists) */
body.theme-light #qualitySelect, body.theme-light .pill-select {
  background: #222;
  color: #fff;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
}
body.theme-light #qualitySelect:hover, body.theme-light .pill-select:hover { background: #333; }
body.theme-light #qualitySelect:active, body.theme-light .pill-select:active { background: #444; }

/* Grid toggle button style reuse */
#gridToggleBtn {
  background:#fff;
  color:#000;
  border:none;
  border-radius:12px;
  padding:8px 12px;
  font-size:12px;
  font-weight:500;
  cursor:pointer;
  transition:all .15s ease;
  box-shadow:0 2px 4px rgba(0,0,0,0.3);
}
#gridToggleBtn:hover { background:#ddd; transform:translateY(-1px); }
#gridToggleBtn:active { background:#bbb; transform:translateY(1px); }
body.theme-light #gridToggleBtn { background:#222; color:#fff; }
body.theme-light #gridToggleBtn:hover { background:#333; }
body.theme-light #gridToggleBtn:active { background:#444; }

/* Value badge */
.value-badge {
  background: #222;
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  text-align: right;
}

/* Buttons */
button {
  background: #fff; /* white buttons */
  color: #000;
  border: none;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

button:hover {
  background: #ddd;
  transform: translateY(-1px);
}

button:active {
  background: #bbb;
  transform: translateY(1px);
}

/* Color input */
input[type=color] {
  width: 100%;
  height: 32px;
  padding: 0;
  border: 1px solid #222;
  border-radius: 8px;
  cursor: pointer;
  background: #000;
}

/* Inline flags */
.inline-flags { display:flex; gap:10px; margin-top:10px; }
.flag { font-size:12px; display:flex; gap:6px; align-items:center; color:#fff; }
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  background: linear-gradient(to right, #fff 0%, #fff 50%, #333 50%, #333 100%);
  transition: background 0.2s ease;
}

/* fallback style (merged) */
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #333; /* fallback */
  outline: none;
  cursor: pointer;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 0;
  height: 0;
  background: transparent;
  cursor: pointer;
}

input[type=range]::-moz-range-thumb {
  width: 0;
  height: 0;
  background: transparent;
  border: none;
}
/* enhanced style layering */
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  background: #333;
  box-shadow: inset 0 0 6px rgba(255,255,255,0.4);
  transition: box-shadow 0.2s ease, background 0.2s ease;
}

input[type=range]:active {
  box-shadow: inset 0 0 10px rgba(255,255,255,0.6);
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 0;
  height: 0;
  background: transparent;
  cursor: pointer;
}

input[type=range]::-moz-range-thumb {
  width: 0;
  height: 0;
  background: transparent;
  border: none;
}
