/* overlay.css - New stylesheet for the responsive UI overlay */

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: Arial, sans-serif;
    color: white;
}

/* Allow scrolling on mobile landscape only */
@media (orientation: landscape) and (max-width: 600px) {
    body, html {
        overflow: auto; /* Enable scrolling for mobile landscape */
    }
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none; /* Pass clicks through by default */
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

/* Make containers clickable */
#ui-overlay > * {
    pointer-events: auto;
}

.social-container, .timer-container, .info-container, .horse-cards-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

.social-container {
    flex: 0 0 auto; /* Don't grow, don't shrink */
    gap: 40px;
}

.social-container img {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.social-container img:hover {
    transform: scale(1.1);
}

#x-logo {
    width: 75px;
}

#pump-logo {
    width: 50px;
}

.timer-container {
    flex-direction: column;
}

#timer-label {
    font-size: 24px;
    font-weight: bold;
}

#timer-countdown {
    font-size: 48px;
    font-weight: bold;
    color: #FFD700;
}

.info-container {
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #FFD700;
    border-radius: 10px;
    padding: 20px;
    max-width: 600px;
    text-align: center;
}

#info-title {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 10px;
}

#info-text {
    font-size: 14px;
}

.horse-cards-container {
    display: grid;
    gap: 15px;
}

/* Desktop/Landscape Layout - only for very wide screens */
@media (orientation: landscape) and (min-width: 1400px) {
    .horse-cards-container {
        grid-template-columns: repeat(8, 1fr);
        width: 98%; /* Use more available width */
        max-width: none; /* Remove width constraint */
        gap: 8px; /* Reduce gap to fit more cards */
        padding: 0 5px; /* Small padding to prevent edge cutoff */
    }
}

/* Default landscape layout - 4 columns for most screens */
@media (orientation: landscape) and (max-width: 1399px) {
    .horse-cards-container {
        grid-template-columns: repeat(4, 1fr);
        width: 98%;
        gap: 12px;
        padding: 0 5px;
    }
}


/* Small landscape screens - tighter spacing */
@media (orientation: landscape) and (max-width: 900px) {
    .horse-cards-container {
        grid-template-columns: repeat(4, 1fr);
        width: 96%;
        gap: 8px;
    }
}

/* Very small landscape screens - 2 columns like portrait */
@media (orientation: landscape) and (max-width: 600px) {
    #ui-overlay {
        overflow-y: auto; /* Enable scrolling for mobile landscape */
        height: 100vh; /* Ensure full height */
    }
    
    .horse-cards-container {
        grid-template-columns: repeat(2, 1fr);
        width: 95%;
        gap: 15px;
        margin-bottom: 20px; /* Add bottom margin for scrolling space */
    }
}

/* Mobile/Portrait Layout */
@media (orientation: portrait) {
    #ui-overlay {
        justify-content: flex-start; /* Align items to the top */
        padding: 10px; /* Reduce padding for more space */
    }

    .horse-card {
        padding: 12px 12px 20px 12px; /* Extra padding on bottom for portrait */
        min-height: 160px; /* Make cards taller in portrait */
        max-height: 180px; /* Allow more height for better sprite display */
    }

    .social-container {
        gap: 25px; /* Reduce gap between logos */
    }

    #x-logo {
        width: 50px; /* Smaller logos */
    }

    #pump-logo {
        width: 35px; /* Smaller logos */
    }

    .timer-container {
        margin-bottom: 10px; /* Reduce margin */
    }

    #timer-label {
        font-size: 16px; /* Smaller text */
    }

    #timer-countdown {
        font-size: 32px; /* Smaller countdown */
    }

    .info-container {
        padding: 12px; /* Smaller padding */
        margin-bottom: 15px;
        max-width: 95%;
    }

    #info-title {
        font-size: 14px; /* Smaller title */
    }

    #info-text {
        font-size: 11px; /* Smaller text */
    }

    .horse-cards-container {
        grid-template-columns: repeat(2, 1fr);
        width: 95%; /* Use more width */
        max-width: none; /* Remove max-width constraint */
        margin: 0 auto; /* Center horizontally */
        position: relative;
        top: auto;
        gap: 25px; /* Generous gap to prevent overlap */
        max-height: calc(100vh - 250px); /* More conservative viewport calculation */
        overflow-y: auto; /* Allow scrolling if needed */
        padding: 5px; /* Add small padding */
    }

    .horse-card {
        padding: 8px; /* Reduce padding */
        min-height: 120px; /* Reduce minimum height */
        max-height: 140px; /* Add maximum height to constrain */
    }

    .horse-card .horse-name {
        font-size: 14px; /* Smaller font */
        margin-bottom: 5px;
    }

    .horse-card .horse-image {
        width: 60px; /* Smaller image */
        height: 45px;
        margin: 5px 0;
    }

    .horse-card .horse-address {
        font-size: 11px; /* Smaller address */
        margin: 3px 0;
    }

    .horse-card .copy-button {
        padding: 6px 8px; /* Smaller button */
        font-size: 10px;
        margin: 5px 0;
    }

    .horse-card .bet-total {
        font-size: 12px; /* Smaller total */
        margin-top: 3px;
    }
}

