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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    margin-bottom: 0;
    overflow: hidden;
}

.game-container {
    width: 100%;
    max-width: 1000px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

header h1 {
    font-size: 2rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.back-btn {
    background: rgba(255, 255, 255, 0.2);
    margin-top: 0;
    color: white;
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.3s ease;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

/* Game Info */
.game-info {
    margin-bottom: 2px;
}

.player-info {
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    margin-bottom: 0;
    gap: 10px;
}

.player-display {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 10px;
    text-align: center;
    transition: all 0.3s ease;
    border: 3px solid transparent;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.player-display.active {
    background: rgba(255, 255, 255, 0.25);
    border-color: #4CAF50;
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.5);
}

    /* Mejor visibilidad del jugador activo en móvil */
    @media (orientation: landscape) and (max-height: 600px) {
        .player-display.active {
            background: rgba(76, 175, 80, 0.3);
            border-color: #4CAF50;
            box-shadow: 0 0 15px rgba(76, 175, 80, 0.7);
        }
    }
    margin-bottom: 8px;
}

.balls-display {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.ball-type {
    font-size: 0.9rem;
    opacity: 0.8;
}

.balls-count {
    font-size: 1.5rem;
    font-weight: bold;
    color: #FFD700;
}

.game-message {
    text-align: center;
    font-size: 1.1rem;
    padding: 10px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    font-weight: 500;
}

/* Balls Tracker */
.balls-tracker-center {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.balls-tracker-grid {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
    min-height: 35px;
}

.balls-tracker-ball {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
    position: relative;
    transition: all 0.3s ease;
}

.balls-tracker-ball.pocketed {
    opacity: 0.3;
    transform: scale(0.8);
    filter: grayscale(1);
}

.balls-tracker-ball.pocketed::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 16px;
    text-shadow: 0 0 3px black;
}

.balls-tracker-ball.striped {
    background: linear-gradient(to bottom,
            var(--ball-color) 0%,
            var(--ball-color) 30%,
            white 30%,
            white 70%,
            var(--ball-color) 70%,
            var(--ball-color) 100%);
    color: black;
}

.balls-tracker-ball.solid {
    background: var(--ball-color);
    color: black;
}

.balls-tracker-ball.black-ball {
    background: #000000;
    color: white;
    width: 32px;
    height: 32px;
    font-size: 14px;
}

/* Canvas */
.canvas-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;
    margin-top: 10px;
    width: 100vw;
    height: 70vh;
    max-width: 1800px;
    max-height: 90vh;
    min-height: 400px;
    min-width: 320px;
}

#gameCanvas {
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    background: #1a5f1a;
    width: 96vw;
    height: 64vh;
    max-width: 1700px;
    max-height: 80vh;
    min-width: 300px;
    min-height: 350px;
    display: block;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Power Bar */
.power-bar-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.85);
    padding: 25px 40px;
    border-radius: 15px;
    border: 3px solid white;
    z-index: 10;
    min-width: 300px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: manipulation;
}

.power-bar-container:active {
    transform: translate(-50%, -50%) scale(0.98);
}

.power-bar-container.hidden {
    display: none;
}

/* Turn Change Message */
.turn-change-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.95), rgba(56, 142, 60, 0.95));
    padding: 30px 50px;
    border-radius: 20px;
    border: 4px solid white;
    z-index: 15;
    font-size: 2rem;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

.turn-change-message.victory {
    background: linear-gradient(135deg, rgba(255, 193, 7, 0.95), rgba(255, 152, 0, 0.95));
    font-size: 2.5rem;
    padding: 40px 60px;
    animation: victoryPulse 0.5s ease-in-out;
}

.turn-change-message.start {
    background: linear-gradient(135deg, rgba(33, 150, 243, 0.95), rgba(21, 101, 192, 0.95));
}

.turn-change-message.foul {
    background: linear-gradient(135deg, rgba(244, 67, 54, 0.95), rgba(211, 47, 47, 0.95));
}

@keyframes victoryPulse {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        transform: translate(-50%, -50%) scale(1.1);
    }
}

.turn-change-message.hidden {
    display: none;
}

.turn-change-message.show {
    animation: fadeInOut 2s ease-in-out forwards;
}

@keyframes fadeInOut {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }

    15% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    85% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

.power-bar-label {
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 15px;
    color: white;
}

.power-bar-bg {
    width: 100%;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.5);
    position: relative;
}

