:root {
    --bg-primary: #0f111a;
    --bg-secondary: #1a1d2d;
    --bg-card: rgba(30, 32, 48, 0.7);
    --bg-card-hover: rgba(40, 42, 60, 0.9);

    --accent-primary: #8b5cf6;
    /* Vibrant Purple */
    --accent-secondary: #10b981;
    /* Emerald Green for wins */
    --accent-error: #ef4444;
    /* Red for losses */

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;

    --border-radius: 12px;
    --border-radius-lg: 16px;

    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-glow: 0 0 15px rgba(139, 92, 246, 0.3);

    --font-stack: 'Outfit', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-stack);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height */
    overflow: hidden;
    margin: 0;
}

#app-container {
    display: flex;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    padding: 2rem;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 3rem;
    color: var(--accent-primary);
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-links li {
    padding: 0.8rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.nav-links li:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-links li.active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2) 0%, rgba(139, 92, 246, 0.05) 100%);
    color: var(--accent-primary);
    border-left: 3px solid var(--accent-primary);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background: radial-gradient(circle at top right, rgba(139, 92, 246, 0.05), transparent 40%);
}

.view {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #fff, #94a3b8);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* The Threat Section */
.the-threat-card {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.2), rgba(153, 27, 27, 0.1));
    border: 1px solid rgba(220, 38, 38, 0.5);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 0 20px rgba(220, 38, 38, 0.2);
    position: relative;
    overflow: hidden;
}

.the-threat-card::before {
    content: "WANTED";
    position: absolute;
    top: -10px;
    right: -20px;
    background: #dc2626;
    color: white;
    padding: 5px 30px;
    transform: rotate(15deg);
    font-weight: 800;
    font-size: 0.8rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
}

.threat-info h2 {
    font-size: 2rem;
    color: #fca5a5;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.threat-stats {
    text-align: right;
}

.threat-stats span {
    display: block;
    font-size: 1.2rem;
    color: var(--text-primary);
}

.threat-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
    display: block;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 1.5rem;
    border-radius: var(--border-radius-lg);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.stat-card h3 {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.stat-card span {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Forms */
.form-container {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--border-radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.05);
    max-width: 600px;
}

.input-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

input[type="text"],
input[type="date"] {
    width: 100%;
    padding: 0.8rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-family: var(--font-stack);
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

.btn {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-stack);
    transition: all 0.2s ease;
}

.btn.primary {
    background: linear-gradient(135deg, var(--accent-primary), #7c3aed);
    color: white;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}

.btn.primary:hover {
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.4);
    transform: translateY(-1px);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* History List */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.game-card {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: var(--border-radius);
    display: grid;
    grid-template-columns: 1fr auto auto;
    /* Content, Badge, Delete */
    gap: 1rem;
    align-items: center;
    border-left: 4px solid var(--border-color, var(--text-secondary));
    transition: background-color 0.2s;
}

.game-card:hover {
    background-color: var(--bg-card-hover);
}

.btn-icon.delete-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    transition: color 0.2s ease;
    padding: 0.5rem;
    border-radius: 50%;
}

.btn-icon.delete-btn:hover {
    color: var(--accent-error);
    background: rgba(239, 68, 68, 0.1);
}


.game-card.win {
    border-color: var(--accent-secondary);
}

.game-card.loss {
    border-color: var(--accent-error);
}

.game-info h4 {
    font-size: 1.1rem;
    margin-bottom: 0.2rem;
}

.game-info p {
    margin: 0;
    font-size: 0.85rem;
}

.game-date {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* Opponent dynamic forms */
.opponent-entry {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* Ensure inputs take full width of grid cell */
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
}

.opponent-entry input {
    width: 100%;
}

.opponent-entry:last-child {
    border-bottom: none;
}

/* Dashboard Stats List */
.stats-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.stat-item {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.cmd-name {
    font-weight: 600;
    color: var(--text-primary);
}

.cmd-details {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.stat-bar-container {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
}

.stat-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 4px;
    transition: width 1s ease-out;
}

.stat-percent {
    position: absolute;
    right: 0;
    top: -1.5rem;
    /* Move it above the bar */
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: none;
    /* Hide for now, shown in info if needed, but app.js puts it in container? */
}

/* Badges */
.badge {
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: inline-block;
}

.badge.win {
    background: rgba(16, 185, 129, 0.2);
    color: var(--accent-secondary);
}

.badge.loss {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-error);
}

/* Settings Link */
.settings-link {
    margin-top: auto;
    padding-top: 2rem;
}

.btn-text-danger {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-stack);
    font-size: 0.9rem;
    opacity: 0.7;
    transition: opacity 0.2s, color 0.2s;
    width: 100%;
}

.btn-text-danger:hover {
    opacity: 1;
    color: var(--accent-error);
}

/* Fullscreen Button */
.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-stack);
    font-size: 0.9rem;
    transition: color 0.2s;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0;
}