/* Very narrow screens (phones in portrait) */
@media (max-width: 480px) and (orientation: portrait) {
    .horse-card {
        padding: 8px 8px 16px 8px; /* Extra bottom padding for small screens */
        min-height: 140px; /* Taller for better sprite display */
        max-height: 160px; /* Allow more height */
    }

    .horse-card .horse-name {
        font-size: 12px; /* Smaller font */
        margin-bottom: 3px;
    }

    .horse-card .horse-image {
        width: 50px; /* Smaller image */
        height: 37px;
        margin: 4px 0;
    }

    .horse-card .horse-address {
        font-size: 10px; /* Smaller address text */
        margin: 2px 0;
    }

    .horse-card .copy-button {
        padding: 4px 6px; /* Smaller button */
        font-size: 9px;
        margin: 3px 0;
    }

    .horse-card .bet-total {
        font-size: 11px; /* Smaller total text */
        margin-top: 2px;
    }
}

/* Narrow screen layout */
@media (max-width: 768px) {
    .horse-cards-container {
        grid-template-columns: repeat(2, 1fr);
        width: 95%;
        max-width: none;
        margin: 0 auto;
        position: relative;
        top: auto;
        gap: 25px; /* Generous gap to prevent overlap */
        max-height: calc(100vh - 250px); /* Consistent viewport calculation */
        padding: 5px;
    }

    .info-container {
        margin-bottom: 15px;
        max-width: 95%;
    }

    .horse-card {
        padding: 10px 10px 18px 10px; /* Extra bottom padding for narrow screens */
        min-height: 150px; /* Taller for better display */
        max-height: 170px; /* Allow more height */
    }

    .horse-card .horse-name {
        font-size: 14px; /* Smaller font */
        margin-bottom: 5px;
    }

    .horse-card .horse-image {
        width: 65px; /* Larger image for taller cards */
        height: 50px;
        margin: 6px 0;
    }

    .horse-card .horse-address {
        font-size: 11px; /* Smaller address */
        margin: 3px 0;
    }

    .horse-card .copy-button {
        padding: 6px 8px; /* Smaller button */
        font-size: 10px;
        margin: 5px 0;
    }

    .horse-card .bet-total {
        font-size: 12px; /* Smaller total */
        margin-top: 3px;
    }
}

/* Landscape mode - move cards lower and ensure proper scaling */
@media (orientation: landscape) {
    .horse-cards-container {
        margin-top: 50px; /* Move cards down */
        max-height: calc(100vh - 200px); /* Ensure cards fit in viewport */
    }

    .horse-card {
        min-height: 160px; /* Slightly taller in landscape */
        padding: 12px; /* Consistent padding */
    }
}

