body {
  margin: 0;
  overflow: hidden;
  overflow-x: hidden; /* Prevent horizontal scrollbar */
  background: #fff;
  font-family: monospace, Arial, sans-serif;
  position: relative;
  background-color: #fff;
  background-repeat: no-repeat;
  background-position:
    top left,
    top right,
    bottom left,
    bottom right;
  background-size: 50px 50px;
  background-image:
    url('data:image/svg+xml;utf8,<svg width="50" height="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><circle cx="25" cy="25" r="24" stroke="black" stroke-width="1" fill="none" stroke-opacity="0.1"/><line x1="0" y1="25" x2="50" y2="25" stroke="black" stroke-width="1" stroke-opacity="0.1"/><line x1="25" y1="0" x2="25" y2="50" stroke="black" stroke-width="1" stroke-opacity="0.1"/></svg>'),
    url('data:image/svg+xml;utf8,<svg width="50" height="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><circle cx="25" cy="25" r="24" stroke="black" stroke-width="1" fill="none" stroke-opacity="0.1"/><line x1="0" y1="25" x2="50" y2="25" stroke="black" stroke-width="1" stroke-opacity="0.1"/><line x1="25" y1="0" x2="25" y2="50" stroke="black" stroke-width="1" stroke-opacity="0.1"/></svg>'),
    url('data:image/svg+xml;utf8,<svg width="50" height="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><circle cx="25" cy="25" r="24" stroke="black" stroke-width="1" fill="none" stroke-opacity="0.1"/><line x1="0" y1="25" x2="50" y2="25" stroke="black" stroke-width="1" stroke-opacity="0.1"/><line x1="25" y1="0" x2="25" y2="50" stroke="black" stroke-width="1" stroke-opacity="0.1"/></svg>'),
    url('data:image/svg+xml;utf8,<svg width="50" height="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><circle cx="25" cy="25" r="24" stroke="black" stroke-width="1" fill="none" stroke-opacity="0.1"/><line x1="0" y1="25" x2="50" y2="25" stroke="black" stroke-width="1" stroke-opacity="0.1"/><line x1="25" y1="0" x2="25" y2="50" stroke="black" stroke-width="1" stroke-opacity="0.1"/></svg>');
}

button, select {
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 4px;
  transition: background 0.2s;
  font-family: Arial, monospace;
}

button:hover:not(:disabled), select:hover:not(:disabled) {
  background: #333;
}

button:disabled:not(#uploadBtn), select:disabled {
  background: #666;
  color: #ccc;
  cursor: not-allowed;
}

#uploadBtn:disabled {
  background: #000;
  color: #fff;
}

label {
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  background: none;
  color: #000;
  font-family: monospace, Arial, sans-serif;
}

input[type="checkbox"] {
  margin-right: 5px;
  accent-color: #000;
}

#devModeChk {
  accent-color: #000;
}

input[type="checkbox"]:disabled + label {
  background: #666 !important;
  color: #ccc !important;
  cursor: not-allowed;
}

#recomposeChk:disabled + label, #devModeChk:disabled + label {
  background: #666 !important;
  color: #ccc !important;
  cursor: not-allowed;
}

.button-with-icon {
  display: flex;
  align-items: center;
  padding: 8px 10px;
}

.button-with-icon .material-icons {
  font-size: 18px;
  margin-right: 6px;
  color: #fff;
}

button:disabled .material-icons {
  color: #ccc;
}

#toolbar-right, #toolbar-left {
  position: fixed;
  display: flex;
  gap: 5px;
  z-index: 20;
}

.top-center-overlay {
  position: fixed;
  top: 0.5rem;
  left: 570px;
  transform: translateX(-50%);
  width: 600px;
  z-index: 2;
  opacity: 0.5;
}

.home-button {
  position: fixed;
  top: 580px;
  left: 1rem;
  transform: translateY(-50%);
  z-index: 9000;
}

.home-button img {
  width: auto;
  height: 310px;
  display: block;
}

.home-button:hover {
  opacity: 0.8;
}

#toolbar-left {
  flex-direction: column;
  top: 40px;
  left: 10px;
}

#toolbar-right {
  top: 40px;
  right: 10px;
}

#toolbar-left .button-with-icon {
  width: 160px;
  justify-content: flex-start;
}

canvas {
  display: block;
  background: #fff;
  z-index: 10;
}

#debugFrame {
  position: fixed;
  bottom: 200px;
  left: 50px;
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 10px;
  border-radius: 4px;
  z-index: 30;
  font-size: 12px;
  width: 425px;
  font-family: monospace, Arial, sans-serif;
}

