/* --- Design System & CSS Variables --- */
:root {
    --bg-main: #141D2F;
    --bg-card: #1E2A47;
    --text-primary: #FFFFFF;
    --text-secondary: #AAB8D8;
    --accent-color: #0079FF;
    --accent-hover: #60ABFF;
    --error-color: #F74646;
    --success-color: #2EA043;
    --border-color: rgba(255, 255, 255, 0.1);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    --shadow-soft: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 10px 20px rgba(0, 0, 0, 0.2);
    --glow-focus: 0 0 0 3px rgba(0, 121, 255, 0.3);
    
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* --- Base Reset & Typography --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 2rem 1.5rem;
    line-height: 1.5;
}

.container {
    width: 100%;
    max-width: 850px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

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

.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    border: 2px solid var(--border-color); /* Updated to 2px for better battle highlighting */
}

/* --- Header & Tabs --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.gh-logo {
    width: 40px;
    height: 40px;
    color: var(--text-primary);
    transition: var(--transition);
}

.gh-logo:hover {
    color: var(--accent-color);
}

.title-group h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.title-group p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.2rem;
}

.mode-toggle {
    display: flex;
    background-color: var(--bg-card);
    padding: 0.3rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    background-color: var(--accent-color);
    color: white;
    box-shadow: var(--shadow-soft);
}

/* --- Search Bar --- */
.search-container {
    display: flex;
    background-color: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 0.5rem;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-color);
    align-items: center;
    transition: var(--transition);
    position: relative;
    z-index: 10;
}

.search-container:focus-within {
    border-color: var(--accent-color);
    box-shadow: var(--glow-focus);
}

.search-input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1rem;
}

.search-icon {
    width: 20px;
    height: 20px;
    color: var(--accent-color);
}

input[type="text"] {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
}

input[type="text"]::placeholder {
    color: var(--text-secondary);
}

.btn-primary {
    background-color: var(--accent-color);
    color: white;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-large {
    padding: 0.8rem 2rem;
    font-size: 1rem;
}

/* --- State Containers (Loading & Error) --- */
.state-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    animation: fadeIn 0.4s ease-out;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(0, 121, 255, 0.2);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
}

.state-container p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Error Card */
.error-card {
    padding: 3rem;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    animation: slideUp 0.4s ease-out;
}

.warning-icon {
    width: 64px;
    height: 64px;
    color: var(--error-color);
    margin-bottom: 0.5rem;
}

.error-card h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
}

.error-card p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-primary);
    border: 1px solid var(--text-secondary);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background-color: rgba(255,255,255,0.05);
    border-color: var(--text-primary);
}

/* --- Normal Profile Card --- */
#results-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    animation: fadeIn 0.5s ease-out;
}

.profile-card {
    padding: 2.5rem;
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.avatar-wrapper {
    flex-shrink: 0;
}

.avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    box-shadow: var(--shadow-soft);
}

.profile-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.profile-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.profile-name h2 {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.profile-username {
    color: var(--accent-color);
    font-size: 1rem;
    text-decoration: none;
    display: inline-block;
    margin-top: 0.25rem;
}

.profile-username:hover {
    text-decoration: underline;
}

.profile-joined {
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding-top: 0.5rem;
}

.profile-bio {
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.6;
}

/* Stats Section */
.profile-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background-color: var(--bg-main);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-top: 0.5rem;
    border: 1px solid var(--border-color);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    text-align: center;
}

.stat-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.stat-label svg {
    width: 14px;
    height: 14px;
    display: none; /* Can be enabled if needed */
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Links Section */
.profile-links {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 0.5rem;
}

.link-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.link-item svg {
    width: 18px;
    height: 18px;
    opacity: 0.7;
}

.link-item a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
}

.link-item a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* --- Repositories Section --- */
.repos-header {
    margin-top: 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.repos-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.repos-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.repo-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: var(--transition);
    text-decoration: none;
    color: inherit;
    animation: slideUp 0.4s ease-out backwards;
}

.repo-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Stagger repo animation delays */
.repos-grid .repo-card:nth-child(1) { animation-delay: 0.1s; }
.repos-grid .repo-card:nth-child(2) { animation-delay: 0.2s; }
.repos-grid .repo-card:nth-child(3) { animation-delay: 0.3s; }
.repos-grid .repo-card:nth-child(4) { animation-delay: 0.4s; }
.repos-grid .repo-card:nth-child(5) { animation-delay: 0.5s; }

.repo-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.repo-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent-color);
    font-size: 1.1rem;
    font-weight: 600;
}

.repo-name svg {
    color: var(--text-secondary);
}

