body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: Arial, sans-serif;
    background-color: #000;
    color: #fff;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
}

.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    flex-direction: row;
}

.screen.active {
    display: flex;
}

.eye-view {
    width: 50%;
    height: 100%;
    box-sizing: border-box;
    border: 1px solid #333;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    transform-origin: center center;
    transition: border-color 0.2s;
}

.calibrated-viewport {
    width: 60vh;
    height: 60vh;
    max-width: 85%;
    max-height: 85%;
    box-sizing: border-box;
    border: 1px dotted #00dd00;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform-origin: center center;
}

.content-wrapper {
    width: 100%;
    height: 100%;
    padding: 6px;
    margin: 0;
    overflow: auto;
    text-align: center;
    display: flex;
    flex-direction: column;
}

/* ========================================
   User Selection Screen
   ======================================== */
#user-selection-screen .content-wrapper {
    width: 100%;
}

.user-setup-header {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding-bottom: 2px;
    margin-bottom: 5px;
    border-bottom: 1px solid #444;
    flex-shrink: 0;
}
.user-setup-header h2 {
    font-size: 1.0em;
    margin: 0;
    text-align: center;
}

.user-controls {
    flex-shrink: 0;
    margin-bottom: 5px;
    width: 100%;
}
.user-controls label { display: block; margin-top: 2px; font-size: 0.7em;}

.scrollable-user-listbox {
    height: 60px;
    border: 1px solid #555;
    overflow-y: auto;
    background-color: #1a1a1a;
    text-align: left;
    padding: 2px;
    margin-bottom: 5px;
}
.scrollable-user-listbox-item {
    padding: 4px 6px;
    cursor: pointer;
    font-size: 0.75em;
    border-bottom: 1px solid #333;
    min-height: 22px;
    line-height: 22px;
}
.scrollable-user-listbox-item:last-child { border-bottom: none; }
.scrollable-user-listbox-item:hover { background-color: #333; }
.scrollable-user-listbox-item.selected { background-color: #0056b3; color: white; font-weight: bold; }

.user-action-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-bottom: 5px;
    flex-shrink: 0;
}
.user-action-buttons button {
    width: auto;
    min-width: 120px;
    max-width: 160px;
    padding: 6px 12px;
    box-sizing: border-box;
    font-size: 0.75em;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    min-height: 32px;
}
.user-controls button#btn-add-user-l,
.user-controls button#btn-add-user-r {
    background-color: #28a745;
    margin-top: 5px;
    width: auto;
    min-width: 120px;
    max-width: 160px;
    padding: 6px 12px;
    font-size: 0.75em;
    display: block;
    margin-left: auto;
    margin-right: auto;
    min-height: 32px;
    border-radius: 4px;
    border: none;
    color: white;
    cursor: pointer;
}
.user-action-buttons button:disabled,
.user-controls button#btn-add-user-l:disabled,
.user-controls button#btn-add-user-r:disabled {
    background-color: #aaa;
}

.user-form {
    margin-top: 5px;
    flex-shrink: 0;
    overflow-y: auto;
    max-height: calc(100% - 70px);
}
.user-form label { display: block; margin-top: 1px; font-size: 0.65em;}
.user-form input,
.user-form .dominant-eye-selector-group,
.user-form select, .user-form textarea, .user-form button {
    width: 100%;
    padding: 4px;
    margin-top: 1px;
    box-sizing: border-box;
    font-size: 0.7em;
}
.user-form .dominant-eye-selector-group {
    display: flex;
    gap: 5px;
    margin-bottom: 3px;
}
.user-form .dominant-eye-button {
    flex-grow: 1;
    padding: 4px 6px;
    font-size: 0.9em;
    background-color: #333;
    border: 1px solid #555;
    color: #ccc;
    cursor: pointer;
    min-height: 28px;
    border-radius: 3px;
}
.user-form .dominant-eye-button.active-dominant-eye {
    background-color: #007bff;
    color: white;
}

