/* ==== VARIABLES GLOBALES ==== */
:root {
    --bg-page: #f8fafc;
    --bg-sidebar: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --accent-color: #06b6d4; /* Turquesa tecnológico */
    --accent-hover: #0891b2;
    --danger-color: #ec4899; /* Rosa innovador */
    --danger-hover: #db2777;
    --border-color: #e2e8f0;
    --card-shadow: 0 10px 25px -5px rgba(6, 182, 212, 0.1), 0 8px 10px -6px rgba(6, 182, 212, 0.05); /* Sombra turquesa sutil */
    --card-shadow-hover: 0 20px 25px -5px rgba(6, 182, 212, 0.2), 0 10px 10px -5px rgba(6, 182, 212, 0.08); /* Glow turquesa */
    --star-color: #ec4899; /* Estrellas rosas */
    --font-main: 'Outfit', sans-serif;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-xl: 20px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Indicador de Sincronización (Badge Premium) */
.sync-status-badge {
    position: absolute;
    top: 20px;
    right: 30px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: transparent;
    border: none;
    font-size: 0.70rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.4);
    transition: var(--transition);
    z-index: 100;
    opacity: 0.6;
}

.sync-status-badge:hover {
    opacity: 1;
    color: rgba(255, 255, 255, 0.8);
}

.sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.sync-status-badge.online {
    color: rgba(16, 185, 129, 0.7);
}
.sync-status-badge.online .sync-dot {
    background-color: #10b981;
    box-shadow: 0 0 8px #10b981;
}

.sync-status-badge.offline {
    color: rgba(239, 68, 68, 0.7);
}
.sync-status-badge.offline .sync-dot {
    background-color: #ef4444;
    box-shadow: 0 0 8px #ef4444;
}

.sync-status-badge.syncing {
    color: rgba(59, 130, 246, 0.7);
}
.sync-status-badge.syncing .sync-dot {
    background-color: #3b82f6;
    box-shadow: 0 0 8px #3b82f6;
    animation: dotPulse 0.8s infinite alternate;
}

@keyframes badgePulse {
    from { opacity: 0.6; }
    to { opacity: 1; }
}

@keyframes dotPulse {
    from { transform: scale(0.8); opacity: 0.5; }
    to { transform: scale(1.2); opacity: 1; }
}

/* ==== RESET Y BASE ==== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-page);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
}

/* ==== LAYOUT PRINCIPAL ==== */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ==== SIDEBAR (Formulario deslizante) ==== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 380px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.1);
    z-index: 10000;
    transform: translateX(-100%);
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sidebar.open {
    transform: translateX(0);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-sidebar {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    padding: 4px;
}

.close-sidebar:hover {
    color: var(--danger-color);
    transform: scale(1.1);
}

.app-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.app-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
}

.app-header h1 span {
    color: var(--accent-color);
}

.app-header p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.character-form {
    padding: 24px;
    flex-grow: 1;
    overflow-y: auto;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
    background-color: #f8fafc;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.15); /* Glow borde turquesa */
}

