/* ==========================================================================
   SUIRODOKU MOBILE LEADERBOARD
   Version: 1.0.0
   Based on mobile.css architecture
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Variables (same as home mobile.css)
   -------------------------------------------------------------------------- */
:root {
    color-scheme: light only;
    --mobile-header-height: 44px;
    
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
    
    --primary: #7c3aed;
    --primary-hover: #6d28d9;
    --primary-light: rgba(124, 58, 237, 0.1);
    --text-primary: #1c1c1e;
    --text-secondary: #374151;
    --text-muted: #6b7280;
    --bg-primary: #fff;
    --bg-secondary: #f2f2f7;
    --border-color: #e5e7eb;
    --border-dark: #484848;
    
    --error: #ff3b30;
    --error-dark: #d70015;
    --success: #28a745;
    --warning: #ff9500;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);
    
    /* Leaderboard specific */
    --lb-row-height: 70px;
    --lb-flag-size: 50px;
}

/* --------------------------------------------------------------------------
   Base Reset (same as home)
   -------------------------------------------------------------------------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* CHROME iOS FIX: Fixed viewport with internal scroll wrapper */
html {
    height: 100% !important;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    overflow: hidden !important;
}

body {
    font-family: var(--font-family);
    background: linear-gradient(135deg, #fef7f0 0%, #fffbf7 50%, #f9f4ef 100%);
    color: var(--text-primary);
    height: 100% !important;
    width: 100% !important;
    overflow: hidden !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
}

body::before {
    content: "";
    position: fixed;
    inset: -20%;
    z-index: -1;
    pointer-events: none;
    background: 
        radial-gradient(650px 650px at 20% 25%, rgba(139, 92, 246, 0.14), transparent 55%),
        radial-gradient(800px 800px at 80% 20%, rgba(124, 58, 237, 0.12), transparent 60%),
        radial-gradient(700px 700px at 35% 80%, rgba(109, 40, 217, 0.10), transparent 58%);
}

/* SCROLL WRAPPER - The scrollable container */
#mobile-scroll-wrapper {
    position: fixed !important;
    top: 44px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain !important;
    z-index: 1 !important;
}

/* Safe area support for scroll wrapper */
@supports (padding-top: env(safe-area-inset-top)) {
    #mobile-scroll-wrapper {
        top: calc(44px + env(safe-area-inset-top)) !important;
        padding-bottom: env(safe-area-inset-bottom) !important;
    }
}

/* --------------------------------------------------------------------------
   Mobile Header (identical to home)
   -------------------------------------------------------------------------- */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 44px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 50px;
}

.header-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 50px;
}

.header-logo {
    display: flex;
    align-items: center;
}

.header-logo img {
    height: 26px;
    width: auto;
}

/* Menu Burger Button (identical to home) */
.menu-burger {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.menu-burger:active {
    background: rgba(0, 0, 0, 0.05);
}

.menu-burger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: all 0.3s ease;
}

/* Header Stats */
.header-stat {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.header-stat .stat-value {
    font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Main Content Area
   -------------------------------------------------------------------------- */
.lb-main {
    padding: 12px !important;
    padding-bottom: 24px !important;
    min-height: 100% !important;
}

/* --------------------------------------------------------------------------
   Title Bar
   -------------------------------------------------------------------------- */
.lb-title-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 14px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
}

.lb-title-icon img {
    display: block;
}

.lb-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

/* --------------------------------------------------------------------------
   Search Section
   -------------------------------------------------------------------------- */
.lb-search-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.search-group {
    width: 100%;
}

.search-input-wrap {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 12px 40px 12px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-primary);
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    caret-color: var(--primary);
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.search-input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

.dropdown-arrow {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    transition: transform 0.2s ease;
}

.search-input-wrap.show .dropdown-arrow {
    transform: translateY(-50%) rotate(180deg);
}

.clear-search {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    font-weight: 300;
    cursor: pointer;
    padding: 4px 8px;
    display: none;
    z-index: 2;
    line-height: 1;
}

.clear-search.show {
    display: block;
}

.clear-search.show + .dropdown-arrow {
    display: none;
}

/* Country Dropdown */
.country-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    max-height: 280px;
    overflow-y: auto;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

.country-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.country-option {
    padding: 13px 16px;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    transition: background 0.15s ease;
}

.country-option:last-child {
    border-bottom: none;
}

.country-option:active,
.country-option.highlighted {
    background: var(--primary-light);
}

.country-separator {
    padding: 10px 16px !important;
    background: rgba(124, 58, 237, 0.06) !important;
    color: var(--text-muted) !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    cursor: default !important;
    pointer-events: none !important;
    border-bottom: none !important;
}

/* Find My Rank Button */
.find-rank-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.find-rank-btn:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.3);
}

