/* Styles spécifiques pour patrons-solides */
:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --secondary: #ec4899;
    --accent: #10b981;
    --dark: #0f0a1f;
    --card-bg: rgba(255, 255, 255, 0.03);
}

/* Override body background from layout */
body {
    background: var(--dark) !important;
    color: white;
}

/* Ensure .app takes full width/height if needed, 
       though it is supervised by <main> now. */

/* Page Title */
.page-title {
    text-align: center;
    padding: 2rem 1rem;
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.15) 0%, transparent 100%);
    position: relative;
}

.page-title h1 {
    font-family: 'Poppins', sans-serif;
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 900;
    background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.page-title p {
    color: rgba(255, 255, 255, 0.6);
    font-size: 1.1rem;
}

/* Layout */
.app {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 1.5rem 3rem;
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
}

@media (max-width: 1000px) {
    .app {
        grid-template-columns: 1fr;
        overflow-x: hidden;
    }
}
@media (max-width: 600px) {
    .app {
        padding: 0 0.75rem 2rem;
    }
    .panel {
        min-width: 0;
    }
}

/* Panel */
.panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 1.25rem;
}

.card-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-title i {
    color: var(--primary-light);
}

/* Solids Grid */
.solids-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.solid-btn {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.02);
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.7rem;
    font-weight: 600;
}

.solid-btn i {
    font-size: 1.4rem;
}

.solid-btn:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    color: white;
}

.solid-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-color: transparent;
    color: white;
    box-shadow: 0 8px 32px rgba(99, 102, 241, 0.3);
}

/* Progress */
.progress-section {
    text-align: center;
}

.progress-value {
    font-family: 'Poppins', sans-serif;
    font-size: 3.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
}

.progress-label {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 1rem;
}

.slider-container {
    position: relative;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    margin-bottom: 1.5rem;
}

.slider-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 4px;
    transition: width 0.1s;
}

.slider-input {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.slider-thumb {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    transition: transform 0.1s;
}

/* L'input range est en opacity:0 : rendre le focus clavier visible */
.slider-input:focus-visible ~ .slider-thumb {
    box-shadow:
        0 0 0 3px var(--primary-light),
        0 2px 10px rgba(0, 0, 0, 0.3);
}

/* Steps */
.steps-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.step-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
    transition: all 0.3s;
}

.step-item.active {
    background: rgba(99, 102, 241, 0.15);
    color: white;
}

.step-item.done {
    color: var(--accent);
}

.step-num {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
}

.step-item.active .step-num {
    background: var(--primary);
}

.step-item.done .step-num {
    background: var(--accent);
}

.step-item.done .step-num i {
    font-size: 0.7rem;
}

/* Buttons */
.btn-group {
    display: flex;
    gap: 0.5rem;
}

.btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem;
    border: none;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: white;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn-success {
    background: linear-gradient(135deg, var(--accent), #059669);
    color: white;
}

.btn-success.playing {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

/* Speed */
.speed-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.speed-label {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
}

.speed-btns {
    display: flex;
    gap: 0.25rem;
    flex: 1;
}

.speed-btn {
    flex: 1;
    padding: 0.4rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.speed-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}
.speed-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Colors */
.colors-grid {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.color-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.color-btn:hover {
    transform: scale(1.1);
}
.color-btn.active {
    border-color: white;
    box-shadow: 0 0 20px currentColor;
}

.color-btn i {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.color-btn.active i {
    opacity: 1;
}

/* Options */
.option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0;
}

.option:not(:last-child) {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.option-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
}

.option-label i {
    width: 18px;
    color: rgba(255, 255, 255, 0.4);
}

.toggle {
    width: 44px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
}

.toggle.active::after {
    transform: translateX(20px);
}

.toggle:focus-visible {
    outline: 2px solid var(--primary-light);
    outline-offset: 2px;
}

/* Info */
.info-card {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.1), rgba(245, 158, 11, 0.05));
    border: 1px solid rgba(251, 191, 36, 0.2);
}

.info-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.info-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.info-name {
    font-size: 1.1rem;
    font-weight: 800;
}

.info-list {
    list-style: none;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
}

.info-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
}