#debugFrame .closeBtn {
  position: absolute;
  top: 5px;
  right: 8px;
  cursor: pointer;
  color: #fff;
}

#debugFrame .closeBtn:hover {
  color: #ccc;
}

#aspectLabel {
  position: absolute;
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 15;
  font-family: monospace, Arial, sans-serif;
}

#brightnessContainer {
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  max-width: 600px;
  background: rgba(255,255,255,0.7);
  padding: 10px;
  border-radius: 6px;
  text-align: left;
  z-index: 25;
  box-sizing: border-box; /* Ensure padding doesn't cause overflow */
}

#contrastContainer {
  position: fixed;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.7);
  padding: 10px;
  border-radius: 6px;
  z-index: 25;
  text-align: center;
}

.slider-container {
  display: flex;
  align-items: center;
  margin: 5px 0;
}

.vertical-slider-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 5px 0;
}

.slider-container .material-icons, .vertical-slider-container .material-icons {
  font-size: 20px;
  width: 24px;
  margin-right: 5px;
  color: #000;
  text-align: center;
}

.vertical-slider-container .material-icons {
  margin-bottom: 5px;
  width: auto;
}

.slider-container label, .vertical-slider-container label {
  font-size: 12px;
  margin-right: 8px;
  width: 100px;
  background: none;
  color: #000;
  text-align: left;
  padding: 4px 8px;
  font-family: monospace, Arial, sans-serif;
}

.vertical-slider-container label {
  margin-bottom: 5px;
  width: auto;
}

.slider-container input[type="range"] {
  flex-grow: 1;
  -webkit-appearance: none;
  height: 6px;
  background: #000;
  outline: none;
  border-radius: 4px;
}

.vertical-slider-container input[type="range"] {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 15px;
  height: 60vh;
  max-height: 300px;
  background: #000;
  outline: none;
  border-radius: 4px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: #000 !important;
  border-radius: 50%;
  cursor: pointer;
  border: 1px solid #fff;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: #000 !important;
  border-radius: 50%;
  cursor: pointer;
  border: 1px solid #fff;
}

.vertical-slider-container input[type="range"]::-webkit-slider-thumb {
  background: #000 !important;
  border: 1px solid #fff;
}

.vertical-slider-container input[type="range"]::-moz-range-thumb {
  background: #000 !important;
  border: 1px solid #fff;
}

input[type="range"]:hover:not(:disabled)::-webkit-slider-thumb {
  background: #333 !important;
}

input[type="range"]:hover:not(:disabled)::-moz-range-thumb {
  background: #333 !important;
}

input[type="range"]:disabled::-webkit-slider-thumb {
  background: #ccc !important;
  cursor: not-allowed;
}

input[type="range"]:disabled::-moz-range-thumb {
  background: #ccc !important;
  cursor: not-allowed;
}

select, #saveModal select, #debugFrame select, #devPanel select {
  background-color: #EFEEEA !important;
  color: #000 !important;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border: 1px solid #ccc;
  font-family: monospace, Arial, sans-serif;
}

#devPanel {
  width: 325px;
  padding: 15px;
  background: #f0f0f0;
  box-sizing: border-box; /* Ensure padding doesn't cause overflow */
}

#devPanel .drag-handle {
  margin-bottom: 10px;
  font-family: monospace, Arial, sans-serif;
}

.dev-panel-row {
  display: flex;
  align-items: center;
  width: 100%;
  margin-bottom: 5px;
}

.dev-panel-row label {
  width: 100px;
  font-size: 12px;
  background: #fff;
  color: #000;
  padding: 4px 8px;
  text-align: left;
  font-family: monospace, Arial, sans-serif;
}

.dev-panel-row select,
.dev-panel-row input[type="number"] {
  flex-grow: 1;
  font-size: 12px;
  padding: 4px;
  border-radius: 4px;
  border: 1px solid #ccc;
  font-family: monospace, Arial, sans-serif;
}

#applyDevBtn {
  margin-top: 10px;
  width: 100%;
}

#loadingIndicator {
  display: none; /* Hide by default */
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  z-index: 30;
  font-family: monospace, Arial, sans-serif;
}