.user-form select[multiple] { height: 40px; }
.user-form button {
    margin-top: 3px;
    min-height: 30px;
    border-radius: 3px;
    cursor: pointer;
}

/* ========================================
   Calibration Screen
   ======================================== */
#calibration-screen .calibrated-viewport {
    border: 1px solid orange;
}

/* Active eye indicator */
.eye-view.active-eye {
    border-color: #00ccff;
    box-shadow: inset 0 0 15px rgba(0, 204, 255, 0.15);
}

/* Calibration wizard bar */
.calibration-wizard-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: linear-gradient(to bottom, rgba(20, 20, 40, 0.95), rgba(20, 20, 40, 0.85));
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.65em;
    border-bottom: 1px solid #444;
    flex-wrap: wrap;
    justify-content: center;
}

.wizard-steps {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
}

.wizard-step-btn {
    padding: 4px 10px;
    font-size: 1em;
    background-color: #333;
    border: 1px solid #555;
    color: #aaa;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 24px;
}
.wizard-step-btn.active {
    background-color: #007bff;
    color: white;
    border-color: #0056b3;
}
.wizard-step-btn:hover {
    background-color: #444;
}

.wizard-hint {
    color: #00ccff;
    flex: 1;
    text-align: center;
    min-width: 150px;
    font-size: 1em;
}

.keyboard-hint {
    color: #666;
    font-size: 0.85em;
    white-space: nowrap;
}

/* Session timer */
.session-timer {
    position: absolute;
    top: 4px;
    right: 10px;
    z-index: 210;
    background: rgba(0, 0, 0, 0.6);
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 0.65em;
    color: #888;
}
.session-timer span {
    color: #0f0;
    font-weight: bold;
}

/* Calibration top controls */
.calibration-top-controls-eye {
    width: 100%;
    background-color: rgba(30, 30, 30, 0.9);
    padding: 4px 6px;
    box-sizing: border-box;
    z-index: 105;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.7em;
    position: absolute;
    top: 0;
    left: 0;
}
.calibration-top-controls-eye h2 {
    margin: 0;
    font-size: 1.1em;
    color: #eee;
    white-space: nowrap;
}
.calibration-top-controls-eye .action-buttons {
    display: flex;
    gap: 3px;
}
.calibration-top-controls-eye .action-buttons button,
.cal-action-btn {
    padding: 4px 8px;
    background-color: #555;
    color: #fff;
    border: 1px solid #777;
    border-radius: 3px;
    cursor: pointer;
    margin-left: 2px;
    min-height: 26px;
    font-size: 0.9em;
}
.cal-action-btn.save-btn {
    background-color: #28a745;
    border-color: #218838;
}

/* Calibration controls panel - slider layout */
.calibration-controls-panel {
    position: absolute;
    top: 32px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 15, 25, 0.92);
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.6em;
    z-index: 10;
    width: 98%;
    box-sizing: border-box;
    text-align: center;
}

/* Slider row layout */
.cal-slider-row {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-bottom: 2px;
    padding: 1px 2px;
    border-radius: 3px;
    transition: background-color 0.3s, box-shadow 0.3s;
}

.cal-slider-row.wizard-highlight {
    background-color: rgba(0, 123, 255, 0.15);
    box-shadow: 0 0 4px rgba(0, 123, 255, 0.3);
}

.cal-slider-row label {
    min-width: 24px;
    text-align: right;
    font-size: 0.95em;
    color: #aaa;
    white-space: nowrap;
    flex-shrink: 0;
}

.cal-adj-btn {
    width: 22px;
    height: 22px;
    min-width: 22px;
    padding: 0;
    font-size: 1.1em;
    line-height: 20px;
    text-align: center;
    background-color: #444;
    color: #fff;
    border: 1px solid #666;
    border-radius: 3px;
    cursor: pointer;
    flex-shrink: 0;
}
.cal-adj-btn:hover {
    background-color: #555;
}
.cal-adj-btn:active {
    background-color: #007bff;
}

