/* ---------------------------------------------------------------
   Tokens del juego. Se enganchan a BoxUI cuando existe, con
   respaldo arcade propio. BoxUI es el ÚNICO framework CSS del
   proyecto: no se importa ningún otro.
   --------------------------------------------------------------- */
:root {
    --bg-color:      #111;
    --panel-bg:      #222;
    --text-color:    #eee;
    --accent-color:  #ffeb3b;          /* amarillo arcade por defecto */
    --btn-bg:        #333;
    --btn-hover:     #444;
    --correct-color: #4caf50;
    --wrong-color:   #f44336;
    --target-color:  #2196f3;

    /* Cada juego redefine SOLO esta variable en su style.css */
    --game-accent:   var(--accent-color);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 10px;
    touch-action: none;
}

.game-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 800px;
    height: 95vh;
    background-color: var(--panel-bg);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

/* Barra Superior Compartida */
.top-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    background: rgba(0,0,0,0.3);
    padding: 12px 20px;
    border-radius: 8px;
    margin-bottom: 16px;
    gap: 10px;
}

.brand {
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--game-accent);
}

.game-info {
    display: flex;
    gap: 15px;
}

.stats-group {
    display: flex;
    gap: 20px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.stat-item .label {
    font-size: 0.8rem;
    color: #aaa;
    letter-spacing: 1px;
}

.stat-item .value {
    font-size: 1.3rem;
    font-weight: bold;
    color: #fff;
}

.actions-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

/* Sin esto un hijo ancho (p. ej. 5 botones) ensancha toda la barra en pantallas de 320px */
.top-bar > * { min-width: 0; }

.icon-btn {
    background: var(--btn-bg);
    border: none;
    color: white;
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Canvas y Contenedor Principal */
.canvas-container {
    position: relative;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
}

canvas {
    background: #000;
    display: block;
    image-rendering: pixelated;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Controles en Pantalla (D-pad) */
.mobile-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: grid;
    grid-template-columns: 50px 50px 50px;
    grid-template-rows: 50px 50px;
    gap: 6px;
    opacity: 0.6;
    z-index: 10;
}

#btn-up { grid-column: 2; grid-row: 1; }
#btn-left { grid-column: 1; grid-row: 2; }
#btn-down { grid-column: 2; grid-row: 2; }
#btn-right { grid-column: 3; grid-row: 2; }

.dpad-btn {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.4);
    color: white;
    border-radius: 8px;
    font-size: 1.2rem;
    touch-action: manipulation;
    cursor: pointer;
}

.dpad-btn:active {
    background: rgba(255,255,255,0.5);
}

/* Botones genéricos */
.btn-primary {
    width: 100%;
    padding: 14px;
    background-color: var(--game-accent);
    color: #000;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
}

.mt-3 {
    margin-top: 16px;
}

/* Modal */
.modal {
    margin: auto;
    border: none;
    border-radius: 12px;
    background-color: var(--panel-bg);
    color: var(--text-color);
    padding: 0;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
}

.modal::backdrop {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}

.modal-content {
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.modal-title {
    color: var(--game-accent);
    margin-bottom: 16px;
    font-size: 1.5rem;
    text-align: center;
}

.question-text, .instructions-text {
    font-size: 1.1rem;
    line-height: 1.5;
    margin-bottom: 24px;
    white-space: normal;
    word-wrap: break-word;
    color: #ddd;
}

.instructions-text p {
    margin-bottom: 10px;
}

.options-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@media (max-width: 600px) {
    .top-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 10px 12px;
    }
    .brand { text-align: center; }
    .game-info { justify-content: space-around; }
    .stats-group { justify-content: space-around; }
    .actions-group { justify-content: center; }
    
    .mobile-controls {
        bottom: 10px;
        right: 10px;
    }
}

/* Botón de acción en estado activo (silencio activado) */
.icon-btn[aria-pressed="true"] { background: var(--game-accent); color: #000; }

/* Accesibilidad: foco visible con teclado */
.icon-btn:focus-visible,
.dpad-btn:focus-visible,
.btn-primary:focus-visible {
    outline: 3px solid var(--game-accent);
    outline-offset: 2px;
}

/* Área táctil mínima real en móvil */
@media (pointer: coarse) {
    .icon-btn { min-width: 48px; min-height: 48px; }
    .dpad-btn { min-width: 56px; min-height: 56px; }
}

/* Sin animaciones para quien las desactivó */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Contenedor DOM para los juegos que no usan canvas */
.board-container {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: #000;
    border-radius: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Franja de retroalimentación bajo la barra */
.feedback-bar {
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 1rem;
    line-height: 1.4;
    display: none;
}
.feedback-bar[data-tipo="ok"]    { display: block; background: rgba(76,175,80,.18);  border-left: 4px solid var(--correct-color); }
.feedback-bar[data-tipo="error"] { display: block; background: rgba(244,67,54,.18);   border-left: 4px solid var(--wrong-color); }
