* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
}

body {
    background-color: #f5f5f5;
    min-height: 100vh;
    position: relative;
}

.container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    text-align: center;
    margin-bottom: 30px;
}

.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    margin-left: -10px;
    margin-right: -10px;
}

.form-column {
    flex: 1;
    padding: 0 10px;
    min-width: 200px; /* Ensure columns don't get too narrow */
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

input, select, textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 16px;
}

.helper-text {
    font-size: 14px;
    color: #666;
    margin-top: 5px;
    font-style: italic;
}

.stimulus-group {
    position: relative;
}

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

.checkbox-container input[type="checkbox"] {
    width: auto;
    margin-right: 10px;
}

.checkbox-container label {
    display: inline;
    font-weight: normal;
}

.checkbox-helper {
    margin-top: 0;
}

button {
    padding: 12px 24px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    display: block;
    margin: 20px auto;
    min-width: 150px;
}

button:hover {
    background-color: #45a049;
}

/* Secondary button style */
.secondary-btn {
    background-color: #2196F3;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin: 10px 0;
    min-width: 0;
    display: inline-block;
}

.secondary-btn:hover {
    background-color: #0b7dda;
}

/* Danger button style */
.danger-btn {
    background-color: #f44336;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin: 10px 0;
    min-width: 0;
    display: inline-block;
}

.danger-btn:hover {
    background-color: #d32f2f;
}

/* Modal styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: white;
    padding: 20px;
    border-radius: 5px;
    width: 80%;
    max-width: 90%;
    max-height: 80vh;
    overflow: auto;
    resize: both; /* Enable resizing */
    min-width: 600px;
    min-height: 300px;
    position: relative;
}

/* Add resize handle visual cue */
.modal-content::after {
    content: "";
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 12px;
    height: 12px;
    background: #ccc;
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
    cursor: se-resize;
}

.close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

close-btn:hover,
.close-btn:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

/* Mapping table styles */
.mapping-table-container {
    margin: 20px 0;
    max-height: 300px;
    overflow: auto; /* Changed from overflow-y to handle both directions */
    width: 100%;
}

#mapping-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    table-layout: fixed; /* Fixed layout for better column control */
}

#mapping-table th,
#mapping-table td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
    min-width: 80px; /* Ensure columns don't get too narrow */
    overflow: hidden;
    text-overflow: ellipsis;
}

#mapping-table th {
    background-color: #f2f2f2;
    position: sticky;
    top: 0;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px; /* Limit width of headers */
}

/* Add hover effect to show full header text */
#mapping-table th:hover {
    overflow: visible;
    white-space: normal;
    z-index: 1;
    background-color: #e0e0e0;
}

#mapping-table input {
    width: 100%;
    padding: 5px;
    box-sizing: border-box;
}

/* Experiment container styles */
#experiment-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background-color: black;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* Experiment screen styles */
#experiment-screen {
    width: 800px;
    height: 600px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: grey; /* Default, will be overwritten by JS */
    position: relative;
}

#fixation-point {
    font-size: 48px;
    font-weight: bold;
    position: absolute;
    z-index: 1;
    color: white; /* Default, will be overwritten by JS */
}

#stimulus-text {
    font-family: Consolas, monospace;
    position: absolute;
    z-index: 1;
    text-align: center;
    max-width: 80%;
    overflow-wrap: break-word;
    /* font-size and color set dynamically in JS */
}

/* For the fixation point and stimulus text elements to enable relative positioning */
#fixation-point, #stimulus-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(0, 0); /* Will be overridden by JS */
}

/* Position fixation point and stimulus text at center by default */
#fixation-point, #stimulus-text, #feedback-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%); /* Center by default */
}

/* Feedback text styles */
#feedback-text {
    font-family: Arial, sans-serif;
    font-size: 36px;
    font-weight: bold;
    position: absolute;
    z-index: 2; /* Ensure feedback appears on top */
    text-align: center;
    max-width: 80%;
    padding: 10px 20px;
    border-radius: 8px;
    background-color: rgb(255, 255, 255); /* Changed from rgba to rgb for full opacity */
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

/* Concurrent stimulus styles */
.concurrent-stimulus {
    font-family: Consolas, monospace;
    position: absolute;
    z-index: 1;
    text-align: center;
    max-width: 80%;
    overflow-wrap: break-word;
}

/* Completion screen styles */
#completion-screen {
    text-align: center;
    position: relative;
    z-index: 20;
}

#completion-screen h2 {
    margin-bottom: 20px;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Media queries for better responsiveness */
@media (max-width: 840px) {
    #experiment-screen {
        width: 90%;
        height: 70vh;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 10px;
    }

    input, select {
        padding: 8px;
    }

    button {
        padding: 10px 20px;
    }
}

