/* CSS Variables for consistent theming */
:root {
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --secondary-color: #4682b4;
    --accent-color: #ff6347;
    --success-color: #28a745;
    --success-hover: #218838;
    --warning-color: #ffd700;
    --warning-hover: #ffc700;
    --background-color: #f0f8ff;
    --card-background: #fff;
    --border-color: #dee2e6;
    --text-color: #333;
    --text-muted: #495057;
    --shadow-light: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 4px 8px rgba(0, 0, 0, 0.15);
    --shadow-heavy: 0 10px 20px rgba(0, 0, 0, 0.1);
    --border-radius: 8px;
    --border-radius-large: 12px;
    --transition: all 0.3s ease;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.container {
    background-color: var(--card-background);
    padding: 30px;
    border-radius: 15px;
    box-shadow: var(--shadow-heavy);
    max-width: 1400px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
    overflow-x: hidden;
}

.left-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.right-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: sticky;
    top: 20px;
}

.main-title {
    grid-column: 1 / -1;
    text-align: center;
    margin-bottom: 0;
}

h1 {
    color: var(--accent-color);
    margin-bottom: 20px;
}

h2 {
    color: var(--secondary-color);
    margin-top: 30px;
    margin-bottom: 10px;
}

.sound-selection {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
}

.sound-selection > p {
    grid-column: 1 / -1;
    font-size: 1.2em;
    margin-bottom: 15px;
    text-align: center;
    font-weight: bold;
    color: var(--secondary-color);
}

.sound-category {
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sound-category:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.sound-category h3 {
    color: var(--text-muted);
    font-size: 1.1em;
    margin: 0 0 15px 0;
    text-align: center;
    font-weight: bold;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}

.sound-buttons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    gap: 8px;
    justify-items: center;
}

.sound-button {
    background-color: var(--warning-color);
    border: none;
    border-radius: var(--border-radius);
    color: var(--text-color);
    padding: 12px 16px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
    min-width: 60px;
    box-shadow: var(--shadow-light);
}

.sound-button:hover {
    background-color: var(--warning-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.sound-button:active {
    transform: translateY(0);
    box-shadow: var(--shadow-light);
}

.custom-sound-section {
    grid-column: 1 / -1;
    padding: 20px;
    background-color: var(--background-color);
    border-radius: 10px;
    border: 2px solid #b3d9ff;
    margin-top: 20px;
}

.custom-sound-section h3 {
    color: var(--text-muted);
    font-size: 1.1em;
    margin: 0 0 15px 0;
    text-align: center;
    font-weight: bold;
}

.custom-sound-input {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

#custom-sound {
    padding: 10px 15px;
    border: 2px solid var(--primary-color);
    border-radius: var(--border-radius);
    font-size: 1em;
    min-width: 200px;
    text-align: center;
    background-color: var(--card-background);
}

#custom-sound:focus {
    outline: none;
    border-color: var(--primary-hover);
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.3);
}

#use-custom-sound {
    background-color: var(--success-color);
    border: none;
    border-radius: var(--border-radius);
    color: white;
    padding: 10px 16px;
    font-size: 1em;
    cursor: pointer;
    transition: var(--transition);
    min-width: 120px;
}

#use-custom-sound:hover {
    background-color: var(--success-hover);
    transform: scale(1.05);
}

#use-custom-sound:active {
    transform: scale(0.95);
}

/* Accessibility styles */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus styles for better accessibility */
*:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.controls-section {
    background-color: #f8f9fa;
    padding: 20px;
    border-radius: var(--border-radius-large);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-light);
}

.controls-section h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #495057;
    font-size: 1.2em;
    text-align: center;
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 8px;
}

.length-selection {
    margin-bottom: 20px;
}

.length-selection p {
    font-size: 1.1em;
    margin-bottom: 12px;
    font-weight: bold;
    color: #495057;
}

#story-length {
    width: 100%;
    padding: 10px 15px;
    border-radius: 8px;
    border: 2px solid #007bff;
    font-size: 1em;
    background-color: #fff;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

