/* --- Import de polices pour le style d'\u00e9poque --- */
@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,700;1,400&family=Merriweather:wght@400;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700;900&display=swap');

@font-face {
    font-family: 'HandWriting';
    src: url('../fonts/hand_writing.ttf');
}

@font-face {
    font-family: 'Religath';
    src: url('../fonts/religath.otf');
}

@font-face {
    font-family: 'MadisonSauvage';
    src: url('../fonts/Madison Sauvage Script.otf');
}

@font-face {
    font-family: 'MrsSaintDelafield';
    src: url('../fonts/MrsSaintDelafield-Regular.ttf');
}

/* --- Variables globales --- */
:root {
    --bg-color: #0B0B0F;
    --surface-color: #191922;
    --border-color: #2D2D3A;
    --accent-color: #F59E0B;
    --text-color: #E2E8F0;
    --text-muted: #94A3B8;
    --delete-color: #e53e3e;

    --font-interface: 'Inter', sans-serif;
    --font-serif: 'Lora', serif;
    --font-handwriting: 'Religath', cursive;
    --font-heading: 'Merriweather', serif;

    --border-radius-sm: 4px;
    --border-radius: 8px;
    --border-radius-md: 12px;

    --shadow-sm: 0 2px 5px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);

    --glass-bg: rgba(25, 25, 34, 0.7);
    --glass-bg-light: rgba(25, 25, 34, 0.85);
}

/* --- Structure de base --- */
body {
    font-family: var(--font-interface);
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;
    padding: 20px;
    background-color: var(--bg-color);
}

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

.main-container {
    max-width: 95vw;
    margin: 0 auto;
    background-color: var(--glass-bg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* --- Arri\u00e8re-plan anim\u00e9 --- */
#particles-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

#particles-bg::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 200%;
    height: 200%;
    background-image: url('https://img.freepik.com/premium-photo/monochrome-wavy-lines-pattern_118124-262370.jpg');
    background-size: 1000px 1000px;
    opacity: 0.1;
    filter: saturate(5) hue-rotate(10deg);
}

/* --- Navigation --- */
nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 25px;
    position: sticky;
    top: 0;
    z-index: 1000;
    background-color: var(--glass-bg-light);
    border-bottom: 1px solid var(--border-color);
}

@media (max-width: 768px) {
    nav {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }
}

.nav-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.5em;
    color: var(--text-color);
}

.nav-links {
    display: flex;
    justify-content: center;
    gap: 10px;
}

@media (max-width: 768px) {
    .nav-links {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
        gap: 5px;
    }
}

nav button.nav-button {
    font-family: var(--font-interface);
    font-weight: 700;
    font-size: 0.96em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: none;
    border: none;
    padding: 10px 15px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s ease;
    border-bottom: 2px solid transparent;
}

@media (max-width: 768px) {
    nav button.nav-button {
        padding: 12px 5px;
        font-size: 0.85em;
        background: rgba(255, 255, 255, 0.02);
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius-sm);
    }

    nav button.nav-button.active {
        background: rgba(245, 158, 11, 0.1);
        border-color: var(--accent-color);
    }
}

nav button.nav-button:hover {
    color: var(--text-color);
}

nav button.nav-button.active {
    color: var(--text-color);
    border-bottom-color: var(--accent-color);
    font-weight: 700;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.nav-actions .storage-usage {
    font-size: 0.8em;
    color: var(--text-muted);
    margin: 0;
    padding: 0;
    background: none;
}

.nav-actions button {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.nav-actions button:hover {
    color: var(--text-color);
    border-color: var(--text-color);
}

.nav-actions .export-context-btn {
    width: 45px;
    height: 45px;
}

.nav-actions .export-context-btn svg {
    width: 32px;
    height: 32px;
}

.nav-actions button svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Mode Lecture / Écriture */
.readonly-btn {
    width: auto !important;
    padding: 0 15px !important;
    border-radius: 20px !important;
    gap: 8px;
    font-size: 0.8em;
    font-weight: bold;
    text-transform: uppercase;
}

.readonly-btn.unlocked {
    background-color: var(--accent-color) !important;
    color: var(--surface-color) !important;
    border-color: var(--accent-color) !important;
}

.readonly-btn.unlocked svg {
    fill: var(--surface-color) !important;
}

/* --- Layout Sections Principales --- */
.content-section {
    padding: 30px 40px;
    display: none;
}

@media (max-width: 768px) {
    .content-section {
        padding: 15px 20px;
    }
}

.content-section.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 25px;
}

@media (max-width: 768px) {
    .section-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 15px;
        padding-bottom: 15px;
    }
}

.section-header .button-group {
    display: flex;
    gap: 10px;
}

