/* =========================================
   1. CONFIGURATION GLOBALE & VARIABLES
   ========================================= */
:root {
    --primary: #4b9bbd;   /* Bleu Lagon (Marque) */
    --secondary: #2d3436; /* Noir Doux (Texte) */
    --bg: #dfe6e9;        /* Gris Clair (Fond Auth) */
    --paper: #fdfbf7;     /* Blanc Cassé (Papier) */
    --error: #d63031;     /* Rouge (Erreur/Supprimer) */
    --archive: #ffeaa7;   /* Jaune (Archive) */
    --success: #00b894;   /* Vert (Validation) */
}

@font-face {
    font-family: 'Pixel';
    src: url('../fonts/Boris.ttf'); /* Assure-toi que le fichier est là */
}

/* Reset & Base */
* {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Empêche le scroll global (géré par le viewport) */
    background-color: #2d3436; /* Fond sombre par défaut (derrière la map) */
    font-family: 'Pixel', 'Courier New', monospace;
    color: var(--secondary);
}

/* =========================================
   2. COMPOSANTS UI (BOUTONS & FORMS)
   ========================================= */

/* Bouton Principal (Bleu) */
.btn-primary {
    background-color: var(--primary);
    color: white;
    border: 3px solid black;
    padding: 12px 25px;
    border-radius: 30px;
    font-family: inherit;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 5px 5px 0 black;
    transition: all 0.1s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    text-transform: uppercase;
}

.btn-primary:hover {
    transform: translate(-2px, -2px);
    box-shadow: 7px 7px 0 black;
    filter: brightness(1.1);
}

.btn-primary:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 black;
}

.btn-primary:disabled {
    background-color: gray;
    box-shadow: none;
    transform: none;
    cursor: not-allowed;
}

/* Bouton Secondaire (Blanc) */
.btn-secondary {
    background-color: white;
    color: black;
    border: 2px solid black;
    padding: 8px 15px;
    border-radius: 15px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    margin-right: 5px;
}
.btn-secondary:hover { background-color: #eee; }
.btn-secondary.active { background-color: var(--primary); color: white; }

/* Bouton Quitter / Fermer (Petit) */
.btn-logout {
    background-color: white;
    color: black;
    text-decoration: none;
    font-weight: bold;
    border: 3px solid black;
    padding: 8px 15px;
    border-radius: 20px;
    box-shadow: 3px 3px 0 rgba(0,0,0,0.2);
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
}
.btn-logout:hover { background-color: var(--error); color: white; border-color: white; }

/* Icône dans les boutons */
.btn-icon {
    height: 24px;
    margin-right: 10px;
    vertical-align: middle;
}

/* Champs de formulaire */
.form-group { margin-bottom: 20px; text-align: left; }
label { display: block; margin-bottom: 8px; font-weight: bold; color: var(--primary); }
input[type="text"], input[type="password"], textarea, input[type="file"] {
    width: 100%;
    padding: 12px;
    border: 3px solid black;
    border-radius: 15px;
    font-family: inherit;
    font-size: 1rem;
    background: white;
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); background: #f0f8ff; }

/* =========================================
   3. PAGES AUTH (LOGIN / REGISTER)
   ========================================= */
.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: var(--bg);
    overflow: auto;
}

.auth-container {
    background: white;
    padding: 40px;
    border-radius: 25px;
    box-shadow: 10px 10px 0 rgba(0,0,0,0.1);
    border: 4px solid black;
    width: 90%;
    max-width: 450px;
    text-align: center;
}

.alert {
    color: var(--error);
    font-weight: bold;
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.1rem;
}