/* Color preview styles */
.color-preview {
    display: inline-block;
    width: 15px;
    height: 15px;
    border: 1px solid #666;
    border-radius: 3px;
    margin-right: 5px;
    vertical-align: middle;
}

/* Color select container */
.color-select-container {
    position: relative;
    display: flex;
    align-items: center;
}

.color-select-container select {
    padding-right: 25px;
}

.color-preview-large {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 1px solid #999;
    border-radius: 3px;
    position: absolute;
    right: 5px;
    pointer-events: none;
}

/* Button group for the mapping modal */
.button-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.button-group button {
    margin: 0;
}

/* Button row for stimulus controls */
.button-row {
    display: flex;
    gap: 10px;
    margin: 10px 0;
}

/* Sequence builder styles */
#sequence-builder-container {
    display: flex;
    gap: 20px;
    margin: 15px 0;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    background-color: #f9f9f9;
}

#available-variables {
    flex: 1;
    min-width: 200px;
    max-width: 300px;
}

#sequence-builder {
    flex: 2;
}

.variable-list-container {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    background-color: white;
    margin-bottom: 10px;
}

.variable-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.variable-buttons button {
    flex: 1;
    margin: 0;
}

.variable-category-item {
    cursor: pointer;
}

.variable-category-item:hover {
    background-color: #f0f0f0;
}

.primary-btn {
    background-color: #4CAF50;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin: 10px 0;
    min-width: 0;
    display: inline-block;
    width: 100%;
}

.primary-btn:hover {
    background-color: #45a049;
}

/* Variable definition modal styles */
.variable-categories-container {
    display: flex;
    gap: 20px;
    margin: 20px 0;
}

/* Study management modal styles */
.saved-items-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    margin: 15px 0;
    background-color: #f9f9f9;
}

.saved-study-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}

.saved-study-item:hover {
    background-color: #f0f0f0;
}

.saved-study-item:last-child {
    border-bottom: none;
}

.saved-study-info {
    flex: 1;
}

.saved-study-name {
    font-weight: bold;
    margin-bottom: 5px;
}

.saved-study-date {
    font-size: 12px;
    color: #666;
}

.saved-study-actions {
    display: flex;
    gap: 5px;
}

.saved-study-actions button {
    padding: 5px 10px;
    margin: 0;
    min-width: 0;
    font-size: 12px;
}

.no-studies-message {
    text-align: center;
    padding: 20px;
    color: #666;
    font-style: italic;
}

#save-study-section, #load-study-section {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

#load-study-section {
    border-bottom: none;
}

/* Custom dialog styles */
.custom-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.dialog-content {
    background-color: white;
    padding: 20px;
    border-radius: 5px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.dialog-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.dialog-content select {
    width: 100%;
    padding: 8px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.variable-list, .variable-values {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    background-color: #f9f9f9;
    min-height: 200px;
}

.variable-values h3 {
    margin-bottom: 15px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 10px;
}

#variable-selection-mode {
    margin-bottom: 15px;
    padding: 10px;
    background-color: #f5f5f5;
    border-radius: 4px;
    display: flex;
    align-items: center;
}

#variable-selection-mode label {
    margin-right: 10px;
    font-weight: bold;
}

#variable-mode-select {
    flex-grow: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
}

.variable-category-item, .variable-value-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    margin-bottom: 5px;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.variable-category-item.selected {
    background-color: #e3f2fd;
    border-color: #2196F3;
}

.add-variable-container, .add-value-container, .variable-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.variable-actions {
    justify-content: space-between;
}

.add-variable-container input, .add-value-container input {
    flex: 1;
}

.add-variable-container button, .add-value-container button {
    margin: 0;
}

.variable-action-buttons {
    display: flex;
    gap: 5px;
}

.variable-action-buttons button {
    padding: 3px 8px;
    min-width: auto;
    margin: 0;
    font-size: 12px;
}

/* Adjust size and appearance of secondary buttons in the group */
.button-group .secondary-btn {
    flex: 1;
    padding: 10px;
    font-size: 14px;
    text-align: center;
    min-width: 120px;
}

/* Make primary button more prominent */
.button-group #save-mappings-btn {
    flex: 1.5;
}

.split-container {
    display: flex;
    width: 100%;
    gap: 20px;
}

.left-panel {
    flex: 1;
    min-width: 600px;
}

.right-panel {
    width: 300px;
    border-left: 1px solid #ccc;
    padding-left: 20px;
}

