/* --- Global Styles --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Default (Dark Blue) Theme variables */
:root {
    --bg-body: #0a192f;
    --bg-panel: #1c2b4a;
    --bg-element: #30416b;
    --text-primary: #e0e0e0;
    --text-secondary: #a0b0d0;
    --border-color: #30416b;
    --accent-color: #64ffda;
}

body {
    font-family: Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-size: 16px; /* Base font size for TV */
    transition: background-color 0.3s, color 0.3s;
}

#app-wrapper {
    max-width: 1400px; /* Max width for wide TVs */
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#content-container {
    flex-grow: 1;
}

a {
    color: var(--accent-color);
    text-decoration: none;
}

img {
    max-width: 100%;
    height: auto;
}

/* --- API Key Modal --- */
#auth-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#auth-modal.visible {
    display: flex;
}

/* Close button for modal (for guests who opened it manually) */
.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
}
.modal-close:hover {
    color: var(--accent-color);
}

.modal-content {
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    width: 90%;
    max-width: 400px;
    position: relative; /* For close button positioning */
}

.modal-content h2 {
    margin-bottom: 1rem;
}

.modal-content p {
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.modal-content input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 1rem;
}

/* --- Header --- */
#app-header {
    background: var(--bg-panel);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; /* For small screens */
    gap: 0.5rem;
}

#app-header h1 {
    font-size: 1.5rem;
    flex-basis: 100%; /* Full width on small screens */
    text-align: center;
    margin-bottom: 0.5rem;
}

.date-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.date-nav button,
.styled-button { /* NEW: Reusable button class */
    background: var(--bg-element);
    color: var(--text-primary);
    border: none;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
}

.styled-button:hover {
    filter: brightness(1.1);
}

#current-date {
    font-size: 1.1rem;
    font-weight: bold;
    min-width: 100px;
    text-align: center;
}

.live-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
}

/* NEW: Header Username */
.header-username {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--text-secondary);
    flex-basis: 100%;
    text-align: right;
    order: -1; /* Move to top on mobile */
    padding: 0 0.5rem;
}

@media (min-width: 768px) {
    .header-username {
        flex-basis: auto;
        order: 0; /* Reset order */
        text-align: left;
    }
    #app-header h1 {
        flex-basis: auto;
        order: 0;
    }
}

.switch-toggle {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}
.switch-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-element);
    -webkit-transition: .4s;
    transition: .4s;
    border-radius: 34px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    -webkit-transition: .4s;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: var(--accent-color);
}
input:focus + .slider {
    box-shadow: 0 0 1px var(--accent-color);
}
input:checked + .slider:before {
    -webkit-transform: translateX(22px);
    -ms-transform: translateX(22px);
    transform: translateX(22px);
}

/* --- Main Content --- */
#content-container {
    padding: 1rem;
}

