/* Body styles */
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>');
}

/* General button and select styles */
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: monospace, Arial, sans-serif;
}

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 positioning */
#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 */
canvas {
  display: block;
  background: #fff;
  z-index: 10;
}

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

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

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

/* Aspect label */
#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;
}

/* Brightness and contrast containers */
#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;
}

#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 styles */
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;
}

/* Dev panel */
#devPanel {
  width: 325px;
  padding: 15px;
  background: #f0f0f0;
  box-sizing: border-box;
}

#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%;
}

/* Loading indicator */
#loadingIndicator {
  display: none;
  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 styles */
.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 {
  background: 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;
}

/* Modal styles */
#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);
}

.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,
.night-mode #saveModal input[type="radio"]:disabled + label {
  color: #888;
}

/* Modal rows */
.modal-content .modal-row {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  margin: 10px 0;
  align-items: flex-start;
}

.modal-content .modal-group {
  flex: 1 1 200px;
  min-width: 150px;
}

.modal-content .modal-group label {
  display: block;
  font-size: 14px;
  padding: 4px 0;
  margin: 0;
}

.modal-content .modal-group select {
  width: 100%;
  padding: 8px;
  font-size: 14px;
  border-radius: 4px;
  border: 1px solid #ccc;
  font-family: monospace, Arial, sans-serif;
}

/* Footer inputs */
.modal-content .footer-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
}

.modal-content .footer-inputs label {
  flex: 0 0 auto;
  font-size: 14px;
  padding: 4px 8px;
  margin: 0;
}

.modal-content .footer-inputs input[type="text"],
.modal-content .footer-inputs input[type="number"] {
  flex: 1 1 150px;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  font-family: monospace, Arial, sans-serif;
}

.modal-content .footer-inputs input[type="number"] {
  flex: 0 0 80px;
}

.night-mode .modal-content .footer-inputs input[type="text"],
.night-mode .modal-content .footer-inputs input[type="number"] {
  background: #555;
  color: #fff;
  border: 1px solid #888;
}

/* Radio and button group */
.modal-content .radio-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.modal-content .radio-group label {
  padding: 4px 8px;
}

.modal-content .radio-group input[type="radio"] {
  margin: 0 5px 0 0;
}

.modal-content .button-group {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-content button {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  background: #000;
  color: #fff;
  cursor: pointer;
  font-family: monospace, Arial, sans-serif;
}

.night-mode .modal-content button {
  background: #555;
}

.modal-content button:hover:not(:disabled) {
  background: #333;
}

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

.modal-content select:disabled, .modal-content input:disabled {
  background: #ddd;
  cursor: not-allowed;
}

.night-mode .modal-content select:disabled, .night-mode .modal-content input:disabled {
  background: #444;
  color: #888;
}

.modal-content p {
  font-size: 14px;
  line-height: 1.5;
  margin: 10px 0;
}

/* Responsive adjustments */
@media (max-width: 600px) {
  .modal-content {
    margin: 10% auto;
    padding: 10px;
    max-width: 90%;
  }
  .modal-content .modal-row {
    flex-direction: column;
    gap: 10px;
  }
  .modal-content .modal-group {
    flex: 1 1 100%;
  }
  .modal-content .button-group {
    flex-direction: column;
    align-items: stretch;
  }
  .modal-content .button-group button {
    width: 100%;
  }
}

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