/* =============================================================================
   MAIN — Core layout, cards, badges, match feed
   Reference: DESIGN_REVAMP.md § 6, § 8
   ============================================================================= */

@import 'variables.css';
@import 'reset.css';
@import 'typography.css';
@import 'skeleton.css';
@import 'buttons.css';
@import 'header.css';
@import 'footer.css';

/* =============================================================================
   PAGE LAYOUT
   ============================================================================= */

.page-wrapper {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 var(--space-6);
}

.page-header {
    padding: var(--space-10) 0 var(--space-8);
}

.page-header .label {
    display: block;
    margin-bottom: var(--space-2);
}

.page-header h1 {
    margin-bottom: var(--space-2);
}

.page-header p {
    color: var(--color-text-secondary);
    font-size: var(--text-callout);
    margin-bottom: 0;
}

/* Three-column layout grid */
.layout-grid {
    display: grid;
    grid-template-columns: 260px 1fr 260px;
    gap: var(--space-8);
    align-items: start;
}

@media (max-width: 1100px) {
    .layout-grid {
        grid-template-columns: 240px 1fr;
    }
    .layout-grid > *:last-child {
        display: none;
    }
}

@media (max-width: 768px) {
    .layout-grid {
        grid-template-columns: 1fr;
    }
    .layout-grid > *:nth-child(3) {
        display: none;
    }

    .page-wrapper {
        padding: 0 var(--space-4);
    }

}

/* =============================================================================
   CARD SYSTEM
   ============================================================================= */

.card {
    background-color: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow var(--duration-fast) var(--ease-decel),
                transform var(--duration-fast) var(--ease-decel);
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* Card with no hover lift (static display cards) */
.card--static:hover {
    box-shadow: var(--shadow-sm);
    transform: none;
}

/* Card anatomy */
.card-label {
    font-size: var(--text-caption);
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    color: var(--color-text-secondary);
    display: block;
    margin-bottom: var(--space-1);
}

.card-header {
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--color-separator);
    font-weight: var(--weight-semibold);
    font-size: var(--text-subhead);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
    color: var(--color-text-secondary);
}

.card-body {
    padding: var(--space-6);
}

.card-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--color-separator);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Stat card: large number + label */
.stat-card {
    padding: var(--space-6);
    text-align: center;
}

.stat-card .stat-number {
    font-size: var(--text-title-1);
    font-weight: var(--weight-bold);
    letter-spacing: var(--tracking-title);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    margin-bottom: var(--space-1);
}

.stat-card .stat-label {
    font-size: var(--text-caption);
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

/* =============================================================================
   BADGE / TAG SYSTEM
   ============================================================================= */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-2);
    border-radius: var(--radius-xs);
    font-size: var(--text-caption);
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    line-height: 1.4;
    white-space: nowrap;
}

.badge-live {
    background: var(--color-live);
    color: #ffffff;
}

.badge-win {
    background: rgba(52, 199, 89, 0.14);
    color: var(--color-win);
    border: 1px solid rgba(52, 199, 89, 0.25);
}

.badge-loss {
    background: rgba(255, 59, 48, 0.10);
    color: var(--color-loss);
    border: 1px solid rgba(255, 59, 48, 0.20);
}

.badge-neutral {
    background: var(--color-bg-inset);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-separator);
}

.badge-accent {
    background: rgba(var(--color-accent-rgb), 0.10);
    color: var(--color-accent);
    border: 1px solid rgba(var(--color-accent-rgb), 0.20);
}

/* =============================================================================
   SIDEBAR LIST (tournament/section nav lists)
   ============================================================================= */

.tournament-list li {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-separator);
    font-size: var(--text-subhead);
    font-weight: var(--weight-medium);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    color: var(--color-text-primary);
    transition: background-color var(--duration-fast) var(--ease-decel);
}

.tournament-list li:last-child {
    border-bottom: none;
}

.tournament-list li:hover {
    background-color: var(--color-bg-inset);
}