/* Adjust card sizes for smaller landscape screens */
@media (orientation: landscape) and (max-width: 1200px) {
    .horse-card {
        min-height: 140px; /* Slightly smaller for medium screens */
        padding: 10px;
    }

    .horse-card .horse-image {
        width: 75px;
        height: 55px;
        margin: 6px 0;
    }

    .horse-card .horse-name {
        font-size: 14px;
        margin-bottom: 4px;
    }

    .horse-card .horse-address {
        font-size: 11px;
        margin: 3px 0;
    }

    .horse-card .copy-button {
        padding: 6px 8px;
        font-size: 10px;
        margin: 4px 0;
    }

    .horse-card .bet-total {
        font-size: 13px;
        margin-top: 3px;
    }
}

/* Further adjustments for small landscape screens */
@media (orientation: landscape) and (max-width: 900px) {
    .horse-card {
        min-height: 120px; /* Compact for small screens */
        padding: 8px;
    }

    .horse-card .horse-image {
        width: 60px;
        height: 45px;
        margin: 5px 0;
    }

    .horse-card .horse-name {
        font-size: 12px;
        margin-bottom: 3px;
    }

    .horse-card .horse-address {
        font-size: 10px;
        margin: 2px 0;
    }

    .horse-card .copy-button {
        padding: 5px 6px;
        font-size: 9px;
        margin: 3px 0;
    }

    .horse-card .bet-total {
        font-size: 11px;
        margin-top: 2px;
    }
}

/* Extra small screens - ensure minimum usability */
@media (max-width: 360px) {
    .horse-card {
        padding: 6px 6px 12px 6px; /* Extra bottom padding for very small screens */
        min-height: 120px;
        max-height: 140px;
    }

    .horse-card .horse-name {
        font-size: 11px;
        margin-bottom: 2px;
    }

    .horse-card .horse-image {
        width: 45px;
        height: 33px;
        margin: 3px 0;
    }

    .horse-card .horse-address {
        font-size: 9px;
        line-height: 1.1;
        margin: 2px 0;
    }

    .horse-card .copy-button {
        padding: 3px 5px;
        font-size: 8px;
        margin: 3px 0;
    }

    .horse-card .bet-total {
        font-size: 10px;
        margin-top: 2px;
    }

    .horse-cards-container {
        gap: 15px; /* Adequate gap for very small screens */
        max-height: calc(100vh - 220px); /* More space for very small screens */
        padding: 3px;
    }
}


.horse-card {
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #FFD700;
    border-radius: 10px;
    padding: 15px; /* Generous padding for all content */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between; /* Distribute content evenly */
    text-align: center;
    min-height: 200px; /* Larger minimum height for all content */
    height: auto; /* Allow height to grow as needed */
    width: auto; /* Allow width to adjust */
    box-sizing: border-box;
    overflow: visible; /* Allow content to be fully visible */
    flex-shrink: 0; /* Prevent shrinking */
    flex-grow: 1; /* Allow growing if needed */
}

.horse-card .horse-name {
    font-size: 16px;
    font-weight: bold;
}

.horse-card .horse-image {
    width: 100px; /* Larger default size */
    height: 75px;
    margin: 10px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 5px;
    overflow: visible; /* Allow sprite to be fully visible */
    background: transparent; /* Remove grey background */
    flex-shrink: 0; /* Don't shrink the image */
}

/* Portrait mode horse image sizing */
@media (orientation: portrait) {
    .horse-card .horse-image {
        width: 80px; /* Larger for portrait */
        height: 60px;
        margin: 8px 0;
    }
}

/* Very narrow screens */
@media (max-width: 480px) and (orientation: portrait) {
    .horse-card .horse-image {
        width: 60px; /* Larger even on small screens */
        height: 45px;
        margin: 6px 0;
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    .horse-card .horse-image {
        width: 55px; /* Still reasonably sized */
        height: 40px;
        margin: 5px 0;
    }
}

.horse-card .horse-sprite {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Ensure full sprite is visible */
    display: block;
    max-width: none; /* Remove any width constraints */
    max-height: none; /* Remove any height constraints */
}

.horse-card .horse-address {
    font-size: 12px;
    word-break: break-all;
}

.horse-card .copy-button {
    background-color: #FFD700;
    color: black;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    margin: 10px 0;
    font-weight: bold;
}

.horse-card .bet-total {
    font-size: 16px;
    color: #FFD700;
}

#audio-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background-color: #333;
    border-radius: 8px;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
}
