:root {
    --primary: #6D5DFE;
    --primary-dark: #5B4BEA;
    --primary-hover: #7C6CFF;
    --primary-light: #a5b4fc;
    --secondary: #f59e0b;
    --background: #0B1020;
    --card: #111A2E;
    --card-secondary: #0F172A;
    --border: rgba(255, 255, 255, 0.08);
    --text: #EAF0FF;
    --text-muted: #A7B0C0;
    --input-bg: #0C1325;
    --input-border: rgba(255, 255, 255, 0.10);
    --input-focus: rgba(109, 93, 254, 0.35);
    --success: #10b981;
    --danger: #ef4444;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--background);
    min-height: 100vh;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    color: var(--text);
}

/* Layout */
#app {
    min-height: 100vh;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
    transition: padding-bottom 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sidebar {
    display: none;
    width: 300px;
    min-height: 100vh;
    position: fixed;
    top: 0;
    background: transparent;
    padding: 20px;
    border-right: none;
}

#sidebar-right {
    border-right: none;
    border-left: 1px solid var(--border);
}

#sidebar-left {
    left: 0;
}

#sidebar-right {
    right: 0;
}

.mobile-banner {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100px;
    background: transparent;
    border-top: none;
    z-index: 100;
}

/* Responsive */
@media (min-width: 1200px) {
    #app {
        width: 100%;
        max-width: none;
        margin: 0;
        padding-left: 320px;
        padding-right: 320px;
    }
    
    .sidebar {
        display: block;
    }
}

/* ✅ Cacher les pubs sur les routes non autorisées (pour AdSense compliance) */
body:not([data-ads-allowed="true"]) .sidebar,
body:not([data-ads-allowed="true"]) .mobile-banner {
    display: none !important;
}

@media (max-width: 1199px) {
    .sidebar {
        display: none !important;
    }
}

@media (max-width: 767px) {
    #app {
        padding-bottom: 120px;
    }
    
    .mobile-banner {
        display: block;
    }
}

/* ✅ Fix: Afficher mobile-banner entre 768px et 1199px aussi */
@media (min-width: 768px) and (max-width: 1199px) {
    #app {
        padding-bottom: 120px;
    }
    
    body[data-ads-allowed="true"] .mobile-banner {
        display: block;
    }
}

/* Cards */
.card {
    background: var(--card);
    border-radius: 1rem;
    padding: 20px;
    border: 2px solid var(--border);
    box-shadow: var(--shadow);
}

.card-large {
    border-radius: 1.5rem;
    padding: 30px;
    box-shadow: var(--shadow-lg);
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border-radius: 1rem;
    font-weight: 600;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-primary:active:not(:disabled) {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--card-secondary);
    border: 2px solid var(--border);
    color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--card);
    border-color: rgba(255, 255, 255, 0.12);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    opacity: 0.9;
}

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

/* Inputs */
.input {
    width: 100%;
    padding: 12px;
    border-radius: 1rem;
    background: var(--input-bg);
    border: 2px solid var(--input-border);
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--input-focus);
}

.input::placeholder {
    color: var(--text-muted);
}

/* Typography */
h1 {
    font-weight: 800;
    font-size: 2.5rem;
    color: var(--text);
    margin-bottom: 1rem;
}

h2 {
    font-weight: 700;
    font-size: 2rem;
    color: var(--text);
    margin-bottom: 0.75rem;
}

h3 {
    font-weight: 600;
    font-size: 1.5rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.text-muted {
    color: var(--text-muted);
    font-weight: 400;
}

.link-primary {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.link-primary:hover {
    color: var(--primary-hover);
}

.link-primary:active {
    color: var(--primary-dark);
}

/* Scoreboard */
#scores-bar {
    background: var(--card);
    border-radius: 1rem;
    padding: 15px 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    overflow-x: auto;
    border: 2px solid var(--border);
    box-shadow: var(--shadow);
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 50px;
    padding: 0 8px;
}

.score-avatar-container {
    position: relative;
    width: 16px;
    height: 35px; /* 16 (head) + 10 (overlap) + 9 (overlap) = 35, rounded */
    display: flex;
    align-items: center;
    justify-content: center;
}

.score-pseudo {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text);
    text-align: center;
}

.score-value {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
}

/* Avatar Selector */
.avatar-selector {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin: 20px 0;
}

.avatar-selector-inline {
    display: flex;
    justify-content: center;
    margin: 30px 0;
}

.avatar-selector-wrapper {
    position: relative;
    display: inline-block;
}

.avatar-arrow-inline {
    position: absolute;
    background: var(--primary);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    z-index: 10;
}

.avatar-arrow-inline:hover {
    background: var(--primary-dark);
}

/* Position arrows around avatar parts (medium size: 96x96, centers at 48, 108, 161) */
.avatar-arrow-inline.head-left {
    top: 30px; /* head center (48) - arrow center (18) = 30 */
    left: -50px;
}

.avatar-arrow-inline.head-right {
    top: 30px; /* head center (48) - arrow center (18) = 30 */
    right: -50px;
}