.info-list i {
    width: 16px;
    color: #f59e0b;
}

/* Viewer */
.viewer {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Plein ecran (videoprojection en classe) : .app prend tout l'ecran avec
   son grid panel(320px) + viewer(1fr) pour garder TOUS les controles
   accessibles : panel gauche (Solide, Patron, Couleurs, Options, Pliage,
   Vitesse) + viewer droit (Quiz, Mesures, Imprimer, Reset, Quitter). */
.app:fullscreen {
    max-width: none;
    width: 100vw;
    height: 100vh;
    padding: 1rem;
    margin: 0;
    box-sizing: border-box;
    background: var(--dark);
    overflow-y: auto;
}
.app:fullscreen .panel {
    overflow-y: auto;
    max-height: calc(100vh - 2rem);
}
.app:fullscreen .viewer {
    height: calc(100vh - 2rem);
}
/* Sur tablette/mobile (≤1000px), le grid passe en 1 col par defaut. En
   plein ecran on garde 2 cols mais compactees, pour ne pas obliger a
   scroller entre panel et viewer. */
@media (max-width: 1000px) {
    .app:fullscreen {
        grid-template-columns: 260px 1fr;
        gap: 0.75rem;
        padding: 0.75rem;
    }
}

.viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    flex-wrap: wrap;
    gap: 0.75rem;
}

.viewer-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
}

.viewer-title i {
    color: var(--primary-light);
}

.viewer-stats {
    display: flex;
    gap: 1.5rem;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
}

.stat {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.stat i {
    color: var(--primary-light);
}
.stat-val {
    color: white;
    font-weight: 700;
}

.viewer-btns {
    display: flex;
    gap: 0.4rem;
}

.viewer-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.viewer-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

#canvas-container {
    flex: 1;
    min-height: 500px;
    background: radial-gradient(ellipse at bottom, #1a1744 0%, #0a0812 100%);
    position: relative;
}

@media (max-width: 768px) {
    #canvas-container {
        min-height: 400px;
    }
}

.viewer-footer {
    display: flex;
    justify-content: center;
    gap: 2rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.4);
    flex-wrap: wrap;
}

.hint {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.hint i {
    color: var(--primary-light);
}

/* Loading */
.loading {
    position: absolute;
    inset: 0;
    background: rgba(10, 8, 18, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 10;
    transition: opacity 0.5s;
}

.loading.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Toast */
.toast {
    position: fixed;
    top: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: linear-gradient(135deg, var(--accent), #059669);
    color: white;
    padding: 1rem 2rem;
    border-radius: 100px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 10px 40px rgba(16, 185, 129, 0.4);
    z-index: 1000;
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Avertissement faux patron (le « L » ne ferme pas le cube) */
.toast.warn {
    background: linear-gradient(135deg, #f59e0b, #dc2626);
    box-shadow: 0 10px 40px rgba(239, 68, 68, 0.4);
    max-width: min(90vw, 560px);
    text-align: center;
    border-radius: 20px;
}

/* Confetti */
.confetti-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 999;
    overflow: hidden;
}

.confetti {
    position: absolute;
    opacity: 0;
    animation: confetti-fall 3s ease-out forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-20px) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* Face Label */
.face-label {
    position: absolute;
    font-family: 'Poppins', sans-serif;
    font-weight: 900;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.15);
    pointer-events: none;
}

/* Patrons Grid */
.patrons-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.patron-btn {
    padding: 0.6rem 0.8rem;
    background: rgba(255, 255, 255, 0.02);
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.patron-btn:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    color: white;
}

.patron-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-color: transparent;
    color: white;
}

.patron-btn.false-pattern {
    border-color: rgba(239, 68, 68, 0.5);
    color: rgba(239, 68, 68, 0.8);
}

.patron-btn.false-pattern:hover {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.patron-btn.false-pattern.active {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    box-shadow: 0 8px 32px rgba(239, 68, 68, 0.3);
}

/* Favorites bar */
.favorites-bar {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 1.5rem 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.favorites-bar .fav-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255, 255, 255, 0.4);
}
.fav-chip {
    padding: 0.35rem 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 100px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.fav-chip:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary);
    color: white;
}
.fav-chip .fav-remove {
    font-size: 0.65rem;
    opacity: 0.5;
}
.fav-chip .fav-remove:hover {
    opacity: 1;
    color: #ef4444;
}
.fav-star {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}
.fav-star:hover {
    border-color: #f59e0b;
    color: #f59e0b;
}
.fav-star.active {
    border-color: #f59e0b;
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.15);
}
.favorites-bar.empty {
    display: none;
}

