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

*:focus {
    outline: none;
}

body {
    background: #F9F5EF;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #333;
    min-height: 100vh;
}

#app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* ============================================ */
/* HEADER + ONGLETS                             */
/* ============================================ */

header {
    margin-bottom: 10px;
}

#header-grid {
    display: grid;
    grid-template-columns: 200px 1fr 250px;
    align-items: flex-end;
    gap: 20px;
}

#header-col-left {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

#header-col-center {
    display: flex;
    justify-content: center;
    margin-bottom: 50px;
}

#header-col-right {
    display: flex;
    justify-content: center;
}

#header-col-right {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#logo-right {
    height: 160px;
    margin-right: 100px;
    margin-bottom: 0;
}

#user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    margin-right: 100px;
}

#user-name {
    font-size: 0.78rem;
    color: #695A47;
    font-weight: 500;
}

#btn-logout {
    font-size: 0.7rem;
    padding: 3px 10px;
    background: #e2d9cc;
    border: 1px solid #c0b5a5;
    border-radius: 5px;
    color: #6b5e52;
    cursor: pointer;
}

#btn-logout:hover {
    background: #d4c9b8;
}

#logo {
    height: 130px;
    margin-left: 170px;
}

#tabs {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    margin-left: 70px;
}

.tab {
    padding: 10px 24px;
    border: 1px solid #c0b5a5;
    background: #e2d9cc;
    color: #6b5e52;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 7px;
    transition: all 0.2s;
}

.tab:hover {
    background: #d4c9b8;
}

.tab.active {
    background: #a08468;
    color: white;
    border-color: #8a7058;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: flex;
}

/* ============================================ */
/* SIMULATEUR                                   */
/* ============================================ */

#tab-simulator {
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
}

#remote-container {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 200px;
    min-width: 200px;
}

#remote-canvas {
    cursor: pointer;
    filter: drop-shadow(4px 6px 10px rgba(0, 0, 0, 0.35));
}

#controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: #f5f5f5;
    padding: 20px;
    border-radius: 12px;
    min-width: 200px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-weight: bold;
    font-size: 0.85rem;
    text-transform: uppercase;
    color: #666;
}

.control-group button {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: #ff6600;
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.control-group button:hover {
    background: #e55a00;
}

.control-group button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.control-group input[type="range"] {
    width: 100%;
    accent-color: #8E7155;
}

.control-group input[type="color"] {
    width: 100%;
    height: 30px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.control-group input[type="file"] {
    font-size: 0.75rem;
    padding: 4px;
}

#simulator {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#canvas {
    cursor: pointer;
    border-radius: 7px;
    border: 1px solid #333;
}

#info-panel {
    background: #ffffff;
    border: 1px solid #333;
    border-radius: 7px;
    width: 250px;
    min-width: 250px;
    max-width: 250px;
    height: 700px;
    max-height: 700px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#info-panel h3 {
    font-size: 1rem;
    color: #666;
    text-transform: uppercase;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#activity-log {
    font-size: 0.85rem;
    line-height: 1.6;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: #f3efe8;
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.08);
    border: 1px solid #d9cfc2;
    border-radius: 3px;
    margin: 0 13px 13px 13px;
    padding: 8px;
}

#activity-log .log-entry {
    padding: 4px 3px;
    margin-bottom: 0;
    background: none;
    border-bottom: 1px dashed #c9bfb2;
    transition: background 0.5s;
}

#activity-log .log-entry.latest {
    background: #e8e0d4;
    animation: logFlash 0.6s ease;
}