.avatar-arrow-inline.chest-left {
    top: 90px; /* chest center (108) - arrow center (18) = 90 */
    left: -50px;
}

.avatar-arrow-inline.chest-right {
    top: 90px; /* chest center (108) - arrow center (18) = 90 */
    right: -50px;
}

.avatar-arrow-inline.legs-left {
    top: 143px; /* legs center (161) - arrow center (18) = 143 */
    left: -50px;
}

.avatar-arrow-inline.legs-right {
    top: 143px; /* legs center (161) - arrow center (18) = 143 */
    right: -50px;
}

.avatar-preview-container {
    position: relative;
    margin-bottom: 10px;
}

/* Avatar sizes based on 128x128 images with proportional spacing */
/* Tiny: 16x16 images, ratio 0.125, gaps: 10px and 9px */
.avatar-preview-tiny {
    width: 16px;
    height: 37px; /* Calculé selon règles proportionnelles */
}

.avatar-preview-small {
    width: 64px;
    height: 149px; /* Calculé selon règles proportionnelles */
}

.avatar-preview-medium {
    width: 96px;
    height: 224px; /* Calculé selon règles proportionnelles */
}

.avatar-preview-large {
    width: 128px;
    height: 234px; /* 128x128: gap tête-chest=90px, gap chest-jambes=80px */
}

.avatar-preview-48px {
    width: 48px;
    height: 112px; /* 48px: gap tête-chest=34px, gap chest-jambes=30px (proportionnel) */
}

.avatar-layer {
    position: absolute;
    left: 0;
}

/* Tiny: 16x16 images, ratio 0.125, gaps proportionnels: 11px et 10px */
.avatar-preview-tiny .avatar-layer.head {
    top: 0;
    width: 16px;
    height: 16px;
    z-index: 3;
}

.avatar-preview-tiny .avatar-layer.chest {
    top: 11px; /* head center (8) + gap (11) - chest center (8) = 11 */
    width: 16px;
    height: 16px;
    z-index: 2;
}

.avatar-preview-tiny .avatar-layer.legs {
    top: 21px; /* chest center (19) + gap (10) - legs center (8) = 21 */
    width: 16px;
    height: 16px;
    z-index: 1;
}

/* Small: 64x64 images, ratio 0.5, gaps proportionnels: 45px et 40px */
.avatar-preview-small .avatar-layer.head {
    top: 0;
    width: 64px;
    height: 64px;
    z-index: 3;
}

.avatar-preview-small .avatar-layer.chest {
    top: 45px; /* head center (32) + gap (45) - chest center (32) = 45 */
    width: 64px;
    height: 64px;
    z-index: 2;
}

.avatar-preview-small .avatar-layer.legs {
    top: 85px; /* chest center (77) + gap (40) - legs center (32) = 85 */
    width: 64px;
    height: 64px;
    z-index: 1;
}

/* Medium: 96x96 images, ratio 0.75, gaps proportionnels: 68px et 60px */
.avatar-preview-medium .avatar-layer.head {
    top: 0;
    width: 96px;
    height: 96px;
    z-index: 3;
}

.avatar-preview-medium .avatar-layer.chest {
    top: 68px; /* head center (48) + gap (68) - chest center (48) = 68 */
    width: 96px;
    height: 96px;
    z-index: 2;
}

.avatar-preview-medium .avatar-layer.legs {
    top: 128px; /* chest center (116) + gap (60) - legs center (48) = 128 */
    width: 96px;
    height: 96px;
    z-index: 1;
}

/* Large: 128x128 images, ratio 1.0, gaps: 90px (tête-chest) et 80px (chest-jambes) */
.avatar-preview-large .avatar-layer.head {
    top: 0;
    width: 128px;
    height: 128px;
    z-index: 3;
}

.avatar-preview-large .avatar-layer.chest {
    top: 90px; /* head center (64) + gap (90) - chest center (64) = 90 */
    width: 128px;
    height: 128px;
    z-index: 2;
}

.avatar-preview-large .avatar-layer.legs {
    top: 170px; /* chest center (154) + gap (80) - legs center (64) = 170 */
    width: 128px;
    height: 128px;
    z-index: 1;
}

/* 48px: taille proportionnelle pour petits avatars, gaps: 34px (tête-chest) et 30px (chest-jambes) */
.avatar-preview-48px .avatar-layer.head {
    top: 0;
    width: 48px;
    height: 48px;
    z-index: 3;
}

.avatar-preview-48px .avatar-layer.chest {
    top: 34px; /* head center (24) + gap (34) - chest center (24) = 34 */
    width: 48px;
    height: 48px;
    z-index: 2;
}

.avatar-preview-48px .avatar-layer.legs {
    top: 64px; /* chest center (58) + gap (30) - legs center (24) = 64 */
    width: 48px;
    height: 48px;
    z-index: 1;
}

.avatar-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.avatar-control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.avatar-control-label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text);
    text-transform: capitalize;
}