.form-group small {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Local Image Configurator */
.local-image-selector {
    margin-top: 10px;
    padding: 10px;
    background: #f1f5f9;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border-color);
    transition: var(--transition);
}

.local-image-selector:hover {
    border-color: var(--accent-color);
}

.local-image-selector small {
    margin-top: 0;
    margin-bottom: 6px;
}

.local-image-selector input[type="file"] {
    font-size: 0.85rem;
    color: var(--text-secondary);
    width: 100%;
    cursor: pointer;
}

/* Rating Stars */
.star-rating {
    display: flex;
    flex-direction: row-reverse;
    justify-content: flex-end;
    gap: 4px;
}

.star-rating input {
    display: none;
}

.star-rating label {
    font-size: 1.5rem;
    color: #cbd5e1;
    cursor: pointer;
    transition: color 0.2s;
    margin: 0;
}

.star-rating label:not(.zero-star):hover,
.star-rating label:not(.zero-star):hover ~ label:not(.zero-star),
.star-rating input:checked ~ label:not(.zero-star) {
    color: var(--star-color);
}

.star-rating .zero-star {
    font-size: 1.2rem;
    margin-right: 8px; /* Separación estética de las estrellas */
    display: flex;
    align-items: center;
}

.star-rating input:checked + .zero-star {
    color: var(--text-secondary);
}

.star-rating .zero-star:hover {
    color: var(--danger-color);
}

/* Checkboxes (Tags) */
.tags-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-checkbox input {
    display: none;
}

.tag-checkbox span {
    display: inline-block;
    padding: 6px 12px;
    background-color: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.tag-checkbox input:checked + span {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    box-shadow: 0 2px 6px rgba(6, 182, 212, 0.3); /* Sombra acento turquesa */
}

/* Botones */
.btn-primary {
    width: 100%;
    padding: 14px;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.25); /* Sombra botón turquesa */
}

.btn-secondary {
    padding: 14px;
    background-color: #f1f5f9;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
}

.btn-secondary:hover {
    background-color: #e2e8f0;
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.sidebar-footer {
    padding: 24px;
    border-top: 1px solid var(--border-color);
    background-color: #f8fafc;
}

.btn-danger {
    width: 100%;
    padding: 12px;
    background-color: transparent;
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
}

.btn-danger:hover {
    background-color: var(--danger-color);
    color: white;
}

/* ==== ÁREA PRINCIPAL (TABLERO) ==== */
/* ==== ÁREA PRINCIPAL (TABLERO DE FANTASÍA MÍSTICA) ==== */
.main-content {
    flex-grow: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    /* Fondo Santuario Celestial (Más claro para resaltar personajes) */
    background-color: #f1f3f9;
    background-image: 
        linear-gradient(rgba(240, 244, 250, 0.8), rgba(255, 255, 255, 0.7)), 
        url('https://images.unsplash.com/photo-1519750783826-e2420f4d687f?q=80&w=2000&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
    perspective: 1200px;
}

/* Efecto de Polvo Rúnico y Pétalos Mágicos en tonos claros */
.main-content::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%; width: 200%; height: 200%;
    background-image: 
        radial-gradient(circle, rgba(251, 191, 36, 0.3) 1px, transparent 1px),
        radial-gradient(circle, rgba(236, 72, 153, 0.2) 2px, transparent 2px);
    background-size: 150px 150px, 200px 200px;
    animation: magicalFloat 45s linear infinite;
    z-index: 0;
    pointer-events: none;
}

@keyframes magicalFloat {
    0% { transform: translateY(0) scale(1) rotate(0deg); }
    50% { transform: translateY(-50px) scale(1.05) rotate(5deg); }
    100% { transform: translateY(-100px) scale(1) rotate(10deg); }
}

/* Degradado suave para profundidad celestial */
.main-content::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(circle at center, transparent 30%, rgba(240, 244, 250, 0.45) 100%);
    pointer-events: none;
    z-index: 1;
}

.board-title-area, .board, .fab-add {
    position: relative;
    z-index: 2;
}

.board-title-area {
    padding: 30px 40px 0 40px;
    text-align: center;
}

.main-title {
    font-size: 3.5rem; /* Un poco más majestuoso */
    font-weight: 800;
    color: #1a1c2c; /* Azul/Negro muy profundo */
    margin-bottom: 5px;
    letter-spacing: 12px; /* Más aireado y elegante */
    text-transform: uppercase;
    text-shadow: 2px 2px 0px rgba(255,255,255,0.8); /* Efecto de relieve claro */
    font-family: var(--font-main);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

/* Adornos dorados a los lados del título */
.main-title::before, .main-title::after {
    content: '✧';
    color: #fbbf24;
    font-size: 1.5rem;
    text-shadow: 0 0 15px #fbbf24;
    animation: pulseGlow 3s infinite ease-in-out;
}

.main-title span {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-weight: 700;
    text-transform: capitalize;
    /* Gradiente Oro-Rubí más dramático */
    background: linear-gradient(135deg, #b45309 0%, #fbbf24 25%, #fef3c7 50%, #fbbf24 75%, #db2777 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 4.5rem;
    margin-left: 10px;
    filter: drop-shadow(0 5px 15px rgba(0,0,0,0.1));
    position: relative;
    padding: 0 10px;
}

/* Brillo mágico que recorre el texto */
.main-title span::after {
    content: '';
    position: absolute;
    top: 0; left: -100%; width: 50%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transform: skewX(-25deg);
    animation: shimmer 4s infinite;
}

@keyframes shimmer {
    0% { left: -150%; }
    30% { left: 150%; }
    100% { left: 150%; }
}

.subtitle {
    font-size: 0.95rem;
    color: #db2777; /* Rosa más intenso para legibilidad */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 5px;
    margin-top: 5px;
    opacity: 0.9;
    border-top: 1px solid rgba(251, 191, 36, 0.3);
    display: inline-block;
    padding-top: 8px;
}

.board {
    flex-grow: 1;
    padding: 50px 80px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 32px;
    justify-content: center;
    align-items: flex-start;
    align-content: flex-start;
    transform: rotateX(5deg);
    transform-origin: top;
    transition: transform 0.5s ease;
    position: relative; /* Contenedor para el Playmat */
    min-height: 80vh;
}

/* Playmat: El Altar de las Sagas (ETÉREO Y VISIBLE) */
.board::before {
    content: '';
    position: absolute;
    top: 20px; left: 20px; right: 20px; bottom: 20px;
    /* Colores más profundos inspirados en la referencia */
    background: 
        radial-gradient(circle at center, rgba(255, 255, 255, 0.5) 0%, rgba(230, 210, 255, 0.4) 40%, rgba(180, 150, 220, 0.3) 100%),
        url("data:image/svg+xml,%3Csvg width='120' height='120' viewBox='0 0 120 120' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M60 0 C 70 30, 90 30, 120 60 C 90 90, 70 90, 60 120 C 50 90, 30 90, 0 60 C 30 30, 50 30, 60 0' fill='none' stroke='%238b5cf6' stroke-width='0.5' opacity='0.3'/%3E%3C/svg%3E"),
        url('https://www.transparenttextures.com/patterns/paper-fibers.png');
    
    background-color: rgba(250, 245, 255, 0.85); /* Fondo base más sólido */
    background-blend-mode: multiply;
    border: 3px double rgba(139, 92, 246, 0.3);
    box-shadow: 
        inset 0 0 100px rgba(139, 92, 246, 0.2),
        0 10px 40px rgba(0,0,0,0.1);
    border-radius: 40px;
    z-index: -1;
    pointer-events: none;
}

/* Estilo Vacío: Altar de Invocación */
.empty-state {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #f472b6;
    text-align: center;
    transform: rotateX(-5deg);
}

.empty-icon {
    font-size: 5.5rem;
    margin-bottom: 24px;
    color: #fbbf24;
    text-shadow: 0 0 40px rgba(251, 191, 36, 0.6);
    animation: mysticalPulse 3s infinite ease-in-out;
}

@keyframes mysticalPulse {
    0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.8; }
    50% { transform: scale(1.1) rotate(5deg); opacity: 1; filter: drop-shadow(0 0 20px #fbbf24); }
}

.empty-state h3 {
    font-size: 2rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-bottom: 12px;
    color: #fce7f3;
    text-shadow: 0 0 15px rgba(0,0,0,0.5);
}

.empty-state p {
    font-size: 1.1rem;
    color: #f9a8d4;
    max-width: 400px;
    line-height: 1.4;
}

/* ==== BOTON FLOTANTE ==== */
.fab-add {
    position: fixed !important;
    bottom: 40px !important;
    right: 40px !important;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--accent-color);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 20000 !important;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition);
    pointer-events: auto !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.fab-add:hover {
    background-color: var(--danger-color); /* Pasa a rosa vibrante al hover! Tecnológico y llamativo */
    transform: scale(1.1) rotate(90deg);
    box-shadow: var(--card-shadow-hover);
}

/* ==== TARJETAS DE PERSONAJE (FLIP CARDS) ==== */
/* ==== ZOOM GALERÍA (MODAL TCG) ==== */
.zoom-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.zoom-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Romper contextos de apilamiento parentales al hacer zoom */
body.zoom-active .main-content {
    perspective: none !important;
}

body.zoom-active .board {
    transform: none !important;
    transition: none !important; /* Force immediate drop of transform matrix to kill stacking context */
    z-index: auto !important; /* Usar auto para NO crear un nuevo stacking context */
}

.character-card.is-zoomed {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    width: 416px !important;
    height: 608px !important;
    transform: translate(-50%, -50%) !important;
    z-index: 9999 !important; /* Muy por encima de todo */
    margin: 0 !important;
    box-shadow: 0 0 100px rgba(0,0,0,1), 0 0 40px rgba(251, 191, 36, 0.6);
    cursor: zoom-out;
    pointer-events: auto !important;
}

/* El hueco que deja la carta en el tablero */
.card-placeholder {
    width: 260px;
    height: 380px;
    background: rgba(0,0,0,0.2);
    border: 2px dashed rgba(251, 191, 36, 0.1);
    border-radius: 12px;
    flex-shrink: 0;
}

/* Evitar inclinación (tilt) durante el zoom, pero PERMITIR el volteo (flip) */
.character-card.is-zoomed .card-inner {
    transform: rotateY(0deg); /* Base sin tilt */
}

.character-card.is-zoomed.is-flipped .card-inner {
    transform: rotateY(180deg) !important; /* Forzar el volteo en zoom */
}

/* Transiciones suaves para el "vuelo" y dimensiones base */
.character-card {
    width: 260px;
    height: 380px;
    perspective: 1500px;
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    will-change: transform;
    transition: transform 0.3s ease, 
                opacity 0.3s ease, 
                top 0.4s ease, 
                left 0.4s ease, 
                width 0.3s ease,
                height 0.3s ease;
}

/* El rastro fantasma que dejas atrás en el mazo */
.character-card.dragging {
    opacity: 0.15;
    transform: scale(0.95);
}

/* La tarjeta debajo se hace pequeña y esquiva como una baraja real */
.character-card.drag-over-visual .card-inner {
    transform: scale(0.92) rotate(4deg) translateY(15px);
    box-shadow: none;
    opacity: 0.6;
}
.character-card.is-flipped.drag-over-visual .card-inner {
    transform: rotateY(180deg) scale(0.92) rotate(4deg) translateY(15px);
    opacity: 0.6;
}

/* Contenedor interior que hace el flip y las poses (CSS driven) */
.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    /* Efecto "muelle" elastico para el movimiento balatro/solitario */
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    transform-style: preserve-3d;
    border-radius: var(--radius-xl);
    box-shadow: var(--card-shadow);
}

.character-card:hover .card-inner {
    box-shadow: var(--card-shadow-hover);
}

/* Al presionar con el ratón se levanta (Pick UP) rotando sutilmente */
.character-card.is-picked-up .card-inner {
    transform: scale(1.08) rotate(-4deg) translateY(-15px);
    box-shadow: 0 40px 50px -10px rgba(0,0,0,0.4);
}
.character-card.is-flipped.is-picked-up .card-inner {
    transform: rotateY(180deg) scale(1.08) rotate(-4deg) translateY(-15px);
    box-shadow: 0 40px 50px -10px rgba(0,0,0,0.4);
}

.character-card.is-flipped .card-inner {
    transform: rotateY(180deg);
}

/* Frontal y Dorso */
.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden; /* Safari */
    backface-visibility: hidden;
    border-radius: var(--radius-xl);
    overflow: hidden;
}

.card-front *, .card-back * {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* FRONT: Imagen completa y estilos TCG Gamificados */
.card-front {
    background-color: #1a202c; /* Fondo base oscuro tipo roca */
    transform: rotateY(0deg) translateZ(1px); /* Prevent bleeding on Safari/Chrome */
}

.char-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    z-index: 1;
}

/* Oscurecimiento sutil para destacar estelaridad y nombre encima de imágenes muy brillantes */
.tcg-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0.55) 0%, transparent 25%, transparent 75%, rgba(0,0,0,0.4) 100%);
    z-index: 2;
}