.find-rank-btn img {
    filter: brightness(10);
}

/* --------------------------------------------------------------------------
   Table Section
   -------------------------------------------------------------------------- */
.lb-table-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    margin-bottom: 12px;
}

.lb-table-header {
    padding: 14px 16px;
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(0,0,0,0.06);
    text-align: center;
}

.lb-table-header.clickable-header {
    cursor: pointer;
    transition: background 0.2s ease;
}

.lb-table-header.clickable-header:active {
    background: var(--primary-light);
}

.lb-table-description-row {
    padding: 12px 16px;
    background: rgba(124, 58, 237, 0.04);
    border-bottom: 1px solid rgba(0,0,0,0.06);
}

.lb-table-description {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
}

.countries-grid {
    font-size: 12px;
    line-height: 2;
}

.country-link {
    color: var(--primary);
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 4px;
    display: inline-block;
}

.country-link:active {
    background: var(--primary-light);
}

/* Table Body */
.lb-table-body {
    min-height: 400px;
}

/* Loading */
.table-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    min-height: 300px;
}

.spinner-large {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* --------------------------------------------------------------------------
   Leaderboard Rows
   -------------------------------------------------------------------------- */
.lb-row {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    height: var(--lb-row-height);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    background: var(--bg-primary);
    cursor: pointer;
    transition: background 0.15s ease;
}

.lb-row:active {
    background: rgba(124, 58, 237, 0.06);
}

.lb-row:last-child {
    border-bottom: none;
}

.lb-row.private-profile {
    cursor: default;
}

.lb-row.private-profile:active {
    background: var(--bg-primary);
}

.lb-row.current-user {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(245, 158, 11, 0.18));
    border-left: 3px solid #f59e0b;
}

.lb-row.search-result {
    background: rgba(59, 130, 246, 0.08);
    border-left: 3px solid #3b82f6;
}

/* Row Columns */
.col-rank {
    width: 36px;
    min-width: 36px;
    font-size: 15px;
    font-weight: 800;
    color: var(--text-primary);
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.col-flag {
    width: calc(var(--lb-flag-size) + 10px);
    min-width: calc(var(--lb-flag-size) + 10px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.flag-circle {
    width: var(--lb-flag-size);
    height: var(--lb-flag-size);
    min-width: var(--lb-flag-size);
    min-height: var(--lb-flag-size);
    border-radius: 50%;
    background-color: #e5e7eb;
    background-size: cover;
    background-position: center;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
}

.col-info {
    flex: 1;
    min-width: 0;
    padding: 0 10px;
}

.player-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
    line-height: 1.3;
}

.player-games {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
}

.privacy-lock {
    display: inline-block;
    margin-left: 4px;
    font-size: 11px;
    opacity: 0.6;
}

.col-rating {
    width: 58px;
    min-width: 58px;
    text-align: right;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

/* Medal styling */
.medal-svg {
    width: 42px;
    height: 42px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

/* --------------------------------------------------------------------------
   Pagination
   -------------------------------------------------------------------------- */
.lb-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
}

.pagination-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.pagination-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.pagination-btn:not(:disabled):active {
    background: var(--primary-light);
    border-color: var(--primary);
}

.page-info {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Go to Page */
.lb-goto-section {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.lb-goto-section input {
    flex: 1;
    padding: 12px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-primary);
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    outline: none;
    caret-color: var(--primary);
}

.lb-goto-section input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.lb-goto-section input::placeholder {
    color: var(--text-muted);
}

.goto-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--primary), #6d28d9);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.goto-btn:active {
    transform: scale(0.97);
}

/* --------------------------------------------------------------------------
   Empty & Error States
   -------------------------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 50px 20px;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 14px;
    opacity: 0.5;
}

.empty-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.empty-text {
    font-size: 14px;
    color: var(--text-muted);
}

.error-state {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #fef7f0 0%, #fffbf7 50%, #f9f4ef 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 2000;
}

.error-icon {
    font-size: 52px;
    margin-bottom: 18px;
}

.error-title {
    font-size: 20px;
    font-weight: 700;
    color: #dc2626;
    margin-bottom: 8px;
}

.error-text {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 28px;
    text-align: center;
}

.error-buttons {
    display: flex;
    gap: 12px;
}

.btn-primary,
.btn-secondary {
    padding: 14px 28px;
    border-radius: 12px;
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: transform 0.15s ease;
}

.btn-primary:active,
.btn-secondary:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #6d28d9 100%);
    color: #fff;
}

.btn-secondary {
    background: var(--bg-primary);
    border: 1.5px solid var(--border-color);
    color: var(--text-secondary);
}

/* --------------------------------------------------------------------------
   Menu (identical to home mobile.css)
   -------------------------------------------------------------------------- */
.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.menu-overlay.open {
    opacity: 1;
    visibility: visible;
}

.menu-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 320px;
    max-width: 85vw;
    background: #fff;
    z-index: 2001;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.menu-overlay.open .menu-panel {
    transform: translateX(0);
}

.menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-color);
}

