/* ============================================
   Kraken's Dice — Fiche de personnage CHAOS
   (L'Ombre du Seigneur Démon)
   ============================================ */

/* La modale réutilise .cs-overlay de character-sheet.css.
   Ici on style uniquement la fiche Chaos. */

.csx-modal {
    max-width: 1200px;
    margin: 0 auto;
    background: #1a1414;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.6);
    overflow: hidden;
    position: relative;
}

/* Barre d'action en haut */
.csx-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .8rem;
    padding: .8rem 1.2rem;
    background: linear-gradient(180deg, #2a1a1a 0%, #1a1414 100%);
    color: #fff;
    border-bottom: 1px solid #4a2a2a;
    flex-wrap: wrap;
}
.csx-toolbar h2 {
    margin: 0;
    font-family: 'Cinzel Decorative', serif;
    font-size: 1.1rem;
    color: #d4a853;
    letter-spacing: .05em;
}
.csx-toolbar-actions {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}
.csx-btn {
    padding: .5rem 1rem;
    border-radius: 50px;
    border: 2px solid rgba(255,255,255,.3);
    background: transparent;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    font-size: .85rem;
    transition: background .2s, border-color .2s;
}
.csx-btn:hover { background: rgba(255,255,255,.1); border-color: #fff; }
.csx-btn-primary {
    background: #8b2020;
    border-color: #8b2020;
}
.csx-btn-primary:hover { background: #a52525; border-color: #a52525; }
.csx-btn-danger {
    background: #5a1818;
    border-color: #5a1818;
}
.csx-btn-danger:hover { background: #7a2020; }

/* Conteneur de la fiche : conserve le ratio du PDF (1200 x 1554) */
.csx-sheet-wrap {
    width: 100%;
    background: #0f0a0a;
    padding: 1rem;
    display: flex;
    justify-content: center;
    overflow-x: auto;
}
.csx-sheet {
    position: relative;
    width: 1200px;
    /* Ratio du PDF original ≈ 1200/1554 */
    aspect-ratio: 1200 / 1554;
    background-color: #efe5d2;
    background-image: url('../assets/chaos-bg.png');
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center;
    /* Le conteneur sert de système de coordonnées : tous les enfants utilisent % */
    flex: 0 0 auto;
}

/* Champs transparents génériques posés sur le fond */
.csx-field {
    position: absolute;
    background: transparent;
    border: none;
    color: #1a1414;
    font-family: 'Georgia', 'Times New Roman', serif;
    font-weight: 600;
    padding: 2px 6px;
    outline: none;
    box-sizing: border-box;
    transition: background .15s, box-shadow .15s;
}
.csx-field:hover {
    background: rgba(212, 168, 83, 0.10);
    box-shadow: inset 0 0 0 1px rgba(212, 168, 83, 0.35);
    border-radius: 4px;
}
.csx-field:focus {
    background: rgba(255, 250, 235, 0.55);
    box-shadow: inset 0 0 0 1.5px #8b2020;
    border-radius: 4px;
}
.csx-field::placeholder { color: transparent; }
/* En mode debug, on rétablit les placeholders pour s'y retrouver. */
.csx-sheet.csx-debug .csx-field::placeholder { color: rgba(60, 30, 30, 0.4); font-style: italic; font-weight: 400; }
/* Et pareil pour la zone avatar : on garde "Cliquez pour ajouter une image" en mode debug uniquement. */
.csx-avatar-hint { display: none; }
.csx-sheet.csx-debug .csx-avatar-hint { display: block; color: rgba(60, 30, 30, 0.5); }
.csx-field[readonly] { cursor: default; }
.csx-field[readonly]:hover { background: transparent; box-shadow: none; }

/* Inputs courts (1 ligne) */
input.csx-field {
    font-size: 1rem;
    line-height: 1.2;
    height: 100%;
}

/* Textareas (multi-lignes) */
textarea.csx-field {
    resize: none;
    font-size: .95rem;
    line-height: 1.35;
    overflow-y: auto;
    width: 100%;
    height: 100%;
}

/* Inputs ronds (caracs autour du pentacle) */
.csx-stat {
    text-align: center;
    font-family: 'Cinzel', 'Georgia', serif;
    font-weight: 700;
    font-size: 1.1rem;
    border-radius: 50%;
    color: #1a1414;
}
.csx-stat-big {
    font-size: 1.5rem;
    color: #8b2020;
}

/* Champs "titres" (Nom, Ascendance...) - police un peu plus marquée */
.csx-title-field {
    font-family: 'Cinzel', 'Georgia', serif;
    font-size: 1.05rem;
    font-weight: 700;
}

/* Zone avatar (sous Description) */
.csx-avatar {
    position: absolute;
    cursor: pointer;
    background: transparent;
    overflow: hidden;
    border-radius: 6px;
    transition: box-shadow .15s, background .15s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(60, 30, 30, 0.4);
    font-size: .85rem;
    text-align: center;
}
.csx-avatar:hover {
    background: rgba(212, 168, 83, 0.15);
    box-shadow: inset 0 0 0 1.5px #8b2020;
}
.csx-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.csx-avatar-hint {
    padding: .3rem;
    font-style: italic;
}

/* Toast safe au-dessus de la modale */
.cs-overlay .toast { z-index: 10001 !important; }

/* Mode debug : montre chaque champ avec son nom (activé via double-clic sur l'en-tête) */
.csx-sheet.csx-debug .csx-field {
    background: rgba(0, 200, 255, 0.15);
    box-shadow: inset 0 0 0 2px rgba(0, 120, 200, 0.7);
    border-radius: 3px;
}

/* Mode édition layout : permet de déplacer / redimensionner chaque champ à la souris */
.csx-sheet.csx-edit-layout .csx-field,
.csx-sheet.csx-edit-layout .csx-avatar {
    cursor: move;
    background: rgba(255, 200, 0, 0.15);
    box-shadow: inset 0 0 0 2px rgba(220, 140, 0, 0.85);
    border-radius: 3px;
    user-select: none;
    pointer-events: auto;
    /* En édition, les inputs ne capturent pas la frappe pour ne pas bloquer le drag */
}
.csx-sheet.csx-edit-layout .csx-field { caret-color: transparent; }
.csx-sheet.csx-edit-layout .csx-field:focus {
    background: rgba(255, 200, 0, 0.25);
    box-shadow: inset 0 0 0 2.5px rgba(220, 90, 20, 1);
}
.csx-resize-handle {
    position: absolute;
    width: 22px;
    height: 22px;
    background: #ff5a00;
    border: 3px solid #fff;
    z-index: 10;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,.5), 0 0 0 1px rgba(0,0,0,.3);
    /* Empêche le drag du champ parent quand on tire une poignée */
    touch-action: none;
}
.csx-resize-handle-se { right: -12px; bottom: -12px; cursor: nwse-resize; }
.csx-resize-handle-sw { left:  -12px; bottom: -12px; cursor: nesw-resize; }
.csx-resize-handle-ne { right: -12px; top:    -12px; cursor: nesw-resize; }
.csx-resize-handle-nw { left:  -12px; top:    -12px; cursor: nwse-resize; }
/* Au survol et focus, on rend les poignées encore plus visibles */
.csx-sheet.csx-edit-layout .csx-field:hover .csx-resize-handle,
.csx-sheet.csx-edit-layout .csx-avatar:hover .csx-resize-handle,
.csx-sheet.csx-edit-layout .csx-field-selected .csx-resize-handle {
    transform: scale(1.25);
    background: #ff7d2a;
    box-shadow: 0 3px 10px rgba(255, 90, 0, .6), 0 0 0 1px rgba(0,0,0,.3);
}
.csx-sheet.csx-edit-layout .csx-field-selected {
    box-shadow: inset 0 0 0 3px #b22020, 0 0 12px rgba(178, 32, 32, .5) !important;
    background: rgba(220, 60, 20, .18) !important;
}
.csx-edit-toolbar {
    position: sticky;
    top: 0;
    background: #2a1a1a;
    color: #fff;
    padding: .6rem 1rem;
    z-index: 100;
    display: flex;
    gap: .8rem;
    align-items: center;
    flex-wrap: wrap;
    border-bottom: 2px solid #d4a853;
    font-size: .85rem;
}
.csx-edit-toolbar code {
    background: #1a1414;
    padding: 1px 6px;
    border-radius: 3px;
    color: #d4a853;
    font-family: monospace;
}
.csx-edit-export {
    position: fixed;
    inset: 5% 5% auto 5%;
    max-height: 90vh;
    background: #1a1414;
    color: #efe5d2;
    z-index: 11000;
    padding: 1rem;
    border-radius: 8px;
    border: 2px solid #d4a853;
    box-shadow: 0 20px 60px rgba(0,0,0,.6);
    display: none;
    flex-direction: column;
}
.csx-edit-export.open { display: flex; }
.csx-edit-export textarea {
    flex: 1;
    width: 100%;
    background: #0a0606;
    color: #d4a853;
    border: 1px solid #5a1818;
    font-family: monospace;
    font-size: .85rem;
    padding: .6rem;
    border-radius: 4px;
    resize: none;
    min-height: 50vh;
}
.csx-edit-export-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .6rem;
}
.csx-sheet.csx-debug .csx-field::before {
    /* Le ::before sur input ne marche pas ; on a un overlay séparé ci-dessous */
}
.csx-debug-label {
    position: absolute;
    background: rgba(0, 120, 200, 0.85);
    color: #fff;
    font-size: .7rem;
    padding: 1px 4px;
    border-radius: 3px;
    pointer-events: none;
    z-index: 5;
    font-family: monospace;
    white-space: nowrap;
}
.csx-sheet.csx-debug .csx-avatar {
    background: rgba(255, 100, 200, 0.2);
    box-shadow: inset 0 0 0 2px rgba(200, 50, 150, 0.8);
}
.csx-debug-hint {
    color: #d4a853;
    font-size: .75rem;
    font-style: italic;
}

/* Responsive : la fiche se rétrécit en gardant ses proportions.
   On utilise un wrapper qui scrolle horizontalement si besoin. */
@media (max-width: 1240px) {
    .csx-sheet-wrap { padding: .5rem; }
    .csx-sheet {
        width: 100%;
        max-width: 1200px;
    }
}

/* Dialogue de choix du type de fiche */
.csx-choose-overlay {
    position: fixed; inset: 0;
    background: rgba(20, 20, 26, 0.78);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.csx-choose-overlay.open { display: flex; }
.csx-choose-card {
    background: #fff;
    border-radius: 16px;
    padding: 2rem;
    max-width: 640px;
    width: 100%;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
    margin: auto;
}
@media (max-width: 540px) {
    .csx-choose-card { padding: 1.4rem 1.2rem; }
}
.csx-choose-card h2 {
    margin: 0 0 .4rem;
    font-family: 'Cinzel Decorative', serif;
    color: var(--teal-dark);
    font-size: 1.3rem;
    text-align: center;
}
.csx-choose-card p {
    text-align: center;
    color: var(--ink-light);
    margin: 0 0 1.4rem;
    font-size: .92rem;
}
.csx-choose-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
@media (max-width: 540px) {
    .csx-choose-options { grid-template-columns: 1fr; }
}
.csx-choose-opt {
    display: block;
    text-align: left;
    padding: 1.2rem;
    border-radius: 12px;
    border: 2px solid var(--teal-pale);
    background: #fff;
    cursor: pointer;
    transition: border-color .2s, transform .15s, box-shadow .2s;
    font-family: inherit;
    width: 100%;
}
.csx-choose-opt:hover {
    border-color: var(--teal);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(45,107,107,.15);
}
.csx-choose-opt-chaos {
    border-color: #5a1818;
    background: linear-gradient(135deg, #1a1414 0%, #2a1a1a 100%);
    color: #efe5d2;
}
.csx-choose-opt-chaos:hover {
    border-color: #8b2020;
    box-shadow: 0 8px 24px rgba(139,32,32,.35);
}
.csx-choose-opt h3 {
    margin: 0 0 .4rem;
    font-family: 'Cinzel Decorative', serif;
    font-size: 1.1rem;
}
.csx-choose-opt-classic h3 { color: var(--teal-dark); }
.csx-choose-opt-chaos h3   { color: #d4a853; }
.csx-choose-opt p {
    margin: 0;
    text-align: left;
    font-size: .85rem;
    line-height: 1.45;
}
.csx-choose-opt-classic p { color: var(--ink-light); }
.csx-choose-opt-chaos p   { color: rgba(239, 229, 210, .75); }
/* ---------- Modale de recadrage d'avatar (Cropper.js) ---------- */
.csx-cropper-overlay {
    position: fixed; inset: 0;
    background: rgba(10, 6, 6, 0.92);
    z-index: 10500;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.csx-cropper-overlay.open { display: flex; }
.csx-cropper-box {
    background: #1a1414;
    color: #efe5d2;
    border: 2px solid #d4a853;
    border-radius: 12px;
    padding: 1rem;
    max-width: min(900px, 95vw);
    width: 100%;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    gap: .8rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.csx-cropper-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
}
.csx-cropper-head strong {
    font-family: 'Cinzel Decorative', serif;
    color: #d4a853;
    font-size: 1.1rem;
}
.csx-cropper-hint {
    font-size: .8rem;
    color: rgba(239, 229, 210, .65);
}
.csx-cropper-stage {
    flex: 1;
    min-height: 300px;
    max-height: 65vh;
    background: #0a0606;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}
.csx-cropper-stage img {
    display: block;
    max-width: 100%;
}
.csx-cropper-tools {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    font-size: .85rem;
}
.csx-cropper-tools .csx-btn {
    padding: .35rem .7rem;
    font-size: .8rem;
}
.csx-cropper-actions {
    display: flex;
    justify-content: flex-end;
    gap: .6rem;
}

.csx-choose-close {
    display: block;
    margin: 1.2rem auto 0;
    background: none;
    border: none;
    color: var(--ink-light);
    font-size: .85rem;
    cursor: pointer;
    text-decoration: underline;
}