#story-length:focus {
    outline: none;
    border-color: #0056b3;
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.3);
}

.options-grid {
    display: grid;
    gap: 15px;
}

.highlight-option,
.variants-option {
    background-color: #fff;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    transition: background-color 0.2s ease;
}

.highlight-option:hover,
.variants-option:hover,
.audio-option:hover {
    background-color: #f0f8ff;
}

.highlight-option label,
.variants-option label,
.audio-option label {
    font-size: 1em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 500;
    color: #495057;
}

.highlight-option input[type="checkbox"],
.variants-option input[type="checkbox"],
.audio-option input[type="checkbox"] {
    transform: scale(1.3);
    cursor: pointer;
    accent-color: #007bff;
}

.sound-variants {
    background-color: #fff;
    padding: 20px;
    border-radius: 12px;
    border: 2px solid #e9ecef;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sound-variants p {
    margin: 0 0 15px 0;
    font-weight: bold;
    color: #495057;
    text-align: center;
    font-size: 1.1em;
}

#variants-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 10px;
    justify-items: center;
}

.variant {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border: 2px solid #90caf9;
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 1.1em;
    font-weight: 600;
    color: #1565c0;
    display: inline-block;
    transition: all 0.3s ease;
    cursor: pointer;
    min-width: 70px;
    text-align: center;
    margin: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.variant:hover {
    background: linear-gradient(135deg, #bbdefb 0%, #90caf9 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(21, 101, 192, 0.3);
    border-color: #64b5f6;
}

.example-word {
    background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%);
    border: 2px solid #ce93d8;
    border-radius: 12px;
    padding: 8px 14px;
    font-size: 1em;
    font-weight: 500;
    color: #7b1fa2;
    display: inline-block;
    transition: all 0.3s ease;
    cursor: pointer;
    margin: 3px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.example-word:hover {
    background: linear-gradient(135deg, #e1bee7 0%, #ce93d8 100%);
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(123, 31, 162, 0.3);
    border-color: #ba68c8;
}

.variants-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0;
    justify-content: flex-start;
    align-items: center;
}

.examples-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 10px 0;
    justify-content: flex-start;
    align-items: center;
}

.syllable {
    display: inline-block; /* Assurer un comportement de bloc pour chaque syllabe */
    margin-right: 1px; /* Léger espacement si nécessaire, peut être ajusté ou supprimé */
}

#story-length {
    padding: 8px 12px;
    border-radius: 5px;
    border: 1px solid #ccc;
    font-size: 1em;
    background-color: #fff;
}

.syllable-arc {
    display: inline-block;
    position: relative;
    padding-bottom: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* Highlight syllables containing the selected sound */
.sound-highlight {
    color: #007bff !important;
    font-weight: bold !important;
    background-color: rgba(0, 123, 255, 0.2) !important;
    border-radius: 3px;
    padding: 1px 0px;
    margin: 0;
    display: inline;
    letter-spacing: normal;
}

/* Fallback for nested sound-highlight */
.syllable-arc .sound-highlight {
    color: #007bff;
    font-weight: bold;
    background-color: rgba(0, 123, 255, 0.1);
    border-radius: 3px;
    padding: 1px 0px;
    margin: 0;
    display: inline;
    letter-spacing: normal;
}

/* Les arcs ne s'affichent que quand le mot parent a la classe 'active' */
.word-container.active .syllable-arc::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    width: 80%;
    height: 5px;
    border-style: solid;
    border-color: #007bff;
    border-width: 0 0 2px 0;
    border-radius: 0 0 50% 50% / 0 0 100% 100%;
    box-sizing: border-box;
    animation: arcAppear 0.3s ease-in-out;
}

@keyframes arcAppear {
    from {
        opacity: 0;
        transform: scaleX(0);
    }
    to {
        opacity: 1;
        transform: scaleX(1);
    }
}

.word-container {
    display: inline;
    cursor: pointer;
}

.word-container:hover {
    background-color: rgba(0, 123, 255, 0.1);
    border-radius: 3px;
}