.menu-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.menu-close {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 28px;
    color: var(--text-muted);
    transition: background 0.2s ease;
}

.menu-close:active {
    background: rgba(0, 0, 0, 0.05);
}

.menu-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.menu-section {
    padding: 8px 0;
}

.menu-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 8px 16px 4px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    font-size: 18px;
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s ease;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
}

.menu-item:active {
    background: rgba(0, 0, 0, 0.05);
}

.menu-item img {
    width: 28px;
    height: 28px;
}

.menu-item svg {
    width: 28px;
    height: 28px;
}

.menu-item.danger {
    color: var(--error);
}

.menu-item.current-page {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 16px;
}

.logout-btn {
    color: #ff3b30 !important;
}

.logout-btn svg {
    stroke: #ff3b30;
}

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

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --------------------------------------------------------------------------
   Safe Area (Notch Support)
   -------------------------------------------------------------------------- */
@supports (padding-top: env(safe-area-inset-top)) {
    .mobile-header {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--mobile-header-height) + env(safe-area-inset-top));
    }
    
    /* .lb-main padding is handled by scroll wrapper */
    .lb-main {
        padding-bottom: calc(24px + env(safe-area-inset-bottom)) !important;
    }
    
    .menu-panel {
        padding-top: env(safe-area-inset-top);
    }
}

/* --------------------------------------------------------------------------
   Loading State
   -------------------------------------------------------------------------- */
.mobile-loading {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 1;
    visibility: visible;
    transition: all 0.3s ease;
}

.mobile-loading.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   RTL Support
   -------------------------------------------------------------------------- */
body.rtl-language {
    direction: rtl;
}

body.rtl-language .mobile-header {
    flex-direction: row-reverse;
}

body.rtl-language .header-left,
body.rtl-language .header-right {
    flex-direction: row-reverse;
}

body.rtl-language .lb-row {
    flex-direction: row-reverse;
}

body.rtl-language .col-rank {
    text-align: center;
}

body.rtl-language .col-rating {
    text-align: left;
}

body.rtl-language .player-name {
    text-align: right;
}

body.rtl-language .menu-panel {
    left: auto;
    right: 0;
    transform: translateX(100%);
}

body.rtl-language .menu-overlay.open .menu-panel {
    transform: translateX(0);
}

body.rtl-language .menu-item {
    flex-direction: row-reverse;
    text-align: right;
}

body.rtl-language .pagination-btn svg {
    transform: scaleX(-1);
}

/* --------------------------------------------------------------------------
   Small Screens (< 360px)
   -------------------------------------------------------------------------- */
@media (max-width: 359px) {
    :root {
        --lb-row-height: 64px;
        --lb-flag-size: 44px;
    }
    
    .col-rank {
        width: 30px;
        min-width: 30px;
        font-size: 13px;
    }
    
    .player-name {
        font-size: 13px;
    }
    
    .col-rating {
        width: 50px;
        min-width: 50px;
        font-size: 13px;
    }
    
    .medal-svg {
        width: 36px;
        height: 36px;
    }
    
    .lb-title {
        font-size: 18px;
    }
}

/* --------------------------------------------------------------------------
   Reduced Motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}