/* ==== TCG: Nombre en Franja TCG (Ancho completo) ==== */
.tcg-title-banner {
    position: absolute;
    bottom: 35px;
    left: 0;
    width: 100%;
    padding: 12px 12px;
    background: linear-gradient(90deg, transparent 0%, rgba(15, 23, 42, 0.92) 20%, rgba(15, 23, 42, 0.92) 80%, transparent 100%);
    backdrop-filter: blur(4px);
    text-align: center;
    border-top: 1px solid rgba(255,255,255,0.15);
    border-bottom: 1px solid rgba(255,255,255,0.15);
    z-index: 5;
    /* Permitir que los ornamentos sobresalgan */
    overflow: visible;
}

/* El ornamento flotante central superior */
.tcg-title-banner::after {
    content: var(--ornament-top, '✧');
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--badge-border);
    font-size: 1.2rem;
    text-shadow: 0 0 10px var(--badge-glow);
    z-index: 6;
}

/* Alas / Filigranas Grandes Laterales del Banner */
.tcg-title-banner::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 140%; /* Más ancho que el banner para las alas */
    height: 120px;
    background-image: var(--ornament-svg-l);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    transform: translate(-50%, -50%);
    filter: var(--ornament-filter);
    opacity: 0.7;
    pointer-events: none;
    z-index: -1;
}

