/* =========================================
   VARIABLES & BASE SETUP
   ========================================= */
:root {
    --xbox-green: #107C10;
    --xbox-glow: rgba(16, 124, 16, 0.6);
    --bg-dark: #0f0f0f;
    --card-bg: #1e1e1e;
    --item-bg: #2a2a2a;
    --text-main: #ffffff;
    --text-muted: #a3a3a3;
    --error-red: #ff4d4d;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-dark);
    background-image: radial-gradient(circle at 50% 0%, #1a2c1a 0%, var(--bg-dark) 70%);
    color: var(--text-main);
    text-align: center;
    padding: 0 0 40px 0; /* Removed top padding to accommodate the Top Nav */
    margin: 0;
    min-height: 100vh;
}

/* =========================================
   TOP NAVIGATION BAR
   ========================================= */
.top-nav {
    background-color: rgba(30, 30, 30, 0.85); 
    backdrop-filter: blur(12px); 
    border-bottom: 2px solid var(--xbox-green);
    padding: 15px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 2000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

.nav-brand a {
    color: var(--text-main);
    text-decoration: none;
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 1px;
    transition: color 0.2s ease, text-shadow 0.2s ease;
}

.nav-brand a:hover {
    color: var(--xbox-green);
    text-shadow: 0 0 10px var(--xbox-glow);
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 10px;
    margin: 0;
    padding: 0;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.nav-links a:hover {
    color: var(--text-main);
    background-color: rgba(16, 124, 16, 0.2);
}

/* =========================================
   MAIN PROFILE CONTAINER
   ========================================= */
.profile-container {
    max-width: 650px;
    margin: 40px auto; /* Added margin-top to separate from nav */
    background-color: var(--card-bg);
    padding: 40px 30px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.profile-container h1 {
    font-size: 1.8rem;
    margin-top: 0;
    margin-bottom: 25px;
    background: linear-gradient(to bottom, #fff, #888);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* =========================================
   INTEGRATED SEARCH FORM
   ========================================= */
.profile-container .form-container {
    background: rgba(0,0,0,0.2);
    padding: 10px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.05);
    margin-bottom: 0;
}

.form-container form {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.form-container input[type="text"] {
    padding: 14px 20px;
    border-radius: 8px;
    border: 1px solid #333;
    background-color: var(--card-bg);
    color: var(--text-main);
    width: 100%;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.form-container input[type="text"]:focus {
    outline: none;
    border-color: var(--xbox-green);
    box-shadow: 0 0 10px var(--xbox-glow);
}

.form-container button {
    padding: 14px 24px;
    border-radius: 8px;
    border: none;
    background-color: var(--xbox-green);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.form-container button:hover:not([disabled]) {
    background-color: #149614;
    box-shadow: 0 0 15px var(--xbox-glow);
    transform: translateY(-2px);
}

.form-container button[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

/* =========================================
   HOW-TO GUIDE
   ========================================= */
.guide-container {
    text-align: left;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01));
    padding: 30px;
    border-radius: 12px;
    margin-top: 30px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 0 20px rgba(0,0,0,0.4);
}

.guide-container h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--xbox-green);
    font-size: 1.2rem;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 10px;
}

.guide-container h3::before { content: '🎮'; }

.guide-container ol { padding-left: 0; list-style: none; margin: 0; }

.guide-container li {
    position: relative;
    padding-left: 35px;
    margin-bottom: 15px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.guide-container li::before {
    content: attr(data-step);
    position: absolute;
    left: 0; top: 0;
    width: 22px; height: 22px;
    background: var(--xbox-green);
    border-radius: 50%;
    text-align: center;
    font-size: 0.75rem;
    line-height: 22px;
    font-weight: bold;
    color: white;
}

.note {
    font-size: 0.8rem;
    color: var(--error-red);
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid rgba(255,255,255,0.05);
    display: block;
    opacity: 0.8;
}

/* =========================================
   PROFILE RESULTS HEADER
   ========================================= */
.profile-header-flex { 
    margin-top: 30px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
}

.display-name {
    font-size: 2rem;
    margin: 10px 0 25px 0;
    color: var(--xbox-green);
    text-shadow: 0 0 10px var(--xbox-glow);
}

.profile-image {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    overflow: hidden;
    border: 4px solid var(--xbox-green);
    box-shadow: 0 0 25px var(--xbox-glow), inset 0 0 10px rgba(0,0,0,0.8);
    transition: transform 0.3s ease;
}

.profile-image:hover { transform: scale(1.05); }

.profile-image img { width: 100%; height: 100%; object-fit: cover; }

/* =========================================
   PROFILE RESULTS GRID (Fixed 2x2 layout)
   ========================================= */
#profile {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    text-align: left;
    margin-top: 20px;
}

.profile-item {
    padding: 20px;
    background: linear-gradient(145deg, var(--item-bg), #222);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255, 255, 255, 0.03);
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.2);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.profile-item:hover {
    transform: translateY(-2px);
    border-color: rgba(16, 124, 16, 0.4);
}

.profile-item span {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    font-weight: 600;
}

.profile-item strong {
    font-size: 1.4rem;
    color: var(--text-main);
}

/* =========================================
   BUTTONS
   ========================================= */
.recently-played-link {
    margin-top: 35px;
    padding-top: 25px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-view-games {
    display: block;
    padding: 16px 24px;
    background-color: var(--xbox-green);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(16, 124, 16, 0.2);
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.btn-view-games:hover {
    background-color: #149614;
    box-shadow: 0 6px 20px rgba(16, 124, 16, 0.5);
    transform: translateY(-3px);
    color: white;
}

.btn-back {
    display: inline-block;
    padding: 10px 20px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: bold;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin-bottom: 20px;
    transition: all 0.2s ease;
}

.btn-back:hover {
    color: white;
    background-color: rgba(255,255,255,0.05);
    border-color: var(--text-main);
}

/* =========================================
   GAMES LIBRARY PAGE
   ========================================= */
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.game-card {
    background-color: var(--item-bg);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
}

.game-card:hover {
    transform: translateY(-5px) scale(1.03);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.6), 0 0 15px var(--xbox-glow);
    border-color: var(--xbox-green);
}

.game-card img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-bottom: 2px solid var(--xbox-green);
}

.game-card-title {
    padding: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    color: var(--text-main);
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =========================================
   MODAL POPUP STYLES
   ========================================= */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    justify-content: center;
    align-items: center;
    animation: fadeInModal 0.2s ease;
}

@keyframes fadeInModal {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: var(--card-bg);
    padding: 30px;
    border-radius: 16px;
    border: 1px solid var(--xbox-green);
    box-shadow: 0 0 40px rgba(16, 124, 16, 0.3);
    max-width: 500px;
    width: 90%;
    text-align: center;
    position: relative;
}

.close-btn {
    position: absolute;
    top: 15px; right: 20px;
    color: var(--text-muted);
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover { color: var(--error-red); }

.modal-content img {
    width: 120px; height: 120px;
    border-radius: 12px;
    object-fit: cover;
    margin: 0 auto 15px auto;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    border: 2px solid var(--item-bg);
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 25px;
    color: var(--text-main);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.stat-box {
    background-color: var(--item-bg);
    padding: 15px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255,255,255,0.02);
}

.stat-box span {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.stat-box strong { font-size: 1.1rem; color: var(--xbox-green); }

/* =========================================
   ACHIEVEMENTS PAGE STYLES
   ========================================= */
.achievements-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

.achievement-card {
    background-color: var(--item-bg);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    gap: 20px;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.achievement-card:hover {
    transform: translateX(5px);
    border-color: var(--xbox-green);
    background-color: #333;
}

.achievement-card.locked { opacity: 0.6; border-left: 4px solid var(--text-muted); }
.achievement-card.locked .ach-icon { filter: grayscale(100%) brightness(0.6); }

.achievement-card.unlocked {
    border-left: 4px solid var(--xbox-green);
    background: linear-gradient(90deg, rgba(16,124,16,0.1) 0%, var(--item-bg) 100%);
}

.ach-icon {
    width: 65px; height: 65px;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    background-color: #1a1a1a;
    flex-shrink: 0;
}

.ach-details { flex-grow: 1; text-align: left; }

.ach-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.ach-title { margin: 0; font-size: 1.1rem; color: var(--text-main); font-weight: 700; }

.ach-unlocked-date {
    font-size: 0.75rem;
    color: var(--xbox-green);
    margin-top: 4px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.ach-score {
    font-weight: bold;
    color: var(--xbox-green);
    background-color: rgba(16, 124, 16, 0.15);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
}

.ach-desc { margin: 0; font-size: 0.9rem; color: var(--text-muted); line-height: 1.4; }

.ach-progress-bar {
    width: 100%; height: 6px;
    background-color: #111;
    border-radius: 3px;
    margin-top: 10px;
    overflow: hidden;
}

.ach-progress-fill { height: 100%; background-color: var(--xbox-green); border-radius: 3px; transition: width 0.5s ease; }
.ach-progress-text { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; text-align: right; }

/* =========================================
   UTILITIES & MESSAGES
   ========================================= */
.fallback-image {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    background-color: #1a1a1a;
    aspect-ratio: 1 / 1;
    border-bottom: 2px solid #333;
}

.error-message, .rate-limit-message {
    background-color: rgba(255, 77, 77, 0.1);
    border: 1px solid var(--error-red);
    color: var(--error-red);
    text-align: center;
    margin: 20px auto;
    padding: 15px;
    border-radius: 8px;
    font-weight: 500;
}

/* =========================================
   FOOTER & DISCLAIMER
   ========================================= */
footer { 
    margin-top: 60px; 
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.05); /* Adds a subtle separator line */
}

.disclaimer { 
    color: var(--text-muted); 
    font-size: 0.85rem; 
    font-style: italic;
    opacity: 0.6; /* Keeps it strictly in the background */
    letter-spacing: 0.5px;
    transition: opacity 0.3s ease;
}

/* Brightens up just a bit if the user happens to hover over it */
.disclaimer:hover {
    opacity: 1;
}

/* =========================================
   LOADING OVERLAY
   ========================================= */
.loader-overlay {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 15, 15, 0.85); /* Dark background */
    backdrop-filter: blur(8px); /* Frosted glass effect */
    z-index: 9999; /* Keeps it on top of everything */
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.loader-spinner {
    border: 6px solid var(--item-bg);
    border-top: 6px solid var(--xbox-green);
    border-radius: 50%;
    width: 70px;
    height: 70px;
    animation: spin 1s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
    margin-bottom: 20px;
    box-shadow: 0 0 20px rgba(16, 124, 16, 0.2);
}

.loader-overlay p {
    color: var(--text-main);
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    animation: pulseText 1.5s infinite;
}

/* Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulseText {
    0%, 100% { opacity: 1; text-shadow: 0 0 10px var(--xbox-glow); }
    50% { opacity: 0.5; text-shadow: none; }
}

/* =========================================
   RESPONSIVE DESIGN (MOBILE)
   ========================================= */
@media (max-width: 600px) {
    .top-nav { flex-direction: column; padding: 15px 20px; gap: 15px; }
    #profile { grid-template-columns: 1fr; }
    .form-container form { flex-direction: column; }
    .profile-container { padding: 30px 15px; }
    .achievement-card { flex-direction: column; align-items: flex-start; }
    .ach-header { flex-direction: column; align-items: flex-start; gap: 10px; }
}

@media (max-width: 450px) {
    .stats-grid { grid-template-columns: 1fr; }
}