:root {
    --bg-dark: #0a0a12;
    --card-bg: rgba(255, 255, 255, 0.05);
    --accent-purple: #a855f7;
    --accent-blue: #3b82f6;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --glass-border: rgba(255, 255, 255, 0.1);
    --neg-color: #ef4444;
    --pos-color: #22c55e;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
}

#app {
    position: relative;
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.ambient-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 50%, rgba(168, 85, 247, 0.1) 0%, transparent 70%);
    z-index: -1;
    animation: pulse 10s infinite alternate ease-in-out;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(1.2); opacity: 0.8; }
}

.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    text-align: center;
    opacity: 0;
    transition: opacity 0.5s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.screen::before,
.screen::after {
    content: '';
    margin: auto;
}

.screen > * {
    flex-shrink: 0;
}

.screen.active {
    display: flex;
    opacity: 1;
}

.glow-text {
    font-size: 4rem;
    font-weight: 600;
    background: linear-gradient(to bottom, #fff, var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1rem;
    filter: drop-shadow(0 0 10px rgba(168, 85, 247, 0.5));
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.25rem;
    margin-bottom: 2rem;
}

.intro-text {
    max-width: 600px;
    margin-bottom: 3rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.primary-btn, .secondary-btn {
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    font-family: inherit;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.primary-btn {
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
    color: white;
    box-shadow: 0 4px 15px rgba(168, 85, 247, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.5);
}

.developer-tag {
    margin-top: 2rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    opacity: 0.6;
    letter-spacing: 2px;
    text-transform: uppercase;
    font-weight: 300;
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

/* HUD */
.hud {
    position: absolute;
    top: 2rem;
    left: 2rem;
    right: 2rem;
    display: flex;
    justify-content: space-between;
    z-index: 10;
}

.hud-item {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    padding: 0.75rem 1.5rem;
    border-radius: 16px;
    display: flex;
    gap: 1rem;
    align-items: center;
}

.hud-item .label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.hud-item .value {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Canvas */
#game-canvas {
    background: radial-gradient(circle at center, #1a1a2e 0%, #0a0a12 100%);
    border-radius: 24px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    max-width: 90vw;
    max-height: 80vh;
}

#hub-screen.active {
    background: rgba(10, 10, 18, 0.95);
    backdrop-filter: blur(20px);
}

.settings-panel {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    padding: 1.5rem 2rem;
    border-radius: 20px;
    margin-bottom: 2.5rem;
    display: flex;
    gap: 3rem;
    align-items: center;
}

#test-hud {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

#test-hud .hud-item {
    flex-grow: 0;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.hint {
    color: var(--accent-purple);
    font-size: 0.7rem;
    margin-top: 0.25rem;
    font-weight: 600;
}

select {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid var(--glass-border);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-family: inherit;
    cursor: pointer;
}

select option {
    background: var(--bg-dark);
}

.mode-selection-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 3rem;
    width: 100%;
    max-width: 900px;
}

.summary-actions {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.secondary-btn.accent {
    border-color: #f59e0b;
    color: #f59e0b;
}

.secondary-btn.accent:hover {
    background: rgba(245, 158, 11, 0.1);
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.3);
}

.mode-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    padding: 2rem;
    border-radius: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mode-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent-purple);
    transform: translateY(-5px);
}

.mode-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
    border-style: dashed;
}

.mode-card.locked:hover {
    transform: none;
    border-color: var(--glass-border);
}

.mode-card h3 {
    font-size: 1.25rem;
    color: var(--text-primary);
}

.mode-card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.mode-card .high-score {
    margin-top: auto;
    font-size: 0.8rem;
    color: var(--accent-purple);
    font-weight: 600;
}

.secondary-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* Overlays */
.overlay {
    position: absolute;
    background: rgba(10, 10, 18, 0.85);
    backdrop-filter: blur(10px);
    padding: 3rem;
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    max-width: 500px;
    max-height: 90dvh;
    overflow-y: auto;
    z-index: 20;
    display: none;
}

.overlay.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