/* Range slider styling */
.cal-slider {
    flex: 1;
    min-width: 40px;
    height: 18px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

.cal-slider::-webkit-slider-runnable-track {
    height: 4px;
    background: linear-gradient(to right, #333, #555);
    border-radius: 2px;
}
.cal-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #00ccff;
    border: 1px solid #009;
    margin-top: -5px;
    cursor: grab;
}
.cal-slider::-webkit-slider-thumb:active {
    background: #fff;
    cursor: grabbing;
}
.cal-slider::-moz-range-track {
    height: 4px;
    background: linear-gradient(to right, #333, #555);
    border-radius: 2px;
    border: none;
}
.cal-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #00ccff;
    border: 1px solid #009;
    cursor: grab;
}

/* Numeric value input */
.cal-value-input {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    padding: 1px 2px;
    font-size: 0.95em;
    font-weight: bold;
    text-align: right;
    background-color: #1a1a2a;
    color: #0f0;
    border: 1px solid #444;
    border-radius: 3px;
    flex-shrink: 0;
    -moz-appearance: textfield;
}
.cal-value-input::-webkit-outer-spin-button,
.cal-value-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.cal-value-input:focus {
    outline: 1px solid #00ccff;
    background-color: #222;
}

.cal-unit {
    font-size: 0.85em;
    color: #888;
    margin-left: 1px;
}

/* Backward compat for old layout */
.control-row {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-bottom: 1px;
}
.control-group {
    display: flex;
    align-items: center;
    gap: 1px;
    font-size: 0.9em;
}
.control-group label {
    margin-right: 1px;
    white-space: nowrap;
}
.calibration-controls-panel span.cal-value {
    display: inline-block;
    min-width: 28px;
    text-align: right;
    padding: 0 1px;
    background-color: #222;
    border-radius: 2px;
    font-weight: bold;
    color: #0f0;
}

/* Calibration view area */
.calibration-content-wrapper {
    width: 100%;
    height: calc(100% - 28px);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #1a1a1a;
    position: relative;
    padding: 0;
    margin-top: 28px;
}
.crosshair-h {
    width: 80%; height: 3px;
    position: absolute; top: 50%; left: 10%; transform: translateY(-50%);
}
.crosshair-v {
    width: 3px; height: 80%;
    position: absolute; left: 50%; top: 10%; transform: translateX(-50%);
}
#left-calibration-viewport .crosshair-h,
#left-calibration-viewport .crosshair-v {
    background-color: red;
}
#right-calibration-viewport .crosshair-h,
#right-calibration-viewport .crosshair-v {
    background-color: yellow;
}

.calibration-circle {
    position: absolute;
    border-radius: 50%;
}

.calibration-target-circle {
    width: 40px;
    height: 40px;
    border: 2px dashed #FFF;
    background-color: transparent;
}

.calibration-alignment-circle {
    width: 20px;
    height: 20px;
    background-color: red;
}

.target-top-left, .align-top-left { top: 25%; left: 25%; transform: translate(-50%, -50%); }
.target-top-right, .align-top-right { top: 25%; left: 75%; transform: translate(-50%, -50%); }
.target-bottom-left, .align-bottom-left { top: 75%; left: 25%; transform: translate(-50%, -50%); }
.target-bottom-right, .align-bottom-right { top: 75%; left: 75%; transform: translate(-50%, -50%); }

.calibration-text {
    font-size: clamp(1.0em, 5vw, 1.8em);
    color: #00ff00; text-align: center; position: absolute;
    width: 100%;
    top: 55%;
    font-weight: bold;
    padding: 0 5px; box-sizing: border-box;
}

/* ========================================
   Main Menu / Content Menu Screen
   ======================================== */
