/* CSS Custom Properties */
:root {
    /* Backgrounds */
    --bg-body: #f5f5f5;
    --bg-card: white;
    --bg-header: white;
    --bg-table-header: #f8f9fa;
    --bg-table-row-even: #f8fbff;
    --bg-table-row-hover: #f8f9fa;
    --bg-card-active: #e3f2fd;
    --bg-h-index-contributor: #e3f2fd;
    --bg-h-index-contributor-even: #d1e7f8;
    --bg-year-badge: #f8f9fa;
    --bg-info-section: #fff3cd;

    /* Text colors */
    --text-primary: #333;
    --text-heading: #2c3e50;
    --text-label: #555;
    --text-secondary: #666;
    --text-muted: #777;
    --text-light: #999;
    --text-badge: #495057;
    --text-info: #856404;

    /* Accent colors */
    --color-primary: #3498db;
    --color-primary-dark: #2980b9;
    --color-success: #27ae60;
    --color-error: #e74c3c;
    --color-warning: #ffc107;

    /* Metric colors */
    --color-metric-hours: #27ae60;
    --color-metric-sessions: #3498db;
    --color-metric-plays: #f39c12;

    /* Muted metric colors (for summary text) */
    --color-metric-hours-muted: #4a9a6a;
    --color-metric-sessions-muted: #5a8ab0;
    --color-metric-plays-muted: #b8893a;

    /* Borders */
    --border-primary: #ddd;
    --border-secondary: #dee2e6;
    --border-tertiary: #e9ecef;
    --border-light: #eee;

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.15);
    --shadow-lg: 0 4px 12px rgba(52, 152, 219, 0.3);
    --shadow-lg-alt: 0 4px 12px rgba(52, 152, 219, 0.4);
    --shadow-sticky: 2px 0 4px rgba(0,0,0,0.05);
    --shadow-hover-bg: rgba(108, 117, 125, 0.05);

    /* Transition timings */
    --transition-theme: 1s;
    --transition-hover: 0.2s;
    --transition-border: 0.3s;
}

[data-theme="dark"] {
    /* Backgrounds */
    --bg-body: #1a1a1a;
    --bg-card: #2d2d2d;
    --bg-header: #2d2d2d;
    --bg-table-header: #252525;
    --bg-table-row-even: #2a2a2a;
    --bg-table-row-hover: #333333;
    --bg-card-active: #1e3a5f;
    --bg-h-index-contributor: #1e3a5f;
    --bg-h-index-contributor-even: #1a3352;
    --bg-year-badge: #383838;
    --bg-info-section: #3d3520;

    /* Text colors */
    --text-primary: #e0e0e0;
    --text-heading: #f5f5f5;
    --text-label: #b0b0b0;
    --text-secondary: #c0c0c0;
    --text-muted: #a0a0a0;
    --text-light: #808080;
    --text-badge: #b0b0b0;
    --text-info: #e6d291;

    /* Accent colors */
    --color-primary: #5dade2;
    --color-primary-dark: #74b9ff;
    --color-success: #2ecc71;
    --color-error: #e74c3c;
    --color-warning: #f39c12;

    /* Metric colors */
    --color-metric-hours: #2ecc71;
    --color-metric-sessions: #5dade2;
    --color-metric-plays: #f39c12;

    /* Muted metric colors (for summary text) */
    --color-metric-hours-muted: #7dbf96;
    --color-metric-sessions-muted: #8bbfd9;
    --color-metric-plays-muted: #d4b068;

    /* Borders */
    --border-primary: #404040;
    --border-secondary: #404040;
    --border-tertiary: #383838;
    --border-light: #353535;

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.4);
    --shadow-lg: 0 4px 12px rgba(93, 173, 226, 0.3);
    --shadow-lg-alt: 0 4px 12px rgba(93, 173, 226, 0.4);
    --shadow-sticky: 2px 0 4px rgba(0,0,0,0.3);
    --shadow-hover-bg: rgba(255, 255, 255, 0.05);
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: background-color var(--transition-theme), color var(--transition-theme), border-color var(--transition-theme), box-shadow var(--transition-theme);
}

html.no-transition * {
    transition: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-body);
    padding: 20px;
}

/* Header */
header {
    background: var(--bg-header);
    padding: 0.75rem;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}

header h1 {
    color: var(--text-heading);
    font-size: 1.25rem;
    margin-bottom: 0;
    flex-shrink: 0;
}