.card-name {
    font-size: 2.2rem; /* Mucho más grande tipo logo */
    font-weight: 900;
    font-family: 'Playfair Display', serif;
    text-transform: uppercase;
    letter-spacing: 2px;
    line-height: 0.9;
    margin-bottom: 4px;
    white-space: nowrap;
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 15px;
    justify-content: center;
    
    /* Efecto Biselado / Metálico tipo el de la imagen */
    color: var(--badge-border);
    background: linear-gradient(to bottom, #fff 0%, var(--badge-border) 40%, var(--badge-bg-mid) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 0px rgba(0,0,0,0.9)) drop-shadow(0 4px 10px rgba(0,0,0,0.5));
}

/* Micro-filigranas pegadas al nombre */
.card-name::before,
.card-name::after {
    content: var(--filigree-icon, '⚜');
    color: var(--badge-border, #fff);
    font-size: 1rem;
    opacity: 0.9;
    text-shadow: 0 0 10px var(--badge-glow);
    -webkit-text-fill-color: initial;
    /* Animación de latido sutil */
    animation: ornamentPulse 4s infinite ease-in-out;
}

@keyframes ornamentPulse {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

.card-name::before { transform: scaleX(-1); }

.banner-title {
    font-size: 0.7rem;
    color: #cbd5e1;
    font-weight: 700;
    font-family: var(--font-main);
    text-transform: uppercase;
    letter-spacing: 2px;
    opacity: 0.9;
}

/* ==== TCG: Insignia Inferior Derecha (Estrellas integradas en esquina) ==== */
.tcg-badge-rating {
    position: absolute;
    bottom: -1px;
    right: -1px;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.95) 100%);
    color: var(--badge-border, var(--star-color));
    padding: 6px 12px 4px 14px;
    border-radius: 16px 0 0 0;
    font-size: 1rem;
    font-weight: 900;
    z-index: 5;
    border: 3px solid var(--badge-border, var(--star-color));
    border-right: none;
    border-bottom: none;
    box-shadow: -4px -4px 12px rgba(0,0,0,0.5);
    letter-spacing: 1px;
}

/* =======================================
   SISTEMA DE RAREZA TCG (BORDES METÁLICOS)
   ======================================= */
/* Aseguramos que el borde se dibuje hacia adentro sin romper el layout */
.character-card, .card-inner, .card-front, .card-back {
    box-sizing: border-box;
}

/* Rareza Oro (5 Estrellas) */
.character-card.rarity-gold {
    --badge-bg-start: #f59e0b; --badge-bg-mid: #b45309; --badge-bg-end: #451a03;
    --badge-border: #fbbf24; --badge-glow: rgba(251, 191, 36, 0.8);
    --badge-icon: '✦';
    --filigree-icon: '⚜';
    --ornament-top: '👑';
    --ornament-filter: drop-shadow(0 0 10px #fbbf24);
    --ornament-svg-l: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M200 70 C 120 70, 80 0, 0 30 C 30 60, 100 100, 200 70' fill='rgba(251,191,36,0.1)' stroke='%23fbbf24' stroke-width='2'/%3E%3Cpath d='M200 70 C 280 70, 320 0, 400 30 C 370 60, 300 100, 200 70' fill='rgba(251,191,36,0.1)' stroke='%23fbbf24' stroke-width='2'/%3E%3C/svg%3E");
}
.character-card.rarity-gold .card-front,
.character-card.rarity-gold .card-back {
    border: 7px solid #fbbf24; 
    box-shadow: 0 0 25px #fbbf24, inset 0 0 15px rgba(251, 191, 36, 0.5);
}
.character-card.rarity-gold .tcg-overlay { box-shadow: inset 0 0 50px rgba(251, 191, 36, 0.4); pointer-events: none; }
.character-card.rarity-gold .tcg-badge-rating { border-color: #fbbf24; color: #fbbf24; }
.character-card.rarity-gold .card-name { 
    background: linear-gradient(to bottom, #fef3c7 0%, #fbbf24 50%, #b45309 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.9));
}
.character-card.rarity-gold .tcg-title-banner { border-color: #fbbf24; }

/* Rareza Plata (4 Estrellas) */
/* Rareza Plata (4 Estrellas) - Plata Cromada Metálica */
.character-card.rarity-silver {
    --badge-bg-start: #cbd5e1; --badge-bg-mid: #64748b; --badge-bg-end: #1e293b;
    --badge-border: #f8fafc; --badge-glow: rgba(248, 250, 252, 0.6);
    --badge-icon: '✧';
    --filigree-icon: '✥';
    --ornament-top: '🌙';
    --ornament-filter: drop-shadow(0 0 10px #60a5fa);
    --ornament-svg-l: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M200 50 L 100 10 L 0 50 L 100 90 L 200 50' fill='none' stroke='%23f8fafc' stroke-width='1' opacity='0.7'/%3E%3Cpath d='M200 50 L 300 10 L 400 50 L 300 90 L 200 50' fill='none' stroke='%23f8fafc' stroke-width='1' opacity='0.7'/%3E%3Ccircle cx='200' cy='50' r='3' fill='%23f8fafc'/%3E%3C/svg%3E");
}
.character-card.rarity-silver .card-front,
.character-card.rarity-silver .card-back {
    border: 6px solid #f8fafc; /* Color más claro para que brille más */
    box-shadow: 
        0 0 25px rgba(248, 250, 252, 0.8), 
        inset 0 0 20px rgba(255, 255, 255, 0.6);
}
.character-card.rarity-silver .tcg-overlay { 
    box-shadow: inset 0 0 50px rgba(148, 163, 184, 0.4); 
    background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 40%, transparent 60%, rgba(255,255,255,0.1) 100%);
    pointer-events: none; 
}
.character-card.rarity-silver .tcg-badge-rating { border-color: #cbd5e1; color: #f8fafc; background: #334155; }
.character-card.rarity-silver .card-name { 
    background: linear-gradient(to bottom, #ffffff 0%, #94a3b8 50%, #f1f5f9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 950;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.8));
}
.character-card.rarity-silver .tcg-title-banner { border-color: #94a3b8; background: rgba(30, 41, 59, 0.9); }

/* Rareza Bronce (3 Estrellas) */
.character-card.rarity-bronze {
    --badge-bg-start: #ea580c; --badge-bg-mid: #9a3412; --badge-bg-end: #431407;
    --badge-border: #fdba74; --badge-glow: rgba(234, 88, 12, 0.6);
    --badge-icon: '❖';
    --filigree-icon: '❧';
    --ornament-top: '🌿';
    --ornament-filter: drop-shadow(0 0 10px #fdba74);
    --ornament-svg-l: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M200 50 C 150 100, 50 100, 0 50 C 50 0, 150 0, 200 50' fill='none' stroke='%23fdba74' stroke-width='1.5'/%3E%3Cpath d='M200 50 C 250 100, 350 100, 400 50 C 350 0, 250 0, 200 50' fill='none' stroke='%23fdba74' stroke-width='1.5'/%3E%3C/svg%3E");
}
.character-card.rarity-bronze .card-front,
.character-card.rarity-bronze .card-back {
    border: 6px solid #ed8936; 
    box-shadow: 0 0 15px rgba(237, 137, 54, 0.5);
}
.character-card.rarity-bronze .tcg-overlay { box-shadow: inset 0 0 40px rgba(237, 137, 54, 0.4); pointer-events: none; }
.character-card.rarity-bronze .tcg-badge-rating { border-color: #ed8936; color: #ed8936; }
.character-card.rarity-bronze .card-name { 
    background: linear-gradient(to bottom, #ffedd5 0%, #ed8936 50%, #7c2d12 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.9));
}
.character-card.rarity-bronze .tcg-title-banner { border-color: #ed8936; }

/* Categoria Sin Usar (0 Estrellas) - Muted Slate */
.character-card.rarity-unused {
    filter: saturate(0.7);
    --badge-bg-start: #475569; --badge-bg-mid: #1e293b; --badge-bg-end: #020617;
    --badge-border: #94a3b8; --badge-glow: rgba(148, 163, 184, 0.2);
    --badge-icon: '⊘';
    --filigree-icon: '❂';
    --ornament-top: '⛓';
    --ornament-svg-l: none;
}
.character-card.rarity-unused .card-front,
.character-card.rarity-unused .card-back {
    border: 5px solid #475569; /* Gris azulado apagado */
    background-color: #0f172a;
}
.character-card.rarity-unused .card-name { color: #94a3b8; }
.character-card.rarity-unused .tcg-badge-rating { border-color: #475569; color: #64748b; }
.character-card.rarity-unused .tcg-title-banner { border-color: #475569; }

/* Badge "SIN USAR" en la esquina superior derecha */
.status-badge-unused {
    position: absolute;
    top: 20px;
    right: -32px;
    background: linear-gradient(135deg, #64748b 0%, #334155 100%);
    color: white;
    font-size: 0.6rem;
    font-weight: 900;
    padding: 3px 0;
    width: 120px;
    text-align: center;
    transform: rotate(45deg);
    box-shadow: 0 2px 10px rgba(0,0,0,0.4);
    z-index: 10;
    letter-spacing: 1.5px;
    border: 1px solid rgba(255,255,255,0.1);
    pointer-events: none;
}

/* Rareza Arcilla / Tierra (2 Estrellas) - Mate */
.character-card.rarity-clay {
    --badge-bg-start: #78350f; --badge-bg-mid: #451a03; --badge-bg-end: #220e01;
    --badge-border: #d97706; --badge-glow: rgba(217, 119, 6, 0.4);
    --badge-icon: '⟐';
    --filigree-icon: '❦';
    --ornament-top: '🍁';
    --ornament-svg-l: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M100 80 Q 200 20, 300 80' fill='none' stroke='%2378350f' stroke-width='3'/%3E%3C/svg%3E");
}
.character-card.rarity-clay .card-front,
.character-card.rarity-clay .card-back {
    border: 5px solid #78350f; /* Marrón tierra / Caoba */
    background-color: #1a0f0a;
}
.character-card.rarity-clay .card-name { color: #b45309; }
.character-card.rarity-clay .tcg-badge-rating { 
    border-color: #78350f !important; 
    color: #d97706 !important; 
}
.character-card.rarity-clay .tcg-title-banner { border-color: #78350f; }

/* Rareza Hierro Oscuro / Acero frío (1 Estrella) - Tonos Azules Metálicos */
.character-card.rarity-iron {
    --badge-bg-start: #2563eb; --badge-bg-mid: #1e3a8a; --badge-bg-end: #0f172a;
    --badge-border: #93c5fd; --badge-glow: rgba(37, 99, 235, 0.6);
    --badge-icon: '◈';
    --filigree-icon: '⚔';
    --ornament-top: '🛡';
    --ornament-svg-l: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 50 L 400 50' fill='none' stroke='%232563eb' stroke-width='5' opacity='0.3'/%3E%3C/svg%3E");
}
.character-card.rarity-iron .card-front,
.character-card.rarity-iron .card-back {
    border: 5px solid #2563eb; /* Azul acero intenso */
    background-color: #081229; /* Azul muy oscuro para el fondo base */
    box-shadow: 0 0 10px rgba(37, 99, 235, 0.4);
}
.character-card.rarity-iron .tcg-overlay { box-shadow: inset 0 0 30px rgba(37, 99, 235, 0.2); pointer-events: none; }
.character-card.rarity-iron .tcg-badge-rating { border-color: #2563eb; color: #60a5fa; }
.character-card.rarity-iron .card-name { color: #93c5fd; }
.character-card.rarity-iron .tcg-title-banner { border-color: #2563eb; background: rgba(15, 23, 42, 0.95); }

/* Categoría Genérica (Fallback) */
.character-card.rarity-basic {
    --badge-bg-start: #64748b; --badge-bg-mid: #334155; --badge-bg-end: #0f172a;
    --badge-border: #94a3b8; --badge-glow: rgba(148, 163, 184, 0.4);
    --badge-icon: '✦';
    --filigree-icon: '⚜';
    --ornament-top: '✧';
    --ornament-svg-l: none;
}
.character-card.rarity-basic .card-front,
.character-card.rarity-basic .card-back {
    border: 4px solid #4b5563; 
    background-color: #111827;
}
.character-card.rarity-basic .card-name { color: #9ca3af; }
.character-card.rarity-basic .tcg-title-banner { border-color: #4b5563; }

/* BACK: Trasfondo y Tags */
.card-back {
    background-color: #110c11; /* Oscuro onírico */
    background-image: 
        radial-gradient(circle at top right, rgba(236, 72, 153, 0.15), transparent 50%),
        radial-gradient(circle at center, rgba(15, 23, 42, 0.7), rgba(0, 0, 0, 0.95)),
        url('data:image/svg+xml;utf8,<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><circle cx="2" cy="2" r="1" fill="rgba(255,255,255,0.03)"/></svg>');
    background-size: 100% 100%, 100% 100%, 15px 15px;
    background-position: center;
    transform: rotateY(180deg);
    display: flex;
    flex-direction: column;
    padding: 24px;
    border: 1px solid #3f3f46;
    box-shadow: inset 0 0 40px rgba(0,0,0,0.9);
    outline: 1px solid rgba(251, 191, 36, 0.35); /* Borde dorado interior rolero */
    outline-offset: -6px;
}

.card-back-header {
    margin-bottom: 12px;
    padding-bottom: 12px;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.card-back-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    width: 80%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(251, 191, 36, 0.6), transparent);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.card-back h4 {
    font-size: 1.1rem;
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    color: #ffffff;
    margin-bottom: 0;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    flex: 1; 

    /* === ESTILO PLACA TCG METÁLICA (DINÁMICO POR RAREZA) === */
    background: linear-gradient(180deg, var(--badge-bg-start, #64748b) 0%, var(--badge-bg-mid, #334155) 35%, var(--badge-bg-end, #0f172a) 100%);
    padding: 5px 24px; /* Más padding para los iconos laterales */
    border: 1px solid var(--badge-border, #fbbf24);
    outline: 2px solid #0f172a; 
    border-radius: 4px 14px 4px 14px; 
    
    box-shadow: 
        inset 0 1px 2px rgba(255, 255, 255, 0.5), 
        inset 0 -3px 6px rgba(0,0,0,0.8), 
        0 5px 10px rgba(0,0,0,0.7), 
        0 0 10px var(--badge-glow, rgba(251, 191, 36, 0.4)); 
    
    text-transform: uppercase;
    letter-spacing: 1.5px;
    text-shadow: 
        1px 1px 0px #000, 
        -1px -1px 0px #000, 
        0 0 6px rgba(255,255,255,0.6);
    position: relative;
}

/* Iconos de ornamento laterales */
.card-back h4::before,
.card-back h4::after {
    content: var(--badge-icon, '✦');
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: var(--badge-border, #fbbf24);
    font-size: 0.8rem;
    text-shadow: 0 0 5px var(--badge-glow, rgba(251, 191, 36, 0.4));
    opacity: 0.9;
}

.card-back h4::before { left: 8px; }
.card-back h4::after { right: 8px; }

.card-back h5 {
    font-size: 0.9rem;
    color: #e2e8f0; /* Blanco roto */
    font-weight: 400;
    white-space: nowrap; 
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
    margin-top: 2px;
}

.card-lore {
    font-size: 0.90rem;
    color: #1a1a1a;
    font-family: 'Playfair Display', serif;
    font-style: italic;
    line-height: 1.5;
    flex-grow: 1;
    overflow-y: auto;
    text-align: left;
    background: 
        linear-gradient(rgba(255, 255, 255, 0.75), rgba(245, 245, 245, 0.85)),
        url('https://www.transparenttextures.com/patterns/paper-fibers.png');
    padding: 18px;
    border-radius: 2px;
    border: 1px solid #000;
    margin: 10px 0 15px 0;
    position: relative;
    backdrop-filter: blur(2px);
    /* El ribete dorado interior */
    outline: 1px solid rgba(184, 134, 11, 0.4);
    outline-offset: -5px;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.1);
}

/* Adornos de las esquinas (Ribetes) */
.card-lore::before, .card-lore::after {
    content: '✦';
    position: absolute;
    font-size: 0.6rem;
    color: rgba(184, 134, 11, 0.8);
    pointer-events: none;
    z-index: 2;
}

.card-lore::before {
    top: 4px;
    left: 4px;
    text-shadow: 247px 0 rgba(184, 134, 11, 0.8); /* Esto es un truco para duplicar el adorno a la derecha si el ancho fuera fijo, pero mejor usamos after */
}

/* Usamos after para las otras esquinas */
.card-lore::after {
    bottom: 4px;
    right: 4px;
}

/* Añadimos un contenedor extra para las otras dos esquinas si queremos perfección, 
   pero con before/after podemos simularlo con sombras de texto */
.card-lore::before {
    top: 3px;
    left: 4px;
    /* Sombras para posicionar el icono en las 4 esquinas */
    text-shadow: 
        218px 0 rgba(184, 134, 11, 0.8), 
        0 248px rgba(184, 134, 11, 0.8), 
        218px 248px rgba(184, 134, 11, 0.8);
}
/* Al ser flexible el lore, el text-shadow de ancho fijo no funcionará perfecto. 
   Mejor usamos un degradado para el ribete */
   
.card-lore {
    background-image: 
        linear-gradient(rgba(255, 255, 255, 0.75), rgba(245, 245, 245, 0.85)),
        radial-gradient(circle at 0 0, rgba(184, 134, 11, 0.4) 2px, transparent 3px),
        radial-gradient(circle at 100% 0, rgba(184, 134, 11, 0.4) 2px, transparent 3px),
        radial-gradient(circle at 0 100%, rgba(184, 134, 11, 0.4) 2px, transparent 3px),
        radial-gradient(circle at 100% 100%, rgba(184, 134, 11, 0.4) 2px, transparent 3px);
}

.card-lore::-webkit-scrollbar {
    width: 4px;
}
.card-lore::-webkit-scrollbar-thumb {
    background: rgba(139, 69, 19, 0.3);
    border-radius: 4px;
}

.card-tags {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    text-align: left;
}

/* Tags tipo TCG Épico */
.tag-bubble {
    position: relative;
    background: linear-gradient(135deg, #374151 0%, #111827 100%);
    color: #e5e7eb;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 
        inset 0 1px 1px rgba(255,255,255,0.1),
        0 2px 4px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    gap: 4px;
}

.tag-bubble::before {
    content: '◈';
    font-size: 0.6rem;
    color: inherit;
    opacity: 0.7;
}

/* Eliminamos la colita de comic */
.tag-bubble::after {
    display: none;
}

/* Botones y Cabecera de Dorso */
.header-name-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}

.card-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.action-btn {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition);
    background-color: transparent;
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.9rem;
}

.edit-btn:hover {
    color: rgba(251, 191, 36, 0.9); /* Dorado en hover */
    transform: scale(1.15);
}

.delete-btn:hover {
    color: rgba(239, 68, 68, 0.9); /* Rojo rubí en hover */
    transform: scale(1.15);
}
