@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;900&display=swap');

#gameCanvas {
    --sd-bg: #f0f4f8;
    --sd-primary: #6c5ce7;
    --sd-primary-dark: #5649b9;
    --sd-secondary: #00b894;
    --sd-text: #2d3436;
    --sd-card-bg: #ffffff;
    
    font-family: 'Nunito', sans-serif;
    background-color: var(--sd-bg);
    color: var(--sd-text);
    width: 100%;
    min-height: 600px;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Align top pour le scroll */
    padding: 20px;
    overflow-y: auto;
}

#gameCanvas * { box-sizing: border-box; }

#story-game-wrapper {
    width: 100%; max-width: 900px;
    background: var(--sd-card-bg);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    padding: 30px;
    min-height: 500px;
    position: relative;
}

.sd-hidden { display: none !important; }

/* --- TITRES & TEXTES --- */
.sd-title { text-align: center; color: var(--sd-primary); font-size: 2.5rem; margin-bottom: 10px; }
.sd-subtitle { text-align: center; color: #636e72; margin-bottom: 30px; font-size: 1.2rem; }

/* --- CONFIGURATION --- */
.sd-config-box {
    background: #f8f9fa; padding: 20px; border-radius: 15px;
    margin-bottom: 30px; border: 2px solid #e9ecef;
}

.sd-config-row {
    display: flex; justify-content: center; align-items: center; gap: 15px; margin-bottom: 20px;
    font-size: 1.2rem; font-weight: bold;
}

.sd-range-selector {
    display: flex; align-items: center; gap: 15px; background: white;
    padding: 5px 15px; border-radius: 50px; box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
#sd-dice-count-display { font-size: 1.5rem; color: var(--sd-primary); min-width: 30px; text-align: center; }

.sd-mode-selector { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; }
.sd-mode-card {
    flex: 1; min-width: 200px; max-width: 300px;
    background: white; border: 2px solid #dfe6e9; 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: #eef2ff;
    box-shadow: 0 5px 15px rgba(108, 92, 231, 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-primary); }
.sd-mode-card p { margin: 0; font-size: 0.9rem; color: #636e72; }

/* --- BOUTONS --- */
.sd-action-buttons { display: flex; justify-content: center; gap: 15px; margin-top: 20px; }

.sd-btn-primary, .sd-btn-secondary, .sd-btn-save, .sd-btn-action {
    padding: 12px 25px; border: none; border-radius: 10px;
    font-size: 1.1rem; font-weight: bold; cursor: pointer; transition: transform 0.1s;
    font-family: 'Nunito', sans-serif;
}
.sd-btn-primary { background: var(--sd-primary); color: white; box-shadow: 0 4px 0 var(--sd-primary-dark); }
.sd-btn-primary:active { transform: translateY(4px); box-shadow: none; }

.sd-btn-secondary { background: #dfe6e9; color: #2d3436; }
.sd-btn-secondary:hover { background: #b2bec3; }

.sd-btn-small {
    width: 30px; height: 30px; border-radius: 50%; border: none;
    background: #dfe6e9; cursor: pointer; font-weight: bold; font-size: 1.2rem;
    display: flex; justify-content: center; align-items: center;
}
.sd-btn-small:hover { background: var(--sd-primary); color: white; }

.sd-btn-icon { background: transparent; border: 1px solid #ccc; padding: 8px 15px; border-radius: 8px; cursor: pointer; }
.sd-btn-icon:hover { background: #eee; }
.sd-btn-icon.text-danger { color: #e17055; border-color: #e17055; }
.sd-btn-icon.text-danger:hover { background: #ffeaa7; }

/* --- JEU (DES) --- */
.sd-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }

#sd-dice-container {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 20px;
    margin: 30px 0; min-height: 100px;
}

.sd-die {
    width: 80px; height: 80px;
    background: white; border-radius: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1), inset 0 -4px 0 rgba(0,0,0,0.1);
    border: 2px solid #e9ecef;
    display: flex; justify-content: center; align-items: center;
    font-size: 3rem; user-select: none;
    transition: transform 0.3s;
}
/* Animation de lancer */
.roll-anim { animation: rollDie 0.6s ease-out; }
@keyframes rollDie {
    0% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(180deg) scale(0.8); }
    50% { transform: rotate(360deg) scale(1.1); }
    75% { transform: rotate(540deg) scale(0.9); }
    100% { transform: rotate(720deg) scale(1); }
}

/* --- ECRITURE --- */
#sd-writing-area {
    display: flex; flex-direction: column; gap: 10px; margin-top: 30px;
}

#sd-story-input {
    width: 100%; 
    min-height: 250px;
    
    /* POLICE ET ESPACEMENT */
    font-family: 'Nunito', sans-serif; 
    font-size: 1.2rem; /* Taille du texte */
    line-height: 34px; /* Hauteur exacte d'une ligne de texte */
    
    /* MARGES INTERNES */
    /* Le padding-top (9px) sert à caler la première ligne de texte pile sur la ligne bleue */
    padding: 9px 20px 9px 20px; 
    
    border: 2px solid #dfe6e9;
    border-radius: 15px;
    color: #2d3436;
    resize: vertical;
    outline: none;
    
    /* LE PAPIER LIGNÉ */
    background-color: #fff;
    /* Le dégradé crée la ligne : transparent sur 33px, couleur sur le 34ème pixel */
    background-image: linear-gradient(transparent 33px, #a29bfe 33px);
    background-size: 100% 34px; /* Doit être IDENTIQUE au line-height */
    
    /* TRES IMPORTANT : Fait scroller les lignes avec le texte */
    background-attachment: local; 
    
    transition: border-color 0.3s;
}

#sd-story-input:focus { 
    border-color: var(--sd-primary); 
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.1);
}

.sd-btn-save { background: var(--sd-secondary); color: white; align-self: flex-end; }
.sd-btn-save:hover { background: #00a884; }

#sd-paper-instruction {
    text-align: center; margin-top: 40px; padding: 20px;
    background: #eef2ff; border-radius: 10px; color: var(--sd-primary);
    font-weight: bold; font-size: 1.2rem;
}

/* --- HISTORIQUE --- */
#sd-history-list { display: flex; flex-direction: column; gap: 15px; }
.sd-history-item {
    background: white; border: 1px solid #eee; border-radius: 10px; padding: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
}
.sd-h-date { font-size: 0.8rem; color: #aaa; margin-bottom: 5px; }
.sd-h-dice { font-size: 1.5rem; margin-bottom: 10px; letter-spacing: 5px; }
.sd-h-text { 
    font-style: italic; color: #555; background: #f9f9f9; padding: 10px; 
    border-radius: 5px; border-left: 4px solid var(--sd-secondary);
    white-space: pre-wrap;
}
.sd-h-paper-tag {
    display: inline-block; background: #eee; color: #777; padding: 2px 8px;
    border-radius: 4px; font-size: 0.8rem; font-style: normal;
}

/* --- TOAST --- */
#sd-toast {
    position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: #2d3436; color: white; padding: 10px 20px; border-radius: 30px;
    opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
#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; }
}