@keyframes logFlash {
    0% { background: #d4c9b8; }
    50% { background: #e8e0d4; }
    75% { background: #d4c9b8; }
    100% { background: #e8e0d4; }
}

/* ============================================ */
/* ÉDITEUR                                      */
/* ============================================ */

#tab-editor, #tab-book {
    flex-direction: column;
}

#editor-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
}

#editor-panel {
    flex: 1;
    max-width: 1150px;
}

/* Barre de mode */
#editor-mode-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}

.mode-btn {
    padding: 8px 20px;
    border: 1px solid #c0b5a5;
    background: #e2d9cc;
    color: #6b5e52;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 7px;
    transition: all 0.2s;
}

.mode-btn:hover {
    background: #d4c9b8;
}

.mode-btn.active {
    background: #a08468;
    color: white;
    border-color: #8a7058;
}

.editor-mode {
    display: none;
}

.editor-mode.active {
    display: block;
}

/* Étapes */
.editor-step {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 12px;
}

.editor-step h3 {
    font-size: 1rem;
    color: #333;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #695A47;
    color: white;
    font-size: 0.85rem;
    font-weight: bold;
}

.step-hint {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 10px;
}

.form-row {
    margin-bottom: 10px;
}

.form-row-inline {
    display: flex;
    gap: 20px;
    margin-bottom: 10px;
}

.form-row-inline .form-row {
    margin-bottom: 0;
}

.note-field {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.note-play-btn {
    width: 22px;
    height: 22px;
    padding: 0;
    margin-top: 4px;
    border: 1px solid #c0b5a5;
    border-radius: 50%;
    background: #e2d9cc;
    color: #6b5e52;
    font-size: 9px;
    cursor: pointer;
    transition: background 0.15s;
}

.note-select {
    width: 70px;
    padding: 8px 10px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
}

.note-select:focus {
    outline: none;
    border-color: #8E7155;
}

.note-play-btn:hover {
    background: #a08468;
    color: white;
}

.file-btn {
    display: inline-block;
    width: 200px;
    text-align: center;
    padding: 8px 16px;
    background: #e2d9cc;
    color: #6b5e52;
    font-weight: 600;
    font-size: 0.85rem;
    border: 1px solid #c0b5a5;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.2s;
}

.file-btn:hover {
    background: #d4c9b8;
}

.file-name {
    display: block;
    font-size: 0.75rem;
    color: #999;
    margin-top: 4px;
}

.form-row label {
    display: block;
    font-size: 0.85rem;
    color: #555;
    margin-bottom: 4px;
    font-weight: 500;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row textarea,
.form-row select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-row input:focus,
.form-row textarea:focus,
.form-row select:focus {
    outline: none;
    border-color: #8E7155;
}

.form-row input[type="color"] {
    width: 60px;
    height: 30px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    cursor: pointer;
    padding: 2px;
}

.form-row input[type="checkbox"] {
    margin-right: 6px;
    accent-color: #8E7155;
}

.form-row input[type="range"] {
    width: calc(100% - 40px);
    vertical-align: middle;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: linear-gradient(to right, #8E7155 0%, #8E7155 var(--range-pct, 0%), #DBD1C1 var(--range-pct, 0%), #DBD1C1 100%);
    border-radius: 3px;
    outline: none;
}

.form-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #564837;
    cursor: pointer;
    border: none;
}

.form-row input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #564837;
    cursor: pointer;
    border: none;
}

/* Difficulté */
.difficulty-tabs {
    display: flex;
    gap: 6px;
    width: 500px;
}

.diff-btn {
    flex: 1;
    padding: 6px 12px;
    border: 1px solid #c0b5a5;
    background: #e2d9cc;
    color: #6b5e52;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 7px;
    transition: all 0.2s;
}

.diff-btn:hover {
    background: #d4c9b8;
}

.diff-btn.active {
    background: #a08468;
    color: white;
    border-color: #8a7058;
}

/* Événements */
#events-list {
    margin-bottom: 10px;
}

.event-item {
    padding: 10px 12px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.event-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.event-row .event-icon {
    font-size: 1.1rem;
}

.event-row .event-desc {
    font-weight: 600;
    min-width: 130px;
}

.event-row .event-spacer {
    width: 20px;
}

.event-row .btn-remove-event {
    background: #f5d4d4;
    border: 1px solid #e0a0a0;
    border-radius: 7px;
    color: #cc0000;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px 6px;
    margin-left: auto;
    transition: background 0.15s;
}

.event-row .btn-remove-event:hover {
    background: #e8b8b8;
}

.event-label {
    font-size: 0.8rem;
    color: #888;
    font-weight: 500;
}

.event-row select,
.event-row input {
    padding: 4px 6px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-size: 0.8rem;
    outline: none;
}

.event-row select:focus,
.event-row input:focus {
    border-color: #8E7155;
    outline: none;
}

.event-trigger-select {
    min-width: 140px;
}

.event-file-btn {
    display: inline-block;
    padding: 5px 12px;
    background: #e2d9cc;
    color: #6b5e52;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid #c0b5a5;
}

.event-file-btn:hover {
    background: #d4c9b8;
}

.event-file-name {
    font-size: 0.78rem;
    color: #888;
    font-style: italic;
}

.event-add-bar {
    display: flex;
    gap: 8px;
    align-items: center;
}

.event-add-bar select {
    width: 40%;
    padding: 8px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    font-size: 0.85rem;
    outline: none;
}

.event-add-bar select:focus {
    border-color: #8E7155;
    outline: none;
}

.event-add-bar button {
    padding: 8px 20px;
    border: 1px solid #8a7058;
    background: #a08468;
    color: white;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.event-add-bar button:hover {
    background: #8e7355;
}

/* Actions */
.editor-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.btn-primary {
    padding: 10px 24px;
    border: none;
    background: #28a745;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #218838;
}

.btn-secondary {
    padding: 10px 20px;
    border: 1px solid #d0d0d0;
    background: white;
    color: #555;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-secondary:hover {
    border-color: #ff6600;
    color: #ff6600;
}

/* Boutons actions éditeur */
.btn-action-test {
    padding: 10px 24px;
    border: 1px solid #9cc09c;
    background: #d4e8d4;
    color: #3d6b3d;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.btn-action-test:hover {
    background: #b8d8b8;
}

.btn-action-open {
    padding: 10px 24px;
    border: 1px solid #9cb0c0;
    background: #d4e0e8;
    color: #3d5a6b;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s;
}

.btn-action-open:hover {
    background: #b8d0d8;
}

.btn-action-save {
    padding: 10px 24px;
    border: 1px solid #d4c48a;
    background: #f5e6b8;
    color: #7a6520;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s;
}

.btn-action-save:hover {
    background: #e8d89e;
}

.btn-action-save.unsaved {
    background: #e8a0a0;
    color: #7a2020;
    border-color: #c07070;
}

.btn-action-save.unsaved:hover {
    background: #d88888;
}

.btn-action-new {
    padding: 10px 24px;
    border: 1px solid #d4aa88;
    background: #f5d4b8;
    color: #7a4a20;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.btn-action-new:hover {
    background: #e8c4a0;
}

.btn-action-io {
    padding: 10px 20px;
    border: 1px solid #c0b5a5;
    background: #e2d9cc;
    color: #6b5e52;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-action-io:hover {
    background: #d4c9b8;
}

/* Boutons du tapis config */
.buttons-config h4 {
    font-size: 0.85rem;
    color: #666;
    margin: 12px 0 6px 0;
    text-transform: uppercase;
}

.buttons-config h4:first-child {
    margin-top: 0;
}

.btn-config-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #eee;
}

.btn-config-row:last-child {
    border-bottom: none;
}

.btn-config-row .btn-icon {
    font-size: 0.85rem;
    min-width: 120px;
    font-weight: 500;
}

.btn-config-row select {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-size: 0.82rem;
}

.btn-config-row input[type="text"] {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-size: 0.82rem;
}

/* Grille règles du jeu */
.rules-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.rules-block {
    padding: 16px;
    border: 1px solid #d9cfc2;
    border-radius: 5px;
}

/* Séquence builder */
.sequence-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #fff;
    cursor: default;
}

.sequence-item .seq-remove {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0 2px;
    margin-left: 2px;
}

.sequence-item .seq-remove:hover {
    color: #fff;
}

/* Indicateurs de difficulté */
.diff-indicator {
    padding: 6px 14px;
    border-radius: 7px;
    opacity: 0.3;
    transition: all 0.3s;
    font-size: 0.78rem;
    font-weight: 600;
    color: #666;
    text-align: center;
    white-space: nowrap;
}

.diff-indicator.active {
    opacity: 1;
    color: #fff;
    box-shadow: 0 0 8px rgba(0,0,0,0.25);
}

/* Jeux sauvegardés */
.saved-game-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-bottom: 6px;
    transition: border-color 0.2s;
}

