/* ============================================================
   Game Layout & Components
   ============================================================ */

/* Profile section */
.profile-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

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

.profile-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.profile-name {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
}

.profile-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: color 0.2s, background 0.2s;
}

.profile-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.x-link-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.x-link-btn:hover {
    border-color: #ef4444;
    color: #ef4444;
}

.x-link-btn.linked {
    border-color: #ef4444;
    color: #ef4444;
}

.x-icon {
    font-size: 1rem;
    font-weight: 700;
}

/* Main game wrapper - 2 column layout */
.game-wrapper {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* Leaderboard panel */
.leaderboard-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 1rem;
    border: 1px solid var(--border);
    padding: 1rem;
    font-size: 0.75rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.panel-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--accent);
    margin-bottom: 0.75rem;
    text-align: center;
    text-shadow: 0 0 10px var(--accent-glow);
}

.total-runs {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: auto;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

/* Leaderboard */
.lb-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 450px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.25rem;
}

/* Custom scrollbar for leaderboard */
.lb-list::-webkit-scrollbar {
    width: 4px;
}
.lb-list::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.02);
}
.lb-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}
.lb-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.lb-entry {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.lb-entry:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--border-hover);
    transform: translateX(2px);
}

.lb-rank {
    font-family: 'Orbitron', monospace;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    width: 24px;
    flex-shrink: 0;
    text-align: center;
}

.lb-rank.gold { color: #fbbf24; text-shadow: 0 0 10px rgba(251, 191, 36, 0.4); }
.lb-rank.silver { color: #e2e8f0; text-shadow: 0 0 10px rgba(226, 232, 240, 0.4); }
.lb-rank.bronze { color: #d97706; }

.lb-name {
    flex: 1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.lb-x-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 700;
    flex-shrink: 0;
    transition: color 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
}

.lb-x-link:hover {
    color: #ef4444;
    transform: scale(1.1);
}

.lb-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--accent);
    flex-shrink: 0;
    font-weight: 600;
}

/* Game area */
.game-area {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 1rem;
    border: 1px solid var(--border);
    padding: 2rem;
    min-height: 480px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.game-screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 340px;
}

.game-screen.active {
    display: flex;
}

/* Start screen */
.start-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 1.5rem;
}

.explanation-box {
    max-width: 600px;
    padding: 1.25rem 2rem;
    margin-bottom: 0.5rem;
}

.explanation-text {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
}

.explanation-text strong {
    color: var(--accent);
    font-weight: 600;
}

.goal-box {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    padding: 1.5rem 2rem;
    border-radius: 1rem;
    margin-bottom: 2rem;
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.goal-text {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.goal-text .highlight {
    color: var(--success);
    font-weight: 700;
    text-shadow: 0 0 15px var(--success-glow);
}

.control-hint {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.control-hint .highlight {
    color: var(--accent);
    font-weight: 600;
}

/* Start button */
.start-button {
    margin-top: 1rem;
    padding: 1.25rem 4rem;
    font-family: 'Orbitron', sans-serif;
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: white;
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 0 30px var(--accent-glow);
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.start-button:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 0 50px var(--accent-glow-strong);
    filter: brightness(1.1);
}

.start-button:active {
    transform: scale(0.98);
}

.start-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255,255,255,0.2),
        transparent
    );
    transition: 0.5s;
}

.start-button:hover::before {
    left: 100%;
}

/* Play screen - compact stats row */
.stats-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0.75rem;
    padding: 0.75rem 1.5rem;
    margin-bottom: 1.5rem;
    width: 100%;
    border: 1px solid var(--border);
}

.mini-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

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

.mini-stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 3ch;
    text-align: center;
    white-space: nowrap;
}

/* Timer */
.timer-display {
    text-align: center;
    display: flex;
    align-items: baseline;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.5rem 1.5rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
}

.timer-value {
    font-family: 'Orbitron', monospace;
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--text-primary);
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
    line-height: 1;
    min-width: 5ch;
    text-align: center;
    display: inline-block;
}

.timer-unit {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-left: 0.35rem;
    font-weight: 600;
}

