/* CSS Variables for Light and Dark Themes */
:root {
  --bg-color: #f0f2f5;
  --text-color: #333;
  --header-bg: #f0f2f5; /* Same as page for seamless appearance */
  --footer-bg: #ffffff;
  --button-bg: #10a37f;
  --button-text: #fff;
  --button-hover-bg: #0e7a62;
  --border-color: #ccc;
  --dropdown-bg: #ffffff;
  --dropdown-text: #333;
  --body-font: Arial, sans-serif; /* Define body font */
}
.dark-theme {
  --bg-color: #121212;
  --text-color: #e0e0e0;
  --header-bg: #121212;
  --footer-bg: #1f1f1f;
  --button-bg: #bb86fc;
  --button-text: #121212;
  --button-hover-bg: #9a67ea;
  --border-color: #444444;
  --dropdown-bg: #1f1f1f;
  --dropdown-text: #e0e0e0;
}

/* Reset and basic styles */
*, *::before, *::after {
  box-sizing: border-box;
}
body, html {
  margin: 0;
  padding: 0;
  font-family: var(--body-font); /* Use variable */
  height: 100%;
  background-color: var(--bg-color);
  color: var(--text-color);
  transition: background-color 0.3s, color 0.3s;
  overflow-x: hidden;
}

/* Shared frame style (used by heatmapContainer and outputContainer) */
.frame {
    width: 1024px;
    height: 1024px;
    border: 1px solid var(--border-color);
    background-color: #fff; /* Default background */
    position: relative; /* Needed for absolute positioning of children */
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); /* Add subtle shadow */
    border-radius: 4px; /* Slightly rounded corners */
}


/* Flat header */
.header {
  width: 100%;
  background-color: var(--bg-color);
  display: flex;
  justify-content: flex-end; /* Align items (title, switch) to the right */
  align-items: center;
  padding: 10px 20px;
}
.header h1 {
  margin: 0 20px 0 0; /* Add margin to the right of the title */
  font-size: 1.2em;
  text-transform: lowercase;
  color: var(--text-color);
  order: 1; /* Place title before theme switch */
}

/* Theme Switcher Toggle */
.theme-switch {
  width: 64px;
  height: 30px;
  z-index: 11000;
  flex-shrink: 0; /* Prevent shrinking */
  order: 2; /* Place theme switch after title */
}
.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: relative;
  background-color: var(--border-color);
  border-radius: 15px;
  cursor: pointer;
  width: 100%;
  height: 100%;
  transition: background-color 0.3s;
}
.slider:before {
  content: '\2600'; /* Sun icon */
  font-family: var(--body-font); /* Ensure icon font loads if needed */
  position: absolute;
  height: 24px;
  width: 24px;
  left: 3px;
  top: 3px;
  background-color: var(--button-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--button-text);
  font-size: 16px;
  transition: transform 0.3s, background-color 0.3s, color 0.3s, content 0.3s;
}
/* Style for the sun icon when checked (dark mode) */
.dark-theme .slider:before {
     background-color: var(--button-bg); /* Use dark theme button color */
     color: var(--button-text);
}
.theme-switch input:checked + .slider:before {
  transform: translateX(32px);
  content: '\263E'; /* Moon icon */
}


/* --- Control Panel Styling --- */
.control-panel {
    position: fixed;
    top: 80px;
    right: 20px; /* Adjust spacing from edge */
    width: 320px; /* Fixed width for the panel */
    background: var(--dropdown-bg);
    color: var(--dropdown-text);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 15px;
    z-index: 1001; /* Ensure it's above main content but below overlay */
    display: flex;
    flex-direction: column;
    gap: 12px; /* Space between control groups */
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    user-select: none; /* Prevent text selection during dragging */
}

/* Allow text selection in input fields */
.control-panel textarea,
.control-panel input[type="text"],
.control-panel input[type="number"] {
    user-select: text;
}

/* Drag handle for the control panel */
.panel-drag-handle {
    cursor: move;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: -15px -15px 10px -15px; /* Negative margin to align with panel edges */
    padding: 8px 15px;
    background-color: rgba(0,0,0,0.05);
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    border-bottom: 1px solid var(--border-color);
}