.saved-game-item:hover {
    border-color: #8E7155;
}

.saved-game-item .game-info {
    flex: 1;
}

.saved-game-item .game-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #333;
}

.saved-game-item .game-date {
    font-size: 0.75rem;
    color: #999;
}

.saved-game-item button {
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
}

.saved-game-item .btn-load-game {
    background: #e2d9cc;
    color: #6b5e52;
    border: 1px solid #c0b5a5;
    border-radius: 7px;
}

.saved-game-item .btn-load-game:hover {
    background: #d4c9b8;
}

.saved-game-item .btn-delete-game {
    background: #f5d4d4;
    border: 1px solid #e0a0a0;
    border-radius: 7px;
    color: #cc0000;
    font-size: 1.1rem;
    padding: 2px 6px;
    transition: background 0.15s;
}

.saved-game-item .btn-delete-game:hover {
    background: #e8b8b8;
}

/* Livre de jeux */
#book-layout {
    display: flex;
    justify-content: center;
}

#book-panel {
    flex: 1;
    max-width: 1150px;
}

.book-page-row, .book-btn-row, .book-assoc-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #eee;
}

.book-page-row:last-child, .book-btn-row:last-child, .book-assoc-row:last-child {
    border-bottom: none;
}

.btn-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
    flex-shrink: 0;
}

