html,
body {
  height: 100%;
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  background: #18181b;
  color: #d4d4d8;
  overflow: hidden;
}

#app-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  height: 50px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0));
  pointer-events: none;
  z-index: 100;
}

#app-header h1 {
  font-size: 1.2rem;
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

#settings-btn {
  pointer-events: auto;
  background: rgba(40, 40, 45, 0.7);
  border: none;
  color: #d4d4d8;
  font-size: 1.5rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  backdrop-filter: blur(5px);
  margin-left: auto;
  /* Pushes to the right in flex container */
}

#settings-btn:hover {
  background: rgba(60, 60, 65, 0.8);
  border-color: #52525b;
}

.info-panel {
  position: absolute;
  background: rgba(24, 24, 27, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid #3f3f46;
  padding: 12px;
  border-radius: 8px;
  z-index: 10;
  font-family: monospace;
  font-size: 12px;
  color: #a1a1aa;
}

.info-panel strong {
  font-family: "Inter", sans-serif;
  color: #e4e4e7;
  font-weight: 500;
}

#controls-bar {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(24, 24, 27, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid #3f3f46;
  border-radius: 12px;
  padding: 8px 15px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

#controls-bar button:not(#settings-btn) {
  white-space: nowrap;
}

#controls-bar label,
#controls-bar button:not(#settings-btn),
#controls-bar select,
#controls-bar span {
  font-size: 13px;
}

/* Specific width for the main clip slider is set below using its ID */
#canvas-container {
  width: 100%;
  height: 100%;
  position: relative;
  /* Make it a positioning context for the loader */
}

/* Panels Positioning */
#camera-info {
  display: none;
  position: absolute;
  bottom: 20px;
  left: 20px;
}

#camera-info strong {
  font-family: Arial, sans-serif;
}

/* New styles for the slice viewer */
#slice-viewer {
  position: absolute;
  top: 100px;
  right: 20px;
  width: 256px;
  height: 256px;
  background: rgba(24, 24, 27, 0.7);
  border: 1px solid #3f3f46;
  border-radius: 8px;
  display: none;
  /* Initially hidden */
  z-index: 10;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

#slice-canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  /* Keeps pixels sharp */
  border-radius: 8px;
}

#slice-info {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.7);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 12px;
  color: #e4e4e7;
  pointer-events: none;
}

/* Cross-section viewers */
#x-section-viewer, #y-section-viewer {
  position: absolute;
  width: 256px;
  height: 256px;
  background: rgba(24, 24, 27, 0.7);
  border: 1px solid #3f3f46;
  border-radius: 8px;
  display: none;
  z-index: 10;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

#x-section-viewer {
  top: 100px;
  right: 20px; /* Same position as slice viewer */
}

#y-section-viewer {
  top: 100px;
  right: 20px; /* Same position as slice viewer */
}

#x-section-canvas, #y-section-canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  border-radius: 8px;
}

#x-section-info, #y-section-info {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.7);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 12px;
  color: #e4e4e7;
  pointer-events: none;
}

/* Main analysis panel (top-left) */
#analysis-info {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 320px;
}

#analysis-info table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
  font-size: 13px;
}

#analysis-info td {
  padding: 4px 0;
  vertical-align: middle;
}

#analysis-info td:first-child {
  font-family: "Inter", sans-serif;
  color: #a1a1aa;
  padding-right: 15px;
}

#analysis-info td:last-child {
  font-weight: 500;
  color: #e4e4e7;
  text-align: right;
  white-space: nowrap;
}

/* New styles for analysis info and MTF chart */

#mtf-chart-container {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 400px;
  height: 300px;
  background: rgba(24, 24, 27, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid #3f3f46;
  border-radius: 8px;
  padding: 15px;
  z-index: 10;
  display: none;
  /* Initially hidden */
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* Settings Popup */
.hidden {
  display: none !important;
}

#settings-popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
}

#settings-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #27272a;
  border: 1px solid #3f3f46;
  border-radius: 12px;
  padding: 20px 25px;
  z-index: 1001;
  box-shadow: 0 5px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.setting-item {
  display: grid;
  grid-template-columns: 100px 1fr 40px;
  align-items: center;
  gap: 10px;
}

/* Custom styled controls */
select,
button {
  background: #3f3f46;
  border: 1px solid #52525b;
  color: #e4e4e7;
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
}

button {
  transition: background 0.2s;
}

button:hover {
  background: #52525b;
}

#clip {
  width: 250px;
  /* Set a fixed large width for the main image slider */
  min-width: 250px;
  /* Prevent it from shrinking in the flex container */
}

input[type="range"] {
  /* This applies to ALL sliders; #clip overrides width for the main one. */
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  background: #3f3f46;
  outline: none;
  border-radius: 5px;
  vertical-align: middle;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #a1a1aa;
  cursor: pointer;
  border-radius: 50%;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: #a1a1aa;
  cursor: pointer;
  border-radius: 50%;
}

/* Loader Overlay */
#loader-overlay {
  position: absolute;
  /* Changed from fixed to cover only the canvas container */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fafafa;
  backdrop-filter: blur(5px);
  /* Must be above the 3D canvas but below UI panels (which have z-index 10+). */
  z-index: 5;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #52525b;
  border-top: 4px solid #a78bfa;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

#loader-status {
  font-size: 1rem;
  font-weight: 500;
}

/* Slice control group */
#slice-control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Cross-section controls */
#cross-section-controls {
  display: flex;
  align-items: center;
  gap: 15px;
}

.cross-section-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cross-section-group input[type="range"] {
  width: 120px;
  min-width: 120px;
}

.cross-section-group span:last-child {
  font-family: monospace;
  min-width: 25px;
  text-align: right;
}

#slice-control-group #clipv {
  font-family: monospace;
  min-width: 35px;
  text-align: right;
  padding-right: 5px;
  /* Add space between number and Z-position */
}

#z-position {
  background: rgba(0, 0, 0, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  width: 90px;
  min-width: 90px;
  /* Keep a fixed width */
  text-align: center;
  color: #a78bfa;
  white-space: nowrap;
}

/* Give loop button a fixed width to prevent layout shifts on text change */
#loop-btn {
  min-width: 95px;
  text-align: center;
}