.header-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.year-filter {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.year-filter label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-label);
    white-space: nowrap;
}

#year-select,
#base-metric-select {
    padding: 0.35rem 0.75rem;
    border: 2px solid var(--border-primary);
    border-radius: 4px;
    font-size: 0.875rem;
    cursor: pointer;
    background: var(--bg-card);
    color: var(--text-primary);
    transition: border-color var(--transition-border), background-color var(--transition-theme), color var(--transition-theme);
}

#year-select:hover,
#base-metric-select:hover {
    border-color: var(--color-primary);
}

#year-select:focus,
#base-metric-select:focus {
    outline: none;
    border-color: var(--color-primary-dark);
}

.year-info-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    background: var(--bg-year-badge);
    border: 1px solid var(--border-secondary);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-badge);
    font-weight: 500;
    flex-shrink: 1;
    min-width: 0;
}

.year-incomplete-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    background: var(--bg-info-section);
    border: 1px solid var(--color-warning);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-info);
    font-weight: 500;
    margin-left: 0.5rem;
    vertical-align: middle;
}

.theme-toggle {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 2px solid var(--border-primary);
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    background: var(--bg-card);
    color: var(--text-primary);
    transition: border-color var(--transition-border), background var(--transition-hover), background-color var(--transition-theme), color var(--transition-theme);
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    border-color: var(--color-primary);
    background: var(--bg-year-badge);
}

.theme-toggle:focus {
    outline: none;
    border-color: var(--color-primary-dark);
}

.theme-toggle svg {
    display: block;
    max-width: 20px;
    max-height: 20px;
}

.header-info-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
}

.year-review-link {
    color: var(--color-primary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    transition: color var(--transition-hover);
}

.year-review-link:hover {
    color: var(--color-primary-dark);
    text-decoration: underline;
}

/* ============================================
   DASHBOARD WIDGET SYSTEM
   12-column grid with variable widget sizes
   ============================================ */

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: minmax(auto, auto);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

/* Widget Size Classes */
.widget {
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    padding: 0.75rem;
    position: relative;
    transition: transform var(--transition-hover), box-shadow var(--transition-hover), background-color var(--transition-theme);
    display: flex;
    flex-direction: column;
    min-height: 0;
    scroll-margin-top: var(--header-scroll-margin, 9rem);
}

/* 1x1: Micro widget - single KPI (3 columns = 25%) */
.widget--1x1 {
    grid-column: span 3;
}

/* 2x1: Small widget - KPI + substats (6 columns = 50%) */
.widget--2x1 {
    grid-column: span 6;
}

/* 4x1: Wide widget - full width row (12 columns = 100%) */
.widget--4x1 {
    grid-column: span 12;
}

/* 2x2: Medium widget - feature cards (6 columns, 2 rows) */
.widget--2x2 {
    grid-column: span 6;
    grid-row: span 2;
}

/* Widget States */
.widget:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.widget.clickable {
    cursor: pointer;
}

.widget.clickable:hover {
    box-shadow: var(--shadow-lg);
}

.widget.active {
    background-color: var(--bg-card-active);
    border: 2px solid var(--color-primary);
    box-shadow: var(--shadow-lg-alt);
}

/* Widget Internal Structure */
.widget__title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.widget__value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--color-primary);
    line-height: 1.2;
}

.widget--1x1 .widget__value {
    font-size: 1.25rem;
}

.widget__description {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.widget__substats {
    margin-top: auto;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-light);
    font-size: 0.8rem;
}