.book-page-row .page-num, .book-btn-row .btn-label, .book-assoc-row .assoc-label {
    min-width: 100px;
    font-weight: 500;
    font-size: 0.85rem;
}

.book-page-row input, .book-btn-row input {
    flex: 1;
    min-width: 0;
    padding: 5px 8px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-size: 0.82rem;
}

.book-btn-row .group-btn-label {
    flex: 4;
}

.group-btn-note {
    width: 120px;
    padding: 4px 6px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-size: 0.8rem;
}

.btn-play-note {
    background: #e2d9cc;
    border: 1px solid #c0b5a5;
    border-radius: 7px;
    padding: 5px 12px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 500;
    color: #6b5e52;
    flex-shrink: 0;
    white-space: nowrap;
}

.btn-play-note:hover {
    background: #d4c9b8;
}

/* Galerie de sons */
.sound-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    border-radius: 6px;
}

.sound-item:hover {
    background: #efe8dc;
}

.sound-item .sound-name {
    flex: 1;
    font-size: 0.85rem;
    color: #333;
}

.sound-item .sound-preview-btn {
    background: #e2d9cc;
    border: 1px solid #c0b5a5;
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 0.78rem;
    color: #6b5e52;
}

.sound-item .sound-preview-btn:hover {
    background: #d4c9b8;
}

.sound-item .sound-delete-btn {
    background: #f5d4d4;
    border: 1px solid #e0a0a0;
    border-radius: 6px;
    color: #cc0000;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.85rem;
}

.sound-item .sound-delete-btn:hover {
    background: #e8b8b8;
}

.sound-empty {
    text-align: center;
    color: #aaa;
    padding: 30px;
    font-size: 0.9rem;
}

.sound-file-name {
    font-size: 0.7rem;
    color: #999;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-remove-page {
    background: #f5d4d4;
    border: 1px solid #e0a0a0;
    border-radius: 7px;
    color: #cc0000;
    font-size: 1rem;
    cursor: pointer;
    padding: 2px 8px;
}

.btn-remove-page:hover {
    background: #e8b8b8;
}

.btn-add-page {
    margin-top: 8px;
    padding: 6px 14px;
    background: #e2d9cc;
    border: 1px solid #c0b5a5;
    border-radius: 7px;
    color: #6b5e52;
    font-size: 0.82rem;
    cursor: pointer;
}

.btn-add-page:hover {
    background: #d4c9b8;
}

.book-assoc-row select {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-size: 0.82rem;
}

.book-assoc-group {
    margin-top: 10px;
}

.book-assoc-group h4 {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 6px;
}

/* Images duo (livre) */
.step-info-images-duo {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    gap: 16px;
}

.picker-with-title {
    text-align: center;
}

.picker-title {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #695A47;
    margin-bottom: 6px;
}

.book-image-picker {
    width: 140px;
    height: 140px;
    border: 2px dashed #c9bfae;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    background: #f5f0e8;
    transition: border-color 0.2s;
}

.book-image-picker:hover {
    border-color: #8E7155;
}

.book-image-picker .picker-label {
    text-align: center;
    font-size: 0.8rem;
    color: #8E7155;
    pointer-events: none;
}

.book-image-picker .picker-label small {
    color: #aaa;
    font-size: 0.7rem;
}

.book-image-picker .picker-preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

.picker-change-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(105, 90, 71, 0.8);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.8rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 2;
}

.book-image-picker:hover .picker-change-btn {
    opacity: 1;
}

.picker-change-btn:hover {
    background: rgba(105, 90, 71, 1);
}