.story-display {
    padding: 25px;
    background: linear-gradient(135deg, #e6e6fa 0%, #f0f8ff 100%);
    border-radius: 15px;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    border: 2px solid #d1d1e0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.story-display h2 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #4682b4;
    text-align: center;
    font-size: 1.4em;
}

#story-text {
    font-size: 1.3em;
    line-height: 1.8;
    color: #444;
    margin-bottom: 25px;
    text-align: left;
    padding: 15px;
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 10px;
    border: 1px solid #ddd;
    display: block;
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-height: 100px;
}

#generate-story {
    background: linear-gradient(135deg, #32cd32 0%, #28a745 100%);
    border: none;
    border-radius: 10px;
    color: white;
    padding: 12px 20px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
    align-self: center;
}

#generate-story:hover {
    background: linear-gradient(135deg, #28a745 0%, #218838 100%);
    transform: translateY(-2px);
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
}

.settings {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
}

.settings label {
    display: block;
    margin-bottom: 8px;
    color: #555;
}

.settings input[type="text"] {
    width: calc(100% - 22px);
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.9em;
}

/* Story header with fullscreen button */
.story-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.story-header h2 {
    margin: 0;
    flex: 1;
}

.fullscreen-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    padding: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.fullscreen-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}

.fullscreen-button svg {
    width: 20px;
    height: 20px;
}

/* Modal plein écran optimisé */
.story-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%; /* Changed from 100vw */
    height: 100%; /* Changed from 100vh */
    margin: 0;
    padding: 0;
    background-color: white; /* Ensure opaque */
    z-index: 9999;           /* Ensure on top */
    box-sizing: border-box;  /* Ensure consistent sizing */
}

.story-modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: none;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #f0f0f0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 0;
    height: 60px;
    box-sizing: border-box;
    margin: 0;
    flex-shrink: 0;
}

.modal-header-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.text-size-button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.text-size-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.text-size-button svg {
    width: 20px;
    height: 20px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5em;
}

.close-button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.close-button svg {
    width: 24px;
    height: 24px;
}

.modal-story-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    margin: 0;
}

#modal-story-text {
    font-size: 1.2em;
    line-height: 1.6;
    color: #333;
    text-align: justify;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    -webkit-hyphens: auto;
    -ms-hyphens: auto;
    margin: 0;
    padding: 0;
    flex: 1;
    white-space: pre-wrap;
}

.modal-controls {
    padding: 15px 20px;
    border-top: 1px solid #f0f0f0;
    text-align: center;
    min-height: 70px;
    box-sizing: border-box;
    margin: 0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-read-btn {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3);
    margin-right: 10px;
}

.modal-read-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4);
}

.modal-generate-btn {
    display: none; /* Masquer le bouton dans le modal plein écran */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.modal-generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}

.modal-stop-btn {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.3);
    margin-right: 10px;
}

.modal-stop-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(220, 53, 69, 0.4);
}

.modal-select-btn {
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 152, 0, 0.3);
    margin-right: 10px;
}

.modal-select-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 152, 0, 0.4);
}

.modal-select-btn.active {
    background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

.word-container.selectable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.word-container.selectable:hover {
    background-color: rgba(255, 152, 0, 0.2);
    border-radius: 4px;
    padding: 2px 4px;
    margin: -2px -4px;
}

.word-container.selected {
    background-color: rgba(76, 175, 80, 0.3);
    border-radius: 4px;
    padding: 2px 4px;
    margin: -2px -4px;
    border: 2px solid #4caf50;
}

/* Word highlighting during reading */
.word-highlight {
    transition: all 0.3s ease;
    padding: 2px 1px;
    border-radius: 3px;
    cursor: pointer;
}

.word-highlight:hover {
    background-color: #e3f2fd;
    color: #1976d2;
    transform: scale(1.02);
    box-shadow: 0 1px 3px rgba(25, 118, 210, 0.3);
}

.word-current {
    background-color: #ffeb3b !important;
    color: #333 !important;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(255, 235, 59, 0.5);
    transform: scale(1.05);
    z-index: 1;
    position: relative;
}

.word-current:hover {
    background-color: #ffeb3b !important;
    color: #333 !important;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-50px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .container {
        display: flex;
        flex-direction: column;
        gap: 20px;
        max-width: 900px;
    }
    
    .main-title {
        order: 0;
    }
    
    .right-panel {
        position: static;
    }
}