.night-mode body {
  background: #333;
  background-image:
    url('data:image/svg+xml;utf8,<svg width="50" height="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><circle cx="25" cy="25" r="24" stroke="white" stroke-width="1" fill="none" stroke-opacity="0.1"/><line x1="0" y1="25" x2="50" y2="25" stroke="white" stroke-width="1" stroke-opacity="0.1"/><line x1="25" y1="0" x2="25" y2="50" stroke="white" stroke-width="1" stroke-opacity="0.1"/></svg>'),
    url('data:image/svg+xml;utf8,<svg width="50" height="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><circle cx="25" cy="25" r="24" stroke="white" stroke-width="1" fill="none" stroke-opacity="0.1"/><line x1="0" y1="25" x2="50" y2="25" stroke="white" stroke-width="1" stroke-opacity="0.1"/><line x1="25" y1="0" x2="25" y2="50" stroke="white" stroke-width="1" stroke-opacity="0.1"/></svg>'),
    url('data:image/svg+xml;utf8,<svg width="50" height="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><circle cx="25" cy="25" r="24" stroke="white" stroke-width="1" fill="none" stroke-opacity="0.1"/><line x1="0" y1="25" x2="50" y2="25" stroke="white" stroke-width="1" stroke-opacity="0.1"/><line x1="25" y1="0" x2="25" y2="50" stroke="white" stroke-width="1" stroke-opacity="0.1"/></svg>'),
    url('data:image/svg+xml;utf8,<svg width="50" height="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><circle cx="25" cy="25" r="24" stroke="white" stroke-width="1" fill="none" stroke-opacity="0.1"/><line x1="0" y1="25" x2="50" y2="25" stroke="white" stroke-width="1" stroke-opacity="0.1"/><line x1="25" y1="0" x2="25" y2="50" stroke="white" stroke-width="1" stroke-opacity="0.1"/></svg>');
}

.night-mode canvas {
  background: #333;
}

.night-mode button, .night-mode select {
  background: #555;
  color: #fff;
}

.night-mode button:hover:not(:disabled), .night-mode select:hover:not(:disabled) {
  background: #777;
}

.night-mode button:disabled:not(#uploadBtn), .night-mode select:disabled {
  background: #444;
  color: #888;
}

.night-mode #uploadBtn:disabled {
  background: #000;
  color: #fff;
}

.night-mode label {
  background: none;
  color: #fff;
  font-family: monospace, Arial, sans-serif;
}

.night-mode input[type="checkbox"] {
  accent-color: #fff;
}

.night-mode #devModeChk {
  accent-color: #000;
}

.night-mode input[type="checkbox"]:disabled + label {
  background: #444 !important;
  color: #888 !important;
  cursor: not-allowed;
}

.night-mode #recomposeChk:disabled + label, .night-mode #devModeChk:disabled + label {
  background: #444 !important;
  color: #888 !important;
  cursor: not-allowed;
}

.night-mode .button-with-icon .material-icons {
  color: #fff;
}

.night-mode button:disabled .material-icons {
  color: #888;
}

.night-mode #brightnessContainer, .night-mode #contrastContainer {
  background: rgba(0,0,0,0.7);
}

.night-mode .slider-container .material-icons, .night-mode .vertical-slider-container .material-icons {
  color: #fff;
}

.night-mode .slider-container label, .night-mode .vertical-slider-container label {
  background: none;
  color: #fff;
}

.night-mode .slider-container input[type="range"] {
  background: #555;
}

.night-mode .vertical-slider-container input[type="range"] {
  background: #555;
}

.night-mode .vertical-slider-container input[type="range"]::-webkit-slider-thumb {
  background: #fff !important;
  border: 1px solid #000;
}

.night-mode .vertical-slider-container input[type="range"]::-moz-range-thumb {
  background: #fff !important;
  border: 1px solid #000;
}

.night-mode input[type="range"]::-webkit-slider-thumb {
  background: #fff !important;
  border: 1px solid #000;
}

.night-mode input[type="range"]::-moz-range-thumb {
  background: #fff !important;
  border: 1px solid #000;
}

.night-mode input[type="range"]:hover:not(:disabled)::-webkit-slider-thumb {
  background: #ccc !important;
}

.night-mode input[type="range"]:hover:not(:disabled)::-moz-range-thumb {
  background: #ccc !important;
}

.night-mode #aspectLabel {
  background: rgba(0,0,0,0.8);
  color: #fff;
}

.night-mode #debugFrame {
  statically: rgba(0,0,0,0.8);
  color: #fff;
}

.night-mode #debugFrame .closeBtn {
  color: #fff;
}

.night-mode #debugFrame .closeBtn:hover {
  color: #ccc;
}