.dark-theme .panel-drag-handle {
    background-color: rgba(255,255,255,0.05);
}

.panel-drag-handle span {
    font-size: 0.9em;
    font-weight: bold;
    opacity: 0.8;
}

.panel-close-button {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-color);
    opacity: 0.5;
    transition: opacity 0.2s;
}

.panel-close-button:hover {
    opacity: 1;
}

.control-group {
    display: flex;
    flex-direction: column; /* Stack label and input/select */
    gap: 4px; /* Space between label and control */
}

.control-group label {
    font-size: 0.9em;
    font-weight: bold;
    white-space: nowrap;
}

.control-group select,
.control-group input[type="number"],
.control-group input[type="range"],
.control-group textarea {
    width: 100%; /* Make controls fill the width */
    background: var(--dropdown-bg) !important;
    color: var(--dropdown-text) !important;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 5px 8px; /* Consistent padding */
    box-sizing: border-box;
    font-size: 0.9em;
    font-family: var(--body-font); /* Inherit font */
    -webkit-appearance: none; /* Remove browser styling */
    -moz-appearance: none;
    appearance: none;
}
.control-group textarea {
    resize: vertical;
    min-height: 60px; /* Minimum height for prompt */
}

/* Textarea with label container */
.textarea-with-label {
    position: relative;
}

.textarea-label {
    position: absolute;
    top: 6px;
    left: 8px;
    color: var(--text-color);
    opacity: 0.75;
    font-size: 9px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: var(--body-font);
    background: var(--dropdown-bg);
    padding: 0 4px;
    z-index: 1;
    pointer-events: none;
}

/* Adjust textarea padding to accommodate label */
.textarea-with-label textarea {
    padding-top: 20px !important;
}

/* Also add label styling for textarea-with-button */
.textarea-with-button .textarea-label {
    position: absolute;
    top: 6px;
    left: 8px;
    color: var(--text-color);
    opacity: 0.75;
    font-size: 9px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: var(--body-font);
    background: var(--dropdown-bg);
    padding: 0 4px;
    z-index: 1;
    pointer-events: none;
}

.textarea-with-button textarea {
    padding-top: 20px !important;
}

/* Ensure disabled textarea is still readable */
.control-group textarea:disabled {
    color: var(--text-color);
    background-color: rgba(0,0,0,0.03);
    cursor: not-allowed;
}

.dark-theme .control-group textarea:disabled {
    background-color: rgba(255,255,255,0.05);
}

.control-inline-group {
    display: flex;
    align-items: center;
    gap: 8px; /* Space between inline elements */
    flex-wrap: wrap; /* Allow wrapping if needed */
}
.control-inline-group label {
    font-weight: normal; /* Normal weight for inline labels */
    cursor: pointer;
}

/* Override general checkbox styling for custom checkboxes */
.control-inline-group .custom-checkbox {
    transform: none; /* Remove scale transform */
    margin-right: 8px; /* Consistent spacing */
}

.control-inline-group input[type="checkbox"]:not(.custom-checkbox) {
    cursor: pointer;
    transform: scale(1.2); /* Slightly larger checkbox for non-custom ones */
    margin-right: 2px; /* Space after checkbox */
}

/* Style for disabled checkbox and label to provide visual feedback */
.control-inline-group input[type="checkbox"]:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.control-inline-group input[type="checkbox"]:disabled + label {
    opacity: 0.7;
    cursor: not-allowed;
    font-style: italic;
}

/* Custom circular checkboxes */
.custom-checkbox {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background-color: transparent;
    cursor: pointer;
    margin-right: 8px;
    position: relative;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.custom-checkbox:hover {
    border-color: var(--button-bg);
}

.custom-checkbox:checked {
    background-color: var(--button-bg);
    border-color: var(--button-bg);
}

.custom-checkbox:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(16,163,127,0.4);
}

.custom-checkbox:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.custom-checkbox:disabled:hover {
    border-color: var(--border-color);
}