.avatar-arrow {
    background: var(--primary);
    color: var(--text);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.avatar-arrow:hover {
    background: var(--primary-dark);
}

/* Loader */
.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(11, 16, 32, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loader-overlay.hidden {
    display: none;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loader-message {
    color: var(--text);
    margin-top: 20px;
    font-weight: 500;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 15px 30px;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    max-width: 90%;
}

.toast.hidden {
    display: none;
}

.toast-message {
    font-weight: 500;
}

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

.text-center {
    text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* Animations */
@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.float {
    animation: float 3s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.pulse {
    animation: pulse 1s ease-in-out infinite;
}

/* Video/Audio */
.video-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    border-radius: 1rem;
    overflow: hidden;
    background: var(--card-secondary);
    border: 1px solid var(--border);
}

.video-container video {
    width: 100%;
    height: auto;
    display: block;
    pointer-events: none;
}

.video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background: transparent;
    z-index: 10;
}

.video-controls {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    gap: 15px;
}

/* Fixed video frame */
.fixed-video-frame {
    width: 100%;
    max-width: 560px;
    aspect-ratio: 16 / 9;
    margin: 0 auto;
    background: #000;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
}

.fixed-video-frame video {
    width: 100%;
    height: 100%;
    object-fit: contain;   /* ✅ scale to fit */
    background: #000;      /* ✅ bandes noires */
    display: block;
    pointer-events: none;
}

.fixed-video-frame .video-overlay {
    border-radius: 16px;
}

/* Video trimmer preview container */
.trimmer-video-container {
    width: 100%;
    max-width: 560px;
    height: 315px;
    margin: 0 auto;
    background: #000;
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
}

.trimmer-video-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Waveform */
.wave-row {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 12px;
}

.wave-actions {
    display: flex;
    gap: 10px;
    flex: 0 0 auto;
}

.wave-wrap {
    position: relative;
    flex: 1 1 auto;
    height: 64px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--card-secondary);
    border: 1px solid var(--border);
    width: 100%;
}

#wave-canvas {
    width: 100%;
    height: 64px;
    display: block;
    cursor: pointer;
}

.wave-playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #ff0000;
    box-shadow: 0 0 4px rgba(255, 0, 0, 0.8); /* Légère lueur rouge */
    left: 0%;
    pointer-events: none;
    z-index: 10;
}

.recording-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 20px 0;
}

.recording-dot {
    width: 12px;
    height: 12px;
    background: var(--danger);
    border-radius: 50%;
}

.recording-dot.pulse {
    animation: pulse 1s ease-in-out infinite;
}

/* Participants List */
.participants-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 10px;
    margin: 20px 0;
}

.participant-card {
    background: var(--card);
    border-radius: 1rem;
    padding: 10px;
    border: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    position: relative;
    min-height: 180px; /* 139 (avatar) + margins + text + badge */
}

.participant-card.host::before {
    content: "👑";
    font-size: 1rem;
    position: absolute;
    top: -8px;
    z-index: 5;
}

.participant-card .avatar-preview-small {
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.participant-card .score-pseudo {
    font-size: 0.75rem;
    margin-top: 12px;
    color: var(--text);
}

.participant-card .status-badge {
    padding: 4px 12px;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.active {
    background: var(--success);
    color: var(--background);
}

.status-badge.offline {
    background: var(--text-muted);
    color: var(--background);
}

.status-badge.left {
    background: var(--danger);
    color: var(--background);
}

.status-badge.ready {
    background: var(--success);
    color: var(--background);
}


.center-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 100px);
    padding: 20px;
}

/* Page containers centered vertically and horizontally */
.page-container {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: calc(100vh - 100px);
    align-items: center;
}

.page-container > .card {
    width: 100%;
    max-width: 800px;
}

/* Legal pages - wider content for better readability */
@media (min-width: 768px) {
    .page-container {
        max-width: 1200px;
        padding: 30px 40px;
    }
    
    .page-container > .card {
        max-width: 1200px;
    }
    
    .page-container .card-large {
        max-width: 1200px;
        padding: 40px 50px;
    }
}

@media (min-width: 1200px) {
    /* Legal pages: reduce side padding to allow wider content */
    #app:has(.page-container) {
        padding-left: 200px !important;
        padding-right: 200px !important;
    }
    
    .page-container {
        max-width: 1400px;
        padding: 30px 50px;
    }
    
    .page-container > .card {
        max-width: 1400px;
    }
    
    .page-container .card-large {
        max-width: 1400px;
        padding: 50px 60px;
    }
}

@media (min-width: 1600px) {
    #app:has(.page-container) {
        padding-left: 250px !important;
        padding-right: 250px !important;
    }
    
    .page-container {
        max-width: 1600px;
    }
    
    .page-container > .card {
        max-width: 1600px;
    }
    
    .page-container .card-large {
        max-width: 1600px;
    }
}

/* Leave button */
#btn-leave-global {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001; /* Au-dessus des overlays (z-index: 1000) */
}

@media (min-width: 1200px) {
    #btn-leave-global {
        right: 340px;
    }
}

@media (max-width: 767px) {
    #btn-leave-global {
        top: 10px;
        right: 10px;
        padding: 8px 16px;
        font-size: 0.875rem;
    }
}