@media (max-width: 768px) {
    .section-header .button-group {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

h2 {
    font-family: var(--font-heading);
    font-size: 1.8em;
    padding-bottom: 10px;
    color: var(--accent-color);
    margin: 0;
}

/* --- Formulaires standards --- */
label {
    font-family: var(--font-interface);
    font-weight: bold;
    font-size: 0.9em;
    margin-bottom: 5px;
}

input[type="text"],
input[type="number"],
input[type="date"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-serif);
    font-size: 1em;
    box-sizing: border-box;
    border-radius: var(--border-radius);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
textarea:focus,
select:focus {
    outline: none;
    background-color: var(--bg-color);
    color: var(--text-color);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Boutons principaux */
.action-button {
    font-family: var(--font-interface);
    padding: 10px 20px;
    background-color: transparent;
    color: var(--accent-color);
    border: 2px solid var(--accent-color);
    cursor: pointer;
    font-size: 1em;
    text-align: center;
    font-weight: 700;
    border-radius: var(--border-radius);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.action-button:hover {
    background-color: var(--accent-color);
    color: var(--surface-color);
}

@media (max-width: 768px) {
    .action-button {
        padding: 8px 12px;
        font-size: 0.9em;
    }
}

.button-group {
    display: flex;
    gap: 10px;
}

/* Bouton Retour en haut */
#back-to-top-btn {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 999;
    background-color: var(--accent-color);
    color: var(--surface-color);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.5em;
    font-weight: bold;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
    line-height: 1;
}

#back-to-top-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

[contenteditable="true"] {
    outline: none;
    background-color: rgba(255, 255, 255, 0.05);
    padding: 2px 5px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

[contenteditable="true"]:hover {
    box-shadow: 0 0 0 1px var(--border-color);
}

[contenteditable="true"]:focus {
    background-color: var(--bg-color);
    box-shadow: 0 0 0 2px var(--accent-color);
}

/* Utils Gallery */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
}

.gallery-item {
    border: 1px solid var(--border-color);
    background-color: transparent;
    padding: 10px;
    text-align: center;
}

.gallery-item img {
    max-width: 100%;
    height: 100px;
    object-fit: contain;
    margin-bottom: 10px;
}

.gallery-item-path {
    font-size: 0.8em;
    font-style: italic;
    word-break: break-all;
}

.gallery-item.cloud-item {
    position: relative;
    border-color: var(--accent-color);
    background-color: rgba(245, 158, 11, 0.05);
}

.delete-cloud-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: var(--delete-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    line-height: 18px;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.delete-cloud-btn:hover {
    opacity: 1;
}

/* --- Carnet d'Intrigues --- */
.plot-notes-section {
    margin-top: 40px;
    padding: 25px;
    background: rgba(25, 25, 34, 0.5);
    border: 1px dashed var(--border-color);
    border-radius: var(--border-radius-md);
}

.plot-notes-section h3 {
    margin-top: 0;
    margin-bottom: 5px;
    color: var(--accent-color);
    font-family: var(--font-heading);
}

.section-subtitle {
    font-size: 0.9em;
    color: var(--text-muted);
    margin-bottom: 20px;
    font-style: italic;
}

.plot-ideas-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.plot-idea-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.plot-idea-item:hover {
    border-color: rgba(245, 158, 11, 0.4);
    background: rgba(0, 0, 0, 0.3);
}

.plot-idea-item.done {
    opacity: 0.6;
    border-color: transparent;
    background: rgba(0, 0, 0, 0.1);
}

.plot-idea-item.done .plot-idea-content textarea {
    text-decoration: line-through;
    color: var(--text-muted);
}

.plot-idea-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-top: 5px;
    cursor: pointer;
    accent-color: var(--accent-color);
}

.plot-idea-content {
    flex: 1;
}

.plot-idea-content textarea {
    width: 100%;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    color: var(--text-color);
    font-family: var(--font-serif);
    /* More readable font */
    font-size: 1.05em;
    line-height: 1.4;
    resize: none;
    min-height: 1.4em;
    overflow: hidden;
}

.plot-idea-content textarea:focus {
    outline: none;
    box-shadow: none;
}

.delete-idea-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5em;
    cursor: pointer;
    line-height: 1;
    padding: 0 5px;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-idea-btn:hover {
    color: var(--delete-color);
}

.plot-notes-footer {
    margin-top: 15px;
    display: flex;
    justify-content: flex-end;
}

#plot-notes-status {
    font-size: 0.8em;
    color: var(--text-muted);
    font-style: italic;
}

#plot-notes-status.syncing {
    color: var(--accent-color);
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 40000;
}

@media (max-width: 768px) {
    .toast-container {
        right: 10px;
        left: 10px;
        bottom: 10px;
    }

    .toast {
        min-width: 0;
        width: 100%;
        font-size: 0.85em;
        padding: 12px 15px;
    }
}

.toast {
    min-width: 250px;
    background-color: var(--surface-color);
    color: var(--text-color);
    padding: 15px 20px;
    border-radius: var(--border-radius-sm);
    border-left: 4px solid var(--accent-color);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    font-size: 0.95em;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: toast-in 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
    transition: all 0.3s ease;
}

.toast.success {
    border-left-color: #10B981;
}

.toast.error {
    border-left-color: #EF4444;
}

.toast.warning {
    border-left-color: #F59E0B;
}

.toast.fade-out {
    opacity: 0;
    transform: translateX(50px);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Modal Footer consistency */
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    margin-top: 25px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.action-button.secondary {
    border-color: var(--text-muted);
    color: var(--text-muted);
}

.action-button.secondary:hover {
    background-color: var(--text-muted);
    color: var(--surface-color);
}

.sync-campaigns-btn {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
}

.sync-campaigns-btn:hover {
    background: var(--accent-color);
    color: var(--bg-color);
    border-color: var(--accent-color);
}

.sync-campaigns-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}