/* --- FUENTES Y ESTILOS GENERALES --- */
*, *::before, *::after {
    box-sizing: border-box;
}
:root {
    --font-main: 'Roboto', sans-serif;
    --font-display: 'Cinzel', serif;
    --color-background: #3E3B39;
    --color-container-bg: #D1C7B8;
    --color-container-border: #6D5B4B;
    --color-text-dark: #312A22;
    --color-text-light: #F5F5F5;
    --color-accent-gold: #D4AF37;
    --color-accent-bronze: #A46628;
    --color-accent-red: #A52A2A;
    --color-panel-bg: #4F4A45;
    --color-panel-header: #312A22;
}

body {
    background-color: var(--color-background);
    background-image: url('data:image/svg+xml,%3Csvg width="60" height="60" viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cg fill="%235a5551" fill-opacity="0.1"%3E%3Cpath d="M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z"/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');
    color: var(--color-text-dark);
    font-family: var(--font-main);
    margin: 0;
    padding: 20px;
}

/* --- CONTENEDOR PRINCIPAL Y CABECERA --- */
.main-container {
    max-width: 900px;
    margin: 0 auto;
    background-color: var(--color-container-bg);
    padding: 20px 30px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5), inset 0 0 15px rgba(0,0,0,0.2);
    border: 5px solid var(--color-container-border);
    border-top-color: #8E765E;
    border-bottom-color: #554335;
}

.main-header {
    text-align: center;
    border-bottom: 3px double var(--color-container-border);
    padding-bottom: 15px;
    margin-bottom: 25px;
}

h1 {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 2.8em;
    color: var(--color-text-dark);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    margin: 0;
}

/* --- CONTROLES Y BOTONES --- */
.controls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 25px;
}

button {
    background: linear-gradient(145deg, #CFAB50, #A46628);
    color: var(--color-text-light);
    border: 2px solid #754719;
    padding: 10px 20px;
    border-radius: 5px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3), inset 0 -2px 2px rgba(0,0,0,0.2);
    text-shadow: 1px 1px 1px rgba(0,0,0,0.4);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 10px rgba(0,0,0,0.35), inset 0 -2px 2px rgba(0,0,0,0.2);
    filter: brightness(1.1);
}

button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 3px rgba(0,0,0,0.3), inset 0 2px 2px rgba(0,0,0,0.3);
}

button.danger {
    background: linear-gradient(145deg, #C04848, #8B0000);
    border-color: #580000;
}

/* --- SELECTOR DE VISTA --- */
.view-selector {
    display: flex;
    justify-content: center;
    gap: 0;
    margin-bottom: 20px;
    background-color: rgba(0,0,0,0.1);
    border-radius: 8px;
    padding: 5px;
}

.view-btn {
    background-color: transparent;
    font-size: 16px;
    color: var(--color-text-dark);
    border: none;
    border-bottom: 4px solid transparent;
    box-shadow: none;
    flex-grow: 1;
    border-radius: 4px;
}

.view-btn:hover {
    background-color: rgba(0,0,0,0.08);
    transform: none;
    box-shadow: none;
    filter: none;
}

.view-btn.active {
    background-color: rgba(255,255,255,0.2);
    border-bottom-color: var(--color-accent-bronze);
    transform: none;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
}

/* --- CABECERA Y FILTROS DEL RANKING --- */
.ranking-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px;
    background-color: rgba(0,0,0,0.05);
    border-radius: 4px;
}

#ranking-title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--color-text-dark);
}

#filters-container { display: flex; align-items: center; gap: 15px; }
.filter-group { display: flex; gap: 10px; }
.hidden { display: none !important; }

select {
    padding: 8px;
    background-color: #EFE8DA;
    color: var(--color-text-dark);
    border: 2px solid #B4A998;
    border-radius: 4px;
    font-family: var(--font-main);
}