.summary-layout {
    display: flex;
    gap: 2rem;
    width: 100%;
    max-width: 1100px;
    margin-bottom: 2.5rem;
}

.comparison-container, .leaderboard-container {
    flex: 1;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    min-width: 0;
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.comparison-container:hover, .leaderboard-container:hover {
    border-color: rgba(168, 85, 247, 0.3);
}

.table-scroll-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    padding-bottom: 0.5rem;
}

/* Custom Scrollbar for tables */
.table-scroll-wrapper::-webkit-scrollbar {
    height: 4px;
}

.table-scroll-wrapper::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 10px;
}

.table-scroll-wrapper::-webkit-scrollbar-thumb {
    background: linear-gradient(to right, var(--accent-purple), var(--accent-blue));
    border-radius: 10px;
    opacity: 0.5;
}

/* Scroll Hint Shadow */
.table-scroll-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(to right, transparent, rgba(10, 10, 18, 0.5));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.table-scroll-wrapper.can-scroll::after {
    opacity: 1;
}

.comparison-container h3, .leaderboard-container h3 {
    color: var(--accent-purple);
    font-size: 1rem;
    margin-bottom: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#comparison-table, #global-leaderboard {
    width: 100%;
    min-width: 480px; /* ensures columns stay readable before scroll kicks in */
    border-collapse: collapse;
}

#comparison-table th, #comparison-table td,
#global-leaderboard th, #global-leaderboard td {
    padding: 1rem 0.5rem;
    text-align: center;
    border-bottom: 1px solid var(--glass-border);
    white-space: nowrap;
}

#comparison-table th, #global-leaderboard th {
    color: var(--text-secondary);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 600;
    padding: 1.25rem 0.75rem;
    background: rgba(255, 255, 255, 0.02);
}

/* Sticky first column for context */
#comparison-table th:first-child,
#comparison-table td:first-child,
#global-leaderboard th:first-child,
#global-leaderboard td:first-child,
#global-leaderboard th:nth-child(2),
#global-leaderboard td:nth-child(2) {
    position: sticky;
    left: 0;
    z-index: 5;
    background: #161625; /* Solid color to prevent overlap artifacts */
    box-shadow: 2px 0 5px rgba(0,0,0,0.3);
}

#comparison-table tr, #global-leaderboard tr {
    transition: background 0.2s ease;
}

#comparison-table tr:hover, #global-leaderboard tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

#comparison-table td:first-child, #global-leaderboard td:nth-child(2) {
    text-align: left;
    color: var(--text-primary);
    font-weight: 600;
}

.score-cell {
    font-size: 1.1rem;
    font-weight: 600;
}

#ladderboard-clickable {
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

#ladderboard-clickable:hover {
    border-color: var(--accent-purple);
    transform: translateY(-5px);
    box-shadow: 0 0 30px rgba(168, 85, 247, 0.2);
}

#ladderboard-clickable h3 .hint {
    font-size: 0.6rem;
    vertical-align: middle;
    margin-left: 0.5rem;
    opacity: 0.7;
}

.fame-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1.5rem;
    width: 100%;
    max-width: 1400px;
    margin-bottom: 3rem;
    max-height: 65vh;
    overflow-y: auto;
    padding: 1rem;
}

.category-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.25rem;
    text-align: left;
}

.category-card h4 {
    font-size: 0.8rem;
    color: var(--accent-purple);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
}

.mini-ladder {
    width: 100%;
    font-size: 0.75rem;
}

.mini-ladder tr td {
    padding: 0.25rem 0;
}

.mini-ladder tr td:first-child {
    color: var(--text-secondary);
    width: 20px;
}

.mini-ladder tr td:last-child {
    text-align: right;
    font-weight: 600;
}

/* Scrollbar for fame-grid */
.fame-grid::-webkit-scrollbar {
    width: 6px;
}

.fame-grid::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.fame-grid::-webkit-scrollbar-thumb {
    background: var(--accent-purple);
    border-radius: 3px;
}