.widget__substat {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.widget__substat:last-child {
    margin-bottom: 0;
}

.widget__substat-label {
    color: var(--text-secondary);
}

.widget__substat-value {
    font-weight: 600;
    color: var(--text-heading);
}


/* Widget Group Labels */
.widget-group-label {
    grid-column: span 12;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.5rem 0 0.25rem;
    border-bottom: 1px solid var(--border-light);
    margin-top: 0.5rem;
    scroll-margin-top: var(--header-scroll-margin, 9rem);
}

.widget-group-label:first-child {
    margin-top: 0;
}

.widget-group-subtitle {
    font-weight: 400;
    font-style: italic;
    text-transform: none;
    letter-spacing: normal;
}

/* Feature Widget (2x2) - special styling for Play Next, Year Review */
.widget--feature {
    padding: 1rem;
}

.widget--feature .widget__title {
    font-size: 0.85rem;
}

.widget--feature .widget__description {
    font-size: 0.85rem;
    flex: 1;
}

.widget--feature .widget__cta {
    margin-top: auto;
    padding-top: 0.75rem;
}

.widget--feature .widget__cta-btn {
    display: inline-block;
    font-size: 0.8rem;
    color: var(--color-primary);
    font-weight: 500;
}

/* Responsive: Tablet */
@media (max-width: 1024px) {
    .widget--1x1 {
        grid-column: span 4;
    }

    .widget--2x1 {
        grid-column: span 6;
    }

    .widget--2x2 {
        grid-column: span 6;
    }

    .shelf-gallery-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Responsive: Mobile */
@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    /* All widgets take full width on mobile for readability */
    .widget--1x1,
    .widget--2x1,
    .widget--4x1,
    .widget--2x2 {
        grid-column: span 2;
        grid-row: span 1;
    }

    .widget {
        padding: 0.75rem;
    }

    .widget__title {
        font-size: 0.7rem;
    }

    .widget__value {
        font-size: 1.5rem;
    }

    .widget__description {
        font-size: 0.8rem;
    }

    .widget__substats {
        font-size: 0.85rem;
    }

    .widget-group-label {
        grid-column: span 2;
        font-size: 0.7rem;
        padding: 0.5rem 0 0.25rem;
    }

}

/* Detail Section - Inline expansion below widgets */
.detail-section {
    grid-column: span 12;
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    border: 2px solid var(--color-primary);
    overflow: hidden;
    animation: expandIn 0.25s ease-out;
    scroll-margin-top: var(--header-scroll-margin, 9rem);
}

@keyframes expandIn {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 80vh;
    }
}

.detail-header {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-card);
}

.detail-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.detail-stat-summary {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.detail-stat-main {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--color-primary);
}

.detail-stat-substats {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.detail-substat {
    display: flex;
    align-items: baseline;
    gap: 0.25rem;
    font-size: 0.85rem;
}

.detail-substat-label {
    color: var(--text-secondary);
}

.detail-substat-value {
    font-weight: 600;
    color: var(--text-heading);
}

.detail-header h2 {
    color: var(--text-heading);
    font-size: 1rem;
    margin: 0;
}

.detail-header-buttons {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.permalink-btn {
    background: transparent;
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-hover), color var(--transition-hover), border-color var(--transition-hover), background-color var(--transition-theme);
    padding: 0;
}

.permalink-btn:hover {
    background: var(--color-primary);
    color: var(--bg-card);
}

.permalink-btn.copied {
    background: var(--color-success);
    color: var(--bg-card);
    border-color: var(--color-success);
}

.close-btn {
    background: transparent;
    color: var(--color-error);
    border: 1px solid var(--color-error);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-hover), color var(--transition-hover), background-color var(--transition-theme);
}

.close-btn:hover {
    background: var(--color-error);
    color: var(--bg-card);
}

.detail-content {
    padding: 0 1rem 1rem;
    overflow-x: auto;
    max-height: 60vh;
    overflow-y: auto;
}

.detail-section table thead {
    background: var(--bg-table-header);
    position: sticky;
    top: 0;
    z-index: 85;
}

/* Tables - Compact styling */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    color: var(--text-heading);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border-secondary);
    background: var(--bg-table-header);
}

/* Sortable table headers */
th.sortable,
th.sorted-asc,
th.sorted-desc {
    cursor: pointer;
}

th.sortable:hover,
th.sorted-asc:hover,
th.sorted-desc:hover {
    background: var(--bg-table-header-hover, rgba(255, 255, 255, 0.05));
}

/* Sort indicators for table headers */
th.sortable::after,
th.sorted-asc::after,
th.sorted-desc::after {
    margin-left: 0.5em;
    color: var(--text-muted);
}

th.sortable::after {
    content: '◇';
    font-size: 1em;
    opacity: 0.5;
}

th.sorted-asc::after {
    content: '▲';
    font-size: 0.7em;
}

th.sorted-desc::after {
    content: '▼';
    font-size: 0.7em;
}

table td {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--border-tertiary);
}

table td.no-wrap {
    white-space: nowrap;
}

table th:first-child,
table td:first-child {
    position: sticky;
    left: 0;
    z-index: 10;
}

table th:first-child {
    background: var(--bg-table-header);
    box-shadow: var(--shadow-sticky);
}

table td:first-child {
    background: var(--bg-card);
    box-shadow: var(--shadow-sticky);
}