.tournament-icon {
    width: 24px;
    height: 24px;
    background-color: var(--color-bg-inset);
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

/* =============================================================================
   DATE DIVIDER
   ============================================================================= */

.date-divider {
    margin: var(--space-6) 0 var(--space-3);
    font-size: var(--text-caption);
    font-weight: var(--weight-semibold);
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
}

/* =============================================================================
   MATCH CARD (homepage feed)
   ============================================================================= */

.match-card {
    background-color: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: transform var(--duration-fast) var(--ease-decel),
                box-shadow var(--duration-fast) var(--ease-decel);
    text-decoration: none;
    color: inherit;
}

.match-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.match-time {
    width: 56px;
    font-size: var(--text-footnote);
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
    text-align: center;
    flex-shrink: 0;
}

.match-time.live {
    color: var(--color-live);
    font-weight: var(--weight-bold);
}

.match-teams {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: 0 var(--space-5);
}

.team-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.team-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-subhead);
    font-weight: var(--weight-semibold);
}

.team-logo {
    width: 20px;
    height: 20px;
    background-color: var(--color-bg-inset);
    border-radius: var(--radius-xs);
    flex-shrink: 0;
    object-fit: contain;
}

.score {
    font-size: var(--text-subhead);
    font-weight: var(--weight-bold);
    font-variant-numeric: tabular-nums;
    width: 20px;
    text-align: right;
    color: var(--color-text-secondary);
}

.score.winner {
    color: var(--color-accent);
}

/* =============================================================================
   HOME MATCHES WIDGET (middle column)
   ============================================================================= */

.home-matches__group + .home-matches__group {
    border-top: 1px solid var(--color-separator);
}

.home-matches__date-label {
    padding: var(--space-2) var(--space-4);
    font-size: 10px;
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
    color: var(--color-text-tertiary);
    background: var(--color-bg-inset);
}

.home-match {
    display: block;
    padding: var(--space-3) var(--space-4);
    text-decoration: none;
    color: inherit;
    transition: background-color var(--duration-fast) var(--ease-standard);
}

.home-match:hover {
    background-color: rgba(128, 128, 128, 0.06);
}

.home-match + .home-match {
    border-top: 1px solid var(--color-separator);
}

.home-match__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-2);
}

.home-match__tournament {
    font-size: var(--text-caption);
    color: var(--color-text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.home-match__time {
    font-size: var(--text-caption);
    font-weight: var(--weight-medium);
    font-variant-numeric: tabular-nums;
    color: var(--color-text-secondary);
    flex-shrink: 0;
}

.home-match__teams {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.home-match__team {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
    min-width: 0;
}

.home-match__team--right {
    justify-content: flex-end;
    text-align: right;
}

.home-match__logo {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-xs);
    overflow: hidden;
    background: var(--color-bg-inset);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 10px;
    font-weight: var(--weight-bold);
    color: var(--color-text-tertiary);
}

.home-match__logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 1px;
}

.home-match__name {
    font-size: var(--text-subhead);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.home-match__score {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-subhead);
    font-weight: var(--weight-bold);
    font-variant-numeric: tabular-nums;
    color: var(--color-text-secondary);
    padding: 0 var(--space-3);
}

.home-match__score .winner {
    color: var(--color-accent);
}

.home-match__score-sep {
    color: var(--color-text-tertiary);
}

.home-match__vs {
    font-size: var(--text-caption);
    font-weight: var(--weight-medium);
    color: var(--color-text-tertiary);
    text-transform: uppercase;
}

/* =============================================================================
   NEWS SIDEBAR
   ============================================================================= */

.news-item {
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-separator);
}

.news-item:last-child {
    border-bottom: none;
}

.news-title {
    font-size: var(--text-subhead);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-1);
    line-height: var(--leading-snug);
}

.news-meta {
    font-size: var(--text-footnote);
    color: var(--color-text-secondary);
}

/* =============================================================================
   SECTION RHYTHM UTILITY
   ============================================================================= */

.section {
    padding: var(--space-12) 0;
}

.section + .section {
    padding-top: 0;
}

.section-header {
    margin-bottom: var(--space-8);
}

.section-header .label {
    display: block;
    margin-bottom: var(--space-2);
}

.section-header h2 {
    margin-bottom: var(--space-2);
}

.section-header p {
    color: var(--color-text-secondary);
    font-size: var(--text-callout);
    max-width: 60ch;
    margin-bottom: 0;
}

/* =============================================================================
   PAGE HERO (home / landing page)
   ============================================================================= */

