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

:root {
    --bg:          #0d1117;
    --bg-card:     #161b22;
    --bg-panel:    #1c2128;
    --bg-hover:    #2d333b;
    --accent:      #e05a28;
    --accent-dim:  rgba(224, 90, 40, 0.12);
    --accent-glow: rgba(224, 90, 40, 0.3);
    --text:        #e6edf3;
    --text-muted:  #7d8590;
    --border:      #30363d;
    --border-lite: #21262d;
    --win:         #3fb950;
    --loss:        #8b949e;
    --radius:      8px;
    --ease:        0.18s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
                 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    font-size: 14px;
}

/* ==================== Header ==================== */
.site-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    height: 58px;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.82rem;
    white-space: nowrap;
    transition: color var(--ease);
    flex-shrink: 0;
}
.back-link:hover { color: var(--text); }

.header-title { flex: 1; min-width: 0; }
.header-title h1 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.header-title .subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Language switcher */
.language-select {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    padding: 4px 24px 4px 9px;
    font-size: 0.78rem;
    cursor: pointer;
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%237d8590' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
    flex-shrink: 0;
    transition: border-color var(--ease), color var(--ease);
}
.language-select:hover {
    border-color: var(--text-muted);
    color: var(--text);
}
.language-select:focus {
    border-color: var(--accent);
    color: var(--text);
}
.language-select option {
    background: var(--bg-card);
    color: var(--text);
}

/* Mobile panel toggle */
.panel-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 5px 11px;
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color var(--ease);
    flex-shrink: 0;
}
.panel-toggle:hover { border-color: var(--accent); }

.fav-badge {
    background: var(--accent);
    color: #fff;
    border-radius: 100px;
    padding: 1px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 18px;
    text-align: center;
    transition: background var(--ease);
}

/* ==================== Page Layout ==================== */
.page-wrap {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.layout {
    flex: 1;
    display: flex;
    max-width: 1440px;
    margin: 0 auto;
    width: 100%;
    padding: 20px 16px;
    gap: 18px;
    align-items: flex-start;
}

/* ==================== Team Panel ==================== */
.team-panel {
    width: 256px;
    flex-shrink: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 78px;
    /* panel itself does NOT scroll — team-grid does */
    max-height: calc(100vh - 98px);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
}

.fav-count { color: var(--text-muted); font-weight: 400; }

.clear-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.72rem;
    padding: 2px 7px;
    cursor: pointer;
    transition: all var(--ease);
}
.clear-btn:hover { border-color: #f85149; color: #f85149; }

/* team-grid is the ONLY scroll container for the panel */
.team-grid {
    flex: 1;
    min-height: 0;      /* critical: lets flex child shrink below content height */
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.team-grid::-webkit-scrollbar { width: 4px; }
.team-grid::-webkit-scrollbar-track { background: transparent; }
.team-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ---- Accordion sections ---- */
.panel-section {
    border: 1px solid var(--border-lite);
    border-radius: 6px;
    background: var(--bg-panel);
    /* no overflow:hidden here — would clip nothing anyway */
}

.section-hdr {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    text-align: left;
    border-radius: 6px;
}

.section-hdr:hover { background: var(--bg-hover); }

/* when section is open, bottom corners are squared to meet the body */
.section-hdr.is-open {
    border-bottom: 1px solid var(--border-lite);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.section-hdr-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.section-hdr-count {
    color: var(--text-muted);
    font-weight: 400;
    flex-shrink: 0;
}

.section-hdr-chevron {
    color: var(--text-muted);
    flex-shrink: 0;
    font-size: 0.7rem;
    width: 14px;
    text-align: right;
}

.section-body {
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    align-content: start;
}

.section-empty {
    grid-column: 1 / -1;
    margin: 0;
}

.teams-loading {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 24px 8px;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.no-data {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    padding: 24px 8px;
    font-size: 0.82rem;
}

/* Team card */
.team-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    padding: 10px 8px 8px;
    min-height: 96px;
    border: 1px solid var(--border-lite);
    border-radius: 6px;
    background: var(--bg-panel);
    cursor: pointer;
    transition: all var(--ease);
    text-align: center;
    width: 100%;
    position: relative;
}

.team-card:hover {
    border-color: var(--accent);
    background: var(--accent-dim);
}

.team-card.selected {
    border-color: var(--accent);
    background: var(--accent-dim);
    box-shadow: inset 0 0 0 1px var(--accent-glow);
}

.team-card.selected::after {
    content: '✓';
    position: absolute;
    top: 3px;
    right: 4px;
    font-size: 0.6rem;
    color: var(--accent);
    line-height: 1;
}

.team-logo {
    width: 40px;
    height: 40px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.team-logo img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    display: block;
}

.team-initials {
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: 800;
    color: var(--text-muted);
    background: var(--bg-hover);
    border-radius: 4px;
    letter-spacing: 0.03em;
}

.team-name {
    display: block;
    width: 100%;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text);
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    padding: 0 4px;
}

/* ==================== Matches Area ==================== */
.matches-area {
    flex: 1;
    min-width: 0;
}

.matches-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

/* Tabs */
.tabs {
    display: flex;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3px;
    gap: 2px;
}

.tab-btn {
    padding: 5px 16px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--ease);
}

.tab-btn.active {
    background: var(--bg-panel);
    color: var(--text);
}

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

/* Favorites filter */
.fav-filter-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 13px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all var(--ease);
}

.fav-filter-btn:hover { border-color: var(--accent); color: var(--accent); }

.fav-filter-btn.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

.fav-filter-btn.active svg { fill: var(--accent); stroke: var(--accent); }

/* Right side of toolbar: filter + HLTV links */
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hltv-links {
    display: flex;
    align-items: center;
    gap: 4px;
}