table tbody tr:nth-child(even) td:first-child {
    background: var(--bg-table-row-even);
}

table tbody tr:hover td:first-child {
    background: var(--bg-table-row-hover);
}

/* H-Index tables: make second column (Game) sticky instead of first (Rank) */
table.h-index-table th:first-child,
table.h-index-table td:first-child {
    position: static;
    background: inherit;
    box-shadow: none;
}

table.h-index-table th:nth-child(2),
table.h-index-table td:nth-child(2) {
    position: sticky;
    left: 0;
    z-index: 10;
}

table.h-index-table th:nth-child(2) {
    background: var(--bg-table-header);
    box-shadow: var(--shadow-sticky);
}

table.h-index-table td:nth-child(2) {
    background: inherit;
    box-shadow: var(--shadow-sticky);
}

table.h-index-table tbody tr:nth-child(even) td:nth-child(2) {
    background: var(--bg-table-row-even);
}

table.h-index-table tbody tr:hover td:nth-child(2) {
    background: var(--bg-table-row-hover);
}

/* H-Index contributing rows */
table.h-index-table tbody tr.h-index-contributor {
    background: var(--bg-h-index-contributor);
}

table.h-index-table tbody tr.h-index-contributor:nth-child(even) {
    background: var(--bg-h-index-contributor-even);
}

table.h-index-table tbody tr.h-index-contributor td:first-child,
table.h-index-table tbody tr.h-index-contributor td:nth-child(2) {
    background: inherit;
}

table tbody tr:nth-child(even) {
    background: var(--bg-table-row-even);
}

table tbody tr:hover {
    background: var(--bg-table-row-hover);
}

/* Game thumbnails in tables */
.game-name-with-image {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.5rem;
}

.game-thumbnail {
    width: 50px;
    height: 38px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border-tertiary);
    flex-shrink: 0;
    transition: opacity var(--transition-hover);
}


.game-image-clickable {
    cursor: pointer;
}

.game-image-clickable:hover .game-name {
    text-decoration: underline;
}

/* Tiny inline thumbnails for summary text */
.game-thumbnail-tiny {
    width: 16px;
    height: 12px;
    object-fit: cover;
    border-radius: 2px;
    vertical-align: middle;
    margin-right: 0.25rem;
}


/* Placeholder for missing images */
.game-thumbnail-placeholder {
    width: 50px;
    height: 38px;
    border-radius: 4px;
    border: 1px solid var(--border-tertiary);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-table-row-even);
    font-weight: 600;
    font-size: 0.65rem;
    line-height: 1.1;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    padding: 2px;
    text-align: center;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: none;
    overflow: hidden;
}

.game-thumbnail-placeholder-hidden {
    display: none;
}

.game-name {
    flex: 1;
    min-width: 0;
}

/* Dark mode adjustments */
[data-theme="dark"] .game-thumbnail {
    border-color: var(--border-primary);
    opacity: 0.9;
}

[data-theme="dark"] .game-thumbnail:hover {
    opacity: 1;
}

[data-theme="dark"] .game-thumbnail-placeholder {
    border-color: var(--border-primary);
    background: var(--bg-secondary);
    color: var(--text-tertiary);
}

/* Image modal */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.85);
    cursor: pointer;
    animation: fadeIn 0.2s ease-in;
    -webkit-tap-highlight-color: transparent;
}

.image-modal * {
    -webkit-tap-highlight-color: transparent;
}

.image-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.image-modal-content {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: scaleIn 0.3s ease-out;
    cursor: zoom-in;
    transition: transform 0.2s ease;
}

/* Disable zoom cursor on touch devices (they have native pinch-to-zoom) */
@media (pointer: coarse) {
    .image-modal-content {
        cursor: default;
    }
}

.image-modal.zoomed .image-modal-content {
    max-width: none;
    max-height: none;
    cursor: zoom-out;
    transform: scale(2);
}

.image-modal-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    color: white;
    border: none;
    font-size: 5rem;
    padding: 2rem 1rem;
    cursor: pointer;
    z-index: 1001;
    opacity: 0.5;
    transition: opacity 0.2s ease;
}

.image-modal-nav:hover {
    opacity: 1;
}

.image-modal-nav:disabled {
    opacity: 0.2;
    cursor: default;
}

.image-modal-nav:disabled:hover {
    opacity: 0.2;
}

.image-modal-prev {
    left: 0;
}