/* Specific layout for delay controls */
.delay-controls {
    display: flex;
    align-items: center;
    gap: 5px; /* Adjust gap */
    width: 100%; /* Take full width */
    justify-content: flex-start; /* Align items to the start */
    flex-wrap: nowrap; /* Keep everything on one line */
}

/* Custom range slider styling */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    opacity: 0.8;
    transition: opacity 0.2s;
}

input[type="range"]:hover {
    opacity: 1;
}

/* Slider thumb for webkit browsers */
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--button-bg);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--button-hover-bg);
    transform: scale(1.1);
}

/* Slider thumb for Firefox */
input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--button-bg);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: background 0.2s, transform 0.2s;
}

input[type="range"]::-moz-range-thumb:hover {
    background: var(--button-hover-bg);
    transform: scale(1.1);
}

/* Disabled state for range slider */
input[type="range"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

input[type="range"]:disabled::-webkit-slider-thumb {
    background: var(--border-color);
    cursor: not-allowed;
}

input[type="range"]:disabled::-moz-range-thumb {
    background: var(--border-color);
    cursor: not-allowed;
}

/* Image controls with upload button */
.image-control-group {
    display: flex;
    gap: 8px;
    width: 100%;
    align-items: center;
}

.image-control-group select {
    flex-grow: 1;
}

.small-button {
    padding: 5px 10px;
    background-color: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85em;
    white-space: nowrap;
}

.small-button:hover {
    background-color: var(--button-hover-bg);
}

.discrete-button {
    padding: 3px 8px;
    background-color: var(--border-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75em;
    opacity: 0.7;
    transition: opacity 0.2s;
    white-space: nowrap;
}

.discrete-button:hover {
    opacity: 1;
}

.textarea-with-button {
    position: relative;
    display: block;
}

.textarea-button {
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: 24px;
    height: 24px;
    padding: 0;
    background-color: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: opacity 0.2s;
    z-index: 1;
}

.textarea-button:hover {
    opacity: 1;
}

.textarea-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.textarea-button-top-right {
    position: absolute;
    right: 6px;
    top: 6px;
    width: 24px;
    height: 24px;
    background: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: opacity 0.2s, background-color 0.2s;
    z-index: 1;
}

.textarea-button-top-right:hover {
    opacity: 1;
    background: var(--button-hover-bg);
}

.textarea-button-top-right:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Dropdown with integrated label - unified box with vertical divider */
.dropdown-with-label {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--dropdown-bg);
    overflow: hidden;
}

.dropdown-label {
    flex-shrink: 0;
    padding: 6px 8px;
    font-size: 9px;
    color: var(--text-color);
    font-weight: 500;
    width: 100px;
    text-align: center;
    border-right: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.02);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dark-theme .dropdown-label {
    background: rgba(255, 255, 255, 0.05);
}

.dropdown-with-label select,
.dropdown-with-label input[type="number"] {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent !important;
    color: var(--dropdown-text) !important;
    font-size: 14px;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Style for long prompt options */
.dropdown-with-label select option {
    white-space: normal;
    word-wrap: break-word;
    padding: 8px;
    line-height: 1.4;
    max-width: 300px;
}

/* Help button and panel */
.help-container {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
}

.help-button {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: var(--button-bg);
    color: var(--button-text);
    font-weight: bold;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.help-button:hover {
    background-color: var(--button-hover-bg);
}

.help-panel {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--dropdown-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    font-size: 0.9em;
    width: 500px;
    max-width: 90vw;
    max-height: 80vh;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 10020;
}

.help-panel.visible {
    display: block;
}

.help-panel h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--button-bg);
    font-size: 1.1em;
}

.help-content {
    max-height: 400px;
    overflow-y: auto;
}

/* Add spacing between settings items */
.help-content .control-inline-group {
    margin-bottom: 12px;
}

.help-content .control-inline-group:last-child {
    margin-bottom: 0;
}

.help-content p {
    margin: 8px 0;
}

.help-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.help-content li {
    margin-bottom: 5px;
}

/* Close button for help panels */
.help-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 30px;
    height: 30px;
    border: none;
    background-color: var(--border-color);
    color: var(--text-color);
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s, background-color 0.2s;
}