/* --- BOTONES DE FILTRO (SALÓN DE LEYENDAS) --- */
.sort-btn {
    background: #C1B6A5;
    color: var(--color-text-dark);
    border: 2px solid #A19685;
    font-size: 14px;
    font-family: var(--font-main);
    font-weight: 700;
    padding: 8px 12px;
    box-shadow: 0 2px 3px rgba(0,0,0,0.2);
}
.sort-btn.active {
    background: var(--color-accent-bronze);
    color: var(--color-text-light);
    border-color: #754719;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

/* --- LISTA Y ENTRADAS DE LUCHADORES --- */
#ranking-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ranking-entry {
    display: flex;
    align-items: center;
    background-color: rgba(255,255,255,0.2);
    padding: 10px;
    border-radius: 5px;
    gap: 15px;
    border: 1px solid rgba(0,0,0,0.1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.2s ease;
}

.ranking-entry:hover {
    transform: scale(1.02);
    border-color: var(--color-accent-bronze);
    background-color: rgba(164, 102, 40, 0.2);
}

.ranking-entry.top-3 {
    background: linear-gradient(90deg, rgba(212,175,55,0.3) 0%, transparent 100%);
    border-left: 4px solid var(--color-accent-gold);
}

.npc-sprite {
    width: 48px;
    height: 48px;
    background-color: var(--color-panel-bg);
    border: 2px solid var(--color-panel-header);
    border-radius: 4px;
    flex-shrink: 0;
    image-rendering: pixelated;
}

.npc-info-main { font-size: 18px; font-weight: bold; font-family: var(--font-display); }
.npc-info-secondary { font-size: 14px; color: #5C544C; }
.status-fallen { opacity: 0.6; filter: grayscale(80%); }

/* --- VISTA DE HISTORIAL DE CAMPEONES --- */
.champion-history-league {
    margin-bottom: 25px;
    border-left: 3px solid var(--color-accent-bronze);
    padding-left: 15px;
}
.champion-history-league h3 {
    font-family: var(--font-display);
    color: var(--color-accent-bronze);
    text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
    margin-top: 0;
}
.champion-reign {
    background-color: rgba(0,0,0,0.05);
    padding: 12px;
    border-radius: 5px;
    margin-bottom: 10px;
}
.champion-reign-header { font-size: 1.1em; font-weight: bold; }
.champion-reign-header .times-champion {
    font-style: italic;
    font-weight: normal;
    color: var(--color-accent-gold);
    margin-left: 8px;
    text-shadow: 1px 1px 1px #000;
}
.champion-reign-details {
    font-size: 0.9em;
    color: var(--color-text-dark);
    opacity: 0.8;
    margin-top: 5px;
}
.champion-reign-details strong { color: var(--color-text-dark); }


/* --- VENTANAS EMERGENTES (LOG Y FICHA DE PERSONAJE) --- */
.log-popup-background {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.log-popup-panel, .char-sheet-panel {
    width: 720px; /* AUMENTADO DE 650PX */
    max-width: 90vw; /* AÑADIDO PARA RESPONSIVIDAD */
    max-height: 85vh;
    background-color: #FBF0D9; /* Color pergamino */
    color: #3D2B1F; /* Color tinta sepia */
    border-radius: 8px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.7);
    border: 8px solid #6F4E37; /* Borde madera oscura */
    border-image: linear-gradient(165deg, #8B5A2B, #5C3317) 1;
    display: flex;
    flex-direction: column;
}

.log-content {
    background-color: rgba(111,78,55,0.05);
    padding: 15px;
    border-radius: 5px;
    border: 1px solid rgba(111,78,55,0.2);
    overflow-y: auto;
    flex-grow: 1;
    line-height: 1.7;
}

.log-popup-panel button { margin-top: 15px; }

/* Colores del log */
.log-content strong { display: block; margin-top: 10px; border-bottom: 1px solid rgba(111,78,55,0.3); padding-bottom: 4px; margin-bottom: 5px; }
.log-content .highlight, .log-content .gold { color: #D4AF37; font-weight: bold; text-shadow: 1px 1px 2px #000; }
.log-content .red { color: #B22222; font-weight: bold; }
.log-content .green { color: #006400; }
.log-content .yellow { color: #B8860B; }
.log-content .orange { color: #C46210; font-weight: bold; }
.log-content .cyan { color: #008B8B; }
.log-content .purple { color: #800080; }
.log-content .gray { color: #5A5A5A; }

/* --- FICHA DE PERSONAJE ESPECÍFICA --- */
.char-sheet-panel {
    flex-direction: row;
    gap: 25px;
}
.char-sheet-sprite-canvas {
    background-color: #D1C7B8;
    border: 2px solid #6D5B4B;
    border-radius: 4px;
    width: 192px; 
    height: 256px;
    image-rendering: pixelated;
}
.char-sheet-info-col { flex-grow: 1; }
.char-sheet-header h2 {
    font-family: var(--font-display);
    margin: 0 0 5px 0;
    color: #8B4513;
    font-size: 28px;
}
.char-sheet-header p { margin: 0 0 15px 0; font-style: italic; color: #6F4E37; }

/* Pestañas de la ficha */
.sheet-tabs { display: flex; border-bottom: 2px solid rgba(111,78,55,0.3); margin-bottom: 15px; }
.sheet-tab-btn {
    padding: 10px 14px; /* AJUSTADO DE 10px 15px */
    cursor: pointer;
    background-color: transparent;
    border: none;
    color: #6F4E37;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 15px; /* AJUSTADO DE 16px */
    border-bottom: 4px solid transparent;
    margin-bottom: -2px;
}
.sheet-tab-btn:hover { background-color: rgba(111,78,55,0.1); }
.sheet-tab-btn.active { color: #8B4513; border-bottom-color: #8B4513; }
.sheet-tab-content { display: none; }
.sheet-tab-content.active { display: block; }

/* Estadísticas y Lore */
.char-sheet-stats-grid { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 12px 24px; /* AUMENTADO DE 10px 20px */
}
.char-sheet-stat { background-color: rgba(111,78,55,0.1); padding: 8px; border-radius: 4px; }
.char-sheet-stat .label { font-size: 14px; color: #6F4E37; display: block; }
.char-sheet-stat .value { font-size: 18px; font-weight: bold; }
.char-sheet-stat .value.gold { color: #C9A227; text-shadow: 1px 1px 1px rgba(0,0,0,0.5); }
.sheet-lore {
    font-style: italic;
    background-color: rgba(0,0,0,0.05);
    padding: 10px;
    border-left: 3px solid #8B4513;
    border-radius: 4px;
}

/* --- (NUEVO) Controles de Exportación en Ficha --- */
.export-controls {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-start;
}

.export-controls {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid rgba(111, 78, 55, 0.2); /* Línea separadora */
}

.export-title {
    margin: 0 0 10px 0;
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    color: #6F4E37;
}

.export-buttons-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.export-controls button {
    font-size: 13px; /* Más pequeños */
    padding: 6px 12px;
    font-family: var(--font-main); /* Fuente más legible a tamaño pequeño */
    font-weight: 700;
}

/* --- (NUEVO) Modo de captura para GIF limpio --- */
.capture-mode {
    box-shadow: none !important;
    border: 8px solid #6F4E37 !important; /* Borde simple y seguro para captura */
}

.premium-feature {
    background: linear-gradient(145deg, #8A2BE2, #4B0082); /* Un color morado/violeta distintivo */
    border-color: #3A006A;
}

.main-menu-container {
    max-width: 600px;
    margin: 40px auto;
    padding: 40px;
    text-align: center;
    background-color: var(--color-container-bg);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5), inset 0 0 15px rgba(0,0,0,0.2);
    border: 5px solid var(--color-container-border);
}

.main-menu-btn {
    display: block;
    width: 80%;
    margin: 15px auto;
    padding: 15px 20px;
    font-size: 20px;
}

.main-menu-btn:disabled {
    background: linear-gradient(145deg, #888, #666);
    border-color: #444;
    cursor: not-allowed;
    opacity: 0.7;
}

/* --- CONTENEDOR PRINCIPAL Y CABECERA --- */
.main-menu-container {
    max-width: 600px;
    margin: 0 auto 40px auto; /* Unir con el header eliminando el margen superior */
    padding: 40px;
    text-align: center;
    background-color: var(--color-container-bg);
    border: 5px solid var(--color-container-border);
    border-top: none; /* La parte superior la pone el header */
    box-shadow: 0 10px 30px rgba(0,0,0,0.5), inset 0 0 15px rgba(0,0,0,0.2);
    /* Unir bordes redondeados */
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

/* --- (MODIFICADO) CONTENEDOR PRINCIPAL DEL JUEGO --- */
.main-container {
    max-width: 900px;
    margin: 0 auto 20px auto; /* Unir con el header eliminando el margen superior */
    background-color: var(--color-container-bg);
    padding: 20px 30px;
    border: 5px solid var(--color-container-border);
    border-top: none; /* La parte superior la pone el header */
    box-shadow: 0 10px 30px rgba(0,0,0,0.5), inset 0 0 15px rgba(0,0,0,0.2);
    /* Unir bordes redondeados */
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}


/* --- (MODIFICADO) CABECERA PRINCIPAL --- */
.main-header {
    text-align: center;
    padding: 20px 40px 15px 40px; 
    margin: 20px auto 0 auto;
    
    background-color: var(--color-container-bg);
    border: 5px solid var(--color-container-border);
    border-bottom: 3px double var(--color-container-border);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5), inset 0 0 15px rgba(0,0,0,0.2);
    
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

/* Nuevas clases para controlar el ancho dinámicamente */
.header-wide {
    max-width: 900px;
}
.header-narrow {
    max-width: 600px;
}
.npc-sprite canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.creator-background {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.creator-panel {
    width: 800px;
    max-width: 95vw;
    /* height: 500px; <-- ELIMINAMOS LA ALTURA FIJA */
    max-height: 90vh;
    background-color: #FBF0D9;
    color: #3D2B1F;
    border-radius: 8px;
    padding: 25px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
    border: 8px solid #6F4E37;
    display: flex;
    gap: 25px;
}

.creator-column {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.creator-column-left {
    flex-basis: 35%;
    background-color: rgba(0,0,0,0.05);
    border-radius: 5px;
    padding: 20px;
}
.creator-column-right {
    flex-basis: 65%;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* AÑADIMOS SCROLL AUTOMÁTICO SI ES NECESARIO */
    padding-right: 15px; /* Pequeño espacio para que el scroll no se pegue */
}

.creator-panel h3 {
    font-family: var(--font-display);
    color: var(--color-panel-header);
    border-bottom: 2px solid rgba(0,0,0,0.1);
    padding-bottom: 10px;
    width: 100%;
    text-align: center;
    margin-top: 0;
}

.creator-preview-text {
    font-family: var(--font-display);
    margin: 5px 0;
    text-align: center;
}
#creator-preview-name {
    font-size: 22px;
    font-weight: bold;
}

.creator-form-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 15px 10px;
    align-items: center;
    width: 100%;
    margin-top: 20px;
}
.creator-form-grid label {
    font-weight: bold;
    text-align: right;
}
.creator-form-grid input, .creator-form-grid select {
    width: 100%;
    padding: 8px;
    border-radius: 4px;
    border: 2px solid #B4A998;
    background-color: #EFE8DA;
}
/* Estilo específico para el selector de color */
.creator-form-grid input[type="color"] {
    padding: 2px;
    height: 40px;
}

.creator-controls {
    margin-top: auto; /* Empuja los botones hacia abajo */
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    width: 100%;
    padding-top: 20px;
}

/* --- (NUEVO) ESTILOS DE DISTINCIÓN DEL JUGADOR --- */

/* Borde dorado para el personaje del jugador en los rankings */
.ranking-entry.player-character {
    box-shadow: 0 0 12px 4px var(--color-accent-gold);
    border-color: var(--color-accent-gold);
    background: linear-gradient(90deg, rgba(212,175,55,0.3) 0%, transparent 80%);
}
.ranking-entry.player-character:hover {
    background: linear-gradient(90deg, rgba(212,175,55,0.4) 0%, transparent 80%);
}


/* Resaltado de eventos del jugador en el diario de sucesos */
.log-player-event {
    background-color: rgba(212, 175, 55, 0.15);
    border-left: 4px solid var(--color-accent-gold);
    padding: 8px;
    margin: 5px 0;
    border-radius: 4px;
}

.roster-entry-controls {
    margin-left: auto; /* Empuja los botones a la derecha */
    display: flex;
    gap: 10px;
}

.roster-entry-controls button {
    font-size: 13px;
    padding: 6px 12px;
    font-family: var(--font-main);
    font-weight: 700;
}

.player-action-card {
    background-color: rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 15px;
}
.player-action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-top: 10px;
}
.action-card {
    padding: 15px;
    border: 2px solid #B4A998;
    border-radius: 5px;
    text-align: center;
    cursor: pointer;
    background-color: #EFE8DA;
    transition: all 0.2s ease;
}
.action-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.action-card.selected {
    border-color: var(--color-accent-bronze);
    background-color: #D1C7B8;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.2);
}
.action-card h5 {
    margin: 0 0 5px 0;
    font-family: var(--font-display);
}
.action-card p {
    font-size: 12px;
    margin: 0;
    color: #6F4E37;
}
.action-card.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #ccc;
}
.opponent-selection-panel {
    grid-column: 1 / -1; /* Ocupa todo el ancho */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 15px;
    padding: 15px;
    background-color: rgba(0,0,0,0.1);
    border-radius: 5px;
}
.opponent-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    border: 2px solid transparent;
    border-radius: 5px;
    cursor: pointer;
    background-color: #EFE8DA;
}
.opponent-card:hover {
    border-color: var(--color-accent-gold);
}
.opponent-card .npc-sprite {
    margin-bottom: 10px;
}
.opponent-card-info {
    font-size: 13px;
    text-align: center;
}
.opponent-card-info strong {
    font-family: var(--font-display);
    display: block;
}

.opponent-selection-panel button.selected {
    background: var(--color-accent-bronze); /* Color sólido y visible */
    border-color: var(--color-accent-gold);
    color: var(--color-text-light);
    transform: translateY(1px); /* Hacemos que parezca presionado */
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.4); /* Sombra interior más marcada */
    filter: brightness(1.1);
}