.image-modal-next {
    right: 0;
}

.image-modal.zoomed .image-modal-nav {
    display: none !important;
}

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

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Shelf Gallery */
.shelf-gallery-full {
    margin-bottom: 1rem;
}

.shelf-gallery-item--full {
    border-radius: 8px;
    border: 1px solid var(--border-tertiary);
    overflow: hidden;
    margin-bottom: 1rem;
}

.shelf-gallery-item--full:last-child {
    margin-bottom: 0;
}

.shelf-gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    padding: 0.5rem 0;
}

.shelf-gallery-item--case {
    border-radius: 8px;
    border: 1px solid var(--border-tertiary);
    overflow: hidden;
}

.shelf-gallery-image {
    display: block;
    width: 100%;
    height: auto;
    cursor: pointer;
    transition: opacity var(--transition-hover);
}

.shelf-gallery-image:hover {
    opacity: 0.9;
}

/* Virtual Shelf */
.virtual-shelf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(clamp(100px, 15vw, 200px), 1fr));
    gap: 0.75rem;
    padding: 0.5rem 0;
    animation: fadeIn 0.2s ease-out;
}

.virtual-shelf-item {
    position: relative;
    cursor: pointer;
}

.virtual-shelf-item .game-thumbnail {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    object-position: top;
    border-radius: 6px;
    border: 1px solid var(--border-tertiary);
    transition: opacity var(--transition-hover), transform var(--transition-hover);
}

.virtual-shelf-item .game-thumbnail:hover {
    opacity: 0.85;
    transform: scale(1.03);
}

.virtual-shelf-item .game-thumbnail-placeholder {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 6px;
    border: 1px solid var(--border-tertiary);
    background: var(--bg-secondary);
}

.virtual-shelf-label {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.2;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Virtual Shelf Controls */
.virtual-shelf-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.virtual-shelf-sort-group {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.virtual-shelf-sort-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-right: 0.25rem;
}

.virtual-shelf-sort-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-hover);
}

.virtual-shelf-sort-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.virtual-shelf-sort-btn.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.virtual-shelf-toggle-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Loading state */
.game-thumbnail[loading="lazy"] {
    background: var(--bg-table-row-even);
}

/* Sticky column compatibility */
table th:first-child .game-name-with-image,
table td:first-child .game-name-with-image {
    overflow: visible;
}

table.h-index-table th:nth-child(2) .game-name-with-image,
table.h-index-table td:nth-child(2) .game-name-with-image {
    overflow: visible;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

footer p {
    margin: 0.25rem 0;
}

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

    header {
        margin-bottom: 0.75rem;
    }

    .detail-section {
        grid-column: span 2;
    }

    .detail-header {
        padding: 0.5rem 0.75rem;
    }

    .detail-header h2 {
        font-size: 0.9rem;
    }

    .detail-content {
        padding: 0 0.75rem 0.75rem;
        max-height: 50vh;
    }

    .detail-header-buttons {
        flex-direction: row;
    }

    .stat-value {
        font-size: 1.25rem;
        margin-bottom: 0.3rem;
    }

    table {
        font-size: 0.9rem;
    }

    table th,
    table td {
        padding: 0.5rem;
    }

    .theme-toggle {
        width: 36px;
        height: 36px;
    }

    .theme-toggle svg {
        max-width: 18px;
        max-height: 18px;
    }

    .shelf-gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
}


/* Gaming Year in Review Detail */
@media (min-width: 1200px) {
    .year-review-detail {
        columns: 2;
        column-gap: 2rem;
    }
}

.year-review-detail .year-review-subsection {
    margin-bottom: 1.5rem;
    break-inside: avoid;
}

.year-review-summary {
    margin-bottom: 1.5rem;
    break-inside: avoid;
}

.year-review-summary ul {
    margin: 0;
    padding-left: 1.5rem;
    list-style-type: disc;
}

.year-review-summary li {
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.year-review-summary li:last-child {
    margin-bottom: 0;
}

.year-review-summary .metric-name {
    font-weight: 400;
}

.year-review-summary .metric-name.hours {
    color: var(--color-metric-hours-muted);
}

.year-review-summary .metric-name.sessions {
    color: var(--color-metric-sessions-muted);
}

.year-review-summary .metric-name.plays {
    color: var(--color-metric-plays-muted);
}

.year-review-detail .year-review-subsection-heading {
    color: var(--text-heading);
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 1rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-primary);
}