.score-pos { color: #3b82f6; text-shadow: 0 0 10px rgba(59, 130, 246, 0.3); }
.score-neg { color: #a855f7; text-shadow: 0 0 10px rgba(168, 85, 247, 0.3); }
.score-zero { color: rgba(255, 255, 255, 0.1); font-weight: 300; }

.top-player {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 80px;
    margin-left: auto;
    margin-right: auto;
}

.top-score {
    font-size: 1rem;
    font-weight: 700;
}

/* Nickname Modal */
#nickname-modal {
    text-align: center;
}

#nickname-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 1rem;
    border-radius: 12px;
    font-size: 1.25rem;
    margin: 1.5rem 0;
    text-align: center;
    outline: none;
    transition: border-color 0.3s ease;
}

#nickname-input:focus {
    border-color: var(--accent-purple);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Recovery Info & Modal Styles */
.recovery-info {
    margin-top: 1.5rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    text-align: center;
}

.recovery-info code {
    display: block;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.5rem;
    border-radius: 4px;
    color: var(--accent-blue);
    font-size: 0.9rem;
    word-break: break-all;
    margin: 0.5rem 0;
}

.mini-btn {
    padding: 0.3rem 0.8rem;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.mini-btn:hover {
    background: var(--accent-blue);
    color: white;
}

.hint-link {
    display: block;
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-decoration: underline;
    opacity: 0.7;
}

.hint-link:hover {
    opacity: 1;
    color: var(--accent-blue);
}

.full-width {
    width: 100%;
    margin-bottom: 1.5rem;
}

#recovery-status {
    margin-top: 1rem;
    font-size: 0.9rem;
    height: 1.2rem;
}

/* --- Responsive Media Queries --- */

@media (max-width: 1024px) {
    .fame-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .glow-text {
        font-size: 3rem;
    }

    .subtitle {
        font-size: 0.9rem;
        margin-bottom: 1.5rem;
        padding: 0 1rem;
        line-height: 1.4;
    }

    .screen {
        padding: 3rem 1rem 1.5rem 1rem;
    }

    .glow-text {
        font-size: 2.5rem;
        margin-top: 1rem;
    }

    .settings-panel {
        gap: 1rem;
        padding: 1rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .hud {
        top: 1rem;
        left: 1rem;
        right: 1rem;
    }

    .hud-item {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }

    .hud-item .value {
        font-size: 1rem;
    }

    .summary-layout {
        flex-direction: column;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    .comparison-container, .leaderboard-container {
        padding: 1.25rem 1rem;
        border-radius: 16px;
    }

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

    .overlay {
        padding: 2rem;
        width: 90%;
    }
}

@media (max-width: 480px) {
    .glow-text {
        font-size: 2.2rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .intro-text {
        font-size: 0.9rem;
        margin-bottom: 2rem;
    }

    .mode-selection-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .mode-card {
        padding: 1.5rem;
    }

    .settings-panel {
        flex-direction: column;
        gap: 1rem;
        width: 100%;
    }

    .setting-item {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }

    .setting-item label {
        font-size: 0.8rem;
    }

    .primary-btn, .secondary-btn {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
        width: 100%;
    }

    .summary-actions {
        flex-direction: column;
        gap: 1rem;
        width: 100%;
    }

    .hud {
        flex-direction: column;
        gap: 0.5rem;
        align-items: center;
    }

    .hud-item {
        width: 100%;
        justify-content: center;
    }

    .fame-grid {
        grid-template-columns: 1fr;
    }

    .comparison-container, .leaderboard-container {
        padding: 0.75rem 0.5rem;
        border-radius: 12px;
    }

    #comparison-table, #global-leaderboard {
        min-width: 400px;
        font-size: 0.8rem;
    }

    #comparison-table th, #global-leaderboard th {
        font-size: 0.55rem;
        letter-spacing: 0.5px;
        padding: 0.6rem 0.25rem;
    }

    #comparison-table td, #global-leaderboard td {
        padding: 0.6rem 0.25rem;
    }

    .score-cell {
        font-size: 0.85rem;
    }

    .summary-actions {
        margin-bottom: 1rem;
    }

    #game-canvas {
        max-width: 95vw;
    }
}
