/* CSS Reset et base - Style Simple */

/* Cacher extra-tools sur mobile par défaut */
.extra-tools {
    display: none;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #FFFFFF;
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    /* Support des safe areas iOS (notch, barres système) */
    padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

*, *:before, *:after {
    box-sizing: border-box;
}

/* Container principal - Style Simple */
.editor-container {
    display: flex;
    flex-direction: column;
    /* Hauteur dynamique avec support multiple navigateurs */
    min-height: 100vh;
    min-height: -webkit-fill-available; /* Safari iOS */
    min-height: 100dvh; /* Navigateurs modernes */
    width: 100vw;
    width: -webkit-fill-available;
    background: #FFFFFF;
    border: none;
    border-radius: 0;
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-padding-bottom: calc(96px + env(safe-area-inset-bottom, 16px));
    /* Safe areas iOS pour ne pas être caché par les encoches */
    padding: max(4px, env(safe-area-inset-top, 4px)) 
             max(4px, env(safe-area-inset-right, 4px)) 
             max(6px, env(safe-area-inset-bottom, 0px)) 
             max(4px, env(safe-area-inset-left, 4px));
    margin: 0;
}

/* Project info optimisé - Style Simple */
.project-info {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 8px 12px;
    background: #FFFFFF;
    border-bottom: 1px solid var(--border-color, #E5E5EA);
    border-radius: 0;
    margin: 0;
    color: var(--text-primary, #1D1D1F);
}

/* Branding réduit sur mobile */
.branding {
    gap: 6px;
}

.branding .app-icon {
    height: 32px;
    width: auto;
}

.branding .app-text {
    height: 28px;
    width: auto;
}

/* Bouton menu avec avatar utilisateur */
.menu-hamburger {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-hover, #F0F0F2);
    border: 2px solid var(--color-primary, #FF7300);
    color: var(--text-primary, #1D1D1F);
    font-size: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    z-index: 10;
    padding: 0;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(255, 115, 0, 0.2);
}

/* Masquer les pseudo-éléments hamburger quand l'avatar est présent */
.menu-hamburger::before,
.menu-hamburger::after {
    display: none;
}

/* Avatar mobile à l'intérieur du bouton menu */
.mobile-user-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.mobile-user-avatar svg,
.mobile-user-avatar img,
.mobile-user-avatar > div {
    width: 100% !important;
    height: 100% !important;
    border-radius: 50% !important;
    object-fit: cover;
}

/* Hover sur le bouton menu */
.menu-hamburger:hover {
    transform: translateY(-50%) scale(1.05);
    box-shadow: 0 4px 16px rgba(255, 115, 0, 0.35);
}

.menu-hamburger:hover, .menu-hamburger:active {
    background: var(--bg-hover, #F0F0F2);
    transform: translateY(-50%) scale(1.05);
}


.project-info h2 {
    font-size: 1.1rem;
    margin: 8px 0;
    color: var(--text-primary, #1D1D1F);
    font-weight: 600;
    flex: 1;
    text-align: center;
    letter-spacing: 0.3px;
}

.project-info .user-profile,
.project-info .logout-btn {
    display: none !important;
}

/* Toolbar principal - Style Simple */
.toolbar {
    padding: 0 8px;
    background: #FFFFFF;
    border: 1px solid var(--border-color, #E5E5EA);
    border-radius: var(--radius-md, 12px);
    margin: 6px;
    transition: all 0.2s ease;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transform: translateY(-10px);
}

.toolbar.visible {
    padding: 12px 8px;
    max-height: clamp(200px, 60vh, 500px);
    overflow-y: auto;
    overflow-x: hidden;
    opacity: 1;
    transform: translateY(0);
    box-shadow: var(--shadow-md, 0 4px 16px rgba(0, 0, 0, 0.08));
}

/* Outils avec boutons optimisés et compacts */
.tools {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
    grid-auto-rows: minmax(44px, auto);
    gap: 4px;
    justify-content: center;
    align-content: start;
    width: 100%;
}

.tools button {
    padding: 10px 12px;
    border: none;
    border-bottom: 1px solid var(--border-color, #E5E5EA);
    border-radius: 0;
    background: #FFFFFF;
    color: var(--text-primary, #1D1D1F);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    touch-action: manipulation;
    transition: background 0.15s ease;
    min-height: 44px;
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: left;
}

.tools .logout-btn-mobile {
    grid-column: 1 / -1;
    justify-self: stretch;
    min-height: 44px;
    font-size: 0.85rem;
    letter-spacing: 0.3px;
    background: #FF453A;
    color: #FFFFFF;
    border: none;
    border-radius: var(--radius-sm, 8px);
}

.tools .logout-btn-mobile:hover {
    background: #E03E35;
}

.tools button:hover {
    background: var(--bg-hover, #F0F0F2);
}

.tools button:active {
    background: var(--bg-secondary, #F5F5F7);
}

/* Style spécial pour le bouton play/stop - Liquid Glass */
#previewBtn {
    font-size: 1.2rem !important;
    background: linear-gradient(135deg, 
        rgba(40, 167, 69, 0.8), 
        rgba(32, 201, 151, 0.8)) !important;
    backdrop-filter: blur(15px) saturate(200%) !important;
    -webkit-backdrop-filter: blur(15px) saturate(200%) !important;
    border: 1px solid rgba(255, 255, 255, 0.4) !important;
    border-radius: 20px !important;
    color: white !important;
    font-weight: bold !important;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
    min-width: 50px !important;
    box-shadow: 
        0 4px 16px rgba(40, 167, 69, 0.3),
        0 2px 8px rgba(32, 201, 151, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.4) !important;
}

#previewBtn:hover {
    background: linear-gradient(135deg, 
        rgba(33, 136, 56, 0.9), 
        rgba(26, 188, 156, 0.9)) !important;
    transform: translateY(-3px) scale(1.05) !important;
    box-shadow: 
        0 8px 32px rgba(40, 167, 69, 0.4),
        0 4px 16px rgba(32, 201, 151, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.5) !important;
}

#previewBtn:active {
    transform: translateY(-1px) scale(0.98) !important;
    background: linear-gradient(135deg, 
        rgba(30, 126, 52, 0.9), 
        rgba(23, 162, 184, 0.9)) !important;
    box-shadow: 
        0 4px 16px rgba(40, 167, 69, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3) !important;
}

/* Animation pulsante quand l'animation est en cours */
#previewBtn.playing {
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7); }
    70% { box-shadow: 0 0 0 6px rgba(40, 167, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(40, 167, 69, 0); }
}

/* Interface compacte mobile - Style Simple */
.tools-compact {
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    padding: 10px;
    padding-left: calc(10px + env(safe-area-inset-left, 0px));
    padding-right: calc(10px + env(safe-area-inset-right, 0px));
    background: var(--bg-sidebar, #FAFAFA);
    border: 1px solid var(--border-color, #E5E5EA);
    border-radius: var(--radius-md, 12px);
    margin: 0 4px 8px;
    box-sizing: border-box;
    z-index: 1100;
}

body.is-mobile .editor-container {
    padding-top: max(4px, env(safe-area-inset-top, 4px));
}

.compact-tools {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Section couleur supprimée - plus nécessaire */

/* Ligne principale des outils */
.compact-main-tools {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 2px;
}

.compact-main-tools::-webkit-scrollbar {
    display: none;
}

/* Outils de gauche : Couleur actuelle + Gomme + Pipette */
.compact-left-tools {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    padding-right: 8px;
    border-right: 1.5px solid #E5E5EA;
    margin-right: 2px;
}

/* Outils de droite : Undo/Redo */
.compact-right-tools {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* Container pour la couleur actuelle avec sélecteur caché */
.compact-current-color-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Sélecteur de couleur invisible mais cliquable */
.compact-color-picker {
    position: absolute;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    z-index: 2;
}

/* Indicateur de couleur actuelle */
.compact-current-color {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: 1px solid var(--border-color, #E5E5EA);
    background-color: #000000;
    flex-shrink: 0;
    pointer-events: none;
    z-index: 1;
}

.compact-eraser-btn {
    padding: 6px 12px;
    border: 1px solid var(--border-color, #E5E5EA);
    border-radius: var(--radius-sm, 8px);
    background: #FFFFFF;
    color: var(--text-primary, #1D1D1F);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.compact-eraser-btn:hover {
    background: var(--bg-hover, #F0F0F2);
}

/* Ligne outils dessin : + Palette / Fill / Symétrie */
.compact-draw-tools {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* Bouton + Palette : clairement différent des pastilles */
.compact-add-color-btn {
    padding: 6px 12px;
    border: 1.5px dashed var(--color-primary, #FF7300);
    border-radius: var(--radius-sm, 8px);
    background: transparent;
    color: var(--color-primary, #FF7300);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.compact-add-color-btn:active {
    background: var(--color-primary-light, #FFF3E8);
}

.compact-eraser-btn.active {
    background: var(--color-primary-light, #FFF3E8);
    border-color: var(--color-primary, #FF7300);
    color: var(--color-primary, #FF7300);
}

/* Symétrie V active (mobile) */
.symmetry-v-btn.active {
    background: #34C759 !important;
    color: white !important;
    border-color: #34C759 !important;
}

/* Sélection active (mobile) */
.selection-btn.active {
    background: #007AFF !important;
    color: white !important;
    border-color: #007AFF !important;
}

.crop-stamp-btn.active {
    background: #00C853 !important;
    color: white !important;
    border-color: #00C853 !important;
}

/* Panneau référence flottant (mobile) */
#mobileReferencePanel {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 24px;
    padding: 8px 14px;
    z-index: 1000;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.mobile-ref-label {
    font-size: 18px;
    flex-shrink: 0;
}

#refOpacitySliderMobile {
    width: 130px;
    accent-color: #FF7300;
}

.mobile-ref-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.mobile-ref-btn.active,
.ref-move-btn.active {
    background: #FF7300 !important;
    border-color: #FF7300 !important;
    color: white !important;
}

/* Bouton pipette compact */
.compact-eyedropper-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border: 1px solid var(--border-color, #E5E5EA);
    border-radius: var(--radius-sm, 8px);
    background: #FFFFFF;
    color: var(--text-primary, #1D1D1F);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.compact-eyedropper-btn:hover {
    background: var(--bg-hover, #F0F0F2);
    border-color: var(--color-primary, #FF7300);
}

.compact-eyedropper-btn.active {
    background: var(--color-primary-light, #FFF3E8);
    border-color: var(--color-primary, #FF7300);
}

.compact-eyedropper-btn svg {
    width: 18px;
    height: 18px;
    display: block;
}

/* Bouton valider couleur mobile */
.compact-validate-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm, 8px);
    background: var(--color-primary, #FF7300);
    color: #FFFFFF;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.compact-validate-btn:hover:not(:disabled) {
    background: var(--color-primary-hover, #E66800);
}

.compact-validate-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.compact-validate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--bg-secondary, #F5F5F7);
    color: var(--text-light, #86868B);
}

.compact-undo-redo-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color, #E5E5EA);
    border-radius: var(--radius-sm, 8px);
    background: #FFFFFF;
    color: var(--text-primary, #1D1D1F);
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.compact-undo-redo-btn:hover {
    background: var(--bg-hover, #F0F0F2);
    border-color: var(--color-primary, #FF7300);
}

.compact-undo-redo-btn:active {
    transform: scale(0.95);
}

.compact-undo-redo-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: var(--bg-secondary, #F5F5F7);
    transform: none;
}

.compact-undo-redo-btn:disabled:hover {
    transform: none;
    background: var(--bg-secondary, #F5F5F7);
}

/* Ligne 2 palette */
.compact-palette-row {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

/* Wrapper scrollable + scrollbar custom */
.palette-scroll-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    gap: 3px;
}

/* Couleurs preset compactes */
.compact-preset-colors {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 0 2px 0;
    /* Masquer la scrollbar native */
    scrollbar-width: none;
}

.compact-preset-colors::-webkit-scrollbar {
    display: none;
}

/* Scrollbar personnalisée */
.palette-scrollbar {
    height: 6px;
    background: #E5E5EA;
    border-radius: 3px;
    position: relative;
    cursor: pointer;
    touch-action: none;
}

.palette-scrollbar-thumb {
    height: 100%;
    background: var(--color-primary, #FF7300);
    border-radius: 3px;
    position: absolute;
    top: 0;
    left: 0;
    min-width: 24px;
    cursor: grab;
    touch-action: none;
    transition: background 0.15s ease;
}

.palette-scrollbar-thumb:active {
    cursor: grabbing;
    background: #E06200;
}

.compact-color-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    max-width: 32px;
    max-height: 32px;
    border: 1px solid var(--border-color, #E5E5EA);
    border-radius: var(--radius-sm, 8px);
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    flex-shrink: 0;
    box-sizing: border-box;
    touch-action: manipulation;
}

.compact-color-btn.custom-color {
    border-color: var(--color-primary, #FF7300);
    box-shadow: 0 0 0 1px rgba(255, 115, 0, 0.2);
}

.compact-color-btn.custom-color::after {
    content: '★';
    position: absolute;
    top: -5px;
    right: -5px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid var(--color-primary, #FF7300);
    color: var(--color-primary, #FF7300);
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.compact-color-btn:hover {
    transform: scale(1.1);
    border-color: var(--color-primary, #FF7300);
}

.compact-color-btn.selected {
    border: 2px solid var(--color-primary, #FF7300);
    box-shadow: 0 0 0 2px rgba(255, 115, 0, 0.2);
    transform: scale(1.05);
}

/* ========================================
   MODAL FPS
   ======================================== */

.fps-control {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 10px;
}

.fps-display {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 10px;
}

.fps-value {
    font-size: 48px;
    color: #667eea;
}

.fps-label {
    font-size: 20px;
    color: #666;
}

.fps-desc {
    font-size: 16px;
    color: #999;
    font-weight: normal;
}

.fps-slider-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
}

.fps-slider {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, #667eea, #764ba2);
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.fps-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: white;
    border: 3px solid #667eea;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.fps-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: white;
    border: 3px solid #667eea;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.fps-min, .fps-max {
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

.fps-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.fps-presets-label {
    font-size: 14px;
    color: #666;
    font-weight: 500;
    width: 100%;
    margin-bottom: 5px;
}

.fps-preset-btn {
    flex: 1;
    min-width: 70px;
    padding: 10px 8px;
    border: 2px solid #667eea;
    border-radius: 8px;
    background: white;
    color: #667eea;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.fps-preset-btn small {
    display: block;
    font-size: 10px;
    margin-top: 2px;
    opacity: 0.7;
}

.fps-preset-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.fps-preset-btn.active {
    background: #667eea;
    color: white;
}

.fps-info {
    background: rgba(102, 126, 234, 0.1);
    border-radius: 8px;
    padding: 12px;
    font-size: 13px;
    color: #666;
}

.fps-info p {
    margin: 5px 0;
}

/* Modal de personnalisation de palette */
.modal {
    display: none;
    position: fixed;
    z-index: 9000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    /* Centrer le contenu du modal */
    align-items: center;
    justify-content: center;
}

/* Afficher le modal centré */
.modal[style*="display: flex"] {
    display: flex !important;
}

.modal-content {
    background: #FFFFFF;
    border: 1px solid var(--border-color, #E5E5EA);
    border-radius: 16px;
    padding: 0;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color, #E5E5EA);
}

.modal-header h3 {
    color: var(--text-primary, #1D1D1F);
    margin: 0;
    font-size: var(--font-size-lg, 1.125rem);
    font-weight: var(--font-weight-semibold, 600);
    line-height: var(--line-height-tight, 1.2);
}

.close-btn {
    background: var(--bg-secondary, #F5F5F7);
    border: 1px solid var(--border-color, #E5E5EA);
    color: var(--text-primary, #1D1D1F);
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.close-btn:hover {
    background: var(--bg-hover, #E5E5EA);
}

.modal-body {
    padding: 20px;
}

.palette-customizer {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.palette-colors-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.palette-color-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.palette-color-preview {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.palette-color-preview:hover {
    transform: scale(1.1);
    border-color: white;
}

.palette-color-input {
    width: 100%;
    height: 30px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
}

.palette-color-label {
    color: white;
    font-size: 12px;
    text-align: center;
    font-weight: 500;
}

.palette-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.reset-btn, .save-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.reset-btn {
    background: rgba(255, 100, 100, 0.2);
    color: #ff6464;
    border: 1px solid rgba(255, 100, 100, 0.3);
}

.reset-btn:hover {
    background: rgba(255, 100, 100, 0.3);
    transform: translateY(-1px);
}

.save-btn {
    background: rgba(100, 255, 100, 0.2);
    color: #64ff64;
    border: 1px solid rgba(100, 255, 100, 0.3);
}

.save-btn:hover {
    background: rgba(100, 255, 100, 0.3);
    transform: translateY(-1px);
}

/* Personnalisateur de couleur individuel */
.color-customizer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.current-color-preview {
    width: 80px;
    height: 80px;
    border-radius: 12px;
    border: 3px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.color-picker-full {
    width: 100%;
    height: 50px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.color-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    width: 100%;
}

/* Section secondaire cachée sur mobile - utiliser l'interface compacte */
.tools-secondary {
    display: none;
}

/* Amélioration pour navigateurs supportant backdrop-filter */
@supports (backdrop-filter: blur(20px)) or (-webkit-backdrop-filter: blur(20px)) {
    .tools-secondary {
        background: rgba(255, 255, 255, 0.08);
    }
}

/* Styles pour les lignes d'outils */
.tools-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

/* Style spécial pour la ligne avec undo + couleurs + redo */
.tools-row:has(.preset-colors) {
    gap: 4px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 4px 0;
}

/* Palette de couleurs compacte */
.color-palette {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

#colorPicker {
    width: 40px;
    height: 40px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    cursor: pointer;
    outline: none;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#colorPicker:hover {
    transform: scale(1.05);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.validate-color-btn {
    padding: 6px 8px;
    border: 2px solid #007AFF;
    border-radius: 4px;
    background-color: #007AFF;
    color: white;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: bold;
    transition: all 0.1s ease;
    min-height: 30px;
    min-width: 30px;
}

.validate-color-btn:hover {
    background-color: #0056b3;
    border-color: #0056b3;
    transform: scale(1.05);
}

.validate-color-btn:active {
    transform: scale(0.95);
}

.validate-color-btn:disabled {
    background-color: #ccc;
    border-color: #ccc;
    cursor: not-allowed;
    transform: none;
}

.undo-redo-btn {
    padding: 8px 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px) saturate(180%);
    -webkit-backdrop-filter: blur(10px) saturate(180%);
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: bold;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    min-height: 40px;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.undo-redo-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.undo-redo-btn:active:not(:disabled) {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(0) scale(0.98);
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.undo-redo-btn:disabled {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.4);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.eraser-btn {
    padding: 10px 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px) saturate(180%);
    -webkit-backdrop-filter: blur(10px) saturate(180%);
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    min-height: 40px;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.eraser-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px) scale(1.02);
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.eraser-btn:active, .eraser-btn.active {
    background: rgba(255, 107, 107, 0.8);
    color: white;
    border-color: rgba(255, 82, 82, 0.8);
    transform: translateY(0) scale(0.98);
    box-shadow: 
        0 2px 8px rgba(255, 107, 107, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.preset-colors {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    overflow-x: auto;
    padding: 2px 0;
    flex: 1;
    min-width: 0;
}

.color-btn {
    width: 32px;
    height: 32px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(5px) saturate(180%);
    -webkit-backdrop-filter: blur(5px) saturate(180%);
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.color-btn:hover {
    transform: scale(1.1) translateY(-2px);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.color-btn:active {
    transform: scale(0.95) translateY(0);
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Styles pour les couleurs de base */
.color-btn.default-color {
    border: 2px solid #ccc;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.color-btn.default-color:hover {
    border-color: #999;
    transform: scale(1.05);
}

/* Bouton "+" pour ajouter une couleur personnalisée */
.color-btn.add-color-btn {
    background: transparent;
    border: 1px dashed rgba(255, 115, 0, 0.6);
    color: rgba(255, 115, 0, 0.9);
    font-size: 20px;
    font-weight: 300;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
}

.color-btn.add-color-btn:hover,
.color-btn.add-color-btn:active {
    background: rgba(255, 115, 0, 0.12);
    border-color: #FF7300;
    color: #FF7300;
    transform: none;
}

/* Styles pour les couleurs personnalisées */
.color-btn.custom-color {
    border: 2px solid #007AFF;
    box-shadow: 0 0 0 1px rgba(0, 122, 255, 0.3), 0 2px 4px rgba(0, 122, 255, 0.2);
    position: relative;
}

.color-btn.custom-color::after {
    content: '★';
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: 0.6rem;
    color: #007AFF;
    background: white;
    border-radius: 50%;
    width: 12px;
    height: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #007AFF;
    font-weight: bold;
}

.color-btn.custom-color:hover {
    border-color: #0056b3;
    transform: scale(1.05);
}

/* Container de la grille - Style Simple */
.grid-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px;
    overflow: hidden;
    background: #FFFFFF;
    border: none;
    border-radius: 0;
    margin: 4px;
    min-height: 200px;
    max-height: calc(100vh - 200px);
    max-height: clamp(280px, calc(100dvh - 180px), 600px);
    position: relative; /* nécessaire pour les panneaux glissants */
}

/* ── Panneaux glissants mobiles ── */
.mobile-slide-panel {
    position: absolute;
    top: 0; bottom: 0;
    width: 200px;
    background: white;
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform 0.22s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,0.12);
}
.mobile-slide-left  { left: 0; transform: translateX(-100%); box-shadow: 3px 0 14px rgba(0,0,0,0.1); }
.mobile-slide-right { right: 0; transform: translateX(100%); box-shadow: -3px 0 14px rgba(0,0,0,0.1); }
.mobile-slide-panel.open { transform: translateX(0); }

/* Header du panneau */
.mobile-panel-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 10px;
    background: #F5F5F7;
    border-bottom: 1px solid #E5E5EA;
    flex-shrink: 0;
}
.mobile-panel-title {
    font-size: 11px;
    font-weight: 700;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 5px;
}
.mobile-panel-title svg { width: 12px; height: 12px; }
.mobile-panel-actions { display: flex; gap: 4px; }

/* Corps scrollable */
.mobile-panel-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Onglets internes (Calques / Tampons) */
.mobile-inner-tabs {
    display: flex;
    background: #F5F5F7;
    border-bottom: 1px solid #E5E5EA;
    flex-shrink: 0;
}
.mobile-inner-tab {
    flex: 1;
    padding: 8px 0;
    font-size: 10px;
    font-weight: 700;
    color: #8E8E93;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.12s;
}
.mobile-inner-tab svg { width: 11px; height: 11px; }
.mobile-inner-tab.active { color: #FF7300; border-bottom-color: #FF7300; background: white; }
.mobile-tab-pane { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.mobile-tab-pane.active { display: flex; }

/* ── Trait-handles ── */
.mobile-trait-handle {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 51;
    cursor: pointer;
    width: 5px;
    height: 40px;
    background: #CDCDD2;
    border-radius: 0 3px 3px 0;
    transition: background 0.15s, width 0.12s;
}
.mobile-trait-left  { left: 0; border-radius: 0 3px 3px 0; }
.mobile-trait-right { right: 0; border-radius: 3px 0 0 3px; }
.mobile-trait-handle.open { background: #FF7300; }

/* Sur mobile : cacher desktop, montrer les panneaux glissants */
@media (max-width: 1023px) {
    .frames-container { display: none; }
    #mobileLayersPanel { display: none !important; }
    .mobile-slide-panel { display: flex; }
    .mobile-trait-handle { display: block; }
}

/* Grille de pixels - viewport fixe, taille injectée par JS */
#pixelGrid {
    /* width/height injectés par applyGridCSSVariables() — toujours fixe */
    --grid-cols: 32;

    position: relative;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    margin: 0 auto;

    background: rgba(255, 255, 255, 0.98);
    border: 3px solid rgba(255, 255, 255, 0.4);
    border-radius: 16px;
    box-shadow:
        0 12px 48px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.5);
    transition: all 0.2s ease;
}

/* Phase 3 : plus de div.pixel — rendu 100% canvas */

#pixelGrid.stamp-mode {
    cursor: crosshair;
}

/* Bouton pipette actif */
.eyedropper-btn.active,
#eyedropperBtn.active {
    background: rgba(0, 122, 255, 0.3) !important;
    border-color: rgba(0, 122, 255, 0.6) !important;
    box-shadow: 0 0 12px rgba(0, 122, 255, 0.4) !important;
}

/* Animations pour les notifications pipette */
@keyframes fadeInOut {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
    15%, 85% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
}

/* Container de frames optimisé - Style Simple */
.frames-container {
    background: var(--bg-sidebar, #FAFAFA);
    border: 1px solid var(--border-color, #E5E5EA);
    border-radius: var(--radius-md, 12px);
    padding: 12px;
    margin: 6px 6px 12px 6px;
    min-height: 120px;
    max-height: 160px;
    overflow-y: auto;
    flex-shrink: 0;
    position: relative;
}

/* Styles pour l'aide */
.help-content {
    padding: 20px;
    line-height: 1.6;
    color: #333;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.help-content h2 {
    color: #007AFF;
    text-align: center;
    margin-bottom: 30px;
    font-size: 1.5rem;
    border-bottom: 2px solid #007AFF;
    padding-bottom: 10px;
}

.help-section {
    margin-bottom: 25px;
    background: #f9f9f9;
    border-radius: 8px;
    padding: 15px;
    border-left: 4px solid #007AFF;
}

.help-section h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.help-item {
    margin-bottom: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

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

.help-item strong {
    color: #007AFF;
    font-weight: 600;
}

.help-item kbd {
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 0.9rem;
    margin: 0 2px;
}

.help-item ul {
    margin: 8px 0 0 20px;
    padding: 0;
}

.help-item li {
    margin: 4px 0;
}

/* Améliorer l'affichage sur mobile */
@media (max-width: 768px) {
    .editor-container {
        height: auto;
        min-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    }
    
    .toolbar.visible {
        max-height: none;
        height: auto;
        overflow: visible;
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    }
}

@media (max-width: 600px) {
    .help-content {
        padding: 15px;
    }
    
    .help-content h2 {
        font-size: 1.3rem;
    }
    
    .help-section h3 {
        font-size: 1.1rem;
    }
    
    .help-section {
        padding: 12px;
        margin-bottom: 20px;
    }
}

/* Styles pour le partage */
.share-content {
    padding: 20px;
    text-align: center;
}

.share-content h3 {
    color: #007AFF;
    margin-bottom: 15px;
}

.share-options {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.share-option {
    background: #f8f9fa;
    border: 2px solid #007AFF;
    border-radius: 8px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.share-option:hover {
    background: #007AFF;
    color: white;
    transform: translateY(-2px);
}

.share-option small {
    display: block;
    margin-top: 5px;
    opacity: 0.7;
    font-size: 0.9rem;
}

.share-instructions {
    background: #f0f8ff;
    border: 1px solid #007AFF;
    border-radius: 8px;
    padding: 15px;
    margin-top: 20px;
    text-align: left;
}

.share-instructions code {
    background: #e6f3ff;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
}

/* Drag & Drop styles */
body.drag-over {
    background-color: rgba(0, 122, 255, 0.1);
}

body.drag-over::before {
    content: '📤 Déposez votre fichier .pixelart ici pour l\'importer !';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 122, 255, 0.9);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    z-index: 10000;
    text-align: center;
    padding: 20px;
}

/* Animation pour le feedback drag & drop */
@keyframes dragPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

body.drag-over .grid-container {
    animation: dragPulse 1s infinite;
}

/* Styles pour l'interface de chargement */
.load-content {
    padding: 20px;
    text-align: center;
}

.load-content h3 {
    color: #007AFF;
    margin-bottom: 15px;
}

.load-options {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.load-option {
    background: #f8f9fa;
    border: 2px solid #007AFF;
    border-radius: 8px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.load-option:hover {
    background: #007AFF;
    color: white;
    transform: translateY(-2px);
}

.load-option small {
    display: block;
    margin-top: 5px;
    opacity: 0.7;
    font-size: 0.9rem;
}

.drop-zone {
    background: #f0f8ff;
    border: 2px dashed #007AFF;
    border-radius: 8px;
    padding: 20px;
    margin: 15px 0;
    text-align: center;
    color: #007AFF;
    font-weight: 500;
    transition: all 0.2s ease;
}

.drop-zone.drag-active {
    background: #007AFF;
    color: white;
    transform: scale(1.02);
}

.load-instructions {
    background: #f0f8ff;
    border: 1px solid #007AFF;
    border-radius: 8px;
    padding: 15px;
    margin-top: 20px;
    text-align: left;
}

.load-instructions ul {
    margin: 10px 0 0 20px;
    padding: 0;
}

.load-instructions li {
    margin: 8px 0;
    line-height: 1.4;
}

/* Améliorer les styles de partage pour iOS */
.share-option:first-child {
    background: linear-gradient(135deg, #007AFF, #0056b3);
    color: white;
    border-color: #0056b3;
    font-weight: 600;
}

.share-option:first-child:hover {
    background: linear-gradient(135deg, #0056b3, #004494);
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

#addFrameBtn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, 
        rgba(40, 167, 69, 0.8), 
        rgba(32, 201, 151, 0.8));
    backdrop-filter: blur(15px) saturate(200%);
    -webkit-backdrop-filter: blur(15px) saturate(200%);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 16px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 8px;
    min-height: 44px;
    touch-action: manipulation;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    box-shadow: 
        0 4px 16px rgba(40, 167, 69, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

#addFrameBtn:hover {
    transform: translateY(-2px) scale(1.02);
    background: linear-gradient(135deg, 
        rgba(33, 136, 56, 0.9), 
        rgba(26, 188, 156, 0.9));
    box-shadow: 
        0 8px 24px rgba(40, 167, 69, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

#addFrameBtn:active {
    transform: translateY(0) scale(0.98);
    background: linear-gradient(135deg, 
        rgba(30, 126, 52, 0.9), 
        rgba(23, 162, 184, 0.9));
    box-shadow: 
        0 2px 8px rgba(40, 167, 69, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* ========================================
   BOUTONS FRAME ACTIONS (Copier/Coller)
   ======================================== */

.frame-actions {
    display: flex;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 10px;
    padding: 0 5px;
}

.frame-action-btn {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
    backdrop-filter: blur(15px) saturate(200%);
    -webkit-backdrop-filter: blur(15px) saturate(200%);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.frame-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.frame-action-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.copy-btn {
    background: linear-gradient(135deg, #FF9800 0%, #F57C00 100%);
}

.paste-btn {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
}

#addFrameBtn {
    flex: 1;
    height: 48px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(15px) saturate(200%);
    -webkit-backdrop-filter: blur(15px) saturate(200%);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

#addFrameBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

#addFrameBtn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

#framesList {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 4px 0;
    min-height: 50px; /* Hauteur minimale garantie */
}

/* Espace publicitaire réservé - Masqué sur mobile */
.ad-space {
    display: none;
}

/* Styles pour les frames */
.frame-container {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.frame-preview {
    padding: 2px;
    background-color: white;
    border: 2px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    touch-action: manipulation;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.frame-preview.active {
    border-color: #007AFF;
    background-color: #e3f2fd;
    box-shadow: 0 0 0 1px rgba(0, 122, 255, 0.3);
}

/* Styles pour les miniatures de frames */
.frame-thumbnail {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    grid-template-rows: repeat(16, 1fr);
    width: 36px;
    height: 36px;
    border: 1px solid #ccc;
    border-radius: 1px;
    overflow: hidden;
    position: relative;
    background: white;
}

.thumbnail-pixel {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
}

/* Numéro de frame pour les frames vides */
.frame-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.7rem;
    font-weight: bold;
    color: #666;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.insert-frame-btn {
    width: 28px;
    height: 28px;
    border: 1px solid #ccc;
    background-color: #f0f0f0;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

/* Dialogues et modales mobiles - Style Simple */
.save-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.save-dialog-content {
    background: #FFFFFF;
    border: 1px solid var(--border-color, #E5E5EA);
    border-radius: var(--radius-lg, 16px);
    padding: 24px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg, 0 8px 32px rgba(0, 0, 0, 0.12));
    animation: slideIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.save-dialog h3 {
    margin: 0 0 20px 0;
    text-align: center;
    font-size: var(--font-size-xl, 1.3rem);
    color: var(--text-primary, #1D1D1F);
    font-weight: var(--font-weight-semibold, 600);
    line-height: var(--line-height-tight, 1.2);
}

.save-dialog input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border-color, #E5E5EA);
    border-radius: var(--radius-md, 12px);
    font-size: var(--font-size-base, 1rem);
    margin-bottom: 20px;
    outline: none;
    background: #FFFFFF;
    color: var(--text-primary, #1D1D1F);
    transition: all 0.15s ease;
}

.save-dialog input::placeholder {
    color: var(--text-light, #86868B);
}

.save-dialog input:focus {
    border-color: var(--color-primary, #FF7300);
    box-shadow: 0 0 0 3px rgba(255, 115, 0, 0.1);
}

.dialog-buttons {
    display: flex;
    gap: 12px;
}

.dialog-buttons button {
    flex: 1;
    padding: 14px 16px;
    border: 1px solid var(--border-color, #E5E5EA);
    border-radius: var(--radius-md, 12px);
    font-size: var(--font-size-base, 1rem);
    font-weight: var(--font-weight-semibold, 600);
    cursor: pointer;
    min-height: 48px;
    touch-action: manipulation;
    transition: all 0.15s ease;
}

#dialogSave {
    background: var(--color-primary, #FF7300);
    color: #FFFFFF;
    border: none;
}

#dialogSave:hover {
    background: var(--color-primary-hover, #E66800);
}

#dialogCancel {
    background: #FFFFFF;
    color: var(--text-primary, #1D1D1F);
}

#dialogCancel:hover {
    background: var(--bg-hover, #F0F0F2);
}

/* Phase 3 : marqueurs DOM supprimés — onion skin rendu sur canvas */

/* Styles pour la modal des crédits */
.credits-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.credits-content {
    background-color: white;
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.close-credits {
    width: 100%;
    padding: 12px;
    background-color: #007AFF;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    margin-top: 16px;
    min-height: 44px;
    touch-action: manipulation;
}

/* ===================================================================
   MEDIA QUERIES POUR DIFFÉRENTES TAILLES D'ÉCRAN
   =================================================================== */

/* Très petits téléphones (iPhone SE 1st gen, etc. — 360px-374px) */
@media screen and (max-width: 374px) {
    .project-info h2 {
        font-size: 0.95rem;
    }

    .tools button {
        font-size: 0.65rem;
        padding: 8px 10px;
        min-height: 44px; /* touch target minimum iOS/Android */
    }

    #pixelGrid {
        --cell-size: clamp(
            6px,
            min(
                calc((100vw - max(16px, env(safe-area-inset-right, 0px) + env(safe-area-inset-left, 0px)) - 4px) / 32),
                calc((100vh - max(140px, env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px)) - 4px) / 32)
            ),
            12px
        );
        min-width: calc(6px * 32);
        min-height: calc(6px * 32);
        max-width: calc(12px * 32);
        max-height: calc(12px * 32);
    }

    .color-btn {
        width: 28px;
        height: 28px;
    }

    .frames-container {
        max-height: 100px;
        margin-bottom: 60px;
    }

    /* Modals : éviter le débordement horizontal */
    .modal-content {
        width: 95vw;
        max-width: 95vw;
        padding: 0;
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-body {
        padding: 14px 16px;
    }

    .save-dialog {
        padding: 12px;
    }

    .save-dialog-content {
        padding: 18px 16px;
        max-width: 100%;
    }

    /* Empiler les boutons du dialog verticalement */
    .dialog-buttons {
        flex-direction: column;
        gap: 8px;
    }

    .dialog-buttons button {
        width: 100%;
    }
}

/* Ultra-petits téléphones (iPhone SE 1st gen 320px, Galaxy A series) */
@media screen and (max-width: 359px) {
    .project-info h2 {
        font-size: 0.85rem;
    }

    .tools button {
        font-size: 0.6rem;
        padding: 6px 8px;
        min-height: 44px;
    }

    #pixelGrid {
        --cell-size: clamp(
            5px,
            min(
                calc((100vw - 8px) / 32),
                calc((100vh - max(130px, env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px))) / 32)
            ),
            10px
        );
        min-width: calc(5px * 32);
        min-height: calc(5px * 32);
        max-width: calc(10px * 32);
        max-height: calc(10px * 32);
    }

    .color-btn {
        width: 24px;
        height: 24px;
    }

    .modal-content {
        width: 98vw;
        max-width: 98vw;
        border-radius: 12px;
    }

    /* Réduire les paddings généraux */
    .modal-header h3 {
        font-size: 15px;
    }

    .close-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
}

/* Petits téléphones (iPhone SE 2nd gen, iPhone 12 mini) */
@media screen and (min-width: 375px) and (max-width: 413px) {
    .project-info h2 {
        font-size: 1rem;
    }
    
    #pixelGrid {
        --cell-size: clamp(
            7px,
            min(
                calc((100vw - max(18px, env(safe-area-inset-right, 0px) + env(safe-area-inset-left, 0px)) - 4px) / 32),
                calc((100vh - max(130px, env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px)) - 4px) / 32)
            ),
            13px
        );
        max-width: calc(13px * 32);
        max-height: calc(13px * 32);
    }
}

/* Téléphones moyens/grands (iPhone 12, 13, 14, Galaxy S21, etc.) */
@media screen and (min-width: 414px) and (max-width: 479px) {
    .project-info h2 {
        font-size: 1.15rem;
    }
    
    .tools button {
        font-size: 0.8rem;
        padding: 11px 13px;
    }
    
    #pixelGrid {
        --cell-size: clamp(
            8px,
            min(
                calc((100vw - max(20px, env(safe-area-inset-right, 0px) + env(safe-area-inset-left, 0px)) - 4px) / 32),
                calc((100vh - max(145px, env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px)) - 4px) / 32)
            ),
            14px
        );
        max-width: calc(14px * 32);
        max-height: calc(14px * 32);
    }
}

/* Grands téléphones (iPhone Pro Max, Galaxy Note, etc.) */
@media screen and (min-width: 480px) and (max-width: 767px) {
    .project-info h2 {
        font-size: 1.2rem;
    }
    
    .tools button {
        font-size: 0.85rem;
        padding: 12px 14px;
    }
    
    #pixelGrid {
        --cell-size: clamp(
            9px,
            min(
                calc((100vw - max(24px, env(safe-area-inset-right, 0px) + env(safe-area-inset-left, 0px)) - 4px) / 32),
                calc((100vh - max(120px, env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px)) - 4px) / 32)
            ),
            16px
        );
        max-width: calc(16px * 32);
        max-height: calc(16px * 32);
    }
    
    .frames-container {
        max-height: 140px;
    }
}

/* Tablettes en portrait (iPad, Galaxy Tab) */
@media screen and (min-width: 768px) and (max-width: 1023px) and (orientation: portrait) {
    .toolbar {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 12px;
    }
    
    .tools {
        display: flex;
        flex-wrap: wrap;
        max-width: none;
    }
    
    .tools button {
        font-size: 0.9rem;
        padding: 10px 16px;
    }
    
    .frames-container {
        max-height: 160px;
    }
    
    /* Grille plus grande sur tablettes */
    #pixelGrid {
        --cell-size: clamp(
            12px,
            min(
                calc((100vw - 32px - 4px) / 32),
                calc((100vh - 120px - 4px) / 32)
            ),
            20px
        );
        
        width: calc(var(--cell-size) * 32);
        height: calc(var(--cell-size) * 32);
        max-width: calc(20px * 32);
        max-height: calc(20px * 32);
        border-radius: 4px;
    }
    
    .project-info h2 {
        font-size: 1.4rem;
    }
}

/* Tablettes en paysage */
@media screen and (min-width: 768px) and (max-width: 1023px) and (orientation: landscape) {
    .grid-container {
        max-height: calc(100vh - 200px);
    }
    
    #pixelGrid {
        --cell-size: clamp(
            10px,
            min(
                calc((100vw - 32px - 4px) / 32),
                calc((100vh - 160px - 4px) / 32)
            ),
            18px
        );
        max-width: calc(18px * 32);
        max-height: calc(18px * 32);
    }
    
    .frames-container {
        max-height: 120px;
    }
}

/* Optimisations spécifiques iOS Safari */
@supports (-webkit-touch-callout: none) {
    /* Fix pour la barre d'URL qui apparaît/disparaît sur iOS */
    .editor-container {
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    .grid-container {
        /* Ajustement pour iOS Safari qui calcule mal parfois */
        max-height: calc(100vh - 280px);
        max-height: calc(-webkit-fill-available - 280px);
    }
}

/* DESKTOP LAYOUT SELON VOS SPECS - Nuancier gauche | Grille centre | Frames droite */

/* Amélioration pour menu hamburger - boutons plus compacts */
.toolbar.visible {
    max-height: clamp(200px, 60vh, 400px);
    overflow: visible;
    overscroll-behavior: contain;
}

.toolbar.visible .tools {
    gap: 3px;
}

.toolbar.visible .tools button {
    font-size: 0.7rem;
    padding: 6px 8px;
    min-height: 32px;
    line-height: 1.1;
}


/* ===================================================================
   OPTIMISATIONS POUR BARRES DU NAVIGATEUR ET ESPACE PERDU
   =================================================================== */

/* Récupérer l'espace perdu entre grille et bannière pub */
.grid-container {
    margin-bottom: 2px; /* Réduire l'espace perdu */
    padding-bottom: 4px; /* Optimiser le padding */
}

/* Optimisation pour barres grises du navigateur */
@media screen and (max-height: 700px) {
    .grid-container {
        max-height: calc(100vh - 160px); /* Plus d'espace pour la grille */
        max-height: calc(100dvh - 160px); /* Support barres dynamiques */
    }
    
    #pixelGrid {
        --cell-size: clamp(
            6px,
            min(
                calc((100vw - 20px - 4px) / 32),
                calc((100vh - 120px - 4px) / 32)
            ),
            12px
        );
    }
}

/* Fix spécifique pour Safari avec barres */
@supports (-webkit-touch-callout: none) {
    .grid-container {
        max-height: calc(100vh - 150px);
        max-height: calc(-webkit-fill-available - 150px);
    }
    
    #pixelGrid {
        --cell-size: clamp(
            7px,
            min(
                calc((100vw - 20px - 4px) / 32),
                calc((100vh - 110px - 4px) / 32)
            ),
            14px
        );
    }
}

/* Optimisation pour Chrome avec barres */
@media screen and (max-height: 600px) {
    .toolbar.visible {
        max-height: 180px; /* Menu plus compact sur petits écrans */
    }
    
    .grid-container {
        max-height: calc(100vh - 140px);
    }
    
    #pixelGrid {
        --cell-size: clamp(
            5px,
            min(
                calc((100vw - 16px - 4px) / 32),
                calc((100vh - 100px - 4px) / 32)
            ),
            10px
        );
    }
}


/* ===================================================================
   BOUTON PLAY DANS LA BARRE DU HAUT - STYLE SIMPLE
   =================================================================== */

.play-button {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-secondary, #F5F5F7);
    border: 1px solid var(--border-color, #E5E5EA);
    color: var(--text-primary, #1D1D1F);
    font-size: 0;
    width: 44px;
    height: 44px;
    border-radius: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    z-index: 10;
}

/* Créer l'icône play avec du CSS pur */
.play-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-left: 10px solid var(--text-primary, #1D1D1F);
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    transform: translate(-40%, -50%);
    transform-origin: center center;
    -webkit-transform: translate(-40%, -50%);
    -webkit-transform-origin: center center;
    transition: all 0.2s ease;
    margin: 0;
    padding: 0;
}

/* Style quand l'animation est en cours (stop) */
.play-button.playing::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    background: var(--text-primary, #1D1D1F);
    border: none;
    transform: translate(-50%, -50%);
    -webkit-transform: translate(-50%, -50%);
    transform-origin: center center;
    -webkit-transform-origin: center center;
    margin: 0;
    padding: 0;
}

.play-button:hover, .play-button:active {
    background: var(--bg-hover, #F0F0F2);
    transform: translateY(-50%) scale(1.05);
}

/* Animation quand l'animation est en cours */
.play-button.playing {
    background: var(--color-primary-light, #FFF3E8);
    border-color: var(--color-primary, #FF7300);
}

.play-button.playing::before {
    background: var(--color-primary, #FF7300);
}

/* ── Panel calques mobile ─────────────────────────────────────────────────── */
#mobileLayersPanel {
    position: fixed;
    bottom: 90px;
    left: 8px;
    right: 8px;
    background: white;
    border: 1px solid #E5E5EA;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 1000;
    max-height: 280px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.mobile-layers-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid #E5E5EA;
    background: #F5F5F7;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.mobile-add-layer-btn {
    margin-left: auto;
    font-size: 11px;
    padding: 4px 10px;
    background: #FF7300;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

#mobileLayersPanel .layers-list {
    overflow-y: auto;
    flex: 1;
}

#mobileLayersPanel .layer-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid #F0F0F2;
    cursor: pointer;
    transition: background 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                border-left 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#mobileLayersPanel .layer-item.active {
    background: #FFF3E8;
    border-left: 3px solid #FF7300;
}
#mobileLayersPanel .layer-name { font-size: 13px; }
#mobileLayersPanel .layer-name-hidden { opacity: 0.35; font-style: italic; }
#mobileLayersPanel .layer-eye { display: flex; align-items: center; color: #555; }
#mobileLayersPanel .layer-eye.layer-hidden { color: #BBBBBB; }
#mobileLayersPanel .layer-action-btn { padding: 4px 8px; font-size: 12px; }
#mobileLayersPanel .layer-drag-handle { font-size: 18px; color: #BBBBBB; cursor: grab; padding: 0 4px; }
#mobileLayersPanel .layer-item.layer-drop-above { border-top: 2px solid #FF7300; }
#mobileLayersPanel .layer-item.layer-drop-below { border-bottom: 2px solid #FF7300; }
#mobileLayersPanel .layer-item.layer-dragging { opacity: 0.4; }

/* ══════════════════════════════════════════
   Panneaux glissants mobiles — cibles tactiles agrandies
   ══════════════════════════════════════════ */

/* Frames */
/* ── Touch size overrides for mobile sliding panels ─────────────────────── */
/* Frames (left panel) */
#mobilePanelLeft .frame-row { padding: 8px 10px; gap: 8px; min-height: 48px; }
#mobilePanelLeft .frame-row-thumb { width: 34px; height: 34px; }
#mobilePanelLeft .frame-drag-handle { font-size: 18px; padding: 0 5px; }
#mobilePanelLeft .frame-row-del { opacity: 1; width: 32px; height: 32px; padding: 0; justify-content: center; }
#mobilePanelLeft .frame-row-del svg { width: 14px; height: 14px; }

/* Layers (right panel) */
#mobilePanelRight .layer-item { padding: 8px 10px; gap: 8px; min-height: 48px; }
#mobilePanelRight .layer-drag-handle { font-size: 18px; padding: 0 4px; }
#mobilePanelRight .layer-eye { width: 32px; height: 32px; padding: 0; justify-content: center; }
#mobilePanelRight .layer-eye svg { width: 16px; height: 16px; }
#mobilePanelRight .layer-actions { gap: 4px; }
#mobilePanelRight .layer-action-btn,
#mobilePanelRight .layer-delete-btn { width: 30px; height: 30px; padding: 0; justify-content: center; font-size: 14px; border-radius: 6px; }

/* Stamps (right panel) */
#mobilePanelRight .stamp-row { padding: 8px 10px; gap: 8px; min-height: 48px; }
#mobilePanelRight .stamp-row-thumb { width: 34px; height: 34px; }
#mobilePanelRight .stamp-drag-handle { font-size: 18px; padding: 0 5px; }
#mobilePanelRight .stamp-row-del { opacity: 1; width: 32px; height: 32px; padding: 0; justify-content: center; }
#mobilePanelRight .stamp-row-del svg { width: 14px; height: 14px; }

/* Delete buttons always visible on touch + touch-friendly shape */
#mobilePanelLeft .frame-row-del,
#mobilePanelRight .stamp-row-del { border-radius: 6px; }

/* Header des panneaux */
.mobile-panel-hdr { padding: 9px 12px; }
.mobile-panel-title { font-size: 12px; }
.mobile-inner-tab { padding: 10px 0; font-size: 11px; }
.mobile-panel-hdr .frames-hdr-btn { width: 34px; height: 34px; }
.mobile-panel-hdr .frames-hdr-btn svg { width: 14px; height: 14px; }