.help-close-btn:hover {
    opacity: 1;
    background-color: var(--button-bg);
    color: var(--button-text);
}
.delay-controls label { /* "Delay (sec):" */
    white-space: nowrap;
    flex-shrink: 0; /* Prevent label from shrinking */
}
.delay-controls span { /* Delay value */
    font-size: 0.9em;
    min-width: 20px; /* Ensure space for value */
    text-align: right;
    font-weight: bold;
    flex-shrink: 0;
    margin-left: 2px; /* Small space after label */
    margin-right: 5px; /* Space before slider */
}
.delay-controls input[type="range"] { /* Slider */
    flex-grow: 1; /* Allow slider to take remaining space */
    min-width: 80px;
    width: auto; /* Override default width: 100% */
}


/* Hide original individual selectors if they exist in HTML */
#heatmapStyleSelector,
#feedbackModeContainer,
#workflowSelector,
#imageSelector,
#stepsContainer,
#promptContainer {
    display: none; /* Hide the original separate divs if they are still in HTML */
}

/* Container */
.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  align-items: center;
  position: relative; /* For absolute positioning of children */
  width: 100%;
}

/* Main content area - now draggable */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  width: 100%;
  /* Removed margin-top, positioning handled by flex */
  position: relative; /* For absolute positioning of children */
}

#draggableContent {
  position: absolute; /* Remove from document flow to enable dragging */
  top: 0px; /* Initial position */
  left: 50%;
  transform: translateX(-50%); /* Center horizontally */
  padding: 0; /* Removed padding */
  background-color: transparent; /* Transparent background */
  /* Removed border radius */
  box-shadow: none; /* Removed shadow */
  border: none; /* Removed border */
  max-width: 2300px;
  z-index: 900; /* Below control panel but above other content */
  user-select: none; /* Prevent text selection during dragging */
}

.dark-theme #draggableContent {
  box-shadow: none; /* Removed shadow in dark theme */
}

/* Drag handle for the content area */
.content-drag-handle {
  cursor: move;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 5px;
  margin: 0 0 10px 0; /* Adjusted margin since parent padding is gone */
  background-color: rgba(0,0,0,0.05);
  border-radius: 4px; /* Rounded corners */
  border: none; /* No border */
}

.dark-theme .content-drag-handle {
  background-color: rgba(255,255,255,0.05);
}

.content-drag-handle span {
  letter-spacing: 3px;
  font-weight: bold;
  opacity: 0.5;
  padding: 0 10px;
  font-size: 12px;
}

.content-drag-handle:hover span {
  opacity: 0.8;
}

/* Controls */
.controls {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}
.controls button {
  padding: 10px 20px;
  border: none;
  background-color: var(--button-bg);
  color: var(--button-text);
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s, color 0.3s;
  min-width: 180px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.controls button:hover:not(:disabled) {
  background-color: var(--button-hover-bg);
}
.controls button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

/* Main Content Layout */
.main-content {
  display: flex !important;
  flex-direction: row !important;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
  max-width: 2200px; /* Allow space for two 1024px frames side by side */
  margin-top: 30px; /* Add some space below header/controls */
}

/* Heatmap Container */
#heatmapContainer {
  /* Uses .frame style for dimensions/border */
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: transparent; /* Default background when no image */
  transition: background-color 0.3s;
  overflow: hidden; /* Needed for panning */
}

/* Heatmap Overlay Styles */
#heatmapOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Allow clicks/drags to go through to the image */
    z-index: 10; /* Ensure heatmap is visually on top of the image */
}
/* Ensure heatmap canvas itself is also transparent to clicks */
#heatmapOverlay .heatmap-canvas {
    pointer-events: none;
}