.btn-text:hover {
    color: var(--text-primary);
}

/* Members Grid */
.members-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.add-member-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--border-radius-lg);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    max-width: 400px;
    margin-bottom: 2rem;
}

.member-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--border-radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
    transition: transform 0.2s;
}

.member-card:hover {
    transform: translateY(-2px);
    border-color: rgba(139, 92, 246, 0.3);
}

.member-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

.member-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-primary);
}

.deck-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.deck-item {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.deck-item i {
    font-size: 0.7rem;
    color: var(--accent-secondary);
}

.add-deck-form {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.add-deck-form input {
    font-size: 0.8rem;
    padding: 0.5rem;
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: var(--border-radius);
}

/* Game Log Rows */
.participant-row {
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    display: grid;
    grid-template-columns: 2fr 2fr auto auto;
    gap: 1rem;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.participant-row select {
    width: 100%;
    padding: 0.8rem;
    background: var(--bg-secondary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-family: var(--font-stack);
}

.participant-row input {
    margin-bottom: 0;
}

.commander-input-wrapper {
    width: 100%;
}

.remove-p-btn {
    background: none;
    border: none;
    color: var(--accent-error);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.5rem;
}

.winner-toggle {
    cursor: pointer;
    font-size: 1.5rem;
    color: rgba(255, 255, 255, 0.2);
    transition: all 0.2s;
}

.winner-toggle:hover {
    color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.winner-toggle.active {
    color: var(--accent-secondary);
    text-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.full-width {
    width: 100%;
}


/* Commander Avatar - Smaller Square */
.cmd-avatar {
    width: 20px;
    /* Match text size */
    height: 20px;
    border-radius: 4px;
    /* Square with slight rounding */
    object-fit: cover;
    border: 1px solid var(--accent-primary);
    background: var(--bg-card);
    vertical-align: middle;
}

.cmd-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Enhancements for lists with avatars */
.member-decks .deck-item,
.game-details p,
.stats-list .stat-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Adjust stats list to accomodate image */
.stat-info .cmd-wrapper {
    margin-right: auto;
}

/* Responsive Design */
@media (max-width: 768px) {
    #app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        padding: 0.5rem 1rem;
        border-right: none;
        border-top: 1px solid rgba(255, 255, 255, 0.05);
        order: 2;
        /* Move to bottom */
        justify-content: space-between;
        align-items: center;
        background: var(--bg-secondary);
        z-index: 100;
        position: relative;
    }

    .logo {
        display: none;
        /* Hide logo on mobile to save space */
    }

    .settings-link {
        display: none;
        /* Hide quick settings on mobile nav, rely on tab */
    }

    .nav-links {
        flex-direction: row;
        width: 100%;
        justify-content: space-around;
        gap: 0;
    }

    .nav-links li {
        flex-direction: column;
        gap: 0.2rem;
        padding: 0.5rem;
        font-size: 0.7rem;
        text-align: center;
        border-radius: 8px;
    }

    .nav-links li i {
        font-size: 1.2rem;
    }

    .nav-links li.active {
        border-left: none;
        border-bottom: 3px solid var(--accent-primary);
        background: transparent;
    }

    .member-name {
        font-size: 1.1rem;
    }

    .main-content {
        padding: 1rem;
        order: 1;
        /* Main content on top */
        height: calc(100dvh - 70px);
        /* Subtract approx nav height */
        padding-bottom: 2rem;
        /* Add spacer for scroll */
    }

    h1 {
        font-size: 1.5rem;
    }

    .stat-card span {
        font-size: 1.5rem;
    }

    .participant-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .participant-row select,
    .participant-row .commander-input-wrapper {
        width: 100%;
    }

    .winner-toggle {
        justify-self: center;
        padding: 0.5rem;
    }

    .remove-p-btn {
        justify-self: center;
        background: rgba(239, 68, 68, 0.1);
        width: 100%;
        border-radius: 4px;
        margin-top: 0.5rem;
    }

    /* Adjust grids */
    .stats-grid,
    .members-grid {
        grid-template-columns: 1fr;
    }

    .game-card {
        grid-template-columns: 1fr;
        gap: 0.5rem;
        text-align: center;
    }

    .game-header {
        justify-content: center;
        flex-direction: column;
        gap: 0.2rem;
    }

    .btn-icon.delete-btn {
        width: 100%;
        background: rgba(255, 255, 255, 0.05);
        border-radius: var(--border-radius);
    }
}