.year-review-table {
    width: 100%;
    max-width: 100%;
    table-layout: auto;
    border-collapse: collapse;
}

.year-review-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-light);
}

/* Year-review table: disable default nth-child alternating */
.year-review-table tbody tr:nth-child(even),
.year-review-table tbody tr:nth-child(even) td:first-child {
    background: transparent;
}

/* Apply even-row background only to data rows (skipping expanded content rows) */
.year-review-table tbody tr:nth-child(even of .year-review-row),
.year-review-table tbody tr:nth-child(even of .year-review-row) td {
    background: var(--bg-table-row-even);
}

/* Expanded content rows always get subtle background */
.year-review-table tbody tr.year-review-expanded-content {
    background: var(--bg-table-row-even);
}

/* Hover state for all data rows */
.year-review-table tbody tr.year-review-row:hover,
.year-review-table tbody tr.year-review-row:hover td {
    background: var(--bg-table-row-hover);
}

.year-review-table .year-review-row-clickable {
    cursor: pointer;
}

.year-review-table .year-review-row-clickable td {
    transition: background-color var(--transition-theme), border-color var(--transition-theme);
}

.year-review-table .year-review-row-clickable:hover td {
    background-color: var(--bg-hover);
    transition: background-color var(--transition-hover) ease;
}

.year-review-table .year-review-expand-icon {
    display: inline-block;
    width: 1em;
    margin-right: 0.5rem;
    transition: transform var(--transition-hover) ease;
    font-size: 0.8em;
}

.year-review-table .year-review-label-detail {
    color: var(--text-label);
    font-size: 0.95rem;
    font-weight: 500;
}

.year-review-table .year-review-value-detail {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1rem;
    text-align: right;
    padding-left: 2rem;
}

.nowrap-date {
    white-space: nowrap;
}

.year-review-table .year-review-expanded-content td {
    padding: 0;
    border-bottom: 1px solid var(--border-light);
    white-space: normal;
}

.year-review-games-list {
    padding: 1rem;
    background-color: var(--bg-secondary);
}

.year-review-milestone-summary {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding-bottom: 0.75rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-light);
}

.year-review-game-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-light);
}

.year-review-game-item:last-child {
    border-bottom: none;
}

.year-review-game-name {
    color: var(--text-primary);
    font-size: 0.9rem;
    flex: 1;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.year-review-game-value {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
}

.metric-name {
    font-weight: 600;
}

.metric-name.hours {
    color: var(--color-metric-hours);
}

.metric-name.sessions {
    color: var(--color-metric-sessions);
}

.metric-name.plays {
    color: var(--color-metric-plays);
}

/* Year Review Filter Toggle */
.year-review-filter-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--bg-card);
    border: 2px solid var(--border-primary);
    border-radius: 22px;
    transition: background-color var(--transition-hover), border-color var(--transition-hover);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    transition: transform var(--transition-hover), background-color var(--transition-hover);
}

.toggle-switch input:checked + .toggle-slider {
    border-color: var(--color-primary);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(18px);
    background-color: var(--color-primary);
}

.toggle-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.year-review-no-games {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.9rem;
}

.top-games-thumbnails {
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
}

.year-review-game-rank {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 2rem;
    flex-shrink: 0;
}

/* Mobile adjustments for year review detail */
@media (max-width: 768px) {
    .year-review-detail .year-review-subsection-heading {
        font-size: 1rem;
    }

    .year-review-table {
        max-width: 100%;
        table-layout: auto;
    }

    .year-review-table td {
        padding: 0.5rem 0.75rem;
        white-space: normal;
    }

    .year-review-table .year-review-label-detail {
        font-size: 0.85rem;
    }

    .year-review-table .year-review-value-detail {
        font-size: 0.9rem;
        padding-left: 1rem;
    }

    .year-review-games-list {
        padding: 0.75rem;
    }

    .year-review-game-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .year-review-game-item--inline {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .year-review-game-name {
        font-size: 0.85rem;
    }

    .year-review-game-value {
        font-size: 0.8rem;
    }
}

/* Info Icon */
.info-icon {
    display: inline-block;
    margin-left: 0.5rem;
    vertical-align: middle;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity var(--transition-hover), transform var(--transition-hover);
}

.info-icon:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Shared tooltip (used by any element with data-tooltip) */
[data-tooltip] {
    position: relative;
    display: inline-block;
    vertical-align: middle;
    cursor: help;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--card-border);
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: normal;
    white-space: normal;
    width: 200px;
    text-align: center;
    text-transform: none;
    letter-spacing: normal;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}

