* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
body { background-color: #111; color: white; font-family: sans-serif; overflow: hidden; }

/* Selector de ROM */
#rom-loader {
    position: absolute; top: 0; left: 0; width: 100vw; height: 100vh;
    background: #1a1a1a; overflow-y: auto; z-index: 1000;
    padding: 30px 20px; text-align: center;
}
.loader-inner { max-width: 720px; margin: 0 auto; }

#rom-loader select, #rom-loader input, #rom-loader button {
    padding: 10px; font-size: 16px; border-radius: 5px; border: none; outline: none;
    font-family: inherit;
}

/* Botón principal: arriba del todo, grande y simple (<button> normal de
   HTML), para que sea lo primero que se ve y se puede pulsar, y para que
   funcione igual en navegadores y TVs antiguos. */
#play-button {
    display: block; width: 100%; max-width: 320px; margin: 18px auto 10px;
    background: #007bff; color: white; cursor: pointer; font-weight: bold;
    font-size: 20px; padding: 16px 10px; border-radius: 8px;
}
#play-button:hover, #play-button:focus { background: #0091ff; }

.list-hint { font-size: 12px; color: #999; line-height: 1.4; margin-bottom: 20px; }

.loader-row {
    display: flex; flex-direction: row; justify-content: center; align-items: flex-start;
    gap: 40px; text-align: left;
}
.loader-col { display: flex; flex-direction: column; gap: 12px; width: 300px; max-width: 100%; }
.loader-col label { font-size: 13px; color: #bbb; font-weight: bold; }

/* Botones Anterior/Siguiente: alternativa al <select> por si éste no se
   ve o no se abre bien en el navegador de la TV. Son <button> normales,
   igual que #play-button, así que funcionan igual de bien con el mando a
   distancia (foco + OK/Enter) en cualquier navegador antiguo. */
.game-nav {
    display: flex; flex-direction: row; align-items: center; gap: 8px;
    width: 100%; margin-bottom: 4px;
}
.game-nav-btn {
    flex: 0 0 auto; background: #333; color: #fff; cursor: pointer;
    font-weight: bold; font-size: 14px; padding: 10px 8px; border-radius: 6px;
    white-space: nowrap;
}
.game-nav-btn:hover, .game-nav-btn:focus { background: #007bff; }
.game-nav-current {
    flex: 1 1 auto; text-align: center; font-size: 13px; color: #fff;
    padding: 6px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Lista de juegos: un <select> nativo, igual que el selector de sistema.
   Es el control más simple y compatible que existe en HTML: funciona igual
   en cualquier navegador, móvil o Smart TV, con o sin mando a distancia. */
#game-select { width: 100%; background: #151515; color: #fff; border: 2px solid #333; }
#core-selector { width: 100%; background: #151515; color: #fff; border: 2px solid #333; }
#rom-file { width: 100%; background: #151515; color: #ccc; }

@media (max-width: 700px) {
    .loader-row { flex-direction: column; align-items: center; gap: 24px; }
    .loader-col { width: 100%; max-width: 340px; }
}

#game-container { width: 100vw; height: 100vh; display: flex; justify-content: center; align-items: center; background: #000; }
#game { width: 100%; height: 100%; max-width: 1280px; max-height: 720px; }

#ui-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
#qr-panel { position: absolute; bottom: 30px; right: 30px; background: rgba(20,20,20,0.9); padding: 20px; border-radius: 10px; border: 2px solid #444; text-align: center; pointer-events: auto; }
#qr-panel h3 { margin-bottom: 10px; font-size: 16px; }
#room-id-display { margin-top: 10px; font-size: 12px; color: #aaa; }

/* Botón para minimizar/mostrar el panel de QR (para que no tape la
   pantalla del juego mientras se está jugando). */
#qr-panel-toggle {
    position: absolute; top: 6px; right: 6px; width: 24px; height: 24px;
    border-radius: 50%; border: none; background: #444; color: #fff;
    font-size: 15px; line-height: 1; font-weight: bold; cursor: pointer;
    padding: 0;
}
#qr-panel-toggle:hover { background: #007bff; }
#qr-panel.minimized { padding: 8px 34px 8px 14px; }
#qr-panel.minimized #qr-panel-body { display: none; }

/* Botón "Iniciar Juego" dentro del panel QR: visible en cuanto se carga
   un juego, para TVs y navegadores donde el botón de inicio de EmulatorJS
   no aparece (webOS 3.x, autoplay bloqueado). Mismo estilo que #play-button
   pero más compacto para caber en el panel lateral. */
#start-game-btn {
    display: none; /* se muestra desde app.js cuando startEmulator() se llama */
    margin-top: 12px; width: 100%;
    background: #28a745; color: white; cursor: pointer;
    font-weight: bold; font-size: 16px;
    padding: 12px 8px; border-radius: 6px; border: none; outline: none;
    font-family: inherit;
}
#start-game-btn:hover, #start-game-btn:focus { background: #34ce57; }
#qr-players { display: flex; gap: 15px; }
.qr-block { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.qr-label { font-size: 12px; color: #ccc; }
#qrcode1, #qrcode2 { background: white; padding: 10px; display: inline-block; }

#settings-menu {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: rgba(20,20,20,0.95); border: 2px solid #555; border-radius: 10px;
    padding: 30px; width: 300px; pointer-events: auto; z-index: 9999;
}
#settings-menu.hidden { display: none; }
#settings-menu h2 { text-align: center; margin-bottom: 20px; border-bottom: 1px solid #444; padding-bottom: 10px; }
#settings-menu ul { list-style: none; }
.menu-item { padding: 15px; margin-bottom: 5px; background: #222; border-radius: 5px; text-align: center; transition: 0.2s; }
.menu-item.active { background: #007bff; font-weight: bold; }

/* === GAMEPAD CELULAR ACTUALIZADO === */
.gamepad-body { overflow: hidden; touch-action: none; display: flex; flex-direction: column; }
#status { text-align: center; background: #333; padding: 5px; font-weight: bold; font-size: 14px; }
#player-badge { text-align: center; background: #007bff; padding: 4px; font-weight: bold; font-size: 12px; }
#player-badge:empty { display: none; }
.gamepad-container { flex: 1; padding: 20px; display: flex; flex-direction: column; justify-content: space-between; }

.triggers { display: flex; justify-content: space-between; width: 100%; padding: 0 10px; }
.btn-trigger { width: 80px; height: 40px; background: #555; border: none; color: white; border-radius: 10px; font-weight: bold; }

.pad-area { display: flex; justify-content: space-between; align-items: center; width: 100%; flex: 1; }

.left-control { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.btn-toggle-stick {
    padding: 6px 14px; border-radius: 20px; border: none;
    background: #333; color: #ccc; font-size: 13px; font-weight: bold;
}
.btn-toggle-stick.active { background: #007bff; color: #fff; }

.dpad { position: relative; width: 150px; height: 150px; }
.dpad.hidden { display: none; }
.btn-dir { position: absolute; width: 50px; height: 50px; background: #444; border: none; color: white; font-size: 20px; border-radius: 5px; }
.btn-dir.up { top: 0; left: 50px; }
.btn-dir.down { bottom: 0; left: 50px; }
.btn-dir.left { top: 50px; left: 0; }
.btn-dir.right { top: 50px; right: 0; }

/* Joystick analogico: pensado para juegos (sobre todo PSX en 3D) que
   requieren el stick y no responden a la cruceta digital. */
.joystick { width: 150px; height: 150px; display: flex; align-items: center; justify-content: center; }
.joystick.hidden { display: none; }
.joystick-base {
    position: relative; width: 130px; height: 130px; border-radius: 50%;
    background: #262626; border: 3px solid #444;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.6);
    touch-action: none;
}
.joystick-knob {
    /* Centrado con top/left fijos en vez de transform:translate(-50%,-50%)
       + calc(), que no funciona en navegadores de TV antiguos (webOS 3.x).
       Base: 130px, knob: 56px → (130-56)/2 = 37px para centrar. */
    position: absolute; top: 37px; left: 37px; width: 56px; height: 56px;
    border-radius: 50%; background: #555;
    border: 2px solid #888;
}
.joystick-knob.dragging { border-color: #007bff; }

.action-btns { position: relative; width: 150px; height: 150px; }
.btn-action { position: absolute; width: 50px; height: 50px; border-radius: 50%; border: none; background: #555; color: white; font-size: 20px; font-weight: bold; }
.btn-action.triangle { top: 0; left: 50px; background: #28a745; }
.btn-action.cross { bottom: 0; left: 50px; background: #007bff; }
.btn-action.square { top: 50px; left: 0; background: #dc3545; }
.btn-action.circle { top: 50px; right: 0; background: #ffc107; color: black; }

.center-btns { display: flex; justify-content: center; align-items: center; gap: 20px; padding-bottom: 20px; }
.btn-menu { padding: 10px 20px; border-radius: 20px; border: none; background: #333; color: white; font-weight: bold; }

/* Botón pequeño (ícono ☰) que abre el menú de EmulatorJS en la TV. */
.btn-menu-small {
    padding: 0; width: 34px; height: 34px; border-radius: 50%;
    font-size: 16px; display: flex; align-items: center; justify-content: center;
    background: #555;
}

/* Botón central fijo: activa el modo de edición del mando (arrastrar y
   redimensionar los grupos de botones). Siempre visible, discreto, para
   no molestar mientras se juega normalmente. */
#layout-edit-btn {
    position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: 34px; height: 34px; border-radius: 50%; border: none;
    background: rgba(80,80,80,0.55); color: #fff; font-size: 16px;
    z-index: 600; opacity: 0.55;
}
#layout-edit-btn.active { background: #007bff; opacity: 1; }

/* --- Modo de edición del mando (mando-layout.js) --- */
.edit-target {
    outline: 2px dashed #00bcd4;
    outline-offset: 3px;
    border-radius: 10px;
    background: rgba(0,188,212,0.08);
}
.edit-target.edit-active { outline-color: #ffc107; background: rgba(255,193,7,0.12); }

.layout-resize-handle {
    position: absolute; right: -14px; bottom: -14px; width: 28px; height: 28px;
    border-radius: 50%; background: #00bcd4; color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; z-index: 601;
}

#layout-edit-toolbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 700;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(15,15,15,0.92); border-top: 1px solid #444;
}
#layout-edit-toolbar span { font-size: 12px; color: #ccc; text-align: center; }
#layout-edit-toolbar button {
    border: none; border-radius: 20px; padding: 8px 18px; font-weight: bold;
}
#layout-edit-toolbar #layout-reset-btn { background: #555; color: #fff; }
#layout-edit-toolbar #layout-done-btn { background: #28a745; color: #fff; }

/* En horizontal la pantalla del teléfono tiene mucha menos altura, y la
   cruceta/botones de acción (150x150px) no entraban en ese espacio: por
   eso se cortaba la última flecha. Se reduce su tamaño (manteniendo las
   mismas proporciones y sin tocar el joystick ni ningún otro botón) para
   que quepan completos, y como red de seguridad adicional se permite
   scroll vertical por si algún teléfono tiene aún menos altura. */
@media (orientation: landscape) {
    .gamepad-container { padding: 8px 20px; overflow-y: auto; }
    .triggers { padding: 0; }
    .btn-trigger { height: 32px; }
    .left-control { gap: 4px; }
    .btn-toggle-stick { padding: 3px 8px; font-size: 10px; }
    .center-btns { padding-bottom: 4px; }
    .btn-menu { padding: 6px 16px; }
    .btn-menu-small { width: 28px; height: 28px; font-size: 13px; }
    #layout-edit-btn { width: 28px; height: 28px; font-size: 13px; }

    .dpad, .action-btns { width: 110px; height: 110px; }
    .btn-dir, .btn-action { width: 38px; height: 38px; }
    .btn-dir.up, .btn-dir.down { left: 36px; }
    .btn-dir.left, .btn-dir.right { top: 36px; }
    .btn-action.triangle, .btn-action.cross { left: 36px; }
    .btn-action.square, .btn-action.circle { top: 36px; }
}