.repo-desc {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.repo-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: auto;
    padding-top: 0.5rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.meta-item.lang svg { color: var(--accent-color); }
.meta-item.star svg { color: #f1e05a; }

/* --- Battle View Enhancements --- */
.battle-arena {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2.5rem;
    position: relative;
    padding: 1rem 0;
    gap: 1.5rem; /* Give space between inputs and VS badge */
}

.battle-input-box {
    flex: 1;
    margin-bottom: 0;
    padding: 0.5rem 1rem;
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}

.battle-input-box input {
    text-align: center;
}

.vs-badge-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.vs-badge {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--accent-color), #8224E3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px rgba(0, 121, 255, 0.4);
    border: 3px solid var(--bg-main);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.vs-badge:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 0 25px rgba(0, 121, 255, 0.6);
}

.vs-badge span {
    color: white;
    font-weight: 800;
    font-size: 1.1rem;
    font-style: italic;
}

/* Battle Action Row Button Glow */
.btn-battle {
    background: linear-gradient(135deg, #0079FF, #8224E3);
    box-shadow: 0 8px 20px rgba(0, 121, 255, 0.3);
    border-radius: 30px;
    font-size: 1.05rem;
    padding: 0.9rem 2.5rem;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-battle:hover {
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 12px 25px rgba(0, 121, 255, 0.5);
    background: linear-gradient(135deg, #0088FF, #9d4ded);
}

/* Comparison Bar Update */
.battle-comparison-header {
    text-align: center;
    margin-bottom: 2rem;
    animation: fadeIn 0.8s ease-out backwards;
}

.battle-comparison-header h3 {
    font-size: 1.8rem;
    text-transform: uppercase;
    background: linear-gradient(135deg, #FFD700, #F7931A);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 2px 10px rgba(255, 215, 0, 0.2);
    letter-spacing: 1px;
}

.comparison-bar-container {
    background-color: var(--bg-card);
    padding: 1.5rem 2rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    margin-bottom: 3rem;
    box-shadow: var(--shadow-soft);
    animation: slideUp 0.6s ease-out backwards;
    animation-delay: 0.1s;
}

.comparison-labels {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
    font-weight: 600;
}

.comp-title { 
    color: var(--text-secondary); 
    font-size: 0.85rem; 
    text-transform: uppercase; 
    letter-spacing: 1px; 
}

.comparison-track {
    width: 100%;
    height: 12px;
    background-color: rgba(255,255,255,0.05);
    border-radius: 6px;
    display: flex;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.comp-bar {
    height: 100%;
    transition: width 1.2s cubic-bezier(0.25, 1, 0.5, 1); /* Smooth wipe */
}

.p1-fill { 
    background: linear-gradient(90deg, #1fa2ff, #12d8fa);
    width: 50%; 
}

.p2-fill { 
    background: linear-gradient(90deg, #b92b27, #1565C0);
    width: 50%; 
    border-left: 2px solid var(--bg-card); 
}

/* Battle Card Constraints */
.battle-cards-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2.5rem;
    margin-bottom: 2rem;
    align-items: stretch; /* Cards stretch to same height */
}

.battle-card {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 3.5rem 2rem 2rem; /* Give room for detached badge */
    position: relative;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1);
}

.battle-card .profile-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.battle-card .profile-stats {
    margin-top: auto; /* Push stats to bottom naturally */
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

/* Enhance Highlight States */
.winner {
    background-color: rgba(46, 160, 67, 0.03) !important;
    border: 2px solid var(--success-color) !important;
    box-shadow: 0 10px 30px rgba(46, 160, 67, 0.15) !important;
    transform: scale(1.05);
    z-index: 5;
}

.loser {
    background-color: rgba(247, 70, 70, 0.02) !important;
    border: 2px solid rgba(247, 70, 70, 0.4) !important;
    opacity: 0.85;
    transform: scale(0.98);
}

.draw {
    border: 2px solid var(--text-secondary) !important;
    opacity: 0.9;
}

/* Float Badges higher to detach from border top */
.battle-badge {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.6rem 2rem;
    border-radius: 30px;
    font-weight: 800;
    font-size: 1rem;
    color: white;
    z-index: 10;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.badge-winner { 
    background: linear-gradient(135deg, #2EA043, #3FB950);
    border: 2px solid #238636;
}

.badge-loser { 
    background: linear-gradient(135deg, #DA3633, #F85149);
    border: 2px solid #B62324;
}

.badge-draw { 
    background: linear-gradient(135deg, #6E7681, #8B949E);
    border: 2px solid #484F58;
}

/* Enhancing normal badges/animation */
.slide-in-left { animation: slideInLeft 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; opacity: 0; animation-delay: 0.3s; }
.slide-in-right { animation: slideInRight 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; opacity: 0; animation-delay: 0.4s; }

@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* --- Animations --- */
@keyframes spin {
    to { transform: rotate(360deg); }
}

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

@keyframes slideUp {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Responsive Design --- */
@media (min-width: 768px) {
    .repos-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .repos-grid .repo-card:first-child {
        grid-column: 1 / -1;
    }
}

@media (max-width: 650px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1.25rem;
    }
    
    .mode-toggle {
        width: 100%;
        justify-content: center;
    }
    
    .tab-btn {
        flex: 1;
        text-align: center;
    }

    /* Normal Card Mobile */
    .profile-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 2rem 1.5rem;
    }
    
    .profile-header {
        flex-direction: column;
        align-items: center;
        gap: 0.25rem;
    }
    
    .profile-joined {
        padding-top: 0;
    }
    
    .profile-stats {
        padding: 1rem;
        gap: 0.5rem;
    }
    
    .profile-links {
        flex-direction: column;
        align-items: flex-start;
        align-self: flex-start;
        width: 100%;
        margin-top: 1rem;
    }

    /* Battle View Mobile */
    .battle-arena {
        flex-direction: column;
        gap: 1rem;
    }
    
    .battle-input-box {
        width: 100%;
    }
    
    .vs-badge-wrapper {
        margin: 0.5rem 0;
    }
    
    .vs-badge {
        width: 45px;
        height: 45px;
        border-width: 2px;
    }

    .vs-badge span {
        font-size: 1rem;
    }
    
    .battle-action-row button {
        width: 100%;
    }
    
    .battle-cards-container {
        grid-template-columns: 1fr;
        gap: 3.5rem; /* Account for badges */
    }
    
    .comparison-labels {
        font-size: 0.85rem;
    }
}