/* Tablettes et petits écrans */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        display: flex;
        flex-direction: column;
        padding: 20px;
        gap: 20px;
        border-radius: 10px;
    }
    
    .main-title {
        order: 0;
        margin-bottom: 10px;
    }
    
    .main-title h1 {
        font-size: 1.8em;
        margin-bottom: 15px;
    }
    
    .right-panel {
        position: static;
    }
    
    .sound-selection {
        display: flex;
        flex-direction: column;
        gap: 15px;
    }
    
    .sound-category {
        padding: 12px;
    }
    
    .sound-buttons-grid {
        grid-template-columns: repeat(auto-fit, minmax(55px, 1fr));
        gap: 8px;
    }
    
    .sound-button {
        padding: 12px 8px;
        font-size: 0.95em;
        min-width: 55px;
        min-height: 44px; /* Taille minimum recommandée pour le touch */
    }
    
    .story-display {
        padding: 20px;
        min-height: 150px;
    }

    #story-text {
        font-size: 1.15em;
        line-height: 1.7;
        padding: 15px;
    }
    
    .controls-section {
        padding: 15px;
    }
    
    .options-grid {
        display: flex;
        flex-direction: column;
        gap: 15px;
    }
    
    #variants-list {
        grid-template-columns: repeat(auto-fit, minmax(65px, 1fr));
        gap: 10px;
    }
    
    .variant-button {
        min-height: 44px;
        padding: 8px 12px;
    }
    
    /* Pas de règles spécifiques pour le modal sur tablettes */
}