.page-title {
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
    /* NEW: For fav button */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.loader {
    text-align: center;
    font-size: 1.5rem;
    padding: 3rem;
}

.error-message {
    background: #5a1d1d;
    color: white;
    padding: 1rem;
    border-radius: 4px;
    text-align: center;
}

/* --- Home Page (Matches) --- */
.league-group {
    margin-bottom: 2rem;
}

.league-header {
    font-size: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.league-header-link {
    font-size: 1.5rem;
    color: var(--text-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.75rem; 
    flex-grow: 1;
    overflow: hidden;
    white-space: nowrap;
}

.league-header-link:hover {
    color: var(--accent-color);
}

.league-header-link span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.league-header-logo {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.matches-container {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem; /* Space between cards */
}

/* --- UPDATED MATCH CARD LAYOUT --- */
.match-card {
    background-color: var(--bg-panel);
    border-radius: 8px;
    padding: 1rem;
    text-decoration: none;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-basis: 400px;
    align-items: center;
    text-align: center;
    border: 2px solid transparent; 
}

.match-card.is-live {
    border-color: var(--accent-color);
}

.match-league {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    width: 100%;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.match-league img {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.match-league span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


@media (max-width: 600px) {
    .match-card {
        flex-basis: 100%; /* Full width on mobile */
    }
}

.match-status {
    text-align: center;
    font-size: 1rem;
    color: var(--accent-color);
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.match-status.not-started {
    color: var(--text-secondary);
    font-weight: normal;
    font-size: 0.9rem;
}

/* New Layout: Side by Side Teams */
.match-teams {
    display: flex;
    flex-direction: row; /* Horizontal alignment */
    justify-content: space-between;
    align-items: flex-start; /* Align tops */
    gap: 0.5rem;
    width: 100%;
}

.team {
    display: flex;
    flex-direction: column; /* Vertical stack inside team */
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    gap: 0.5rem; 
    flex: 1; /* Equal width */
    width: 40%;
}

.team img {
    width: 60px; /* Big Logo */
    height: 60px;
    object-fit: contain;
}

.team-info-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    width: 100%;
}

.team-name {
    font-size: 0.95rem; 
    font-weight: bold;
    line-height: 1.2;
    overflow: hidden;
    /* Allow multi-line for names under big logos */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.team-name.team-link {
    cursor: pointer;
}
.team-name.team-link:hover {
    text-decoration: underline;
    color: var(--accent-color);
}

.score-container {
    font-size: 1.8rem; /* Larger Score */
    font-weight: bold;
    text-align: center;
    min-width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px; /* Match logo height approximately */
    color: var(--text-primary);
}

.fav-toggle {
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
    flex-shrink: 0;
    color: var(--text-secondary);
}
.fav-toggle:hover {
    color: var(--accent-color);
}

/* --- League Page & Match Page Tabs --- */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
}

.tab-button {
    padding: 0.75rem 1rem;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: bold;
    border-bottom: 3px solid transparent;
}

.tab-button.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.standings-table {
    width: 100%;
    border-collapse: collapse;
}

.standings-table th,
.standings-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.standings-table th {
    background: var(--bg-panel);
    font-size: 0.8rem;
    text-transform: uppercase;
}

.standings-table td.rank {
    font-weight: bold;
    width: 30px;
}

.standings-table td.team-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.standings-table img {
    width: 24px;
    height: 24px;
}

.group-title {
    font-size: 1.3rem;
    color: var(--accent-color);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.stats-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-panel);
    padding: 0.75rem;
    border-radius: 4px;
}

.stat-item .rank {
    font-size: 1.2rem;
    font-weight: bold;
    width: 30px;
}

.stat-item img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
}

.stat-item-info {
    flex-grow: 1;
}

.stat-item-player {
    font-weight: bold;
}

.stat-item-team {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.stat-item-value {
    font-size: 1.2rem;
    font-weight: bold;
}

/* NEW: Filters for Matches Tab */
.filters-container {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-select {
    padding: 0.5rem;
    background: var(--bg-element);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    flex-grow: 1;
    min-width: 150px;
}

/* --- Match Details Page --- */
.match-details-header {
    text-align: center;
    background: var(--bg-panel);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.match-details-header .league {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.match-details-teams {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}

.match-details-team {
    width: 35%;
    text-align: center;
}

.match-details-team img {
    width: 60px;
    height: 60px;
    margin-bottom: 0.5rem;
}

.match-details-team h2 {
    font-size: 1.2rem;
}

.match-details-score {
    font-size: 2.5rem;
    font-weight: bold;
}

.match-details-status {
    font-size: 1rem;
    color: var(--accent-color);
    margin-top: 0.5rem;
}

.live-track-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--bg-panel);
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: 1rem;
}

.match-details-info {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}

.match-events {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.event-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
}

.event-item.away-event {
    flex-direction: row-reverse;
    text-align: right;
}

.event-time {
    font-weight: bold;
    width: 40px;
}

.event-icon {
    font-size: 1rem;
}

.event-player {
    font-weight: bold;
}

.event-detail {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* NEW: Statistics Tab */
.stats-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.stat-row {
    display: flex;
    align-items: center;
    font-size: 1.1rem;
    background: var(--bg-panel);
    border-radius: 4px;
    overflow: hidden;
}
.stat-value {
    padding: 0.75rem;
    font-weight: bold;
    width: 80px;
    text-align: center;
}
.stat-name {
    flex-grow: 1;
    text-align: center;
    font-weight: bold;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* NEW: Lineup Tab */
.lineup-container {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap; /* For small screens */
}
.lineup-team {
    flex: 1;
    min-width: 250px;
    background: var(--bg-panel);
    padding: 1rem;
    border-radius: 8px;
}
.lineup-team h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}
.lineup-team img {
    width: 30px;
    height: 30px;
}
.lineup-info {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}
.lineup-list {
    list-style: none;
    padding: 0;
}
.lineup-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}
.lineup-list li:last-child {
    border-bottom: none;
}
.lineup-list .player-number {
    display: inline-block;
    width: 30px;
    font-weight: bold;
    color: var(--text-secondary);
}
.lineup-list-title {
    font-weight: bold;
    color: var(--accent-color);
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}


.h2h-container h3 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    text-align: center;
}


/* --- Team Page --- */
.team-info-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: var(--bg-panel);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.team-info-header img {
    width: 80px;
    height: 80px;
}

.team-info-details h2 {
    font-size: 1.8rem;
    display: flex; /* For fav button */
    align-items: center;
    gap: 0.5rem;
}

.team-info-details p {
    font-size: 1rem;
    color: var(--text-secondary);
}

/* --- Footer --- */
#app-footer {
    text-align: center;
    padding: 1.5rem 1rem;
    margin-top: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    align-items: center;
}

#btn-auth-action,
#reset-settings-btn,
#update-settings-btn,
#theme-select {
    /* Use the reusable class */
    background: var(--bg-element);
    color: var(--text-primary);
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: bold;
}

#theme-select {
    padding-right: 1.5rem; /* For select arrow */
}

/* --- Theme Overrides (NEW & DEEPER) --- */

/* Dark Red Theme */
.theme-dark-red {
    --bg-body: #1a0b0b;
    --bg-panel: #2b1111;
    --bg-element: #4a1c1c;
    --text-primary: #f0e0e0;
    --text-secondary: #c0a0a0;
    --border-color: #4a1c1c;
    --accent-color: #ff6464;
}

/* Darky Dark Theme */
.theme-darky-dark {
    --bg-body: #121212;
    --bg-panel: #1e1e1e;
    --bg-element: #333333;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #333333;
    --accent-color: #bb86fc;
}

/* Light Theme */
.theme-light {
    --bg-body: #f0f2f5;
    --bg-panel: #ffffff;
    --bg-element: #e4e6eb;
    --text-primary: #1c1e21;
    --text-secondary: #65676b;
    --border-color: #dddfe2;
    --accent-color: #006aff;
}

/* --- NEW THEMES --- */

/* Morocco (Dark) */
.theme-morocco {
    --bg-body: #002a16; /* Dark Green */
    --bg-panel: #003f22;
    --bg-element: #005a31;
    --text-primary: #f0f0f0;
    --text-secondary: #b0b0b0;
    --border-color: #005a31;
    --accent-color: #C1272D; /* Red */
}

/* Morocco Away (Light) */
.theme-morocco-away {
    --bg-body: #f0f2f5;
    --bg-panel: #ffffff;
    --bg-element: #e4e6eb;
    --text-primary: #1c1e21;
    --text-secondary: #65676b;
    --border-color: #dddfe2;
    --accent-color: #006233; /* Green */
}

/* USK (Dark) */
.theme-usk {
    --bg-body: #1a0b0b; /* Dark Red */
    --bg-panel: #2b1111;
    --bg-element: #4a1c1c;
    --text-primary: #f0e0e0;
    --text-secondary: #c0a0a0;
    --border-color: #4a1c1c;
    --accent-color: #FFFFFF; /* White */
}

/* Raja (Dark) */
.theme-raja {
    --bg-body: #002a16; /* Dark Green */
    --bg-panel: #003f22;
    --bg-element: #005a31;
    --text-primary: #FFFFFF;
    --text-secondary: #c0c0c0;
    --border-color: #005a31;
    --accent-color: #FFFFFF; /* White */
}


.theme-light .match-card,
.theme-light .modal-content,
.theme-light .standings-table th,
.theme-light .stat-item,
.theme-light .match-details-header,
.theme-light .team-info-header,
.theme-light .lineup-team, /* NEW */
.theme-light .stat-row, /* NEW */
.theme-light .filter-select /* NEW */
{
    border: 1px solid var(--border-color);
}

.theme-light .match-card.is-live {
     border: 2px solid var(--accent-color);
}