@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap');

#gameCanvas {
    /* Charte Ergo'Land */
    --sd-primary: #667eea;
    --sd-secondary: #764ba2;
    --sd-bg-gradient: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
    --sd-text: #2d3748;
    --sd-white: #ffffff;
    --sd-danger: #f56565;
    
    font-family: 'Poppins', sans-serif;
    background: var(--sd-bg-gradient);
    width: 100%;
    min-height: 650px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

#gameCanvas * { box-sizing: border-box; }

#story-game-wrapper {
    width: 100%; max-width: 850px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.15);
    padding: 30px;
    min-height: 550px;
    position: relative;
    display: flex; flex-direction: column;
}

/* PLEIN ECRAN */
#story-game-wrapper:fullscreen {
    width: 100vw; height: 100vh;
    border-radius: 0;
    justify-content: center; overflow-y: auto;
    background: #f7fafc; /* Fond uni en plein écran pour lisibilité */
}

.hidden { display: none !important; }
.sd-screen { width: 100%; animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* --- TITRES --- */
.sd-title { 
    text-align: center; margin: 0; 
    background: linear-gradient(to right, var(--sd-primary), var(--sd-secondary));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    font-size: 2.2rem; font-weight: 700;
}
.sd-subtitle { text-align: center; color: #718096; margin-top: 5px; margin-bottom: 30px; }

/* --- CONFIGURATION --- */
.sd-config-box {
    background: #f8fafc; padding: 25px; border-radius: 15px;
    margin-bottom: 25px; border: 2px solid #e2e8f0;
}

.sd-config-row {
    display: flex; justify-content: center; align-items: center; gap: 15px; margin-bottom: 20px;
    font-size: 1.1rem; font-weight: 600; color: var(--sd-text);
}

.sd-range-selector {
    display: flex; align-items: center; gap: 15px; background: white;
    padding: 5px 15px; border-radius: 50px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid #e2e8f0;
}
#sd-dice-count-display { font-size: 1.5rem; color: var(--sd-secondary); font-weight: bold; min-width: 30px; text-align: center; }

/* Cartes Mode */
.sd-mode-selector { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; }
.sd-mode-card {
    flex: 1; min-width: 200px; max-width: 280px;
    background: white; border: 2px solid #e2e8f0; border-radius: 15px;
    padding: 20px; text-align: center; cursor: pointer;
    transition: all 0.2s;
}
.sd-mode-card:hover { transform: translateY(-3px); border-color: var(--sd-primary); }
.sd-mode-card.active {
    border-color: var(--sd-primary); background-color: #ebf4ff;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.2);
}
.sd-mode-icon { font-size: 2.5rem; display: block; margin-bottom: 10px; }
.sd-mode-card h3 { margin: 0 0 5px 0; color: var(--sd-secondary); font-size: 1.1rem; }
.sd-mode-card p { margin: 0; font-size: 0.9rem; color: #718096; }

/* --- BOUTONS --- */
.sd-action-buttons { display: flex; justify-content: center; gap: 15px; margin-top: 20px; flex-wrap: wrap; }

.sd-btn-primary {
    background: linear-gradient(to right, var(--sd-primary), var(--sd-secondary));
    color: white; border: none; padding: 12px 25px; border-radius: 50px;
    font-size: 1rem; font-weight: bold; cursor: pointer; transition: transform 0.1s;
    box-shadow: 0 4px 15px rgba(118, 75, 162, 0.3);
}
.sd-btn-primary:active { transform: translateY(2px); }
.sd-btn-primary.big { font-size: 1.2rem; padding: 15px 40px; }

.sd-btn-secondary {
    background: white; border: 2px solid var(--sd-primary); color: var(--sd-primary);
    padding: 10px 25px; border-radius: 50px; font-weight: bold; cursor: pointer; transition: 0.2s;
}
.sd-btn-secondary:hover { background: #ebf4ff; }

.sd-btn-round {
    width: 32px; height: 32px; border-radius: 50%; border: none;
    background: #edf2f7; cursor: pointer; font-weight: bold; font-size: 1.2rem;
    color: var(--sd-text); display: flex; justify-content: center; align-items: center;
}
.sd-btn-round:hover { background: var(--sd-primary); color: white; }

.sd-btn-icon {
    background: #f7fafc; border: 1px solid #e2e8f0; padding: 8px 15px; 
    border-radius: 10px; cursor: pointer; color: #718096; font-weight: 600;
}
.sd-btn-icon:hover { background: #e2e8f0; color: var(--sd-primary); }

.sd-btn-icon-abs {
    position: absolute; top: 20px; right: 20px;
    background: transparent; border: 1px solid #cbd5e0; 
    width: 40px; height: 40px; border-radius: 50%; 
    cursor: pointer; display: flex; justify-content: center; align-items: center;
    font-size: 1.2rem; color: #718096;
}
.sd-btn-icon-abs:hover { background: #f7fafc; color: var(--sd-primary); }

.sd-btn-action {
    background: #ebf8ff; color: var(--sd-primary); border: 1px solid var(--sd-primary);
    padding: 8px 20px; border-radius: 50px; font-weight: bold; cursor: pointer;
}
.sd-btn-action:hover { background: var(--sd-primary); color: white; }

/* --- JEU (DES) --- */
.sd-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; padding-bottom: 10px; border-bottom: 1px solid #e2e8f0; }
.sd-header-left { display: flex; gap: 10px; }

#sd-dice-container {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 20px;
    margin: 30px 0; min-height: 100px;
}

.sd-die {
    width: 90px; height: 90px;
    background: white; border-radius: 18px;
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.15);
    border: 2px solid #e2e8f0;
    display: flex; justify-content: center; align-items: center;
    font-size: 3.5rem; user-select: none;
    transition: transform 0.3s;
}
/* Animation */
.roll-anim { animation: rollDie 0.6s ease-out; }
@keyframes rollDie {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(180deg) scale(1.1); }
    100% { transform: rotate(360deg) scale(1); }
}

/* --- ECRITURE --- */
#sd-writing-area { display: flex; flex-direction: column; gap: 15px; margin-top: 20px; }
#sd-story-input {
    width: 100%; min-height: 300px;
    font-family: 'Poppins', sans-serif; font-size: 1.1rem; line-height: 1.8;
    padding: 15px 25px; 
    border: 2px solid #e2e8f0; border-radius: 15px;
    color: #4a5568; resize: vertical; outline: none;
    background-color: #fff;
    /* Lignes cahier */
    background-image: linear-gradient(transparent 35px, #e2e8f0 35px);
    background-size: 100% 36px; background-attachment: local; 
    transition: border-color 0.3s;
}
#sd-story-input:focus { border-color: var(--sd-primary); box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); }

.sd-save-row { text-align: right; }

#sd-paper-instruction {
    display: flex; justify-content: center; margin-top: 30px;
}
.sd-paper-card {
    background: #ebf8ff; border: 2px solid #bee3f8;
    padding: 30px; border-radius: 15px; text-align: center;
    max-width: 500px;
}
.sd-paper-card h3 { color: var(--sd-secondary); margin-top: 0; }

/* --- HISTORIQUE --- */
#sd-history-list { display: flex; flex-direction: column; gap: 15px; }
.sd-history-item {
    background: white; border: 1px solid #e2e8f0; border-radius: 12px; padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02); position: relative;
}

.sd-h-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sd-h-date { font-size: 0.85rem; color: #a0aec0; font-weight: 600; }

.sd-btn-delete-item {
    background: #fff5f5; color: #c53030;
    border: none; width: 28px; height: 28px; border-radius: 50%;
    cursor: pointer; font-size: 0.9rem;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s;
}
.sd-btn-delete-item:hover { transform: scale(1.1); background: #feb2b2; color: white; }

.sd-h-dice { font-size: 1.8rem; margin-bottom: 15px; letter-spacing: 5px; }
.sd-h-text { 
    font-size: 0.95rem; color: #4a5568; background: #f7fafc; padding: 15px; 
    border-radius: 8px; border-left: 4px solid var(--sd-primary);
    white-space: pre-wrap; line-height: 1.6;
}
.sd-h-paper-tag {
    display: inline-block; background: #edf2f7; color: #718096; padding: 4px 10px;
    border-radius: 20px; font-size: 0.8rem; font-weight: 600;
}

.sd-btn-danger-text { background: none; border: none; color: var(--sd-danger); cursor: pointer; text-decoration: underline; font-size: 0.9rem; }

/* --- TOAST --- */
#sd-toast {
    position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
    background: #2d3748; color: white; padding: 12px 25px; border-radius: 50px;
    font-weight: bold; box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    opacity: 0; transition: opacity 0.3s; pointer-events: none; z-index: 100;
}
#sd-toast.show { opacity: 1; }

@media (max-width: 600px) {
    .sd-title { font-size: 1.8rem; }
    .sd-mode-selector { flex-direction: column; }
    .sd-die { width: 60px; height: 60px; font-size: 2.2rem; }
}