@font-face {
    font-family: pressstart2p;
    src: url("./fuentes/pressstart2p.ttf") format("truetype");
}

/* ==========================================================================
   ESTRUCTURA PRINCIPAL Y AMBIENTACIÓN DEL ALTILLO
   ========================================================================== */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'pressstart2p', monospace, sans-serif;
    color: #fff;
    min-height: 100vh;
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: center;
    transition: background-image 0.5s ease;
    overflow-x: hidden;
}

#contenedor {
    font-family: 'pressstart2p', monospace, sans-serif;
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px 15px 30px 15px;
    position: relative;
    z-index: 2;
}

/* Viga de madera superior del ático */
.attic-top-beam {
    height: 18px;
    background: repeating-linear-gradient(90deg, #3e2723, #4e342e 40px, #27160c 80px);
    border-bottom: 4px solid #1a0e07;
    box-shadow: 0 4px 10px rgba(0,0,0,0.6);
    position: relative;
}

.attic-top-beam::after {
    content: "▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲";
    position: absolute;
    bottom: -10px;
    left: 0;
    right: 0;
    font-size: 8px;
    color: #27160c;
    letter-spacing: 12px;
    overflow: hidden;
    white-space: nowrap;
}

/* ==========================================================================
   CABECERA Y MODOS DÍA / NOCHE
   ========================================================================== */
.cabeceraOn {
    padding: 10px 15px;
    min-height: 110px;
    position: relative;
    font-family: 'pressstart2p', monospace, sans-serif;
    background-color: rgba(255, 255, 255, 0.45);
    border: 4px solid #ffffff;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    margin-bottom: 12px;
    transition: all 0.4s ease;
}

.cabeceraOff {
    padding: 10px 15px;
    min-height: 110px;
    position: relative;
    font-family: 'pressstart2p', monospace, sans-serif;
    background-color: rgba(20, 20, 20, 0.75);
    border: 4px solid #ffd54f;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 0 25px rgba(255, 213, 79, 0.3);
    backdrop-filter: blur(4px);
    margin-bottom: 12px;
    transition: all 0.4s ease;
}

.cabecera-brand {
    display: flex;
    align-items: center;
    gap: 15px;
}

.cabecera-logo-img {
    max-height: 90px;
    width: auto;
    filter: drop-shadow(2px 2px 0 #000);
}

/* ==========================================================================
   BARRA DE MENÚ Y ESTADO EN LA NUBE (GOOGLE DRIVE)
   ========================================================================== */
.menuOn {
    padding: 8px 12px;
    font-family: 'pressstart2p', monospace, sans-serif;
    background-color: rgba(32, 98, 28, 0.9);
    border: 4px dashed #81c784;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    transition: all 0.4s ease;
}

.menuOff {
    padding: 8px 12px;
    font-family: 'pressstart2p', monospace, sans-serif;
    background-color: rgba(13, 40, 11, 0.9);
    border: 4px dashed #ffb300;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
    box-shadow: 0 0 15px rgba(255, 179, 0, 0.25);
    transition: all 0.4s ease;
}

.menu-nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.menu-tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Barra de Google Drive Cloud */
.drive-status-badge {
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #4fc3f7;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 8px;
    color: #e1f5fe;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.drive-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ff5252;
    box-shadow: 0 0 4px #ff5252;
}

.drive-dot.connected {
    background: #69f0ae;
    box-shadow: 0 0 6px #69f0ae;
}

.drive-dot.syncing {
    background: #ffd740;
    box-shadow: 0 0 8px #ffd740;
    animation: blink-fast 0.4s infinite;
}

/* ==========================================================================
   CUERPO PRINCIPAL DEL ALTILLO
   ========================================================================== */
#cuerpo {
    min-height: 520px;
    background-color: rgba(30, 15, 5, 0.85);
    background-image: 
        repeating-linear-gradient(0deg, rgba(0,0,0,0.15) 0px, rgba(0,0,0,0.15) 30px, transparent 30px, transparent 32px),
        linear-gradient(to bottom, rgba(50, 25, 10, 0.9), rgba(20, 10, 5, 0.95));
    border: 4px solid #5d4037;
    border-radius: 8px;
    font-family: 'pressstart2p', monospace, sans-serif;
    padding: 16px;
    margin-bottom: 15px;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8), 0 8px 20px rgba(0, 0, 0, 0.6);
    overflow-y: auto;
}

