* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: #080b10;
  color: #dfe6ee;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: #0e141b;
  border-bottom: 1px solid #2a3947;
}
.brand h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.5px;
  color: #65f4d1;
}
.brand .subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: #8b98a7;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
#export-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 90;
}
#export-scrim[hidden] { display: none; }
#export-panel, #presets-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 250px;
  background: #0e141b;
  border-left: 1px solid #2a3947;
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.5);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 100;
  transform: translateX(102%);
  transition: transform 0.22s ease;
}
#export-panel.open, #presets-panel.open { transform: none; }
#export-panel button, #presets-panel button { text-align: left; width: 100%; }
#presets-panel input[type="text"], #presets-panel select {
  width: 100%;
  background: #080b10;
  color: #dfe6ee;
  border: 1px solid #2a3947;
  border-radius: 5px;
  padding: 7px;
  font: inherit;
  font-size: 13px;
}
.export-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #65f4d1;
  font-size: 13px;
  letter-spacing: 1px;
  padding: 2px 4px 8px;
}
#btn-export-close, #btn-presets-close {
  width: auto;
  padding: 4px 10px;
}
.export-group {
  font-size: 11px;
  letter-spacing: 1px;
  color: #8b98a7;
  padding: 6px 8px 2px;
}
button {
  background: #14202b;
  color: #dfe6ee;
  border: 1px solid #2a3947;
  border-radius: 6px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: #65f4d1; color: #65f4d1; }
button:disabled { opacity: 0.45; cursor: default; }
#btn-rebuild { border-color: #65f4d1; }
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}
.sidebar {
  width: 300px;
  flex: 0 0 300px;
  background: #0e141b;
  border-right: 1px solid #2a3947;
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sidebar section {
  border: 1px solid #2a3947;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar h2 {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 1px;
  color: #65f4d1;
}
.sidebar section.collapsible > h2 { cursor: pointer; user-select: none; }
.sidebar section.collapsible > h2::after { content: ' ▾'; color: #8b98a7; }
.sidebar section.collapsible.collapsed > h2::after { content: ' ▸'; }
.sidebar section.collapsible.collapsed > :not(h2) { display: none; }
.sidebar label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: #dfe6ee;
}
.sidebar label.check { justify-content: flex-start; }
.sidebar input[type="number"], .sidebar input[type="text"], .sidebar select {
  width: 120px;
  background: #080b10;
  color: #dfe6ee;
  border: 1px solid #2a3947;
  border-radius: 5px;
  padding: 5px 7px;
  font: inherit;
  font-size: 13px;
}
.sidebar input[type="checkbox"] { accent-color: #65f4d1; width: 16px; height: 16px; }
.sidebar input[type="range"] { width: 120px; accent-color: #65f4d1; }
.conditional-options {
  border: 1px solid #2a3947;
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.conditional-options[hidden] { display: none; }
#status {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #2a3947;
  border-radius: 8px;
  font-size: 13px;
  color: #8b98a7;
  min-height: 38px;
  white-space: pre-wrap;
}
.diagnostics {
  color: #8b98a7;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.viewport-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 60vh;
}
#viewport { position: absolute; inset: 0; }
#viewport canvas { display: block; width: 100%; height: 100%; }
#hud {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(14, 20, 27, 0.88);
  border: 1px solid #2a3947;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: #8b98a7;
  pointer-events: none;
  max-width: calc(100% - 24px);
}
#hud b { color: #65f4d1; font-weight: 600; }
#viewbar {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 60%;
}
#viewbar button {
  background: rgba(14, 20, 27, 0.88);
  padding: 6px 9px;
  font-size: 12px;
}
#viewbar button.on { border-color: #65f4d1; color: #65f4d1; }
#viewbar-tools {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 40%;
}
#viewbar-tools button {
  background: rgba(14, 20, 27, 0.88);
  padding: 6px 9px;
  font-size: 12px;
}
#viewbar-tools button.on { border-color: #65f4d1; color: #65f4d1; }
#custom-holes { display: flex; flex-direction: column; gap: 8px; }
#holder-holes { display: flex; flex-direction: column; gap: 8px; }
#custom-labels { display: flex; flex-direction: column; gap: 8px; }
.hole-row {
  border: 1px solid #2a3947;
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hole-row .r1 { display: flex; gap: 6px; }
.holder-hole-row .r1 { align-items: flex-end; }
.holder-hole-drag {
  flex: 0 0 22px;
  align-self: center;
  color: #8b98a7;
  cursor: grab;
  font-size: 17px;
  letter-spacing: -3px;
  line-height: 1;
  user-select: none;
  text-align: center;
}
.holder-hole-drag:active { cursor: grabbing; }
.holder-hole-row.dragging { opacity: 0.45; }
.holder-hole-row.drag-over { border-color: #65f4d1; }
.holder-hole-row .r1 label {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: #8b98a7;
}
.holder-hole-row .r1 select,
.holder-hole-row .r1 input {
  width: 100%;
  min-width: 0;
  background: #080b10;
  color: #dfe6ee;
  border: 1px solid #2a3947;
  border-radius: 5px;
  padding: 5px 6px;
  font: inherit;
  font-size: 13px;
}
.hole-row .r1 select {
  flex: 1;
  min-width: 0;
  background: #080b10;
  color: #dfe6ee;
  border: 1px solid #2a3947;
  border-radius: 5px;
  padding: 5px 7px;
  font: inherit;
  font-size: 13px;
}
.hole-row .custom-del {
  flex: 0 0 28px;
  padding: 5px 0;
  text-align: center;
}
.hole-row .lab-del {
  flex: 0 0 28px;
  padding: 5px 0;
  text-align: center;
}
.hole-row .r1 input[type="text"] {
  flex: 2;
  min-width: 0;
  background: #080b10;
  color: #dfe6ee;
  border: 1px solid #2a3947;
  border-radius: 5px;
  padding: 5px 7px;
  font: inherit;
  font-size: 13px;
}
.hole-row .r2 { display: flex; gap: 6px; }
.hole-row .r3 { display: flex; gap: 6px; }
.hole-row .r4 { display: flex; gap: 6px; align-items: flex-end; }
.hole-row .r4 select {
  flex: 1;
  min-width: 0;
  background: #080b10;
  color: #dfe6ee;
  border: 1px solid #2a3947;
  border-radius: 5px;
  padding: 5px 7px;
  font: inherit;
  font-size: 13px;
}
.hole-row .r4 label {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: #8b98a7;
}
.hole-row .r4 input {
  width: 100%;
  background: #080b10;
  color: #dfe6ee;
  border: 1px solid #2a3947;
  border-radius: 5px;
  padding: 5px 6px;
  font: inherit;
  font-size: 13px;
}
.hole-row .r4 input:disabled { opacity: 0.4; }
.hole-row .r3 input {
  flex: 1;
  min-width: 0;
  background: #080b10;
  color: #dfe6ee;
  border: 1px solid #2a3947;
  border-radius: 5px;
  padding: 5px 6px;
  font: inherit;
  font-size: 13px;
}
.hole-row .r2 label {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: #8b98a7;
}
.hole-row .r2 input {
  width: 100%;
  background: #080b10;
  color: #dfe6ee;
  border: 1px solid #2a3947;
  border-radius: 5px;
  padding: 5px 6px;
  font: inherit;
  font-size: 13px;
}
.hint { font-size: 11px; line-height: 1.45; color: #8b98a7; margin: 4px 0 0; }
#alerts {
  background: #2a1215;
  border-bottom: 1px solid #ff5d5d;
  color: #ffb3b3;
  font-size: 13px;
  padding: 8px 16px;
  white-space: pre-wrap;
}
#alerts.critical {
  background: #55171d;
  border-bottom-width: 3px;
  color: #fff0f0;
  font-size: 15px;
  font-weight: 700;
  padding: 12px 16px;
}
#alerts[hidden] { display: none; }
.upload-btn {
  background: #14202b;
  color: #dfe6ee;
  border: 1px solid #2a3947;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  text-align: center;
  cursor: pointer;
}
.upload-btn:hover { border-color: #65f4d1; color: #65f4d1; }
.sidebar section[hidden] { display: none; }