#main-menu-screen .content-wrapper {
    width: 100%;
}
.main-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0 0px 3px 0px;
    box-sizing: border-box;
    margin-bottom: 2px;
    border-bottom: 1px solid #444;
    flex-shrink: 0;
}
.main-menu-header h2 {
    font-size: 0.9em;
    margin: 0;
    flex-grow: 1;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
    min-width: 0;
}
.main-menu-header .header-button-group {
    display: flex;
    flex-shrink: 0;
    gap: 3px;
}
.main-menu-header .header-button {
    padding: 4px 8px;
    font-size: 0.7em;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    flex-shrink: 0;
    min-height: 28px;
}
.main-menu-header .exit-button {
    background-color: #6c757d;
}

.filter-controls {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-bottom: 5px;
    flex-wrap: wrap;
    flex-shrink: 0;
}
.filter-controls button {
    padding: 3px 6px;
    font-size: 0.65em;
    border: 1px solid #555;
    background-color: #333;
    color: #ccc;
    border-radius: 3px;
    cursor: pointer;
    min-height: 24px;
}
.filter-controls button.active-filter {
    background-color: #007bff;
    color: white;
    border-color: #0056b3;
}
.filter-controls button[data-filter="exercise"] {
    border-color: #28a745;
}
.filter-controls button[data-filter="exercise"].active-filter {
    background-color: #28a745;
    border-color: #1e7e34;
}

.content-listbox-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
}

.scrollable-content-listbox {
    height: 100px;
    flex-grow: 1;
    border: 1px solid #444;
    overflow-y: auto;
    background-color: #111;
    text-align: left;
    padding: 1px;
    margin-bottom: 5px;
}
.scrollable-content-listbox-item {
    padding: 4px 6px;
    cursor: pointer;
    font-size: 0.75em;
    border-bottom: 1px solid #2c2c2c;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 24px;
    line-height: 20px;
}
.scrollable-content-listbox-item:last-child { border-bottom: none; }
.scrollable-content-listbox-item:hover { background-color: #333; }
.scrollable-content-listbox-item.selected { background-color: #004a99; color: white; font-weight: bold; }

.content-list-actions {
    display: flex;
    gap: 5px;
    justify-content: center;
    flex-shrink: 0;
}
.content-list-actions button {
    padding: 5px 10px;
    font-size: 0.75em;
    min-height: 28px;
    border-radius: 3px;
    border: 1px solid #555;
    background-color: #333;
    color: #fff;
    cursor: pointer;
}
.content-list-actions button:hover {
    background-color: #444;
}

/* ========================================
   Add Content Screen
   ======================================== */
#add-content-screen .content-wrapper {
    width: 100%;
}
.add-content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding-bottom: 3px;
    margin-bottom: 5px;
    border-bottom: 1px solid #444;
    flex-shrink: 0;
}
.add-content-header h2 { font-size: 0.9em; margin: 0; text-align: left; flex-grow: 1;}
.add-content-header .header-button {
    padding: 4px 8px; font-size: 0.7em; background-color: #6c757d;
    color: white; border: none; border-radius: 3px; cursor: pointer;
    min-height: 28px;
}

.add-content-form-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 3px;
    gap: 1px;
}
.add-content-form-item label {
    font-size: 0.7em;
    white-space: nowrap;
    margin-bottom: 1px;
    text-align: left;
    width: 100%;
}
.add-content-form-item input[type="text"],
.add-content-form-item .type-selector-button-group,
.add-content-form-item textarea {
    width: 100%;
    padding: 4px;
    font-size: 0.7em;
    background-color: #222;
    border: 1px solid #555;
    color: #fff;
    box-sizing: border-box;
}
.add-content-form-item textarea {
    min-height: 30px;
    resize: vertical;
}
.type-selector-button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    border: none;
    padding: 0;
    margin-bottom: 3px;
}
.type-selector-button {
    padding: 4px 6px;
    font-size: 0.65em;
    background-color: #333;
    border: 1px solid #555;
    color: #ccc;
    border-radius: 3px;
    cursor: pointer;
    flex-grow: 1;
    min-height: 26px;
}
.type-selector-button.active-type {
    background-color: #007bff;
    color: white;
    border-color: #0056b3;
}