/* Outputs */
.outputs {
  position: relative; /* Needed for spinner positioning */
  max-width: 1024px;
  width: 100%;
  text-align: center;
}
.output-box {
  width: 100%;
  margin-bottom: 20px;
  text-align: center;
}
.output-box img {
  width: 100%;
  max-width: 1024px; /* Match native generated image size */
  height: auto; /* Maintain aspect ratio */
  border: 1px solid var(--border-color);
  border-radius: 5px;
  transition: border-color 0.3s;
}
.output-box button {
  margin-top: 10px;
  padding: 8px 16px;
  border: none;
  background-color: var(--button-bg);
  color: var(--button-text);
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s, color 0.3s;
}
.output-box button:hover {
  background-color: var(--button-hover-bg);
}

/* Loading Spinner */
#loadingSpinner {
  position: absolute;
  top: 45%; /* Adjust vertical position */
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  display: none; /* Initially hidden */
}
.spinner {
  border: 4px solid rgba(0, 0, 0, 0.1);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border-left-color: var(--button-bg);
  animation: spin 1s linear infinite;
  transition: border-left-color 0.3s;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Error Message */
.error {
  color: #d93025;
  margin: 10px 0; /* Adjusted margin */
  text-align: center;
  width: 100%;
  font-weight: bold;
  display: none; /* Initially hidden */
}

/* Footer */
.footer {
  background-color: var(--footer-bg);
  padding: 10px 20px;
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: #999;
  transition: background-color 0.3s, color 0.3s;
  margin-top: auto; /* Push footer to bottom */
}

/* Overlay */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: none; /* Initially hidden */
  justify-content: center;
  align-items: center;
  z-index: 10010; /* Ensure overlay is on top of most content */
}
.guide-content {
  background-color: var(--header-bg);
  padding: 30px; /* Increased padding */
  border-radius: 10px;
  max-width: 600px;
  width: 90%;
  text-align: center;
  color: var(--text-color);
  position: relative;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.guide-content h2 {
  margin-top: 0;
  margin-bottom: 15px; /* Space below heading */
  color: var(--button-bg); /* Use accent color */
}
.guide-content p {
    line-height: 1.6; /* Improve readability */
    margin-bottom: 10px;
}
.guide-content button {
  margin-top: 20px;
  padding: 12px 25px; /* Larger button */
  border: none;
  background-color: var(--button-bg);
  color: var(--button-text);
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s, color 0.3s;
  margin-right: 10px; /* Add spacing between buttons */
}
.guide-content button:last-child {
  margin-right: 0; /* Remove margin from last button */
}
.guide-content button:hover {
  background-color: var(--button-hover-bg);
}

/* WebGazer Overlays */
#webgazerVideoContainer,
#webgazerFaceOverlay,
#webgazerFaceFeedbackBox {
  position: fixed !important; /* Keep fixed positioning */
  z-index: 10001 !important; /* Keep high z-index */
  /* Let WebGazer use its default top/left/transform */
}

/* Loading/Error message style inside container */
.message {
    display: none; /* Initially hidden */
    flex-direction: column; /* Stack message and details */
    justify-content: center;
    align-items: center;
    text-align: center;
    height: 100%;
    padding: 20px;
    color: var(--text-color);
    font-size: 1.1em;
    line-height: 1.5;
    position: absolute; /* Position over the container */
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.8); /* Semi-transparent background */
    z-index: 5; /* Below heatmap overlay but above image */
}
.dark-theme .message { /* Adjust message background for dark theme */
    background: rgba(30, 30, 30, 0.8);
    color: #ccc;
}
.error-message {
    color: #d93025;
    font-weight: bold;
}
.dark-theme .error-message {
     color: #ff8a80; /* Lighter red for dark theme */
}

.message small {
    margin-top: 10px;
    font-size: 0.85em;
    color: #777;
}
.dark-theme .message small {
    color: #aaa;
}

/* Roam mode layout swap - use order property for consistent behavior */
body.tracking-mode-roam #heatmapContainer {
    order: 2;
}
body.tracking-mode-roam .composite-wrapper {
    order: 1;
}

