:root {
    --primary-color: #d3b978;
    /* LoL Gold/Prestige-ish */
    --primary-hover: #b39556;
    --bg-color: #0d1117;
    /* Dark background */
    --card-bg: #161b22;
    --border-color: #30363d;
    --text-main: #e6edf3;
    --text-muted: #8b949e;
    --error-color: #f85149;
    --success-color: #238636;

    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
}

button {
    cursor: pointer;
    font-family: inherit;
}

.hidden {
    display: none !important;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--spacing-lg);
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: var(--spacing-xl);
}

.app-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: var(--spacing-xs);
}

.home-link {
    display: inline-flex;
    align-items: center;
    margin-bottom: var(--spacing-md);
    text-decoration: none;
    transition: opacity 0.2s;
}

.home-link:hover {
    opacity: 0.8;
}

.home-logo {
    max-height: 40px;
    width: auto;
}

.home-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

.subtitle {
    color: var(--text-muted);
}

/* Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-lg);
}

@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 450px 1fr;
        align-items: start;
    }
}

/* Cards */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
}

.card-header h2 {
    font-size: 1.25rem;
    color: var(--text-main);
}

/* Inputs */
.players-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.player-row {
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
    background-color: rgba(255, 255, 255, 0.03);
    padding: var(--spacing-sm);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
}

.player-row:focus-within {
    border-color: var(--primary-color);
    background-color: rgba(255, 255, 255, 0.05);
}

.row-index {
    width: 20px;
    text-align: right;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

input[type="text"],
input[type="number"],
select {
    background-color: #0d1117;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.input-name {
    flex: 1;
    min-width: 0;
}

.input-role {
    width: 80px;
}

.input-tier {
    width: 110px;
}

.input-division {
    width: 60px;
}

.lp-control {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    position: relative;
}

.lp-checkbox {
    cursor: pointer;
}

.input-lp {
    width: 60px;
}

.calculate-action {
    margin-top: var(--spacing-lg);
}

/* Buttons */
.btn {
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #1a1a1a;
    width: 100%;
}

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

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

.btn-outline:hover {
    border-color: var(--text-main);
    color: var(--text-main);
}

.btn-sm {
    padding: 4px 8px;
    font-size: 0.8rem;
}

.btn-secondary {
    background-color: var(--border-color);
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-secondary:hover {
    background-color: #434c56;
}

/* Results */
.result-section {
    position: sticky;
    top: var(--spacing-lg);
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.result-actions {
    display: flex;
    gap: var(--spacing-sm);
}

.teams-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
    position: relative;
    margin-bottom: var(--spacing-md);
}

@media (min-width: 768px) {
    .teams-grid {
        grid-template-columns: 1fr auto 1fr;
    }
}

.team-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
}

.team-a {
    border-top: 3px solid #f85149;
}

/* Red side */
.team-b {
    border-top: 3px solid #238636;
}

/* "Green" side or Blue side logic, using Green for clear contrast */
/* Actually LoL is Blue/Red. Let's stick to standard colors if possible or just distinct ones. 
    Blue: #2b7de9, Red: #e92b2b
*/
.team-a {
    border-top-color: #2b7de9;
}

.team-b {
    border-top-color: #e92b2b;
}

.team-title {
    text-align: center;
    margin-bottom: var(--spacing-sm);
    font-size: 1.1rem;
}

.team-stats {
    display: flex;
    justify-content: space-around;
    background: rgba(0, 0, 0, 0.2);
    padding: var(--spacing-sm);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-md);
}

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

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

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

.team-members li {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-color);
}

.team-members li:last-child {
    border-bottom: none;
}

.member-name {
    font-weight: 500;
}

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

.vs-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1.5rem;
    color: var(--text-muted);
    opacity: 0.3;
}

.mmr-diff-info {
    text-align: center;
    background: var(--card-bg);
    padding: var(--spacing-sm);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-bottom: var(--spacing-lg);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-backdrop {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
}

.modal-content {
    position: relative;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    z-index: 1001;
    display: flex;
    flex-direction: column;
}

.modal-header,
.modal-footer {
    padding: var(--spacing-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
}

.modal-body {
    padding: var(--spacing-md);
}

.modal-footer {
    border-top: 1px solid var(--border-color);
}

textarea#paste-area {
    width: 100%;
    background: #0d1117;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: var(--spacing-sm);
    margin-top: var(--spacing-sm);
    font-family: monospace;
}

.error-message {
    color: var(--error-color);
    font-size: 0.9rem;
    margin-top: var(--spacing-sm);
}

.example-box {
    background: rgba(255, 255, 255, 0.05);
    padding: var(--spacing-sm);
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
}

/* --- Rich Footer --- */
.app-footer {
    margin-top: 60px;
    padding: 40px 0;
    background: #050505;
    /* Darker contrast */
    border-top: 1px solid #1e232a;
    text-align: center;
    position: relative;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
}

/* Hextech/Gold accent line on top */
.app-footer::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary-color), transparent);
    opacity: 0.5;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.footer-links a {
    color: #8b949e;
    text-decoration: none;
    font-size: 0.85rem;
    text-transform: uppercase;
    /* More premium feel */
    letter-spacing: 1px;
    font-weight: 600;
    transition: all 0.3s ease;
    position: relative;
}

.footer-links a::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0%;
    height: 1px;
    background-color: var(--primary-color);
    transition: width 0.3s ease;
}

.footer-links a:hover {
    color: var(--primary-color);
    text-shadow: 0 0 8px rgba(200, 170, 110, 0.4);
}

.footer-links a:hover::after {
    width: 100%;
}

.copyright {
    font-size: 0.75rem;
    color: #484f58;
    letter-spacing: 0.5px;
}

/* --- Mobile Optimization --- */
@media (max-width: 600px) {
    .app-container {
        padding: var(--spacing-md);
    }

    .app-header h1 {
        font-size: 1.5rem;
    }

    /* Global Options: Stack vertical */
    .global-options {
        flex-direction: column;
        gap: 12px !important;
        align-items: flex-start !important;
    }

    /* Player Row: Wrap content */
    .player-row {
        flex-wrap: wrap;
        padding: 12px;
        position: relative;
    }

    .row-index {
        position: absolute;
        top: 12px;
        left: 12px;
        font-size: 0.7rem;
        background: #30363d;
        color: #fff;
        padding: 2px 6px;
        border-radius: 4px;
        width: auto;
        text-align: center;
        z-index: 2;
    }

    /* Name: Full width, push to new line if consistent or just flex */
    .input-name {
        flex: 1 1 100%;
        width: 100%;
        margin-left: 0;
        margin-top: 20px;
        /* Space for the absolute index */
        margin-bottom: 8px;
    }

    /* Selectors: Flex grow to fill space */
    .input-role,
    .input-tier,
    .input-division {
        flex: 1;
        /* Distribute space evenly */
        min-width: 0;
    }

    .input-role {
        /* Role might need min width */
        min-width: 70px;
    }

    .lp-control {
        flex: 1;
        justify-content: flex-end;
    }

    /* Result actions: Stack buttons */
    .header-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .header-actions button {
        flex: 1;
        font-size: 0.75rem;
    }

    /* Modal: Smaller margins */
    .modal-content {
        width: 95%;
        max-height: 90vh;
        /* Prevent overflow */
        overflow-y: auto;
    }
}