.topbar {
    grid-template-columns: auto minmax(280px, 1fr) auto;
}

.view-switch,
.ranking-tabs {
    display: flex;
    gap: 4px;
}

.view-switch {
    height: 42px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.view-switch button,
.ranking-tabs button {
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.view-switch button {
    padding: 0 12px;
}

.view-switch button:hover,
.ranking-tabs button:hover {
    color: var(--text);
    background: var(--soft);
}

.view-switch button.is-active,
.ranking-tabs button.is-active {
    border-color: var(--text);
    background: var(--text);
    color: #ffffff;
}

.ranking-mode .topbar {
    grid-template-columns: max-content;
}

.ranking-mode .search-box,
.ranking-mode .topbar-actions,
.ranking-mode #catalogView,
.catalog-mode .ranking-workspace {
    display: none;
}

.ranking-workspace {
    display: grid;
    gap: 12px;
}

.ranking-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 20px;
    align-items: end;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.ranking-head h2 {
    margin: 5px 0 7px;
    font-size: 24px;
    letter-spacing: 0;
}

.ranking-head p,
.ranking-health span {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.ranking-health {
    display: grid;
    gap: 5px;
    max-width: 360px;
    text-align: right;
}

.ranking-health strong,
.rank-number strong,
.rank-score strong {
    font-family: "Geist Mono", "JetBrains Mono", Consolas, monospace;
}

.ranking-tabs {
    overflow-x: auto;
    padding-bottom: 2px;
}

.ranking-tabs button {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 0 11px;
    border-color: var(--line);
    background: var(--panel);
}

.ranking-tabs button span {
    margin-left: 5px;
    font-family: "Geist Mono", "JetBrains Mono", Consolas, monospace;
    font-weight: 500;
}

.ranking-list {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.ranking-row {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr) 104px;
    gap: 14px;
    align-items: center;
    min-height: 98px;
    padding: 13px 15px;
    border-bottom: 1px solid var(--line);
    transition: background 140ms ease, transform 140ms ease;
}

.ranking-row:last-child {
    border-bottom: 0;
}

.ranking-row:hover {
    position: relative;
    z-index: 1;
    background: var(--soft);
    transform: translateY(-1px);
}

.rank-number,
.rank-score {
    display: grid;
    gap: 4px;
}

.rank-number {
    align-content: center;
    min-height: 62px;
    padding-right: 12px;
    border-right: 1px solid var(--line);
}

.rank-number strong {
    font-size: 26px;
    line-height: 1;
}

.rank-move {
    color: var(--muted);
    font-size: 11px;
}

.rank-copy {
    min-width: 0;
}

.rank-title-line {
    display: flex;
    gap: 9px;
    align-items: center;
    min-width: 0;
}

.rank-title-line h3 {
    overflow: hidden;
    margin: 0;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rank-title-line span {
    flex: 0 0 auto;
    color: var(--faint);
    font-size: 10px;
}

.rank-copy p {
    margin: 6px 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.55;
}

.rank-copy small {
    color: var(--faint);
    font-size: 10px;
}

.rank-score {
    justify-items: end;
    text-align: right;
}

.rank-score strong {
    font-size: 20px;
}

.rank-score span {
    color: var(--faint);
    font-size: 10px;
}

.rank-score a {
    color: var(--text);
    font-size: 11px;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.ranking-empty {
    margin: 0;
    padding: 24px;
    color: var(--muted);
    text-align: center;
}

@media (max-width: 1080px) {
    .catalog-mode .topbar {
        grid-template-columns: minmax(0, 1fr);
    }

    .view-switch {
        width: max-content;
    }
}

@media (max-width: 680px) {
    .ranking-mode .sidebar {
        gap: 0;
        padding: 14px;
    }

    .ranking-mode .sidebar .side-section,
    .ranking-mode .sidebar-footer {
        display: none;
    }

    .ranking-mode .brand {
        padding-bottom: 0;
        border-bottom: 0;
    }

    .ranking-head {
        grid-template-columns: minmax(0, 1fr);
        align-items: start;
    }

    .ranking-health {
        max-width: none;
        text-align: left;
    }

    .ranking-row {
        grid-template-columns: 56px minmax(0, 1fr);
        gap: 11px;
    }

    .rank-number {
        padding-right: 9px;
    }

    .rank-score {
        grid-column: 2;
        grid-template-columns: auto auto 1fr;
        justify-items: start;
        align-items: baseline;
        text-align: left;
    }

    .rank-score a {
        justify-self: end;
    }
}

@media (max-width: 420px) {
    .view-switch {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
    }

    .ranking-head h2 {
        font-size: 20px;
    }

    .ranking-row {
        padding: 12px 10px;
    }

    .rank-title-line {
        display: grid;
        gap: 3px;
    }

    .rank-title-line h3 {
        white-space: normal;
        overflow-wrap: anywhere;
    }
}