/* Modale galerie d'images */
#image-gallery-modal,
#sound-gallery-modal,
#music-gallery-modal,
#saved-games-modal,
#saved-books-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-gallery-content {
    background: #F9F5EF;
    border-radius: 12px;
    padding: 24px;
    width: 600px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.image-gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.image-gallery-header h3 {
    margin: 0;
    color: #695A47;
    font-size: 1.1rem;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: #999;
    padding: 4px 8px;
}

.modal-close-btn:hover {
    color: #333;
}

.image-gallery-actions {
    margin-bottom: 16px;
}

#image-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
    overflow-y: auto;
    max-height: 50vh;
    padding: 4px;
}

.gallery-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    aspect-ratio: 1;
    background: #eee;
    transition: border-color 0.2s;
}

.gallery-item:hover {
    border-color: #8E7155;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item .gallery-item-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.6);
    color: white;
    font-size: 0.65rem;
    padding: 3px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-item .gallery-item-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(200,0,0,0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 0.7rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.gallery-item:hover .gallery-item-delete {
    display: flex;
}

.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: #aaa;
    padding: 30px;
    font-size: 0.9rem;
}

/* Miniature livre dans la liste sauvegardée */
.saved-book-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.saved-book-thumb-empty {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: #e2d9cc;
    flex-shrink: 0;
}

/* Bandeau livre actif */
.current-book-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: #efe8dc;
    border: 1px solid #d4c9b8;
    border-radius: 8px;
    margin-bottom: 12px;
}

.current-book-banner-img {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
}

.current-book-banner-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #695A47;
}

/* Layout étape 1 éditeur (infos + image tapis) */
.step-info-layout {
    position: relative;
    min-height: 160px;
}

/* Éditeur : 1 image 250px */
/* Éditeur et Livre : 2 images 200px */
#tab-editor .step-info-layout,
#tab-book .step-info-layout {
    min-height: 230px;
}

#tab-editor .step-info-fields,
#tab-book .step-info-fields {
    margin-right: 436px;
}

#tab-editor .book-image-picker,
#tab-book .book-image-picker {
    width: 200px;
    height: 200px;
}

.step-info-fields .form-row {
    margin-bottom: 6px;
}

.step-info-fields .form-row textarea {
    resize: vertical;
}

.step-info-image {
    position: absolute;
    top: 0;
    right: 0;
    width: 250px;
    height: 250px;
}

.step-info-image .book-image-picker {
    width: 250px;
    height: 250px;
    border: 1px solid #c9bfae;
}

/* Nodes editor */
#nodes-editor {
    display: flex;
    gap: 0;
    width: 95vw;
    height: 80vh;
    border-radius: 7px;
    overflow: hidden;
    border: 1px solid #c9bfae;
    margin-left: 50%;
    transform: translateX(-50%);
    position: relative;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

/* Palette */
#nodes-palette {
    width: 210px;
    min-width: 210px;
    background: #fff;
    padding: 14px;
    overflow-y: auto;
    color: #4a3f35;
    border-right: 1px solid #d9cfc2;
}

#nodes-palette h4 {
    font-size: 0.72rem;
    text-transform: uppercase;
    color: #8a7e72;
    margin: 14px 0 6px 0;
    letter-spacing: 0.5px;
    font-weight: 600;
}

#nodes-palette h4:first-child {
    margin-top: 0;
}

.palette-block {
    padding: 8px 12px;
    margin-bottom: 5px;
    border-radius: 7px;
    font-size: 0.82rem;
    cursor: grab;
    transition: all 0.15s;
    user-select: none;
    font-weight: 500;
    border: 1px solid transparent;
}

.palette-block:active {
    cursor: grabbing;
}

.palette-block[data-type^="trigger"] {
    background: #d4e8d4;
    color: #3d6b3d;
    border-color: #9cc09c;
}

.palette-block[data-type^="action"] {
    background: #d4e0f0;
    color: #2d4a6b;
    border-color: #9cb5d4;
}

.palette-block[data-type^="condition"] {
    background: #f5e6b8;
    color: #7a6520;
    border-color: #d4c48a;
}

.palette-block[data-type^="logic"] {
    background: #e8d4f0;
    color: #5a3d6b;
    border-color: #c09cd4;
}

.palette-block:hover {
    transform: translateX(3px);
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Canvas container */
#nodes-canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f3efe8;
}

