/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: #000;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.container {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Webcam video - hidden, used as source for canvas drawing */
#webcam {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    z-index: 0;
}

/* Main compositing canvas */
#display-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: scaleX(-1);
    z-index: 2;
}

/* Status message */
#status {
    position: absolute;
    top: 20px;
    left: 20px;
    padding: 12px 18px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 500;
    z-index: 20;
    backdrop-filter: blur(4px);
}

/* Instructions panel */
#instructions {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 18px 30px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    font-size: 20px;
    text-align: center;
    z-index: 20;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 80%;
    transition: opacity 0.5s;
}

#instructions p {
    margin: 0;
    color: #333;
}

/* Full-screen X-ray toggle button */
#btn-fullxray {
    position: absolute;
    bottom: 30px;
    right: 20px;
    padding: 12px 20px;
    background: rgba(0, 60, 120, 0.7);
    color: #fff;
    border: 1px solid rgba(0, 200, 255, 0.4);
    border-radius: 10px;
    font-size: 15px;
    cursor: pointer;
    z-index: 20;
    backdrop-filter: blur(4px);
    transition: background 0.2s, transform 0.1s;
}

#btn-fullxray:hover {
    background: rgba(0, 100, 200, 0.8);
    transform: scale(1.05);
}

#btn-fullxray.active {
    background: rgba(0, 150, 255, 0.7);
    border-color: rgba(0, 200, 255, 0.8);
    box-shadow: 0 0 12px rgba(0, 200, 255, 0.4);
}

/* Bone editor toggle button */
#btn-boneeditor {
    position: absolute;
    bottom: 30px;
    right: 160px;
    padding: 12px 20px;
    background: rgba(120, 60, 0, 0.7);
    color: #fff;
    border: 1px solid rgba(255, 180, 0, 0.4);
    border-radius: 10px;
    font-size: 15px;
    cursor: pointer;
    z-index: 20;
    backdrop-filter: blur(4px);
    transition: background 0.2s, transform 0.1s;
}

#btn-boneeditor:hover {
    background: rgba(180, 100, 0, 0.8);
    transform: scale(1.05);
}

#btn-boneeditor.active {
    background: rgba(200, 140, 0, 0.7);
    border-color: rgba(255, 200, 0, 0.8);
    box-shadow: 0 0 12px rgba(255, 200, 0, 0.4);
}

/* Bone editor panel */
#bone-editor {
    position: absolute;
    top: 80px;
    right: 20px;
    width: 240px;
    padding: 10px 12px;
    background: rgba(0, 10, 25, 0.92);
    color: #fff;
    border-radius: 12px;
    font-size: 12px;
    z-index: 30;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 180, 0, 0.3);
    max-height: 85vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 180, 0, 0.3) transparent;
}

#bone-editor h3 {
    margin: 0 0 10px 0;
    font-size: 15px;
    color: #ffcc00;
}

.bone-group {
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.bone-group-global {
    border-bottom: 2px solid rgba(255, 180, 0, 0.3);
    margin-bottom: 8px;
    padding-bottom: 8px;
}

.bone-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 3px;
}

.bone-group-label {
    font-weight: bold;
    color: #aad;
    font-size: 11px;
    text-transform: uppercase;
}

/* Toggle switch */
.bone-toggle {
    position: relative;
    display: inline-block;
    width: 30px;
    height: 16px;
    cursor: pointer;
}

.bone-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.bone-toggle-slider {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    transition: background 0.2s;
}

.bone-toggle-slider::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    left: 2px;
    bottom: 2px;
    background: #888;
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}

.bone-toggle input:checked + .bone-toggle-slider {
    background: rgba(57, 255, 20, 0.3);
}

.bone-toggle input:checked + .bone-toggle-slider::before {
    transform: translateX(14px);
    background: #39FF14;
}

.bone-slider-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 1px 0;
}

.bone-slider-row label {
    width: 22px;
    font-size: 10px;
    color: #888;
}

.bone-slider-row input[type="range"] {
    flex: 1;
    height: 3px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
    outline: none;
}

.bone-slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    background: #ffcc00;
    border-radius: 50%;
    cursor: pointer;
}

.bone-slider-row .bone-val {
    width: 36px;
    text-align: right;
    font-size: 10px;
    color: #aaa;
    font-family: monospace;
}

.bone-editor-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.bone-editor-actions button {
    flex: 1;
    padding: 8px;
    background: rgba(0, 80, 160, 0.6);
    color: #fff;
    border: 1px solid rgba(0, 200, 255, 0.3);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.bone-editor-actions button:hover {
    background: rgba(0, 120, 220, 0.8);
}

/* Calibration panel */
.calib-panel { padding: 4px 0; }
.calib-step { font-size: 11px; color: #aad; text-transform: uppercase; margin-bottom: 4px; }
.calib-instruction { font-size: 13px; color: #fff; margin-bottom: 8px; }
.calib-hint { font-size: 10px; color: #888; margin-bottom: 6px; }

.calib-btn {
    width: 100%; padding: 8px; margin: 3px 0;
    background: rgba(0, 80, 160, 0.5); color: #fff;
    border: 1px solid rgba(0, 200, 255, 0.3); border-radius: 6px;
    font-size: 12px; cursor: pointer;
}
.calib-btn:hover { background: rgba(0, 120, 220, 0.7); }
.calib-btn.danger { background: rgba(255, 60, 60, 0.4); border-color: rgba(255,100,100,0.4); }

.calib-keyframe { font-size: 9px; color: #aaa; font-family: monospace; margin: 2px 0; }
.calib-keyframe.done { color: #39FF14; }

.advanced-toggle {
    font-size: 10px; color: #888; cursor: pointer;
    text-align: center; padding: 4px 0;
    border-top: 1px solid rgba(255,255,255,0.08); margin-top: 4px;
}
.advanced-toggle:hover { color: #aad; }
.advanced-content { display: none; }
.advanced-content.open { display: block; }

/* Hidden utility class */
.hidden {
    display: none !important;
}

/* Fade out */
.fade-out {
    opacity: 0 !important;
    pointer-events: none;
}

/* High contrast mode for accessibility */
.high-contrast #status {
    background: #000 !important;
    border: 3px solid #fff !important;
    color: #fff !important;
}

.high-contrast #instructions {
    background: #000 !important;
    border: 3px solid #fff !important;
}

.high-contrast #instructions p {
    color: #fff !important;
}

/* Loading spinner */
.loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 10px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #status {
        font-size: 14px;
        padding: 10px 14px;
    }

    #instructions {
        font-size: 16px;
        padding: 14px 20px;
        bottom: 20px;
    }
}
