/* High Score Grid Display Styles */

body, html {
    margin: 0;
    padding: 0;
    overflow: hidden; /* Prevent scrolling */
    width: 100vw;
    height: 100vh;
}

#nav {
    display: none; /* Hide navigation for display mode */
}

.high-score-grid-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    box-sizing: border-box;
    overflow: hidden;
    background-color: #0f1a40; /* Match body background */
    position: relative;
}

.high-score-grid {
    display: grid;
    gap: 1.5rem;
    width: 100%;
    height: 100%;
    overflow: hidden;
    align-items: stretch;
    justify-items: stretch;
    grid-auto-flow: row;
    position: relative;
}

/* Grid item styling */
.high-score-grid-item {
    display: none; /* Hidden by default, shown by JS */
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
    overflow: hidden;
    align-self: stretch;
    justify-self: stretch;
    position: relative;
}

.high-score-grid-item.active {
    display: flex;
    opacity: 1;
}

/* Responsive grid columns - adjust based on viewport */
/* Default: 2 columns, 2 rows */
.high-score-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

/* Larger screens: 3 columns */
@media (min-width: 1600px) {
    .high-score-grid {
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: repeat(2, 1fr);
    }
}

/* Very large screens: 4 columns */
@media (min-width: 2400px) {
    .high-score-grid {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(2, 1fr);
    }
}

/* Smaller screens: 1 column */
@media (max-width: 1200px) {
    .high-score-grid {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(2, 1fr);
    }
}

/* Ensure tables fit within grid cells */
.high-score-grid-item .hstable {
    max-width: 100% !important;
    width: 100% !important;
    height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
    margin: 0;
    padding: 0.75rem;
    align-items: stretch;
    justify-content: flex-start;
}

.high-score-grid-item .hstablebox {
    flex: 1 1 auto;
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    min-height: 0;
    width: 100%;
}

.high-score-grid-item .highscore-column-left,
.high-score-grid-item .highscore-column-right {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    gap: 0.5rem;
}

.high-score-grid-item .hs_table {
    font-size: 0.85rem;
    flex: 1 1 auto;
    min-height: 0;
    display: table;
    width: 100% !important;
    margin: 0;
    table-layout: fixed !important;
    border-collapse: separate;
    border-spacing: 0;
}

.high-score-grid-item .hs_table thead {
    flex-shrink: 0;
    display: table-header-group;
    width: 100%;
}

.high-score-grid-item .hs_table tbody {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
    display: table-row-group;
    width: 100%;
}

.high-score-grid-item .hs_table tbody tr {
    display: table-row;
    width: 100%;
}

.high-score-grid-item .hs_table thead tr {
    display: table-row;
    width: 100%;
}

/* Adjust font sizes for grid display */
.high-score-grid-item .hshead {
    flex-shrink: 0;
    padding: 0.5rem 0;
    margin-bottom: 0.75rem;
}

.high-score-grid-item .hshead p {
    font-size: 2.0rem !important;
    margin: 0.25rem 0 !important;
    line-height: 1.2;
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    text-align: center;
}

/* Allow wrapping only if JavaScript determines it's needed */
.high-score-grid-item .hshead p.allow-wrap {
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    text-overflow: clip;
}

.high-score-grid-item .hshead h6 {
    font-size: 0.6rem !important;
    margin: 0.25rem 0 !important;
}

.high-score-grid-item caption {
    font-size: 1rem !important;
    flex-shrink: 0;
    padding: 0.6rem 0 !important;
    line-height: 1.3;
}

.high-score-grid-item tbody td,
.high-score-grid-item thead th {
    font-size: 1rem !important;
    padding: 8px 6px !important;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
    text-align: center !important;
}

.high-score-grid-item thead th {
    padding: 10px 6px !important;
    font-size: 1.1rem !important;
    text-align: center !important;
}

.high-score-grid-item tbody td {
    text-align: center !important;
}

/* Column width distribution - rank (narrow), initials (medium), score (wide) */
.high-score-grid-item .hs_table thead th:first-child,
.high-score-grid-item .hs_table tbody td:first-child {
    width: 12% !important;
    min-width: 12% !important;
    max-width: 12% !important;
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow: visible !important;
    text-overflow: clip !important;
}

.high-score-grid-item .hs_table thead th:nth-child(2),
.high-score-grid-item .hs_table tbody td:nth-child(2) {
    width: 26% !important;
    min-width: 26% !important;
    max-width: 26% !important;
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow: hidden;
    text-overflow: ellipsis;
}