.add-content-find-buttons-container {
    display: flex;
    gap: 5px;
    margin-bottom: 3px;
}
.add-content-find-buttons-container button {
    flex-grow: 1;
    padding: 4px 6px;
    font-size: 0.65em;
    min-height: 26px;
    border-radius: 3px;
    border: 1px solid #555;
    background-color: #333;
    color: #fff;
    cursor: pointer;
}

.add-content-form-buttons {
    display: flex;
    justify-content: space-around;
    gap: 5px;
    margin-top: 4px;
}
.add-content-form-buttons button {
    padding: 5px 10px;
    font-size: 0.7em;
    min-height: 28px;
    border-radius: 3px;
    border: none;
    color: #fff;
    cursor: pointer;
}

/* ========================================
   Video Player Screen
   ======================================== */
#video-player-screen { background-color: #000; }
#video-player-screen .calibrated-viewport { border: none; }

.video-controls-bar-eye {
    width: 100%; background-color: rgba(30, 30, 30, 0.85);
    padding: 4px 2px; box-sizing: border-box; text-align: center;
    z-index: 100; display: flex; flex-wrap: nowrap;
    justify-content: space-around;
    align-items: center;
    gap: 3px; font-size: 0.7em;
    position: absolute; top: 0; left: 0;
}
.video-controls-bar-eye button {
    padding: 4px 6px; background-color: #444; color: #fff;
    border: 1px solid #666; border-radius: 3px; cursor: pointer;
    white-space: nowrap;
    min-width: 26px;
    min-height: 26px;
}
.video-controls-bar-eye .video-position-controls button {
    font-size: 0.85em;
    padding: 2px 4px;
    min-width: 22px;
    min-height: 22px;
}
.video-controls-bar-eye span.offset-display {
    color: #0f0;
    margin: 0 1px 0 0px;
    font-weight: bold;
    min-width: 35px;
    display: inline-block;
    text-align: center;
    font-size: 0.85em;
}
.video-position-controls {
    display: flex;
    gap: 2px;
}

.video-content-wrapper {
    width: 100%; height: 100%; padding: 0; border: none;
    display: flex; align-items: center; justify-content: center;
    background-color: #000;
    box-sizing: border-box;
}
.video-content-wrapper video, .video-content-wrapper iframe {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

/* ========================================
   Media Viewer Screen
   ======================================== */
#media-viewer-screen { background-color: #111; }
#media-viewer-screen .calibrated-viewport { border: none; }
.media-controls-bar {
    position: absolute; top: 0; left: 0; width: 100%;
    background-color: rgba(50, 50, 50, 0.8); padding: 4px;
    text-align: center; z-index: 100; display: flex;
    justify-content: center; align-items: center;
    gap: 4px; font-size: 0.75em;
}
.media-controls-bar button {
    padding: 4px 8px;
    min-height: 28px;
    border-radius: 3px;
    border: 1px solid #555;
    background-color: #444;
    color: #fff;
    cursor: pointer;
}
.media-content-wrapper {
    display: flex; align-items: center; justify-content: center;
    font-size: clamp(1.2em, 7vw, 2.5em); color: #fff;
    width: 100%; height: 100%;
    box-sizing: border-box;
}
#media-viewer-screen .media-content-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* ========================================
   Exercise Canvas
   ======================================== */
.exercise-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* ========================================
   Debug Message Box
   ======================================== */
.debug-message-box {
    position: fixed;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(40, 100, 40, 0.85);
    color: white;
    padding: 8px 14px;
    border-radius: 6px;
    z-index: 2000;
    font-size: 0.8em;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
}
.debug-message-box.visible {
    opacity: 1;
}

/* ========================================
   Global button improvements
   ======================================== */
button {
    cursor: pointer;
    touch-action: manipulation;
}
button:focus-visible {
    outline: 2px solid #00ccff;
    outline-offset: 1px;
}