.night-mode #devPanel {
  background: #333;
}

.night-mode #devPanel label {
  background: none;
  color: #fff;
}

.night-mode #devPanel .drag-handle {
  background: #555;
  color: #fff;
}

.night-mode #saveModal .modal-content, .night-mode #helpModal .modal-content {
  background: #333;
  color: #fff;
  border: 1px solid #fff;
}

.night-mode #saveModal label, .night-mode #helpModal label {
  color: #fff;
}

.night-mode #saveModal input[type="checkbox"]:disabled + label {
  color: #888;
}

.night-mode select, .night-mode #saveModal select, .night-mode #debugFrame select, .night-mode #devPanel select {
  background-color: #EFEEEA !important;
  color: #000 !important;
  border: 1px solid #ccc;
  
}

#saveModal, #helpModal {
  display: none;
  position: fixed;
  z-index: 100;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.4);
}

.modal-content {
  background-color: #fefefe;
  margin: 5% auto;
  padding: 15px;
  border: 1px solid #888;
  width: 90%;
  max-width: 800px;
  text-align: left;
  border-radius: 8px;
  font-family: monospace, Arial, sans-serif;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#saveModal select, #saveModal input[type="text"], #helpModal input, #helpModal textarea {
  margin: 5px 0;
  padding: 8px;
  width: 100%;
  font-size: 14px;
  box-sizing: border-box;
  border-radius: 4px;
  border: 1px solid #ccc;
  font-family: monospace, Arial, sans-serif;
}

#saveModal button, #helpModal button {
  margin: 10px 5px;
}

#saveModal p, #helpModal p {
  font-size: 14px;
  line-height: 1.5;
  margin: 10px 0;
}

#saveModal select:disabled, #saveModal input:disabled, #helpModal input:disabled, #helpModal textarea:disabled {
  background: #ddd;
  cursor: not-allowed;
}

#helpModal img {
  max-width: 100%;
  height: auto;
  margin: 10px 0;
}


/* Added styles for histogram feature */
.draggable {
  position: absolute;
}

.drag-handle {
  background: #f0f0f0;
  color: #000;
  padding: 4px;
  text-align: center;
  cursor: move;
  font-family: monospace, Arial, sans-serif;
}

.night-mode .drag-handle {
  background: #555;
  color: #fff;
}

#histogramFrame {
  width: 325px;
  height: 200px;
  background: #f0f0f0;
  border: 1px solid #ccc;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  z-index: 30; /* Ensure above canvas (z-index: 10) and toolbars (z-index: 20) */
}

.night-mode #histogramFrame {
  background: #333;
  border: 1px solid #fff;
  z-index: 30; /* Maintain in night mode */
}

#histogram {
  display: block;
  margin: 10px auto;
}



body.night-mode, .night-mode {
  background-color: #1a1a1a;
  color: #fff;
}






#saveModal .modal-content {
  display: flex;
  flex-direction: column;
  max-width: 700px;
  margin: 20px auto;
  padding: 10px;
  background: #fff;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

#saveModal .modal-header {
  margin-bottom: 10px;
}

#saveModal .modal-header h2 {
  margin: 0 0 5px;
}

#saveModal .modal-header p {
  margin: 0;
  font-size: 0.9em;
}

#saveModal .modal-controls {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

#saveModal .modal-group {
  flex: 1;
  display: flex;
  flex-direction: column;
}

#saveModal .modal-group label {
  margin-bottom: 5px;
}

#saveModal .modal-group select {
  padding: 5px;
  width: 100%;
}

#saveModal .modal-footer {
  display: flex;
  flex-direction: column; /* Changed to vertical stack */
  gap: 10px;
  margin-bottom: 10px;
}

#saveModal .footer-inputs {
  display: flex;
  flex-direction: column; /* Stacked vertically */
  gap: 10px;
  width: 100%;
}

#saveModal .input-group {
  display: flex;
  flex-direction: column;
  max-width: 100%; /* Full width of container */
}

#saveModal .input-group input[type="text"],
#saveModal .input-group input[type="number"] {
  padding: 5px;
  width: 100%;
  box-sizing: border-box;
  font-size: 0.9em;
}

#saveModal .modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

#saveModal .modal-actions .modal-group {
  flex: 1;
}

#saveModal .button-group {
  display: flex;
  gap: 10px;
}

#saveModal button {
  padding: 5px 10px;
}


.drag-handle {
  user-select: none; /* Prevent text selection on drag handles */
}