/* Background Constellation Network */
.constellation-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 0; /* Behind content but above base background */
}

/* =============================================================================
   HOMEPAGE — Compact dashboard layout
   ============================================================================= */

.home-dashboard {
    max-width: 1440px;
    margin: 0 auto;
    padding: var(--space-6);
    position: relative;
    z-index: 1;
}

/* Top bar: branding left, stats right */
.home-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-5);
    border-bottom: 1px solid var(--color-separator);
}

.home-topbar__title {
    font-size: var(--text-title-3);
    font-weight: var(--weight-bold);
    letter-spacing: var(--tracking-title);
    color: var(--color-text-primary);
    margin: 0;
}

.home-topbar__sub {
    font-size: var(--text-footnote);
    color: var(--color-text-tertiary);
    margin: var(--space-1) 0 0;
}

.home-topbar__stats {
    display: flex;
    gap: var(--space-8);
}

.home-topbar__stat {
    text-align: center;
}

.home-topbar__stat-num {
    display: block;
    font-size: var(--text-title-3);
    font-weight: var(--weight-bold);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    color: var(--color-text-primary);
    margin-bottom: 2px;
}

.home-topbar__stat-label {
    font-size: 10px;
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    color: var(--color-text-tertiary);
}

/* 3-column grid: Left (tournaments) | Middle | Right (players + teams) */
.home-grid {
    display: grid;
    grid-template-columns: 3fr 5fr 3fr;
    gap: var(--space-5);
    align-items: start;
}

/* Column wrappers — each fills its grid cell, stacking widgets vertically */
.home-col {
    display: flex;
    flex-direction: column;
    gap: 0; /* individual widgets handle their own margin-top */
    min-width: 0;
}

/* Shared widget card */
.home-widget {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}


.home-widget__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-4) var(--space-3);
    border-top-left-radius: calc(var(--radius-md) - 1px);
    border-top-right-radius: calc(var(--radius-md) - 1px);
}

.home-widget__header h3 {
    font-size: var(--text-subhead);
    font-weight: var(--weight-semibold);
    margin: 0;
}

.home-widget__link {
    font-size: var(--text-caption);
    color: var(--color-accent);
    text-decoration: none;
    white-space: nowrap;
}

.home-widget__list {
    list-style: none;
    margin: 0;
    padding: 0;
    border-bottom-left-radius: calc(var(--radius-md) - 1px);
    border-bottom-right-radius: calc(var(--radius-md) - 1px);
}

.home-widget__empty {
    padding: var(--space-8) var(--space-4);
    text-align: center;
    color: var(--color-text-tertiary);
    font-size: var(--text-footnote);
}

/* --- Shared row height across all widgets --- */
.home-tourney-row,
.home-widget__row {
    min-height: 52px;
    box-sizing: border-box;
}

/* --- Tournament compact rows --- */
.home-tourney-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    text-decoration: none;
    color: inherit;
    transition: background-color var(--duration-fast) var(--ease-standard);
}

.home-tourney-row:hover {
    background-color: rgba(128, 128, 128, 0.06);
}

.home-tourney-row + .home-tourney-row {
    border-top: 1px solid var(--color-separator);
}

.home-tourney-row__logo {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--color-bg-inset);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: var(--text-caption);
    font-weight: var(--weight-bold);
    color: var(--color-text-tertiary);
}

.home-tourney-row__logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 2px;
}

.home-tourney-row__info {
    flex: 1;
    min-width: 0;
}