/* Quiz mode */
.quiz-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 8, 18, 0.92);
    backdrop-filter: blur(10px);
    z-index: 500;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1.5rem;
}
.quiz-overlay.active {
    display: flex;
}
.quiz-box {
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 2rem;
    max-width: 520px;
    width: 90%;
    text-align: center;
}
.quiz-question {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}
.quiz-choices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.quiz-choice {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.04);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.quiz-choice:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}
.quiz-choice.correct {
    border-color: var(--accent);
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent);
}
.quiz-choice.wrong {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}
.quiz-score {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
}
.quiz-score strong {
    color: var(--primary-light);
    font-size: 1.1rem;
}
.quiz-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
}

/* Measurement toggle */
.measurement-label {
    position: absolute;
    font-family: 'Poppins', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    color: #f59e0b;
    background: rgba(0, 0, 0, 0.6);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    pointer-events: none;
    white-space: nowrap;
}

/* Print styles */
@media print {
    body {
        background: white !important;
        color: black !important;
    }
    .panel,
    .viewer-header,
    .viewer-footer,
    .page-title,
    .favorites-bar,
    .toast,
    .confetti-container,
    .quiz-overlay,
    nav,
    footer,
    header {
        display: none !important;
    }
    .app {
        display: block !important;
        padding: 0 !important;
    }
    .viewer {
        border: none !important;
        background: none !important;
        backdrop-filter: none !important;
        page-break-inside: avoid;
    }
    #canvas-container {
        /* En mode print on cache le canvas WebGL (souvent vide a la capture)
           au profit de l'image PNG snapshot generee au click Imprimer. */
        display: none !important;
    }
    /* Position fixed pour echapper au flex parent (.viewer en flex column
       qui ne donnait pas de hauteur a l'img). Le snapshot prend tout l'ecran
       print, centre, en preservant son ratio. */
    #printSnapshot {
        display: block !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        object-fit: contain !important;
        background: white !important;
        z-index: 99999 !important;
        page-break-inside: avoid;
    }
    /* Cache TOUT le reste de la page en mode print pour ne pas avoir des
       artefacts de layout sous l'img qui occupent une 2e page blanche.
       Exclut #printSnapshot (notre image PNG du solide) qui doit etre
       le seul element visible a l'impression. */
    body > *:not(#printSnapshot):not(script):not(style):not(link) {
        display: none !important;
    }
    .print-info {
        display: block !important;
        text-align: center;
        padding: 1rem;
        font-family: 'Poppins', sans-serif;
        color: black;
        border-bottom: 2px solid #333;
        margin-bottom: 1rem;
    }
    .print-info h2 {
        font-size: 1.5rem;
        margin: 0 0 0.3rem;
    }
    .print-info p {
        font-size: 0.9rem;
        color: #555;
        margin: 0;
    }
}
.print-info {
    display: none;
}
/* Snapshot canvas pour print : invisible en mode normal, affichee en print */
#printSnapshot {
    display: none;
}

/* Keyboard shortcut hint badge */
.kbd {
    display: inline-block;
    padding: 0.1rem 0.35rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    font-size: 0.65rem;
    font-family: monospace;
    color: rgba(255, 255, 255, 0.4);
    margin-left: 0.3rem;
    vertical-align: middle;
}

/* ===== DARK MODE ===== */
[data-theme='dark'] body {
    background: linear-gradient(135deg, #0f172a 0%, #1a1f35 100%) !important;
}