/* ==========================================================================
   ESTANTE DE CONSOLAS RETRO (SELECTOR MULTIPLATAFORMA)
   ========================================================================== */
.console-shelf-container {
    background: #27160c;
    border: 4px solid #1a0e07;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 18px;
    box-shadow: inset 0 4px 10px rgba(0,0,0,0.8), 0 4px 8px rgba(0,0,0,0.5);
}

.shelf-title {
    font-size: 10px;
    color: #ffb74d;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px dashed #4e342e;
    padding-bottom: 6px;
}

.console-cartridges-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
}

.console-cartridge-btn {
    background: #37474f;
    border: 3px solid #263238;
    border-radius: 6px;
    color: #cfd8dc;
    font-family: 'pressstart2p', monospace;
    font-size: 8px;
    padding: 8px 4px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 4px 0 #102027;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    user-select: none;
}

.console-cartridge-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #102027;
    color: #fff;
    filter: brightness(1.2);
}

.console-cartridge-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #102027;
}

.console-cartridge-btn.active {
    background: #c62828;
    border-color: #ef5350;
    color: #fff;
    box-shadow: 0 4px 0 #5f0909, 0 0 10px rgba(239, 83, 80, 0.6);
}

.console-icon-pixel {
    font-size: 14px;
}

/* Colores específicos de consolas */
.console-cartridge-btn[data-core="nes"].active { background: #b71c1c; border-color: #ff5252; }
.console-cartridge-btn[data-core="snes"].active { background: #4a148c; border-color: #ba68c8; }
.console-cartridge-btn[data-core="segaMD"].active { background: #01579b; border-color: #4fc3f7; }
.console-cartridge-btn[data-core="gb"].active { background: #33691e; border-color: #9ccc65; }
.console-cartridge-btn[data-core="gba"].active { background: #311b92; border-color: #7c4dff; }
.console-cartridge-btn[data-core="n64"].active { background: #bf360c; border-color: #ff7043; }
.console-cartridge-btn[data-core="psx"].active { background: #212121; border-color: #00e676; box-shadow: 0 4px 0 #000, 0 0 10px rgba(0, 230, 118, 0.5); }

/* ==========================================================================
   BANDEJA RÁPIDA DE CARTUCHOS BAJO LA TV
   ========================================================================== */
.quick-rom-tray-container {
    margin-top: 14px;
    background: #1e1108;
    border: 3px solid #8d6e63;
    border-radius: 6px;
    padding: 10px;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.8);
    animation: fadeIn 0.25s ease-out;
}

.quick-tray-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 8px;
    color: #ffca28;
    margin-bottom: 8px;
    border-bottom: 1px dashed #5d4037;
    padding-bottom: 5px;
}

.quick-tray-link {
    color: #69f0ae;
    text-decoration: none;
    font-size: 7px;
}

.quick-tray-link:hover {
    color: #00e676;
    text-decoration: underline;
}

.quick-rom-tray-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 6px;
    max-height: 160px;
    overflow-y: auto;
    padding: 2px;
}

.quick-tray-cartridge-btn {
    background: #2b2b2b;
    border: 2px solid #4e342e;
    border-radius: 4px;
    color: #eee;
    font-family: 'pressstart2p', monospace;
    font-size: 7px;
    padding: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    user-select: none;
}

.quick-tray-cartridge-btn:hover {
    background: #4e342e;
    border-color: #ffd54f;
    color: #ffd54f;
    transform: translateY(-1px);
}

.quick-tray-btn-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* ==========================================================================
   EXPLORADOR DE ROMS Y PESTAÑAS DEL CATÁLOGO
   ========================================================================== */
.rom-explorer-container {
    background: rgba(15, 10, 5, 0.9);
    border: 3px solid #8d6e63;
    border-radius: 8px;
    padding: 14px;
    margin-top: 15px;
}

.rom-explorer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 10px;
    border-bottom: 2px dashed #5d4037;
    padding-bottom: 10px;
}

.rom-explorer-title-box {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

.rom-explorer-active-badge {
    font-size: 8px;
    color: #81c784;
}

.rom-explorer-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.catalog-count-badge {
    background: #27160c;
    border: 1px solid #ffca28;
    color: #ffd54f;
    padding: 4px 8px;
    font-size: 7px;
    border-radius: 4px;
}

.rom-view-toggle-group {
    display: inline-flex;
    gap: 4px;
    background: #212121;
    padding: 2px;
    border-radius: 4px;
    border: 1px solid #424242;
}

.rom-view-btn {
    background: transparent;
    border: none;
    color: #b0bec5;
    font-family: 'pressstart2p', monospace;
    font-size: 7px;
    padding: 5px 8px;
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.15s;
}

.rom-view-btn:hover {
    color: #fff;
}

.rom-view-btn.active {
    background: #ff6f00;
    color: #000;
    font-weight: bold;
    box-shadow: 0 0 6px rgba(255, 111, 0, 0.6);
}

.rom-nav-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    border-bottom: 3px solid #5d4037;
    padding-bottom: 8px;
    flex-wrap: wrap;
}

.rom-tab-btn {
    background: #4e342e;
    border: 2px solid #3e2723;
    color: #d7ccc8;
    font-family: 'pressstart2p', monospace;
    font-size: 8px;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s;
}

.rom-tab-btn:hover {
    background: #6d4c41;
    color: #fff;
}

.rom-tab-btn.active {
    background: #ff6f00;
    border-color: #ffa000;
    color: #000;
    font-weight: bold;
    box-shadow: 0 0 8px rgba(255, 111, 0, 0.6);
}

/* ==========================================================================
   VISTA 1: CUADRÍCULA (GRID VIEW)
   ========================================================================== */
.rom-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 8px;
    max-height: 380px;
    overflow-y: auto;
    padding: 6px;
}

.rom-item-card {
    background: #212121;
    border: 2px solid #424242;
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 8px;
    color: #eee;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.15s;
    text-align: left;
    gap: 8px;
}

.rom-item-card:hover {
    background: #37474f;
    border-color: #00e676;
    color: #00e676;
    transform: scale(1.02);
}

.rom-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: bold;
}

.rom-format-tag {
    font-size: 6px;
    background: #37474f;
    border: 1px solid #78909c;
    color: #eceff1;
    padding: 1px 4px;
    border-radius: 2px;
}

.rom-size-text {
    font-size: 6px;
    color: #90a4ae;
}

.rom-item-card .rom-save-tag {
    font-size: 7px;
    background: #e65100;
    color: #fff;
    padding: 2px 5px;
    border-radius: 2px;
}

/* ==========================================================================
   VISTA 2: LISTA DETALLADA (TABLE / LIST VIEW)
   ========================================================================== */
.rom-list-table {
    max-height: 400px;
    overflow-y: auto;
    padding: 4px;
}

.rom-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8px;
    text-align: left;
}