/* Smartphones et très petits écrans */
@media (max-width: 480px) {
    body {
        padding: 2px;
        font-size: 14px;
    }
    
    .container {
        padding: 10px;
        border-radius: 8px;
        margin: 0;
        display: flex;
        flex-direction: column;
        gap: 10px;
        grid-template-columns: none;
        grid-gap: unset;
        align-items: stretch;
    }
    
    .main-title {
        grid-column: unset;
        order: 0;
    }
    
    .main-title {
        text-align: center;
        margin-bottom: 15px;
    }
    
    .main-title h1 {
        font-size: 1.4em;
        margin-bottom: 8px;
        line-height: 1.2;
    }
    
    .left-panel {
        order: 2;
        display: flex;
        flex-direction: column;
        position: static;
        top: unset;
    }
    
    .right-panel {
        order: 1;
        display: flex;
        flex-direction: column;
        position: static;
        top: unset;
    }
    
    .sound-selection {
        order: 2;
    }
    
    .sound-category {
        padding: 8px;
        margin-bottom: 10px;
    }
    
    .sound-category h3 {
        font-size: 0.95em;
        margin-bottom: 8px;
        text-align: center;
    }
    
    .sound-buttons-grid {
        grid-template-columns: repeat(auto-fit, minmax(45px, 1fr));
        gap: 4px;
    }
    
    .sound-button {
        padding: 8px 4px;
        font-size: 0.85em;
        min-width: 45px;
        min-height: 40px;
        border-radius: 6px;
    }
    
    .custom-sound-section {
        margin-top: 20px;
        padding: 15px;
        background: #e3f2fd;
        border-radius: 12px;
        border: 1px solid #bbdefb;
        order: 4;
    }
    
    .custom-sound-section h3 {
        font-size: 1em;
        margin-bottom: 12px;
        text-align: center;
        color: #1976d2;
        font-weight: 600;
    }
    
    .custom-sound-input {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    
    #custom-sound {
        width: 100%;
        padding: 12px;
        border: 2px solid #2196f3;
        border-radius: 8px;
        font-size: 1em;
        background: white;
        box-sizing: border-box;
    }
    
    #custom-sound:focus {
        outline: none;
        border-color: #1976d2;
        box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2);
    }
    
    #use-custom-sound {
        padding: 12px 20px;
        background: #2196f3;
        color: white;
        border: none;
        border-radius: 8px;
        font-size: 1em;
        font-weight: 600;
        min-height: 44px;
        cursor: pointer;
    }
    
    #use-custom-sound:active {
        background: #1976d2;
        transform: scale(0.98);
    }
    
    #story-text {
        font-size: 1.1em;
        line-height: 1.6;
        padding: 15px;
        background: #fafafa;
        border-radius: 8px;
        border-left: 4px solid #667eea;
        margin: 10px 0;
        min-height: 80px;
        display: block;
        text-align: left;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .story-display {
        padding: 15px;
        margin-top: 20px;
        background: white;
        border-radius: 12px;
        border: 2px solid #e3f2fd;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        order: 3;
    }
    
    .story-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        margin-bottom: 10px;
        padding-bottom: 8px;
        border-bottom: 1px solid #e0e0e0;
    }
    
    .story-header h2 {
        margin: 0;
        font-size: 1.1em;
        flex: 1;
        text-align: left;
    }
    
    .fullscreen-button {
        padding: 10px;
        margin: 0;
        background: #667eea;
        color: white;
        border: none;
        border-radius: 8px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    }
    
    .fullscreen-button:active {
        transform: scale(0.95);
        background: #5a6fd8;
    }
    
    .fullscreen-button svg {
        width: 18px;
        height: 18px;
    }
    
    .controls-section {
        padding: 12px;
        background: #f8f9fa;
        border-radius: 8px;
        margin-bottom: 10px;
    }
    
    .controls-section h3 {
        font-size: 1.1em;
        margin-top: 0;
        margin-bottom: 12px;
        text-align: center;
        color: #333;
    }
    
    .length-selection {
        margin-bottom: 15px;
    }
    
    .length-selection p {
        font-size: 0.9em;
        margin-bottom: 8px;
        text-align: center;
    }
    
    .length-selection select {
        width: 100%;
        padding: 10px;
        border-radius: 6px;
        border: 1px solid #ddd;
        font-size: 0.9em;
    }
    
    .options-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .option-group {
        text-align: left;
        padding: 8px;
        background: white;
        border-radius: 6px;
        border: 1px solid #e0e0e0;
    }
    
    .option-group label {
        font-size: 0.9em;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .option-group input[type="checkbox"] {
        width: 18px;
        height: 18px;
    }
    
    select, input[type="text"], button {
        font-size: 16px; /* Évite le zoom sur iOS */
        min-height: 44px;
    }
    
    .custom-sound-input {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    #custom-sound {
        width: 100%;
        padding: 12px;
        border-radius: 6px;
    }
    
    #use-custom-sound {
        padding: 12px 20px;
        font-size: 1em;
    }
    
    .sound-variants {
        margin-top: 15px;
    }
    
    #variants-list {
        grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
        gap: 8px;
    }
    
    .variant-button {
        padding: 8px 10px;
        font-size: 0.9em;
        min-height: 44px;
    }
    
    #generate-story {
        padding: 12px 20px;
        font-size: 1em;
        margin-top: 15px;
        width: 100%;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border: none;
        border-radius: 8px;
        font-weight: 600;
        min-height: 44px;
        box-shadow: 0 3px 12px rgba(102, 126, 234, 0.3);
    }
    
    #generate-story:active {
        transform: scale(0.98);
        background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
    }
    
    .sound-variants {
        margin-top: 12px;
        padding: 10px;
        background: #f8f9fa;
        border-radius: 8px;
    }
    
    .sound-variants p {
        font-size: 0.9em;
        margin-bottom: 8px;
        text-align: center;
        color: #666;
    }
    
    /* Aucune règle spécifique pour le modal sur mobile */
}

/* Aucune règle spécifique pour le mode paysage */

/* Optimisations tactiles minimales uniquement */
@media (hover: none) and (pointer: coarse) {
    /* Zones de touch minimales */
    button {
        min-height: 44px;
        min-width: 44px;
    }
}