* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    /* Prevent zoom on input focus on mobile */
    touch-action: manipulation;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    padding: 30px;
    position: relative;

    /* Avoid blinking */
    opacity: 0;
    visibility: hidden;
    animation: fadeIn 0.5s ease-in-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        visibility: hidden;
    }
    to {
        opacity: 1;
        visibility: visible;
    }
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
    font-size: 2em;
}

.language-selector {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 100;
}

.language-selector select {
    padding: 8px 12px;
    font-size: 14px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

.language-selector select:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.language-selector select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.section {
    margin-bottom: 25px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.section.alert {
    background: #ff3636aa;
    border: 2px solid #aa2222ff;
}

.section.warning {
    background: #ffcc00aa;
    border: 2px solid #cc8800ff;
}

.section.alert, .section.warning {
    /* Avoid blinking */
    opacity: 0;
    visibility: hidden;
    animation: fadeIn 0.3s ease-in-out forwards;
    animation-delay: 200ms;
}

.section h2 {
    color: #555;
    margin-bottom: 15px;
    font-size: 1.2em;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
}
.section h2:has(input[type="checkbox"]:not(:checked)){
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

label {
    display: block;
    margin-bottom: 8px;
    color: #444;
    font-weight: 500;
}
.section h2 label {
    color: #555;
    font-weight: inherit;
    font-size: inherit;
}
.section h2 label:has(input[type="checkbox"]){
    cursor: pointer;
}
.section h2 label:has(input[type="checkbox"]:not(:checked)){
    border-bottom: none;
    margin-bottom: 0;
}


.hint {
    font-size: 12px;
    color: #666;
    margin-top: 5px;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
    /* Touch-friendly */
    min-height: 44px;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: #667eea;
}

input[type="file"] {
    width: 100%;
    padding: 15px;
    border: 2px dashed #667eea;
    border-radius: 8px;
    background: #f0f4ff;
    cursor: pointer;
    transition: all 0.3s;
    /* Touch-friendly */
    min-height: 50px;
}

input[type="file"]:hover, input[type="file"].drag-over {
    background: #e0e8ff;
    border-color: #764ba2;
}

input[type="color"] {
    width: 100%;
    height: 100%;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    /* Touch-friendly */
    min-width: 44px;
    min-height: 44px;
}
input[type="color"]::-moz-color-swatch {
    border: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
    border-radius: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
}

input[type="range"] {
    width: 100%;
    height: 8px;
    padding: 8px;
    border-radius: 4px;
    background: #ddd;
    outline: none;
    cursor: pointer;
}

.row {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.row > div {
    display: flex;
    flex-grow: 1;
    flex-basis: 1px;
    flex-direction: column;
    min-width: 150px;
}

.preview-container {
    text-align: center;
    padding: 20px;
    background: #fff;
    border-radius: 10px;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #eee;
    position: relative;
}

#preview {
    max-width: 100%;
    max-height: 500px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.placeholder {
    color: #aaa;
    font-size: 18px;
}

.btn {
    display: inline-block;
    padding: 15px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    width: 100%;
    margin-top: 10px;
    /* Touch-friendly */
    min-height: 50px;
    touch-action: manipulation;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-download {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

.btn-download:hover {
    box-shadow: 0 5px 20px rgba(17, 153, 142, 0.4);
}

.hidden {
    display: none !important;
}

canvas {
    display: none;
}

/* Styles pour la section avancée */

.advanced-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 10px 15px;
    background: #e9ecef;
    border-radius: 8px;
    margin-top: 15px;
    transition: background 0.3s;
    user-select: none;
}

.advanced-toggle:hover {
    background: #dee2e6;
}

.advanced-toggle h3 {
    color: #555;
    font-size: 1em;
    margin: 0;
}

.advanced-toggle .icon {
    font-size: 1.2em;
    transition: transform 0.3s;
}

.advanced-toggle.active .icon {
    transform: rotate(180deg);
}

.advanced-options {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out;
    padding-bottom: 4px;
}

.advanced-options.open {
    max-height: 1000px;
    transition: max-height 0.5s ease-in;
}

.advanced-content {
    padding-top: 15px;
}

/* Format selection */

.export-buttons {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    margin-top: 15px;
}

.export-buttons .btn {
    flex: 1;
    min-width: 150px;
    margin-top: 0;
}

.btn-export-html {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.btn-export-html:hover {
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.btn-export-png {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

.btn-export-png:hover {
    box-shadow: 0 5px 20px rgba(17, 153, 142, 0.4);
}

.btn-export-jpg {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.btn-export-jpg:hover {
    box-shadow: 0 5px 20px rgba(245, 87, 108, 0.4);
}

/* Format selection */
.format-selection {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.format-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 15px;
    background: #e9ecef;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    /* Touch-friendly */
    min-height: 44px;
}

.format-option input[type="radio"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    /* Touch-friendly */
    min-width: 20px;
    min-height: 20px;
}

.format-option.selected {
    background: #667eea;
    color: white;
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

/* Loading Indicator (fixed top-right) */
.loading-indicator {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: white;
    border-radius: 50px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    transition: opacity 0.3s ease, transform 0.3s ease;
    max-width: 400px;
}

.loading-indicator.hidden {
    opacity: 0;
    transform: translateX(20px);
    pointer-events: none;
}

.loading-indicator:not(.hidden) {
    opacity: 1;
    transform: translateX(0);
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e0e0e0;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

.loading-indicator #loadingText {
    color: #555;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.page-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 15px;
    justify-content: center;
}

.page-selector button {
    padding: 8px 15px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    /* Touch-friendly */
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

.page-selector button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.page-selector span {
    font-weight: 500;
    color: #555;
}

/* Position Grid for Second Watermark */
.position-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-width: 200px;
    margin: 12px;
}

.position-btn {
    width: 50px;
    height: 50px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #666;
}

.position-btn:hover {
    border-color: #667eea;
    background: linear-gradient(135deg, #e0e8ff 0%, #d0dcff 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.position-btn.selected {
    border-color: #667eea;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.position-btn::after {
    content: "●";
    font-size: 16px;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        padding: 20px 15px 60px 15px;
        border-radius: 10px;
    }

    h1 {
        font-size: 1.5em;
        margin-bottom: 20px;
    }

    .language-selector {
        top: auto;
        bottom: 20px;
        right: 20px;
    }

    .section {
        padding: 15px;
        margin-bottom: 20px;
    }

    .section h2 {
        font-size: 1.1em;
        margin-bottom: 12px;
    }

    /* Stack row elements on mobile */
    .row {
        flex-direction: column;
        gap: 15px;
    }

    .row > div {
        min-width: 100%;
    }

    /* Larger touch targets */
    input[type="text"],
    input[type="number"],
    select {
        font-size: 16px; /* Prevents iOS zoom */
        padding: 14px;
    }

    input[type="file"] {
        padding: 20px 15px;
        font-size: 14px;
    }

    /* Full-width color picker on mobile */
    input[type="color"] {
        width: 100%;
        height: 50px;
    }

    /* Larger sliders */
    input[type="range"] {
        padding: 0;
        height: 10px;
        pointer-events: none;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
        background: #667eea;
        -webkit-appearance: none;
        pointer-events:auto;
    }

    input[type="range"]::-moz-range-thumb {
        width: 24px;
        height: 24px;
        background: #667eea;
        -webkit-appearance: none;
        pointer-events:auto;
    }

    /* Bigger buttons */
    .btn {
        padding: 18px 30px;
        font-size: 18px;
        min-height: 56px;
    }

    .page-selector {
        flex-wrap: wrap;
        gap: 8px;
    }

    .page-selector button {
        flex: 1;
        min-width: 100px;
        padding: 12px 10px;
        font-size: 13px;
    }

    .page-selector span {
        width: 100%;
        text-align: center;
        margin: 5px 0;
    }

    /* Stack format options */
    .format-selection {
        flex-direction: column;
        gap: 10px;
    }

    .export-buttons {
        flex-direction: column;
        gap: 10px;
    }

    .export-buttons .btn {
        width: 100%;
        min-width: 100%;
    }
    
    .format-option {
        width: 100%;
        justify-content: center;
        padding: 15px;
    }

    /* Adjust preview container */
    .preview-container {
        min-height: 200px;
        padding: 15px;
    }

    #preview {
        max-height: 400px;
    }

    /* Smaller advanced toggle */
    .advanced-toggle {
        padding: 12px 15px;
    }

    .advanced-toggle h3 {
        font-size: 0.95em;
    }

    .position-grid {
        max-width: 100%;
        gap: 10px;
    }

    .position-btn {
        width: 60px;
        height: 60px;
        font-size: 24px;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    body {
        padding: 5px;
    }

    .container {
        padding: 15px 10px 60px 10px;
    }

    h1 {
        font-size: 1.3em;
    }

    .language-selector select {
        padding: 6px 10px;
        font-size: 13px;
    }

    .section {
        padding: 12px 10px;
    }

    .section h2 {
        font-size: 1em;
    }

    /* Smaller text for compact screens */
    label {
        font-size: 14px;
    }

    input[type="text"],
    input[type="number"],
    select {
        padding: 12px;
    }

    .btn {
        padding: 16px 20px;
        font-size: 16px;
    }

    .page-selector button {
        padding: 10px 8px;
        font-size: 12px;
    }

    .format-option {
        padding: 12px 10px;
        font-size: 14px;
    }

    .position-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .container {
        max-height: 95vh;
        overflow-y: auto;
    }

    .preview-container {
        min-height: 150px;
    }

    #preview {
        max-height: 300px;
    }
}