/* Accuracy display */
.accuracy-display {
    text-align: center;
    margin-bottom: 1.5rem;
    position: relative;
    padding: 1rem;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.accuracy-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 5rem;
    font-weight: 900;
    background: linear-gradient(180deg, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5));
    min-width: 5ch;
    text-align: center;
    display: inline-block;
}

.accuracy-value.hot {
    background: linear-gradient(135deg, #10b981, #34d399);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 20px var(--success-glow));
    animation: pulse 0.5s ease infinite;
}

.pct-sign {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-muted);
    vertical-align: super;
}

/* Chart */
.chart-container {
    width: 100%;
    margin-bottom: 1.5rem;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    position: relative;
}

.chart-container::before {
    content: 'ACCURACY HISTORY';
    position: absolute;
    top: 0.5rem;
    left: 0.75rem;
    font-size: 0.6rem;
    color: var(--text-muted);
    letter-spacing: 0.1em;
}

#training-chart {
    width: 100%;
    height: 120px;
    display: block;
}

/* Slider */
.slider-container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    background: rgba(0,0,0,0.2);
    padding: 1.5rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.slider-container.pulse {
    animation: sliderPulse 2s ease-in-out infinite;
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

@keyframes sliderPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 20px var(--accent-glow);
    }
    50% {
        transform: scale(1.02);
        box-shadow: 0 0 40px var(--accent-glow-strong);
    }
}

.slider-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.slider-label span {
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 1.1rem;
    text-shadow: 0 0 10px var(--accent-glow);
}

.slider-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-family: 'JetBrains Mono', monospace;
}

.lr-slider {
    width: 100%;
    height: 48px;
    -webkit-appearance: none;
    background: transparent;
    cursor: grab;
    margin: 0;
}

.lr-slider:active { cursor: grabbing; }

.lr-slider::-webkit-slider-runnable-track {
    height: 6px;
    background: linear-gradient(90deg, #1e293b, var(--accent), var(--danger));
    border-radius: 3px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}

.lr-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 32px;
    height: 32px;
    background: #fff;
    border: 2px solid var(--accent);
    border-radius: 50%;
    margin-top: -13px;
    box-shadow: 0 0 20px var(--accent-glow), 0 2px 5px rgba(0,0,0,0.5);
    transition: transform 0.1s;
    position: relative;
    z-index: 2;
}

.lr-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    background: #f8fafc;
    box-shadow: 0 0 30px var(--accent-glow-strong), 0 2px 5px rgba(0,0,0,0.5);
}

.lr-slider::-moz-range-track {
    height: 6px;
    background: linear-gradient(90deg, #1e293b, var(--accent), var(--danger));
    border-radius: 3px;
}

.lr-slider::-moz-range-thumb {
    width: 32px;
    height: 32px;
    background: #fff;
    border: 2px solid var(--accent);
    border-radius: 50%;
    border: none;
    box-shadow: 0 0 20px var(--accent-glow);
}

.slider-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
    font-style: italic;
}

/* Stop Button */
.stop-button {
    margin-top: 1.5rem;
    padding: 0.75rem 2rem;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    background: transparent;
    color: var(--danger);
    border: 2px solid var(--danger);
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.2);
}

.stop-button:hover {
    background: var(--danger);
    color: white;
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 0 30px var(--danger-glow);
}

/* Complete screen */
.complete-content {
    text-align: center;
}

.complete-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 3rem;
    font-weight: 900;
    color: var(--success);
    margin-bottom: 1rem;
    text-shadow: 0 0 30px var(--success-glow);
    animation: bounceIn 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.final-time {
    font-family: 'Orbitron', monospace;
    font-size: 4rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2rem;
    text-shadow: 0 0 20px rgba(255,255,255,0.2);
}

.final-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 2rem;
    background: rgba(255,255,255,0.03);
    padding: 1.5rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
}

.final-stat {
    text-align: center;
}

.final-stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
}

.final-stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    text-shadow: 0 0 10px var(--accent-glow);
}