.rom-table thead th {
    background: #27160c;
    color: #ffd54f;
    padding: 8px 10px;
    border-bottom: 2px solid #5d4037;
    position: sticky;
    top: 0;
    z-index: 2;
    font-size: 7px;
    letter-spacing: 0.5px;
}

.rom-table-row {
    border-bottom: 1px solid #333;
    transition: background 0.15s;
    cursor: pointer;
}

.rom-table-row:hover {
    background: rgba(0, 230, 118, 0.15);
}

.rom-table-row:hover .rom-table-name strong {
    color: #00e676;
}

.rom-table-row td {
    padding: 8px 10px;
    vertical-align: middle;
}

.rom-table-name {
    color: #fff;
    display: flex;
    align-items: center;
    word-break: break-word;
    font-size: 8px;
}

.rom-table-sys-badge {
    background: #1a237e;
    color: #8c9eff;
    border: 1px solid #3d5afe;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 6px;
}

.rom-source-drive {
    color: #69f0ae;
    font-size: 7px;
}

.rom-source-local {
    color: #ffd54f;
    font-size: 7px;
}

/* ==========================================================================
   MODALES RETRO 8-BITS
   ========================================================================== */
.retro-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    backdrop-filter: blur(4px);
}

.retro-modal-box {
    background: #212121;
    border: 5px solid #ffca28;
    border-radius: 8px;
    padding: 20px;
    max-width: 580px;
    width: 100%;
    color: #fff;
    box-shadow: 0 0 30px rgba(255, 202, 40, 0.4), inset 0 0 15px rgba(0,0,0,0.9);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.retro-modal-title {
    font-size: 11px;
    color: #ffd54f;
    margin-top: 0;
    margin-bottom: 14px;
    border-bottom: 2px dashed #ffca28;
    padding-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.retro-modal-close {
    background: #b71c1c;
    border: 2px solid #fff;
    color: #fff;
    cursor: pointer;
    font-family: 'pressstart2p', monospace;
    font-size: 9px;
    padding: 2px 6px;
}

/* ==========================================================================
   SISTEMA DE TOASTS RETRO 8-BITS
   ========================================================================== */
#retro-toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.retro-toast {
    background: #1b1b1b;
    border: 3px solid #00e676;
    border-radius: 4px;
    padding: 10px 14px;
    color: #fff;
    font-size: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.8), 0 0 10px rgba(0, 230, 118, 0.4);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: toast-in 0.3s ease-out;
    pointer-events: auto;
    max-width: 320px;
    line-height: 1.5;
}