/* Responsive adjustments - stack vertically only on small screens */
@media (max-width: 800px) {
    .main-content {
        flex-direction: column !important;
        align-items: center;
    }
    .control-panel {
        position: relative;
        top: auto;
        right: auto;
        width: 90%;
        max-width: 600px;
        margin: 20px auto;
    }
}

@media (max-width: 1200px) {
    .frame {
        width: 90%; /* Make frames responsive */
        max-width: 1024px; /* Keep native resolution when possible */
        height: auto; /* Adjust height automatically */
        aspect-ratio: 1 / 1; /* Maintain square aspect ratio */
    }
    .outputs {
        max-width: 100%; /* Allow output to take full width */
    }
}

@media (max-width: 1100px) {
    .frame {
        width: 95%;
        max-width: 900px;
    }
}

@media (max-width: 950px) {
    .frame {
        width: 95%;
        max-width: 700px;
    }
}

@media (max-width: 600px) {
    .header h1 {
        font-size: 1em;
    }
    .controls button {
        font-size: 14px;
        padding: 8px 15px;
    }
    .guide-content {
        padding: 20px;
    }
    .guide-content h2 {
        font-size: 1.2em;
    }
    .guide-content button {
        padding: 10px 20px;
        font-size: 14px;
    }
    /* Optionally hide WebGazer UI on very small screens if it's too obtrusive */
    /*
    #webgazerVideoContainer,
    #webgazerFaceOverlay,
    #webgazerFaceFeedbackBox {
        display: none !important;
    }
    */
}

/* ————————————— Composite Preview ————————————— */

/* Remove hardcoded dimensions - inherits from .frame class */
#compositeContainer {
  position: relative;
  overflow: hidden;
  background-color: transparent;
  cursor: grab;
}
#compositeContainer:active {
  cursor: grabbing;
}

/* image is positioned absolutely at top-left, hidden until loaded */
#compositeImage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  display: none;
  width: auto !important;
  height: auto !important;
}

/* Rainbow border class */
.rainbow-border {
  border: 4px solid #D0FE1D !important;
  border-image: linear-gradient(45deg, red, orange, yellow, green, blue, indigo, violet) 1 !important;
}

/* Basic crop box styles */
#cropBox {
  border: 4px solid #D0FE1D;
  border-image: linear-gradient(45deg, red, orange, yellow, green, blue, indigo, violet) 1;
  z-index: 1000;
}

/* Red border when being dragged */
#cropBox.active {
  border: 4px solid #ff0000 !important;
  border-image: none !important;
}

/* centered spinner on top of container, hidden by default */
#compositeSpinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  display: none;
}

/* ————— Download Button Wrapper & Styling ————— */

/* stack the preview + button vertically, center aligned */
.composite-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* center the button below the frame with matching spacing */
.download-controls {
  display: flex;
  justify-content: center;
  margin: 20px 0;
  width: 100%;
}

/* match other control-buttons’ look & feel */
.download-controls button {
  margin-top: 10px;             /* same as .output-box */
  padding: 8px 16px;
  border: none;
  background-color: var(--button-bg);
  color: var(--button-text);
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s, color 0.3s;
}
.download-controls button:hover:not(:disabled) {
  background-color: var(--button-hover-bg);
}
.download-controls button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

/* --------------------------------------- */
/* Download button: hidden → fade‑in state */
/* --------------------------------------- */
#downloadBtn {               /* default – hidden */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;    /* no hover or clicks */
    transition: opacity .25s ease;
}
#downloadBtn.visible {       /* added by JS when ready */
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ------------------------------------------ */
/* COM Button styling                         */
/* ------------------------------------------ */
.control-button {
    padding: 6px 12px;
    border: none;
    background-color: var(--button-bg);
    color: var(--button-text);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background-color 0.3s, opacity 0.3s;
    white-space: nowrap;
}

.control-button:hover:not(:disabled) {
    background-color: var(--button-hover-bg);
}

.control-button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

/* ------------------------------------------ */
/* Delay slider & value: inactive appearance  */
/* ------------------------------------------ */
.delay-controls.disabled label[for="iterativeDelaySlider"],
.delay-controls.disabled #iterativeDelayValue,
.delay-controls.disabled #iterativeDelaySlider {
    opacity: .45;            /* grey‑out delay elements only */
    pointer-events: none;    /* ignore hovers/clicks */
}