#study-window {
    max-height: 400px;
    min-height: 200px; /* Add minimum height */
    height: 400px; /* Add default height */
    overflow-y: auto;
    width: 100%;
    min-width: 600px;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin: 20px 0;
    background: #f9f9f9;
    resize: vertical; /* Allow vertical resizing */
    position: relative; /* Required for resize handle positioning */
}

/* Add resize handle visual cue */
#study-window::after {
    content: "";
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 12px;
    height: 12px;
    background: #ccc;
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
    cursor: ns-resize;
}

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

#add-to-study-btn {
    background-color: #4CAF50;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

#add-to-study-btn:hover {
    background-color: #45a049;
}

.study-buttons-container {
    width: 100%;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#begin-study-btn {
    width: 100%;
    background-color: #2196F3;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

#begin-study-btn:hover {
    background-color: #0b7dda;
}

.study-file-buttons {
    display: flex;
    gap: 10px;
    width: 100%;
}

#save-study-btn, #load-study-btn {
    flex: 1;
    background-color: #607D8B;
    color: white;
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}

#save-study-btn:hover, #load-study-btn:hover {
    background-color: #455A64;
}

.study-config-item {
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 8px;
    padding: 15px;
    width: 100%;
    min-width: 600px; /* Increased from 400px */
}

.study-config-item:hover {
    background: #f0f0f0;
}

.config-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    width: 100%;
}

.block-name-input {
    border: 1px solid #ddd;
    background: #ffffff;
    font-size: 16px;
    width: 300px; /* Fixed width instead of percentage */
    padding: 8px 12px;
    margin-right: 10px;
    border-radius: 4px;
    cursor: text;
    display: block; /* Ensure it's a block element */
    position: relative; /* Ensure it's above other elements */
    z-index: 1; /* Ensure it's clickable */
}

.block-name-input:hover {
    border-color: #2196F3;
    background: #fff;
}

.block-name-input:focus {
    border-color: #2196F3;
    background: #fff;
    outline: none;
    box-shadow: 0 0 5px rgba(33, 150, 243, 0.3);
}

.block-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.move-up-btn, .move-down-btn, .remove-config-btn {
    padding: 8px 12px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    min-width: 40px;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.move-up-btn:hover, .move-down-btn:hover {
    background: #e0e0e0;
    border-color: #ccc;
}

.remove-config-btn:hover {
    background: #ffebee;
    border-color: #ffcdd2;
    color: #d32f2f;
}

.config-details {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: #666;
    width: 100%;
    margin-top: 5px;
    gap: 4px;
}

.config-details small {
    display: inline-block;
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 3px;
    margin-right: 8px;
}

#completion-stats {
    margin: 20px 0;
    padding: 15px;
    background-color: #f5f5f5;
    border-radius: 4px;
    text-align: left;
}

#completion-message {
    color: #2196F3;
    margin-bottom: 20px;
}

.study-completion-stats {
    background-color: #f5f5f5;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    text-align: left;
}

.download-section {
    margin-top: 20px;
    text-align: center;
}

.download-btn {
    background-color: #4CAF50;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}

.download-btn:hover {
    background-color: #45a049;
}

/* Form Switch Styles */
.form-switch-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    gap: 10px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #2196F3;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: #4CAF50;
}

input:focus + .slider {
    box-shadow: 0 0 1px #4CAF50;
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

.switch-label {
    font-weight: bold;
    color: #666;
}

.survey-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
}

.survey-container .form-group {
    margin-bottom: 20px;
}

.survey-container textarea,
.survey-container input[type="text"] {
    width: 100%;
    max-width: 580px;
}

/* Question item styles */
.question-item {
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 20px;
    background-color: #f9f9f9;
}

/* Slider configuration styles */
.slider-config {
    margin: 10px 0;
}

.slider-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.slider-field {
    flex: 0 0 48%;
}

.slider-field label {
    display: block;
    margin-bottom: 5px;
    font-size: 14px;
}

.slider-field input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Slider display styles */
.slider-container {
    margin: 20px 0;
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 5px;
}

.slider-labels span {
    font-size: 14px;
    color: #666;
}

input[type="range"] {
    width: 100%;
    margin: 10px 0;
}

.slider-value-display {
    text-align: center;
    font-weight: bold;
    margin-top: 5px;
    font-size: 16px;
    color: #2196F3;
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.question-header h4 {
    margin: 0;
    color: #2196F3;
}

.remove-question-btn {
    background-color: #f44336;
    color: white;
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.remove-question-btn:hover {
    background-color: #d32f2f;
}

#add-question-btn {
    margin: 10px 0;
    background-color: #4CAF50;
}

.button-group {
    margin-top: 20px;
    padding: 10px;
    border-top: 1px solid #eee;
}

.stats-container {
    max-width: 400px;
    margin: 0 auto;
    padding: 15px;
}