.power-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4CAF50, #FFC107, #FF5722);
    border-radius: 8px;
    transition: width 0.05s linear;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.power-bar-instruction {
    text-align: center;
    margin-top: 15px;
    font-size: 0.95rem;
    color: #FFD700;
    font-weight: bold;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* Controls Info */
.controls-info {
    text-align: center;
    font-size: 0.9rem;
    opacity: 0.8;
    margin-bottom: 4px;
    margin-top: 0;
}

/* Restart Button */
.restart-btn {
    width: 100%;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    border: none;
    color: white;
    padding: 15px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: bold;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    margin-top: 4px;
    margin-bottom: 0;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

.restart-btn:active {
    transform: translateY(0);
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

/* Responsive Design */
@media (max-width: 968px) {
    body {
        padding: 5px;
    }

    .game-container {
        padding: 10px;
        border-radius: 12px;
    }

    header {
        margin-bottom: 10px;
    }

    header h1 {
        font-size: 1.4rem;
    }

    .back-btn {
        padding: 6px 12px;
        font-size: 0.85em;
    }

    .player-info {
        gap: 8px;
        margin-bottom: 5px;
    }

    .player-display {
        padding: 10px;
        gap: 5px;
    }

    .player-name {
        font-size: 1rem;
        margin-bottom: 4px;
    }

    .balls-count {
        font-size: 1.2rem;
    }

    .balls-tracker-grid {
        min-height: 25px;
        gap: 4px;
    }

    .balls-tracker-ball {
        width: 22px;
        height: 22px;
        font-size: 9px;
    }

    .balls-tracker-ball.black-ball {
        width: 26px;
        height: 26px;
        font-size: 11px;
    }

    .game-message {
        font-size: 0.9rem;
        padding: 6px;
    }

    .canvas-container {
        height: 55vh;
        min-height: 280px;
        margin-bottom: 10px;
    }

    #gameCanvas {
        height: 50vh;
        min-height: 250px;
    }

    .power-bar-container {
        min-width: 220px;
        padding: 15px 25px;
    }

    .power-bar-label {
        font-size: 1rem;
        margin-bottom: 10px;
    }

    .power-bar-bg {
        height: 30px;
    }

    .controls-info {
        font-size: 0.75rem;
    }

    .restart-btn {
        padding: 10px;
        font-size: 1rem;
    }
}

/* Landscape mobile optimizations - OPTIMIZADO PARA JUEGO HORIZONTAL */
@media (orientation: landscape) and (max-height: 600px) {
    body {
        padding: 2px;
        padding-top: 50px;
        align-items: flex-start;
    }

    .game-container {
        max-width: 100%;
        width: 100%;
        padding: 3px 8px;
        margin: 0;
        border-radius: 8px;
        min-height: auto;
        max-height: 100vh;
        display: flex;
        flex-direction: column;
    }

    /* Header compacto */
    header {
        margin-bottom: 2px;
        padding: 2px 0;
    }

    header h1 {
        font-size: 0.9rem;
    }

    .back-btn {
        padding: 4px 10px;
        font-size: 0.7rem;
        border-radius: 6px;
    }

    /* Información de jugadores en una sola línea horizontal */
    .game-info {
        margin-bottom: 0;
    }

    .player-info {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 4px;
        margin-bottom: 0;
        padding: 0 5px;
    }

    .player-display {
        flex-direction: row;
        align-items: center;
        padding: 3px 8px;
        gap: 6px;
        flex: 1;
        max-width: 42%;
    }

    /* Nombres de jugador compactos en móvil */
    .player-name {
        font-size: 0.7rem;
        margin-bottom: 0;
        white-space: nowrap;
    }

    .balls-display {
        gap: 4px;
        flex-direction: row;
        align-items: center;
    }

    .ball-type {
        font-size: 0.65rem;
    }

    .balls-count {
        font-size: 0.9rem;
    }

    /* Ocultar tracker de bolas para ahorrar espacio */
    .balls-tracker-grid {
        display: none;
    }

    /* Bola negra en el centro más pequeña */
    .balls-tracker-center {
        padding: 0;
        margin: 0 3px;
    }

    .balls-tracker-ball.black-ball {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }

    /* Ocultar mensaje del juego */
    .game-message {
        display: none;
    }

    /* Canvas ocupa el máximo espacio disponible */
    .canvas-container {
        height: calc(100vh - 135px);
        max-height: calc(100vh - 135px);
        min-height: unset;
        margin-bottom: 1px;
        margin-top: 0;
        width: 100%;
    }

    #gameCanvas {
        height: calc(100vh - 136px);
        max-height: calc(100vh - 136px);
        min-height: unset;
        width: 100%;
        max-width: 100%;
    }

    /* Mensajes del juego más pequeños */
    .turn-change-message {
        font-size: 1.2rem;
        padding: 15px 25px;
        border-radius: 12px;
        border-width: 2px;
    }

    .turn-change-message.victory {
        font-size: 1.5rem;
        padding: 20px 30px;
    }

    /* Barra de potencia más compacta */
    .power-bar-container {
        min-width: 180px;
        padding: 12px 20px;
        border-width: 2px;
    }

    .power-bar-label {
        font-size: 0.85rem;
        margin-bottom: 8px;
    }

    .power-bar-bg {
        height: 25px;
    }

    .power-bar-instruction {
        margin-top: 8px;
        font-size: 0.75rem;
    }

    /* Ocultar controles info */
    .controls-info {
        display: none;
    }

    /* Botón de reinicio compacto */
    .restart-btn {
        padding: 3px 6px;
        font-size: 0.65rem;
        margin-top: 1px;
        margin-bottom: 2px;
        border-radius: 5px;
        height: auto;
        line-height: 1.1;
    }

    /* Ocultar anuncios en móvil horizontal para ganar espacio */
    .game-container > div[style*="text-align"] {
        display: none !important;
    }
}

/* Dispositivos móviles muy pequeños en horizontal */
@media (orientation: landscape) and (max-height: 450px) {
    body {
        padding: 1px;
        padding-top: 48px;
    }

    .game-container {
        padding: 2px 5px;
        min-height: auto;
        max-height: 100vh;
        display: flex;
        flex-direction: column;
    }

    header {
        margin-bottom: 2px;
        padding: 1px 0;
    }

    header h1 {
        font-size: 0.8rem;
    }

    .back-btn {
        padding: 3px 8px;
        font-size: 0.65rem;
    }

    .game-info {
        margin-bottom: 1px;
    }

    .player-info {
        gap: 3px;
        padding: 0 3px;
    }

    .player-display {
        padding: 2px 6px;
        gap: 4px;
    }

    .player-name {
        font-size: 0.65rem;
    }

    .ball-type {
        font-size: 0.6rem;
    }

    .balls-count {
        font-size: 0.85rem;
    }

    .balls-tracker-center {
        margin: 0 2px;
    }

    .balls-tracker-ball.black-ball {
        width: 18px;
        height: 18px;
        font-size: 9px;
    }

    /* Maximizar espacio del canvas */
    .canvas-container {
        height: calc(100vh - 115px);
        max-height: calc(100vh - 115px);
        margin-top: 0;
        margin-bottom: 1px;
    }

    #gameCanvas {
        height: calc(100vh - 116px);
        max-height: calc(100vh - 116px);
    }

    .turn-change-message {
        font-size: 1rem;
        padding: 12px 20px;
    }

    .turn-change-message.victory {
        font-size: 1.3rem;
        padding: 15px 25px;
    }

    .power-bar-container {
        min-width: 160px;
        padding: 10px 18px;
    }

    .power-bar-label {
        font-size: 0.75rem;
        margin-bottom: 6px;
    }

    .power-bar-bg {
        height: 22px;
    }

    .power-bar-instruction {
        margin-top: 6px;
        font-size: 0.7rem;
    }

    .restart-btn {
        padding: 2px 5px;
        font-size: 0.6rem;
        margin-top: 1px;
        margin-bottom: 2px;
        height: auto;
        line-height: 1;
    }

    /* Ocultar anuncios en móvil horizontal */
    .game-container > div[style*="text-align:center"] {
        display: none !important;
    }
}