.delay-controls input[type="range"]:disabled {
    cursor: not-allowed;     /* show “blocked” cursor */
}

/* Panel brand—bottom-right watermark */
.control-panel {
  display: flex;
  flex-direction: column;
  /* …your other rules (padding, gap, etc.)… */
}

.control-panel .panel-brand {
  /* push to bottom */
  margin-top: auto;
  align-self: flex-end;        /* right-align in the column */
  
  /* typography */
  font-size: 0.75em;
  font-weight: bold;           /* make it bold */
  text-transform: uppercase;        /* keep lowercase */
  
  /* subtle styling */
  color: var(--dropdown-text);
  opacity: 0.7;
  
  /* no pointer interaction */
  pointer-events: none;
}

/* Toggle Switches (Calibration-Cache and Fit-Composite) */
.control-inline-group .cache-switch,
.control-inline-group .fit-switch {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  font-size: 0.9em;
}

.cache-switch input,
.fit-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.cache-switch .slider {
  position: relative;
  width: 40px;
  height: 20px;
  background-color: var(--border-color);
  border-radius: 10px;
  margin-right: 8px;
  transition: background-color 0.2s;
}

.cache-switch .slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background-color: var(--button-bg);
  border-radius: 50%;
  transition: transform 0.2s;
}

/* Fit switch - pill style */
.fit-switch .slider {
  position: relative;
  width: 50px;
  height: 20px;
  background-color: #e0e0e0;
  border-radius: 10px;
  margin: 0 4px;
  transition: background-color 0.2s;
}

.fit-switch .slider::before {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  top: -2px;
  background-color: var(--button-bg);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  z-index: 1;
  transition: transform 0.3s ease;
}

/* Fit toggle positions */
.fit-switch input:not(:checked) + .slider::before {
  transform: translateX(2px);
}

.fit-switch input:checked + .slider::before {
  transform: translateX(24px);
}

/* Checked state for cache switch */
.cache-switch input:checked + .slider {
  background-color: var(--button-bg);
}

.cache-switch input:checked + .slider::before {
  transform: translateX(20px);
}

/* Optional focus ring */
.cache-switch input:focus + .slider,
.fit-switch input:focus + .slider {
  box-shadow: 0 0 0 2px rgba(16,163,127,0.4);
}

/* Disabled state */
.fit-switch.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.fit-toggle-container.disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Fit toggle container and labels */
.fit-toggle-container {
  display: flex;
  align-items: center;
  margin-left: 10px;
  position: relative;
}

.toggle-label {
  font-size: 0.8em;
  color: var(--text-color);
  opacity: 0.75;
  white-space: nowrap;
  font-weight: 500;
  transition: all 0.3s ease;
  user-select: none;
}

.toggle-label.left {
  margin-right: 0;
  padding-right: 4px;
}

.toggle-label.right {
  margin-left: 0;
  padding-left: 4px;
}

/* Style for the active toggle side */
input:not(:checked) ~ .toggle-label.left,
input:checked ~ .toggle-label.right {
  opacity: 1;
  font-weight: bold;
  color: var(--button-bg);
}

/* Dark theme adjustments */
.dark-theme .fit-switch .slider {
  background-color: #474747;
}


.calibration-marker {
  width: 22px;
  height: 22px;
  background: #10a37f;
  border-radius: 50%;
  position: fixed;
  z-index: 10020; /* Higher than both overlay (10010) and WebGazer (10001) */
  cursor: pointer;
  outline: none; /*1px solid #dfff00; /* Thin lime-yellow outline */

  /* slide between positions */
  transition: top 0.4s ease, left 0.4s ease;
}

@keyframes pulse {
  from { transform: scale(1); }
  to   { transform: scale(1.2); }
}

/* hide preview boxes until after calibration */
#stage,
#compositeContainer,
/* #heatmapContainer {    /* ← add this */
  display: none;
}