.home-tourney-row__name {
    display: block;
    font-size: var(--text-subhead);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.home-tourney-row__meta {
    display: block;
    font-size: var(--text-caption);
    color: var(--color-text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.home-tourney-row__badge {
    font-size: 10px;
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    padding: 2px var(--space-2);
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.home-tourney-row__badge--live      { background: var(--color-text-primary); color: var(--color-bg-elevated); }
.home-tourney-row__badge--completed { background: rgba(128, 128, 128, 0.12); color: var(--color-text-secondary); }
.home-tourney-row__badge--upcoming  { background: rgba(128, 128, 128, 0.08); color: var(--color-text-tertiary); }

/* --- Tournament group dropdown (season grouping) --- */
.home-tourney-group {
    position: relative;
    border-bottom: 1px solid var(--color-separator);
}

.home-tourney-group:last-child {
    border-bottom: none;
}

.home-tourney-row--category {
    cursor: pointer;
    user-select: none;
}

.home-tourney-group__main {
    position: relative;
}

.home-tourney-group__toggle {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--color-separator);
    border-radius: var(--radius-full);
    background: var(--color-bg-elevated);
    color: var(--color-text-tertiary);
    cursor: pointer;
    transition: color var(--duration-fast) var(--ease-standard);
}

.home-tourney-group__toggle:hover {
    color: var(--color-text-secondary);
}

.home-tourney-group__toggle svg {
    transition: transform var(--duration-fast) var(--ease-standard);
}

.home-tourney-group.is-expanded .home-tourney-group__toggle svg {
    transform: rotate(180deg);
}

.home-tourney-group__older {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--duration-moderate) var(--ease-standard);
}

.home-tourney-group.is-expanded .home-tourney-group__older {
    max-height: 500px;
}

.home-tourney-row--older {
    padding-left: calc(var(--space-4) + var(--space-6));
}

/* --- Ranking list rows (players & teams) --- */
.home-widget__row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    transition: background-color var(--duration-fast) var(--ease-standard);
}

.home-widget__row:hover {
    background-color: rgba(128, 128, 128, 0.06);
}

.home-widget__row + .home-widget__row {
    border-top: 1px solid var(--color-separator);
}

.home-widget__rank {
    font-size: var(--text-caption);
    font-weight: var(--weight-bold);
    color: var(--color-text-tertiary);
    min-width: 20px;
    font-variant-numeric: tabular-nums;
}

.home-widget__avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    overflow: hidden;
    background: var(--color-bg-inset);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: var(--text-caption);
    font-weight: var(--weight-bold);
    color: var(--color-text-tertiary);
}

.home-widget__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.home-widget__avatar--team {
    border-radius: var(--radius-sm);
}

.home-widget__avatar--team img {
    object-fit: contain;
    padding: 2px;
}

.home-widget__info {
    flex: 1;
    min-width: 0;
}

.home-widget__name {
    display: block;
    font-size: var(--text-subhead);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

a.home-widget__name:hover {
    color: var(--color-accent);
}

.home-widget__meta {
    display: block;
    font-size: var(--text-caption);
    color: var(--color-text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.home-widget__stats {
    text-align: right;
    flex-shrink: 0;
}

.home-widget__rating {
    display: block;
    font-size: var(--text-footnote);
    font-weight: var(--weight-bold);
    font-variant-numeric: tabular-nums;
    color: var(--color-text-primary);
    line-height: 1;
    margin-bottom: 2px;
}

.home-widget__mv {
    display: block;
    font-size: 10px;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-tertiary);
    line-height: 1;
}

/* ── Widget Tournament Nav (chevron arrows) ── */
.home-widget__nav {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.home-widget__nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-elevated);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: border-color var(--duration-fast) var(--ease-standard),
                color var(--duration-fast) var(--ease-standard);
    flex-shrink: 0;
}

.home-widget__nav-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.home-widget__nav-label {
    font-size: var(--text-caption);
    font-weight: var(--weight-semibold);
    color: var(--color-text-secondary);
    white-space: nowrap;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .home-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* Left column spans both columns on tablet */
    .home-col--left {
        grid-column: 1 / -1;
    }
}

@media (max-width: 768px) {
    .home-topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-4);
    }

    .home-topbar__stats {
        width: 100%;
        justify-content: space-between;
    }

    .home-grid {
        grid-template-columns: 1fr;
    }

    /* All columns stack on mobile */
    .home-col--left,
    .home-col--middle,
    .home-col--right {
        grid-column: auto;
    }

    .home-dashboard {
        padding: var(--space-4);
    }
}

/* =============================================================================
   SCROLL REVEAL (applied via IntersectionObserver in JS)
   ============================================================================= */

.reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity var(--duration-slow) var(--ease-decel),
                transform var(--duration-slow) var(--ease-decel);
}

.reveal.revealed {
    opacity: 1;
    transform: none;
}

@media (prefers-reduced-motion: reduce) {
    .reveal {
        opacity: 1;
        transform: none;
    }
}