/* Portrait mobile - show rotate message */
@media (orientation: portrait) and (max-width: 768px) {
    .parent .div18 {
        display: none !important;
    }

    .app-header {
        display: none !important;
    }

    #rotateMessage {
        display: flex !important;
    }
}

/* Optimización adicional para tablets en horizontal */
@media (orientation: landscape) and (min-width: 600px) and (max-height: 800px) {
    body {
        padding-top: 50px;
    }

    .game-container {
        padding: 5px 10px;
    }

    header h1 {
        font-size: 1rem;
    }

    .canvas-container {
        height: calc(100vh - 100px);
        max-height: calc(100vh - 100px);
    }

    #gameCanvas {
        height: calc(100vh - 105px);
        max-height: calc(100vh - 105px);
    }
}

/* Asegurar que el canvas siempre mantenga la proporción correcta */
@media (orientation: landscape) {
    #gameCanvas {
        object-fit: contain;
    }
}
/* Modal de Instrucciones */
.billar-modal {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.billar-modal.hidden {
    display: none;
}

.billar-modal-content {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    border-radius: 20px;
    padding: 40px;
    max-width: 600px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    color: white;
    text-align: center;
    animation: slideIn 0.4s ease;
}

.billar-modal-content h2 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.game-subtitle {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 30px;
}

.instructions-section {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 30px;
}

.instructions-section h3 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: #FFD700;
}

.instructions-grid {
    display: grid;
    gap: 15px;
    text-align: left;
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    transition: all 0.3s ease;
}

.instruction-item:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(5px);
}

.instruction-icon {
    font-size: 1.8rem;
    min-width: 40px;
    text-align: center;
}

.start-btn {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    color: #1e3c72;
    border: none;
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(255, 215, 0, 0.4);
}

.start-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(255, 215, 0, 0.6);
}

.start-btn:active {
    transform: translateY(-1px);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .billar-modal-content {
        padding: 30px 20px;
        max-width: 90%;
    }

    .billar-modal-content h2 {
        font-size: 2rem;
    }

    .instruction-icon {
        font-size: 1.5rem;
        min-width: 35px;
    }

    .instruction-item {
        font-size: 0.9rem;
    }
}