.hltv-global-link {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 11px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--ease);
    white-space: nowrap;
}

.hltv-global-link:hover {
    border-color: #f5a623;
    color: #f5a623;
}

/* ==================== State messages ==================== */
.state-msg {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 72px 20px;
    color: var(--text-muted);
    text-align: center;
    font-size: 0.875rem;
}

.error-state { color: #f85149; }

.spinner {
    width: 30px;
    height: 30px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.mini-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.retry-btn {
    padding: 7px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font-size: 0.82rem;
    transition: all var(--ease);
}
.retry-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ==================== Match List ==================== */
.no-matches {
    text-align: center;
    color: var(--text-muted);
    padding: 60px 20px;
    font-size: 0.875rem;
}

.date-group { margin-bottom: 24px; }

.date-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    padding: 0 4px 7px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

/* ==================== Match Card ==================== */
.match-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 7px;
    overflow: hidden;
    transition: border-color var(--ease);
}

.match-card:hover { border-color: #444c56; }

.match-card.is-fav { border-left: 2px solid var(--accent); }

/* Match header row */
.match-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 10px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-lite);
    gap: 8px;
}

.match-event {
    font-size: 0.72rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.match-meta-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.match-bo {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-hover);
    padding: 1px 5px;
    border-radius: 3px;
}

.match-time {
    font-size: 0.72rem;
    color: var(--accent);
    font-weight: 600;
}

/* Match teams row */
.match-teams {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    gap: 6px;
}

.match-team {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.match-team.team-r {
    flex-direction: row-reverse;
    text-align: right;
}

.match-team.won .team-n { color: var(--win); font-weight: 600; }
.match-team.lost .team-n { color: var(--loss); }

/* Team logo in match card */
.t-logo {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.t-logo img {
    width: 30px;
    height: 30px;
    object-fit: contain;
}

.t-logo.placeholder {
    background: var(--bg-hover);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 700;
}

.t-init {
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    font-size: 0.58rem;
    font-weight: 800;
    color: var(--text-muted);
    background: var(--bg-hover);
    border-radius: 4px;
    letter-spacing: 0.03em;
}

.team-n {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Center: score or vs */
.match-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    width: 80px;
    gap: 3px;
}

.vs-sep {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.score-display {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.12em;
    font-variant-numeric: tabular-nums;
}

.result-time {
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* ==================== Live match styles ==================== */
.live-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #f85149;
}

.live-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #f85149;
    flex-shrink: 0;
    animation: pulse-dot 1.4s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.4; transform: scale(0.7); }
}

.live-pill {
    font-size: 0.65rem;
    font-weight: 700;
    color: #f85149;
    letter-spacing: 0.04em;
    animation: pulse-dot 1.4s ease-in-out infinite;
}

.live-badge {
    font-size: 0.65rem;
    font-weight: 700;
    color: #f85149;
    letter-spacing: 0.05em;
}

.match-card.is-live {
    border-color: rgba(248, 81, 73, 0.35);
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(248, 81, 73, 0.04) 100%);
}

.match-card.is-live:hover { border-color: rgba(248, 81, 73, 0.6); }

/* ==================== Event filter bar ==================== */
.event-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.event-filter-bar::-webkit-scrollbar { height: 3px; }
.event-filter-bar::-webkit-scrollbar-track { background: transparent; }
.event-filter-bar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.event-chip {
    padding: 3px 11px;
    border: 1px solid var(--border);
    border-radius: 100px;
    background: var(--bg-panel);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--ease);
    flex-shrink: 0;
}

.event-chip:hover {
    border-color: var(--accent);
    color: var(--text);
}

.event-chip.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

/* ==================== Timezone select ==================== */
.tz-select {
    appearance: none;
    background: var(--bg-card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%237d8590'/%3E%3C/svg%3E") no-repeat right 8px center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.78rem;
    padding: 5px 26px 5px 10px;
    cursor: pointer;
    transition: all var(--ease);
    white-space: nowrap;
    flex-shrink: 0;
}

.tz-select:hover { border-color: var(--accent); color: var(--text); }
.tz-select:focus { outline: none; border-color: var(--accent); }
.tz-select option { background: #1c2128; color: var(--text); }

/* ==================== Countdown ==================== */
.match-countdown {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

/* ==================== Fav team name highlight ==================== */
.team-n.is-fav-team {
    color: var(--accent);
    font-weight: 600;
}


/* ==================== Footer ==================== */
footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 14px 20px;
    color: var(--text-muted);
}

/* ==================== Responsive ==================== */
@media (max-width: 860px) {
    .panel-toggle { display: flex; }

    .layout {
        flex-direction: column;
        padding: 12px;
        gap: 12px;
    }

    .team-panel {
        width: 100%;
        position: relative;
        top: auto;
        max-height: 0;
        overflow: hidden;
        border: none;
        transition: max-height 0.3s ease, border var(--ease);
    }

    .team-panel.open {
        max-height: 320px;
        border: 1px solid var(--border);
        overflow: hidden; /* team-grid inside handles scroll */
    }

    .section-body {
        grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    }
}

@media (max-width: 480px) {
    .header-inner { height: 52px; }
    .header-title .subtitle { display: none; }
    .matches-toolbar { gap: 6px; }

    .toolbar-right { gap: 5px; }
    .fav-filter-btn span { display: none; }
    .fav-filter-btn { padding: 6px 10px; }
    .hltv-global-link span { display: none; }
    .hltv-global-link { padding: 6px 8px; }

    .match-center { width: 58px; }
    .score-display { font-size: 0.9rem; }
    .team-n { font-size: 0.8rem; }

    .t-logo { width: 26px; height: 26px; }
    .t-logo img { width: 26px; height: 26px; }
}