[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Info Tooltip */
.info-tooltip {
    margin-left: 0.25rem;
}

.info-tooltip .info-tooltip-icon {
    display: block;
    opacity: 0.6;
    transition: opacity var(--transition-hover), transform var(--transition-hover);
}

.info-tooltip:hover .info-tooltip-icon {
    opacity: 1;
    transform: scale(1.1);
}

/* Experimental Badge */
.experimental-badge {
    margin-left: 0.5rem;
}

.experimental-icon {
    display: block;
    opacity: 0.6;
    transition: opacity var(--transition-hover), transform var(--transition-hover);
}

.experimental-badge:hover .experimental-icon {
    opacity: 1;
    transform: scale(1.1);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

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

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 10000;
    animation: scaleIn 0.2s ease-out;
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 2px solid var(--border-primary);
}

.modal-header h3 {
    color: var(--text-heading);
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background var(--transition-hover), color var(--transition-hover);
}

.modal-close:hover {
    background: var(--bg-table-row-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    color: var(--text-primary);
}

.modal-definition {
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.modal-example {
    background: var(--bg-table-header);
    padding: 1rem;
    border-radius: 6px;
    border-left: 4px solid var(--color-primary);
    margin-bottom: 1.5rem;
}

.modal-example p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-primary);
}

.modal-summary {
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.modal-explanation h4 {
    color: var(--text-heading);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.modal-explanation ol {
    margin: 0;
    padding-left: 1.5rem;
}

.modal-explanation li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        max-height: 85vh;
    }

    .modal-header {
        padding: 1rem 1.25rem;
    }

    .modal-header h3 {
        font-size: 1.1rem;
    }

    .modal-body {
        padding: 1.25rem;
    }

    .modal-definition {
        font-size: 0.95rem;
    }

    .info-icon {
        margin-left: 0.35rem;
    }
}

/* Game Detail Modal */
.game-detail-modal-content {
    max-width: 550px;
}

.game-detail-buttons {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.game-detail-cover {
    text-align: center;
    margin-bottom: 1.25rem;
}

.game-detail-name {
    margin-top: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-heading);
}

.game-detail-rating {
    margin-top: 0.25rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.game-detail-cover img {
    max-width: 400px;
    max-height: 520px;
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    object-fit: cover;
}

.game-detail-cover .game-thumbnail-placeholder:not(.game-thumbnail-placeholder-hidden) {
    width: 200px;
    height: 200px;
    margin: 0 auto;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--text-secondary);
}

.game-detail-primary-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.game-detail-stat-card {
    background: var(--bg-table-header);
    padding: 0.75rem 0.5rem;
    border-radius: 6px;
    text-align: center;
}

.game-detail-stat-card .stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.25rem;
}

.game-detail-stat-card .stat-value {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-heading);
}

.game-detail-stat-card .stat-year-value {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.game-detail-section {
    margin-bottom: 1rem;
}

.game-detail-section h4 {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.5rem;
}

.game-detail-sections-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.game-detail-section-card {
    background: var(--bg-table-header);
    border-radius: 6px;
    padding: 0.75rem 1rem;
}

.game-detail-section-card h4 {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.5rem;
}

.game-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.2rem 0;
    font-size: 0.85rem;
}

.game-detail-row .label {
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.game-detail-row .value {
    color: var(--text-primary);
    font-weight: 500;
    text-align: right;
}

.game-detail-expansions-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.game-detail-expansion-item {
    text-align: center;
}

.game-detail-expansion-item img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    object-position: top;
    border-radius: 4px;
}

.game-detail-expansion-item .game-thumbnail-placeholder:not(.game-thumbnail-placeholder-hidden) {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    font-size: 1rem;
    font-weight: bold;
    color: var(--text-secondary);
}

.game-detail-expansion-item .expansion-name {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 0.2rem;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

@media (max-width: 768px) {
    .game-detail-modal-content {
        max-width: 95%;
    }

    .game-detail-modal-content .modal-body {
        padding: 1rem;
    }

    .game-detail-cover img {
        max-width: 320px;
        max-height: 400px;
    }

    .game-detail-sections-grid {
        grid-template-columns: 1fr;
    }

    .game-detail-section-card {
        padding: 0.75rem;
    }

    .game-detail-expansions-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