.retro-toast.error {
    border-color: #ff1744;
    box-shadow: 0 4px 15px rgba(0,0,0,0.8), 0 0 10px rgba(255, 23, 68, 0.5);
}

.retro-toast.warning {
    border-color: #ffd600;
    box-shadow: 0 4px 15px rgba(0,0,0,0.8), 0 0 10px rgba(255, 214, 0, 0.5);
}

@keyframes toast-in {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ==========================================================================
   PIE DE PÁGINA Y DETALLES DEL ALTILLO
   ========================================================================== */
.pieOn {
    padding: 8px 12px;
    background-color: rgba(0, 75, 202, 0.6);
    font-family: 'pressstart2p', monospace, sans-serif;
    border: 4px dashed #90caf9;
    border-radius: 8px;
    text-align: center;
    font-size: 8px;
    color: #e3f2fd;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    transition: all 0.4s ease;
}

.pieOff {
    padding: 8px 12px;
    background-color: rgba(0, 22, 64, 0.7);
    font-family: 'pressstart2p', monospace, sans-serif;
    border: 4px dashed #ffca28;
    border-radius: 8px;
    text-align: center;
    font-size: 8px;
    color: #fff8e1;
    box-shadow: 0 0 15px rgba(255, 202, 40, 0.2);
    transition: all 0.4s ease;
}

/* Efectos de imagen legados */
.imagenEscalaGris { filter: grayscale(90%); }
.imagenEscalaGris:hover {
    filter: grayscale(0%);
    transform: scale(1.03);
    transition: all 0.3s ease-in-out;
}

.imagenSaturada:hover {
    filter: saturate(195%);
    transition: all 0.3s ease-in-out;
}

.imagenSaturadaMax:hover {
    filter: saturate(365%);
    transition: all 0.3s ease-in-out;
}

.imagenZoom:hover {
    transform: scale(1.03);
    transition: all 0.3s ease-in-out;
}

.latido {
    animation-name: pulse_animation;
    animation-duration: 3000ms;
    transform-origin: 70% 70%;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}

@keyframes pulse_animation {
    0% { transform: scale(1); }
    30% { transform: scale(1); }
    40% { transform: scale(1.08); }
    50% { transform: scale(1); }
    60% { transform: scale(1); }
    70% { transform: scale(1.05); }
    80% { transform: scale(1); }
    100% { transform: scale(1); }
}

/* Scrollbar retro */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-thumb {
    background: #ffb300;
    border: 2px solid #27160c;
}
::-webkit-scrollbar-track {
    background: #27160c;
}

/* Responsividad */
@media (max-width: 860px) {
    #contenedor {
        margin: 0;
        padding: 5px;
    }
    .cabeceraOn, .cabeceraOff {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }
    .menuOn, .menuOff {
        justify-content: center;
    }
    .rom-explorer-header {
        flex-direction: column;
        align-items: flex-start;
    }
}