#nodes-toolbar {
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    background: #fff;
    border-bottom: 1px solid #d9cfc2;
    align-items: center;
}

#nodes-toolbar button {
    padding: 6px 14px;
    border: 1px solid #c0b5a5;
    border-radius: 7px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

#nodes-toolbar button:hover {
    filter: brightness(0.95);
}

#nodes-toolbar #btn-nodes-test {
    background: #d4e8d4;
    color: #3d6b3d;
    border-color: #9cc09c;
}

#nodes-toolbar #btn-nodes-clear {
    background: #f5d4d4;
    color: #7a2020;
    border-color: #e0a0a0;
}

#nodes-toolbar #btn-nodes-save {
    background: #f5e6b8;
    color: #7a6520;
    border-color: #d4c48a;
}

#nodes-toolbar #btn-nodes-export,
#nodes-toolbar #btn-nodes-import {
    background: #e2d9cc;
    color: #6b5e52;
    border-color: #c0b5a5;
}

#nodes-info {
    flex: 1;
    text-align: right;
    font-size: 0.75rem;
    color: #a09080;
}

#nodes-canvas {
    flex: 1;
    cursor: default;
}

/* Liste musique */
.music-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border: 1px solid #d9cfc2;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.15s;
    background: #fff;
}

.music-item:hover {
    background: #f5f0e8;
    border-color: #a08468;
}

.music-item .music-title {
    font-weight: 600;
    color: #4a3f35;
}

.music-item .music-duration {
    font-size: 0.85rem;
    color: #888;
}

#music-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.3);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Modale d'édition de node */
#node-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.3);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
}

#node-modal, #music-modal {
    background: #faf7f2;
    border-radius: 14px;
    min-width: 300px;
    max-width: 400px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    overflow: hidden;
    animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

#node-modal-header, #music-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: #e8e0d4;
    border-bottom: 1px solid #d9d0c3;
}

#node-modal-title, #music-modal-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: #4a3f35;
}

#node-modal-close, #music-modal-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #8a7e72;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}

#node-modal-close:hover {
    background: rgba(0,0,0,0.08);
}

#node-modal-body {
    padding: 18px;
}

.node-modal-row {
    margin-bottom: 14px;
}

.node-modal-row:last-child {
    margin-bottom: 0;
}

.node-modal-row label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #6b5e52;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.node-modal-row input[type="number"],
.node-modal-row input[type="text"],
.node-modal-row select {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #d9d0c3;
    border-radius: 8px;
    font-size: 0.9rem;
    background: #fff;
    color: #4a3f35;
    transition: border-color 0.2s;
    font-family: inherit;
}

.node-modal-row input:focus,
.node-modal-row select:focus {
    outline: none;
    border-color: #b8a899;
    box-shadow: 0 0 0 3px rgba(184,168,153,0.2);
}

.node-modal-row input[type="color"] {
    width: 100%;
    height: 40px;
    border: 1.5px solid #d9d0c3;
    border-radius: 8px;
    padding: 3px;
    cursor: pointer;
    background: #fff;
}

.node-modal-row input[type="range"] {
    width: 100%;
    accent-color: #b8a899;
}

.node-modal-range-value {
    text-align: center;
    font-size: 0.85rem;
    color: #6b5e52;
    font-weight: 600;
    margin-top: 2px;
}

/* LED ring dans la modale */
.modal-led-ring {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 4px auto 10px;
}

.modal-led-dot {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1.5px solid #c0b8ae;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: #8a7e72;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    font-family: inherit;
}

.modal-led-dot:hover {
    border-color: #888;
    transform: scale(1.12);
}

.modal-led-warning {
    position: absolute;
    font-size: 14px;
    z-index: 101;
    pointer-events: none;
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.3));
}

.modal-led-label {
    position: absolute;
    background: rgba(30, 30, 40, 0.85);
    color: #ccc;
    font-size: 10px;
    padding: 3px 7px;
    border-radius: 8px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 100;
}

#node-modal-footer {
    padding: 12px 18px;
    background: #f0ebe4;
    border-top: 1px solid #d9d0c3;
    text-align: right;
}

#node-modal-ok {
    padding: 9px 28px;
    border: none;
    border-radius: 8px;
    background: #8fbc8f;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

#node-modal-ok:hover {
    background: #7aab7a;
}