.high-score-grid-item .hs_table thead th:nth-child(3),
.high-score-grid-item .hs_table tbody td:nth-child(3) {
    width: 62% !important;
    min-width: 62% !important;
    max-width: 62% !important;
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Base font size for all cells - larger for distance reading */
.high-score-grid-item .hs_table tbody td {
    font-size: 1rem !important;
}

.high-score-grid-item .hs_table thead th {
    font-size: 1.1rem !important;
}

/* Rank 1 - Largest emphasis (first row) */
.high-score-grid-item .hs_table tbody tr:first-child td {
    font-size: 1.4rem !important;
    font-weight: bold !important;
}

.high-score-grid-item .hs_table tbody tr:first-child td:first-child {
    font-size: 1.5rem !important;
}

/* Rank 2 - Medium emphasis (second row) */
.high-score-grid-item .hs_table tbody tr:nth-child(2) td {
    font-size: 1.25rem !important;
    font-weight: bold !important;
}

.high-score-grid-item .hs_table tbody tr:nth-child(2) td:first-child {
    font-size: 1.3rem !important;
}

/* Rank 3 - Smaller emphasis (third row) */
.high-score-grid-item .hs_table tbody tr:nth-child(3) td {
    font-size: 1.15rem !important;
    font-weight: bold !important;
}

.high-score-grid-item .hs_table tbody tr:nth-child(3) td:first-child {
    font-size: 1.2rem !important;
}

/* Ranks 4+ - standard size */
.high-score-grid-item .hs_table tbody tr:nth-child(n+4) td {
    font-size: 1rem !important;
}

/* Ensure rows extend full width with new column widths */
.high-score-grid-item .hs_table thead tr th:first-child {
    width: 12% !important;
}

.high-score-grid-item .hs_table thead tr th:nth-child(2) {
    width: 26% !important;
}

.high-score-grid-item .hs_table thead tr th:nth-child(3) {
    width: 62% !important;
}

/* Ensure tables don't overflow */
.high-score-grid-item * {
    max-width: 100%;
    box-sizing: border-box;
}

/* Improve table cell text handling */
.high-score-grid-item .hs_table td,
.high-score-grid-item .hs_table th {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Rank column - no wrapping for numbers */
.high-score-grid-item .hs_table td:first-child,
.high-score-grid-item .hs_table th:first-child {
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow: visible !important;
    text-overflow: clip !important;
}

/* Initials column - no wrapping, even for cooperative games */
.high-score-grid-item .hs_table td:nth-child(2),
.high-score-grid-item .hs_table th:nth-child(2) {
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Ensure cells fill their column width - override with new percentages */
.high-score-grid-item .hs_table td:first-child,
.high-score-grid-item .hs_table th:first-child {
    width: 12% !important;
    text-align: center !important;
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow: visible !important;
    text-overflow: clip !important;
}

.high-score-grid-item .hs_table td:nth-child(2),
.high-score-grid-item .hs_table th:nth-child(2) {
    width: 26% !important;
    text-align: center !important;
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.high-score-grid-item .hs_table td:nth-child(3),
.high-score-grid-item .hs_table th:nth-child(3) {
    width: 62% !important;
    text-align: center !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Better spacing and alignment */
.high-score-grid-item .hstable {
    justify-content: flex-start;
    align-items: stretch;
    border-radius: 12px;
}

/* Improve visual consistency */
.high-score-grid-item .hs_table {
    border-radius: 8px;
}

/* Ensure columns fill their space properly */
.high-score-grid-item .highscore-column-left,
.high-score-grid-item .highscore-column-right {
    flex: 1 1 0;
    width: 100%;
}

/* Override base styles and inline styles for grid display */
.high-score-grid-item .hs_table thead th:nth-child(2),
.high-score-grid-item .hs_table thead th:nth-child(3) {
    text-align: center !important;
    padding-left: 4px !important;
    width: auto !important;
}

.high-score-grid-item .hs_table tbody td:nth-child(2),
.high-score-grid-item .hs_table tbody td:nth-child(3) {
    text-align: center !important;
    padding-left: 4px !important;
    width: auto !important;
}

/* Override ALL inline font-size styles with consistent sizing */
/* Individual overrides handled by rank-specific rules above */

.high-score-grid-item .hs_table thead th[style*="font-size"] {
    font-size: 1.1rem !important;
}

/* Override inline width styles - use table-layout: fixed with proper percentages */
.high-score-grid-item .hs_table thead th[style*="width"],
.high-score-grid-item .hs_table thead th {
    width: auto !important;
}

.high-score-grid-item .hs_table tbody td[style*="width"],
.high-score-grid-item .hs_table tbody td {
    width: auto !important;
}

/* Ensure all cells are centered and fill width */
.high-score-grid-item .hs_table td,
.high-score-grid-item .hs_table th {
    text-align: center !important;
    padding: 6px 4px !important;
}

/* Make sure rows extend full width */
.high-score-grid-item .hs_table tbody tr {
    width: 100% !important;
    display: table-row !important;
}

.high-score-grid-item .hs_table thead tr {
    width: 100% !important;
    display: table-row !important;
}

/* Make sure table uses full width and rows extend */
.high-score-grid-item .hs_table {
    width: 100% !important;
    border-collapse: separate;
    border-spacing: 0;
}

.high-score-grid-item .hs_table tbody,
.high-score-grid-item .hs_table thead {
    width: 100%;
    display: table-row-group;
}

.high-score-grid-item .hs_table thead {
    display: table-header-group;
}


/* Better text alignment in cells */
.high-score-grid-item .hs_table td {
    vertical-align: middle;
    text-align: center !important;
}

.high-score-grid-item .hs_table th {
    vertical-align: middle;
    text-align: center !important;
}

/* Ensure table rows extend full width */
.high-score-grid-item .hs_table {
    width: 100% !important;
}

.high-score-grid-item .hs_table colgroup,
.high-score-grid-item .hs_table col {
    width: auto;
}

/* Force rows to fill width */
.high-score-grid-item .hs_table tbody tr {
    display: table-row;
    width: 100%;
    table-layout: fixed;
}

.high-score-grid-item .hs_table thead tr {
    display: table-row;
    width: 100%;
    table-layout: fixed;
}

/* Animation for cycling */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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