.auth-footer { margin-top: 40px; font-size: 0.9rem; color: #666; }
.auth-footer a { color: var(--primary); text-decoration: underline; font-weight: bold; }

/* =========================================
   4. INTERFACE JEU (MAP & HUD)
   ========================================= */

/* Le cadre de vue (Viewport) */
.map-viewport {
    position: absolute; top: 0; left: 0; width: 100vw; height: 100vh;
    overflow: hidden;
    cursor: grab;
    z-index: 0; /* Tout au fond */
    opacity: 0;
    transition: opacity 1s;
}
.map-viewport.loaded { opacity: 1; }
.map-viewport:active { cursor: grabbing; }

/* La Carte Géante */
.world-map {
    position: relative;
    width: 2500px;
    height: 1560px;
    background-color: #e6dcb6; /* BEIGE SABLE/PARCHEMIN */
    background-size: 100% 100%;
    image-rendering: pixelated; /* Pixel Art net */
    user-select: none;
}

/* Les Maisons */
.house {
    position: absolute;
    width: 60px;
    text-align: center;
    transform: translate(-50%, -80%); /* Ancrage au sol */
    transition: transform 0.1s, filter 0.2s;
}
.house:hover { z-index: 100; filter: brightness(1.2); transform: translate(-50%, -85%) scale(1.1); }
.house img { width: 100%; filter: drop-shadow(0px 4px 4px rgba(0,0,0,0.3)); pointer-events: none; }

.house-label {
    background: white;
    padding: 2px 6px;
    border: 2px solid black;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: bold;
    position: absolute; bottom: -15px; left: 50%; transform: translateX(-50%);
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}

/* Sélection maison */
.house.selected img { filter: drop-shadow(0 0 10px var(--primary)); transform: scale(1.2); }
.house.selected .house-label { background: var(--primary); color: white; border-color: black; }

/* Ma Maison (plus grosse) */
.my-house { z-index: 90; width: 80px; }

/* HUD (Interface flottante) */
.hud-top-left {
    position: fixed; top: 20px; left: 20px; z-index: 1000;
    background: white; border: 3px solid black; border-radius: 50px;
    padding: 10px 25px; box-shadow: 5px 5px 0 rgba(0,0,0,0.3);
    font-size: 1.2rem; display: flex; align-items: center; gap: 10px;
    font-weight: bold; color: var(--primary);
}
.hud-top-right { position: fixed; top: 20px; right: 20px; z-index: 1000; }

/* Bouton Écrire (Flottant bas) */
#action-bar {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
    z-index: 1000; display: none; /* Caché par défaut */
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes popIn { 0% { transform: translateX(-50%) scale(0); opacity: 0; } 100% { transform: translateX(-50%) scale(1); opacity: 1; } }

/* =========================================
   5. TIROIR A COURRIER (INBOX) & CARTES 3D
   ========================================= */
#mail-drawer {
    position: fixed; bottom: -100%; left: 0; width: 100%; height: 85vh;
    background: rgba(255, 255, 255, 0.98);
    border-top: 5px solid black;
    border-radius: 30px 30px 0 0;
    z-index: 2000;
    transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding: 20px;
    overflow-y: auto;
    display: flex; flex-direction: column; align-items: center;
}
#mail-drawer.open { bottom: 0; }

/* Tabs (Archives / Inbox) */
.drawer-tabs { display: flex; gap: 10px; margin-bottom: 20px; }
.tab-btn { padding: 8px 15px; border: 2px solid black; border-radius: 20px; cursor: pointer; background: white; font-weight: bold; }
.tab-btn.active { background: var(--primary); color: white; }

/* Grille de cartes */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 30px;
    width: 100%; max-width: 1000px;
    padding-bottom: 50px;
}

/* --- LA CARTE 3D --- */
.card-scene {
    width: 100%;
    aspect-ratio: 3/2; /* 10x15 Paysage */
    perspective: 1000px;
    cursor: pointer;
}

.card-object {
    position: relative; width: 100%; height: 100%;
    transition: transform 0.8s;
    transform-style: preserve-3d;
    border-radius: 10px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.15);
}
/* Classe pour retourner la carte via JS */
.card-object.flipped { transform: rotateY(180deg); }

.face {
    position: absolute; width: 100%; height: 100%;
    backface-visibility: hidden; -webkit-backface-visibility: hidden;
    border-radius: 10px; overflow: hidden;
    border: 1px solid #ccc;
    background: white;
}

.face.front img { width: 100%; height: 100%; object-fit: cover; }

.face.back {
    background-color: var(--paper);
    transform: rotateY(180deg);
    padding: 15px;
    display: flex;
    background-image: radial-gradient(#ddd 1px, transparent 1px);
    background-size: 15px 15px;
}

.stamp-area {
    position: absolute; top: 10px; right: 10px;
    width: 60px; height: 70px;
}
.real-stamp { width: 100%; height: 100%; object-fit: contain; transform: rotate(5deg); filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.2)); }

.message-content {
    font-family: 'Courier New', monospace; font-weight: bold; color: #333;
    font-size: 0.9rem; line-height: 1.2;
    margin-right: 70px; text-align: left;
    overflow-y: auto; height: 100%;
}
.meta { color: var(--primary); border-bottom: 1px solid #ccc; padding-bottom: 5px; margin-bottom: 5px; font-size: 0.7rem; }

/* Boutons d'action sur la carte (Grille) */
.card-actions {
    position: absolute; bottom: 10px; left: 10px;
    display: flex; gap: 5px; z-index: 10;
}
.action-btn {
    background: white; border: 2px solid black; border-radius: 50%;
    width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 1rem; transition: transform 0.1s;
}
.action-btn:hover { transform: scale(1.1); }
.action-btn.archive:hover { background: var(--archive); }
.action-btn.delete:hover { background: var(--error); color: white; }

/* =========================================
   6. MODALES & POPUPS
   ========================================= */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); z-index: 3000;
    align-items: center; justify-content: center;
    backdrop-filter: blur(5px);
}

