/* gamelist-styles.css */

/* CSS Variables for consistent theming */
:root {
    /* Colors */
    --primary-color: #2196F3;
    --secondary-color: #2563eb;
    --background-color: #f3f4f6;
    --card-background: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --border-color: #ddd;
    --success-color: #059669;
    --error-color: #dc2626;
    --warning-color: #d97706;
    --info-color: #0891b2;
    --text-color: #333;
    --bg-color: #fff;
    --header-bg: #f5f5f5;
    --hover-color: #f0f0f0;

    /* Badges */
    --host-badge-bg: #3b82f6;
    --version-badge-bg: #059669;

    /* Spacing */
    --container-padding: 1.25rem;
    --card-padding: 1.5rem;
    --grid-gap: 1rem;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;

    /* Transitions */
    --transition-speed: 0.2s;
}

/* Dark mode variables */
:root[data-theme="dark"] {
    /* Colors */
    --primary-color: #60a5fa;
    --secondary-color: #3b82f6;
    --background-color: #111827;
    --card-background: #1f2937;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --border-color: #333;
    --success-color: #34d399;
    --error-color: #f87171;
    --warning-color: #fbbf24;
    --info-color: #22d3ee;
    --text-color: #fff;
    --bg-color: #1a1a1a;
    --header-bg: #2d2d2d;
    --hover-color: #333;

    /* Badges */
    --host-badge-bg: #2563eb;
    --version-badge-bg: #059669;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

/* Dark mode specific overrides */
:root[data-theme="dark"] .error-message {
    background-color: #7f1d1d;
    border-color: var(--error-color);
    color: #fecaca;
}

:root[data-theme="dark"] .slider {
    background-color: #4b5563;
}

:root[data-theme="dark"] input:checked + .slider {
    background-color: var(--primary-color);
}

/* Transition styles for smooth theme switching */
.container,
.game-card,
.stat-box,
.player-item,
.error-message {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header Section */
.header {
    background-color: var(--header-bg);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.header h1 {
    margin-bottom: 20px;
    text-align: center;
}

.header nav {
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.header nav a {
    display: inline-block;
    border-radius: 4px;
    font-weight: 600;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    text-decoration: none;
    transition: background 0.5s, opacity 0.5s;
    padding: 8px 16px;
    text-transform: uppercase;
    opacity: 0.4;
}

.header nav a:hover,
.header nav a.active {
    background: rgba(0, 0, 0, 1);
    opacity: 1;
}

:root[data-theme="dark"] .header nav a {
    background: rgba(255, 255, 255, 0.6);
    color: #000;
}

:root[data-theme="dark"] .header nav a:hover,
:root[data-theme="dark"] .header nav a.active {
    background: rgba(255, 255, 255, 1);
}

.header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.reset-button {
    padding: 8px 16px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.reset-button:hover {
    background-color: #1976D2;
}

.refresh-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

/* Version Select Styles */
.header-controls .version-select,
.header-controls .search {
    position: relative;
    min-width: 150px;
    display: inline-block;
}

.header-controls .search label {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-controls .version-select select,
.header-controls .search input {
    display: block;
    width: 100%;
    padding: 8px 12px;
    padding-right: 32px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 14px;
    line-height: 1.5;
}

.header-controls .version-select select {
    cursor: pointer;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: right 8px center !important;
    background-size: 16px !important;
    transition: all 0.3s ease;
}

:root[data-theme="dark"] .header-controls .version-select select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e") !important;
}

.header-controls .version-select select:hover {
    border-color: var(--primary-color);
}

.header-controls .version-select select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
}

:root[data-theme="dark"] .header-controls .version-select select {
    background-color: var(--bg-color);
    color: var(--text-color);
    border-color: var(--border-color);
}

:root[data-theme="dark"] .header-controls .version-select select:hover {
    border-color: var(--primary-color);
}

:root[data-theme="dark"] .header-controls .version-select select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.2);
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

/* Statistics Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--grid-gap);
    margin-bottom: 2rem;
}

.stat-box {
    background: var(--card-background);
    padding: var(--card-padding);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    text-align: center;
    transition: transform var(--transition-speed);
}

/* Hide optional columns by default */
.hide-optional-stats .optional-stat {
    display: none;
}


.stat-box:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0.5rem 0;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
}

/* Game Cards */
.game-card {
    background: var(--card-background);
    border-radius: var(--radius-md);
    padding: var(--card-padding);
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-speed);
}

.game-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.game-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Badges */
.game-version {
    background-color: var(--version-badge-bg);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.host-badge {
    background-color: var(--host-badge-bg);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* Game Metadata */
.game-meta {
    color: var(--text-secondary);
    font-size: 0.875rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.icon-img {
    width: 24px;
    height: 24px;
    display: none;
}

/* Player List */
.player-list {
    margin-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.player-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.player-item:last-child {
    border-bottom: none;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.player-time {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Empty State */
.no-games {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
    background: var(--card-background);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

/* Error Message */
.error-message {
    background-color: #fee2e2;
    border: 1px solid var(--error-color);
    color: #991b1b;
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    display: none;
}

/* Loading State */
.loading {
    display: none;
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.loading-spinner {
    animation: spin 1s linear infinite;
    display: inline-block;
    margin-right: 0.5rem;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .header {
        padding: 15px;
    }
    
    .header-controls {
        flex-direction: column;
        gap: 15px;
    }

    .header-controls .search {
        width: 100%;
    }

    .header-controls .search label {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
        width: 100%;
    }
    
    .control-group {
        width: 100%;
        justify-content: space-between;
    }
    
    .version-select, .theme-toggle {
        width: 100%;
    }
    
    .version-select select {
        width: 100%;
        font-size: 14px;
    }
    
    .leaderboard-table {
        margin: 0 -10px;
        border-radius: 0;
    }
    
    table {
        font-size: 14px;
    }
    
    th, td {
        padding: 8px 4px;
    }
    
    .header h1 {
        font-size: 24px;
    }
    
    .theme-label {
        font-size: 14px;
    }
}

/* Small Mobile Devices */
@media (max-width: 480px) {
    .container {
        padding: 5px;
    }
    
    .header {
        padding: 10px;
    }
    
    .header h1 {
        font-size: 20px;
    }
    
    table {
        font-size: 12px;
    }
    
    th, td {
        padding: 6px 3px;
    }
    
    .reset-button {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .version-select select {
        font-size: 12px;
        padding: 6px 8px;
        padding-right: 28px;
        background-size: 14px;
    }

    .refresh-section {
        justify-content: flex-start;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
    }

    .refresh-section,
    .loading,
    .error-message {
        display: none;
    }

    .game-card,
    .stat-box {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid var(--border-color);
    }
}

/* Add this to your existing CSS file */

.game-host-badge {
    background-color: var(--host-badge-bg);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    margin-left: 0.75rem;
    display: inline-flex;
    align-items: center;
}

.game-host-badge::before {
    content: "Hosting user:";
    margin-right: 0.25rem;
    opacity: 0.9;
}

@media (max-width: 640px) {
    .game-title {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .game-host-badge {
        margin-left: 0;
    }
}

/* Leaderboard Table Styles */
.leaderboard-table {
    background-color: var(--bg-color);
    border-radius: 8px;
    overflow: hidden;
    white-space: nowrap;
    border: solid 1px var(--border-color);
}

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: var(--header-bg);
    font-weight: bold;
    cursor: pointer;
    user-select: none;
}

th:hover {
    background-color: var(--hover-color);
}

tr:hover {
    background-color: var(--hover-color);
}

/* Theme Toggle Styles */
.theme-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
}

/* Dark mode specific overrides for leaderboard */
:root[data-theme="dark"] .leaderboard-table {
    background: var(--card-background);
}

:root[data-theme="dark"] .leaderboard-table th {
    background-color: var(--primary-color);
}

:root[data-theme="dark"] .leaderboard-table tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

:root[data-theme="dark"] .leaderboard-table tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Header Controls */
.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.reset-button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--transition-speed);
}

.reset-button:hover {
    background-color: var(--secondary-color);
}

:root[data-theme="dark"] .reset-button {
    background-color: var(--primary-color);
}

:root[data-theme="dark"] .reset-button:hover {
    background-color: var(--secondary-color);
}

/* Responsive adjustments for mobile */
@media (max-width: 600px) {
    .container {
        max-width: 100vw;
        padding: 0.5rem;
    }
    .leaderboard-table {
        margin: 1rem 0;
        border-radius: 0.5rem;
        box-shadow: var(--shadow-sm);
    }
    .leaderboard-table table {
        font-size: 11px;
        min-width: 480px;
    }
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .header-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        width: 100%;
        margin-top: 0.5rem;
    }
    .reset-button {
        width: 100%;
        font-size: 1rem;
        padding: 0.75rem 0;
    }
    .theme-toggle {
        width: 100%;
        justify-content: flex-start;
    }
    .theme-label {
        font-size: 1rem;
    }
}

/**
 * DETAILS MODAL
 */
.show-details {
    color: inherit;
    font-size: 10px;
    font-style: italic;
    opacity: 0.5;
    margin-left: 5px;
    transition: opacity 0.5s;
}

.show-details:hover {
    opacity: 1;
}

.show-mobile {
    display: none;
}

.detailed-stats-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s;
}

.show-modal .detailed-stats-modal {
    opacity: 1;
    visibility: visible;
}

.detailed-stats-modal .backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.925);
    z-index: 1000;
}

.detailed-stats-modal .modal {
    width: 90vw;
    height: 90vh;
    max-width: 960px;
    max-height: 800px;
    z-index: 1001;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -30%);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.3s 0.1s, opacity 0.3s;
}

.show-modal .detailed-stats-modal .modal {
    transform: translate(-50%, -50%);
    opacity: 1;
    visibility: visible;
}

.detailed-stats-modal .modal .inner,
.detailed-stats-modal .modal .leaderboard-table {
    height: 100%
}

.detailed-stats-modal .scroller {
    max-height: 750px;
    overflow-y: auto;
}

.detailed-stats-modal table {
    table-layout: fixed;
}

.detailed-stats-modal table th {
    cursor: initial !important;
}

.detailed-stats-modal table td {
    width: 50%;
    white-space: pre-line;
}

.detailed-stats-modal .close-modal {
    position: absolute;
    top: 0;
    right: 0;
    font-weight: bold;
    height: 50px;
    line-height: 50px;
    padding: 0 36px;
    text-transform: none;
    color: #000;
    text-decoration: none;
    opacity: 0.5;
    transition: opacity 0.5s;
}

:root[data-theme="dark"] .detailed-stats-modal .close-modal {
    color: #fff;
    opacity: 0.75;
}

.detailed-stats-modal .close-modal:hover {
    opacity: 1 !important;
}

.detailed-stats-modal .modal .leaderboard-table {
    margin: 0 !important;
}

.detailed-stats-modal .modal .leaderboard-table table {
    min-width: 0 !important;
}

.filtered-out {
    display: none !important;
}

@media (max-width: 768px) { 
    .detailed-stats-modal .scroller {
        max-height: min(800px, calc(90vh - 31px));
    }

    .detailed-stats-modal .close-modal {
        height: 31px;
        line-height: 31px;
        padding: 0 16px;
        font-size: 12px;
    }

    .show-mobile {
        display: block;
    }

    .show-details .show-mobile {
        display: inline-block;
    }

    .leaderboard-table {
        margin: 1rem 0;
    }
}

@media (max-width: 600px) { 
    .detailed-stats-modal .leaderboard-table {
        margin: 0;
    }

    .detailed-stats-modal .leaderboard-table table {
        min-width: 0;
        font-size: 13px;
    }

    .detailed-stats-modal .scroller {
        max-height: min(800px, calc(90vh - 29px));
    }

    .detailed-stats-modal .close-modal {
        height: 29px;
        line-height: 29px;
        padding: 0 10px;
        font-size: 13px;
    }
}