.pb-badge {
    display: inline-block;
    padding: 0.5rem 1.5rem;
    background: linear-gradient(135deg, var(--warning), #f97316);
    color: white;
    font-weight: 800;
    font-size: 1rem;
    border-radius: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 15px rgba(249, 115, 22, 0.4);
    animation: bounce 0.6s ease infinite;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.restart-button {
    padding: 1rem 3rem;
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    background: transparent;
    color: var(--text-primary);
    border: 2px solid var(--accent);
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.restart-button:hover {
    background: var(--accent);
    color: white;
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 0 30px var(--accent-glow);
}

/* Failed screen */
.failed-content {
    text-align: center;
}

.failed-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 3rem;
    font-weight: 900;
    color: var(--danger);
    margin-bottom: 0.5rem;
    text-shadow: 0 0 30px var(--danger-glow);
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-10px); }
    40%, 80% { transform: translateX(10px); }
}

.failed-subtitle {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.failed-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 2rem;
}

.retry-countdown {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    color: var(--text-muted);
    padding: 0.75rem 1.5rem;
    background: rgba(255,255,255,0.05);
    border-radius: 0.5rem;
    display: inline-block;
    border: 1px solid var(--border);
}

.retry-countdown span {
    color: var(--warning);
    font-weight: 700;
    font-size: 1.2rem;
}

/* ============================================================
   Modals
   ============================================================ */

.modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-backdrop.show {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    max-width: 320px;
    width: 90%;
    text-align: center;
}

.modal-icon {
    font-size: 2.5rem;
    font-weight: 700;
    color: #ef4444;
    margin-bottom: 0.5rem;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.modal-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.modal-input-prefix {
    position: absolute;
    left: 0.75rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.modal-input {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.modal-input.with-prefix {
    padding-left: 1.75rem;
}

.modal-input:focus {
    border-color: var(--accent);
}

.modal-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    margin-bottom: 1rem;
}

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

.modal-btn {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.modal-btn-cancel {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.modal-btn-cancel:hover {
    background: var(--border);
}

.modal-btn-save {
    background: var(--accent);
    color: white;
}

.modal-btn-save:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.modal-btn-unlink {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
}

.modal-btn-unlink:hover {
    background: var(--danger);
    color: white;
}

/* ============================================================
   Mobile
   ============================================================ */

@media (max-width: 700px) {
    .profile-section {
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }

    .profile-label {
        display: none;
    }

    .x-text {
        display: none;
    }

    .game-wrapper {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .leaderboard-panel {
        order: 2;
    }

    .game-area {
        order: 1;
        min-height: 380px;
        padding: 1.5rem;
        width: 100%;
        box-sizing: border-box;
    }

    .slider-container {
        max-width: 100%;
        padding: 1rem;
        margin: 0 auto;
    }

    .chart-container {
        padding: 0.75rem;
    }

    .stats-bar {
        padding: 0.5rem 1rem;
        flex-wrap: wrap;
        justify-content: center;
        max-width: 100%;
    }

    .accuracy-display {
        padding: 0.5rem;
    }

    .stop-button {
        width: 100%;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }

    .panel-title {
        font-size: 0.6rem;
        margin-bottom: 0.35rem;
    }

    .lb-list {
        display: flex;
        flex-direction: column;
        gap: 0.35rem;
    }

    .lb-entry {
        padding: 0.3rem 0.4rem;
    }

    .lb-rank {
        font-size: 0.65rem;
        width: 20px;
    }

    .lb-name {
        font-size: 0.6rem;
    }

    .lb-time {
        font-size: 0.65rem;
    }

    .app-title {
        font-size: 1.5rem;
    }

    .explanation-box {
        padding: 1rem 1.5rem;
        max-width: 100%;
    }

    .explanation-text {
        font-size: 0.85rem;
        line-height: 1.5;
    }

    .accuracy-value {
        font-size: 2.5rem;
        min-width: 4ch;
    }

    .accuracy-display {
        min-height: 80px;
    }

    .mini-stat-value {
        min-width: 2.5ch;
    }

    .timer-value {
        min-width: 4ch;
    }

    .timer-value {
        font-size: 2rem;
    }

    .stats-bar {
        gap: 1rem;
    }

    .failed-title {
        font-size: 1.5rem;
    }

    /* Hide loss stat on mobile */
    .mini-stat:last-child {
        display: none;
    }
}