/* Modale d'Écriture (Blanche) */
.modal-box {
    background: white;
    border: 4px solid black;
    border-radius: 25px;
    padding: 30px;
    width: 95%; max-width: 550px;
    box-shadow: 15px 15px 0 black;
    position: relative;
    max-height: 95vh; overflow-y: auto;
}

/* Modale de Visionnage (Transparente) */
.modal-box-viewer {
    background: transparent;
    width: 100%; height: 100%;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    pointer-events: none; /* Laisse passer les clics */
}
.modal-box-viewer > * { pointer-events: auto; } /* Réactive clics sur contenu */

.close-btn {
    position: absolute; top: 15px; right: 20px;
    cursor: pointer; color: var(--error);
    font-size: 1.5rem; z-index: 10;
    font-weight: bold;
}

/* Barre d'actions Visionneuse */
.modal-actions {
    margin-top: 25px;
    display: flex; justify-content: center; align-items: center;
    gap: 15px; flex-wrap: wrap;
    pointer-events: auto;
    padding-bottom: 20px;
}

.btn-viewer {
    background: white; border: 3px solid black; border-radius: 30px;
    padding: 10px 20px; font-size: 1rem; cursor: pointer;
    box-shadow: 4px 4px 0 rgba(0,0,0,0.2);
    text-decoration: none; display: flex; align-items: center; gap: 5px;
    color: var(--secondary); font-family: inherit; font-weight: bold;
    transition: transform 0.1s;
}
.btn-viewer:hover { transform: scale(1.05); }
.btn-viewer:active { transform: scale(0.95); box-shadow: 2px 2px 0 rgba(0,0,0,0.2); }

.btn-dl { background-color: var(--primary); color: white; }
.btn-arch { background-color: var(--archive); }
.btn-del { background-color: var(--error); color: white; }
.btn-close { background-color: white; }

/* =========================================
   7. OUITLS D'ÉCRITURE (CROPPER & TIMBRE)
   ========================================= */

/* Cropper Container */
.img-container {
    max-height: 350px;
    margin-bottom: 20px; margin-top: 10px;
    background: #eee; border: 3px solid black;
    overflow: hidden;
}
#image-to-crop { max-width: 100%; display: block; }

/* Sélecteur de Timbres */
.stamp-selector {
    display: flex; justify-content: center; gap: 15px;
    margin-bottom: 20px; padding: 10px;
    background: rgba(0,0,0,0.05); border-radius: 15px; border: 2px solid #ccc;
}
.stamp-thumb {
    width: 50px; height: 60px; object-fit: contain;
    cursor: grab; transition: transform 0.2s;
    filter: drop-shadow(2px 2px 2px rgba(0,0,0,0.2));
}
.stamp-thumb:active { cursor: grabbing; transform: scale(0.9); }

/* Zone de dépôt Timbre */
.target-zone {
    position: absolute; top: 10px; right: 10px;
    width: 70px; height: 80px;
    border: 2px dashed #ccc; border-radius: 5px;
    background: rgba(0,0,0,0.02);
    display: flex; align-items: center; justify-content: center;
    transition: all 0.3s ease;
}
.target-zone.hovered { border-color: var(--primary); background: rgba(75, 155, 189, 0.15); transform: scale(1.05); }

/* Timbre collé */
.stamped-img {
    width: 90%; height: 90%; object-fit: contain;
    transform: rotate(3deg); filter: drop-shadow(1px 1px 1px rgba(0,0,0,0.2));
}

/* =========================================
   8. LOADER & CONSTRUCTION
   ========================================= */
#loading-screen {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: #2d3436; z-index: 9999;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: opacity 0.5s;
}
.loading-pulse { animation: pulse 1.5s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: 0.6; transform: scale(0.98); } 50% { opacity: 1; transform: scale(1); } }

#ghost-box { position: absolute; width: 80px; transform: translate(-50%, -80%); pointer-events: none; z-index: 500; display: none; opacity: 0.9; }
#status-text { font-weight: bold; padding: 4px 8px; border-radius: 10px; border: 2px solid black; position: absolute; bottom: -25px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: 0.8rem; background: var(--error); color: white; }