.sg-waterfall-page {
    --sg-wf-accent: var(--focus-color, #f3a90a);
    --sg-wf-text: var(--main-color, #252733);
    --sg-wf-muted: var(--muted-color, #7b8190);
    --sg-wf-border: var(--main-border-color, rgba(35, 40, 55, .1));
    --sg-wf-surface: var(--main-bg-color, #fff);
    align-items: flex-start;
}

.sg-waterfall-main {
    padding: 0;
    overflow: hidden;
}

.sg-waterfall-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    padding: 24px 26px 20px;
    border-bottom: 1px solid var(--sg-wf-border);
}

.sg-waterfall-header h1 i {
    margin-right: 5px;
    color: var(--sg-wf-accent);
    font-size: 20px;
    line-height: 1;
    vertical-align: middle;
}

.sg-waterfall-header h1 {
    margin: 0;
    color: var(--sg-wf-text);
    font-size: 25px;
    line-height: 1.25;
    display: flex;
    align-items: center;
}

.sg-waterfall-header-tools {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 14px;
}

.sg-waterfall-count {
    display: flex;
    align-items: center;
    gap: 5px;
    flex: 0 0 auto;
    color: var(--sg-wf-muted);
    font-size: 12px;
    line-height: 1;
}

.sg-waterfall-count strong {
    color: var(--sg-wf-accent);
    font-size: 22px;
    line-height: 1;
}

.sg-waterfall-count span {
    line-height: 1;
    padding-bottom: 2px;
}

.sg-waterfall-view-switch {
    display: inline-flex;
    overflow: hidden;
    border: 1px solid var(--sg-wf-border);
    border-radius: 6px;
    background: var(--muted-bg-2-color, #f6f7f8);
}

.sg-waterfall-view-button {
    display: inline-grid;
    width: 34px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 0;
    place-items: center;
    background: transparent;
    color: var(--sg-wf-muted);
    cursor: pointer;
    font-size: 13px;
    transition: color .2s ease, background-color .2s ease;
}

.sg-waterfall-view-button + .sg-waterfall-view-button {
    border-left: 1px solid var(--sg-wf-border);
}

.sg-waterfall-view-button:hover,
.sg-waterfall-view-button:focus-visible {
    color: var(--sg-wf-accent);
}

.sg-waterfall-view-button.is-active {
    background: var(--focus-color-opacity1, rgba(243, 169, 10, .1));
    color: var(--sg-wf-accent);
}

.sg-waterfall-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    padding: 20px;
}

.sg-waterfall-grid.is-single {
    grid-template-columns: minmax(0, 1fr);
}

.sg-waterfall-grid.is-single .sg-waterfall-card-content {
    grid-template-columns: minmax(220px, 44%) minmax(0, 1fr);
}

.sg-waterfall-card {
    display: block;
    min-width: 0;
    overflow: hidden;
    background: var(--sg-wf-surface);
    border: 1px solid var(--sg-wf-border);
    border-radius: 8px;
    box-shadow: 0 5px 18px rgba(30, 38, 60, .05);
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.sg-waterfall-card-content {
    display: grid;
    grid-template-columns: minmax(118px, 44%) minmax(0, 1fr);
    min-width: 0;
    align-items: stretch;
}

.sg-waterfall-grid.is-single .sg-waterfall-card-content {
    grid-template-columns: minmax(220px, 44%) minmax(0, 1fr);
}

/* 标题双位置：桌面显示在内容列内，窄视口切换到卡片顶部（按视口宽度，不依赖设备 UA） */
.sg-waterfall-title-top {
    display: none;
}

.sg-waterfall-meta-label .sg-waterfall-label-short {
    display: none;
}

.sg-waterfall-date-short {
    display: none;
}

@media (max-width: 767px) {
    .sg-waterfall-title-top {
        display: block;
        padding: 10px 12px 6px;
        margin: 0;
        border-bottom: 1px solid var(--sg-wf-border);
    }

    .sg-waterfall-title-inline {
        display: none;
    }

    .sg-waterfall-meta-label .sg-waterfall-label-long {
        display: none;
    }

    .sg-waterfall-meta-label .sg-waterfall-label-short {
        display: inline;
    }

    .sg-waterfall-date-long {
        display: none;
    }

    .sg-waterfall-date-short {
        display: inline;
    }

    .sg-waterfall-card .sg-waterfall-card-content {
        display: flex;
        flex-direction: row;
        grid-template-columns: none;
    }

    .sg-waterfall-card .sg-waterfall-thumb {
        flex: 0 0 42%;
        max-width: 42%;
    }
}

.sg-waterfall-card:hover {
    border-color: #f3a90a;
    box-shadow: 0 12px 28px rgba(30, 38, 60, .13);
    transform: translateY(-3px);
}

.sg-waterfall-thumb {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 188px;
    overflow: hidden;
    background: transparent;
}

.sg-waterfall-thumb img {
    display: block;
    width: auto !important;
    max-width: 100%;
    height: auto !important;
    max-height: 100%;
    min-height: 0;
    object-fit: contain !important;
    background: transparent;
}

.sg-waterfall-no-image {
    display: grid;
    min-height: 188px;
    place-items: center;
    color: var(--sg-wf-muted);
    font-size: 28px;
}

.sg-waterfall-card-body {
    display: flex;
    min-width: 0;
    flex-direction: column;
    padding: 15px 16px 12px;
}

.sg-waterfall-title {
    margin: 0 0 10px;
    font-size: 16px;
    line-height: 1.45;
}

.sg-waterfall-title a {
    display: -webkit-box;
    overflow: hidden;
    color: var(--sg-wf-text);
    text-decoration: none;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.sg-waterfall-title a:hover {
    color: var(--sg-wf-accent);
}

.sg-waterfall-meta {
    display: grid;
    gap: 4px;
    color: var(--sg-wf-muted);
    font-size: 12px;
    line-height: 1.35;
}

.sg-waterfall-meta-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 7px;
}

.sg-waterfall-meta-row b {
    overflow: hidden;
    color: var(--sg-wf-muted);
    font-weight: 400;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 移动端：比例和张数并排，幅面和大小并排 */
@media (max-width: 767px) {
    .sg-waterfall-meta {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 2px 14px;
    }

    .sg-waterfall-meta-row {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        gap: 4px;
        min-width: 0;
    }

    /* 名称和厂家占满一行 */
    .sg-waterfall-meta-row:not(.sg-waterfall-meta-row-pair-1):not(.sg-waterfall-meta-row-pair-2) {
        grid-column: 1 / -1;
    }

    /* 配对顺序：比例│张数、幅面│大小（源顺序保持 名称/厂家/比例/幅面/张数/大小） */
    .sg-waterfall-meta-row--scale {
        order: 1;
    }

    .sg-waterfall-meta-row--pages {
        order: 2;
    }

    .sg-waterfall-meta-row--format {
        order: 3;
    }

    .sg-waterfall-meta-row--size {
        order: 4;
    }

    /* 并排数据不换行，保证完整显示 */
    .sg-waterfall-meta-row b {
        white-space: nowrap;
    }
}

.sg-waterfall-category {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 10px;
    overflow: hidden;
    color: var(--sg-wf-accent);
    font-size: 12px;
    white-space: nowrap;
}

.sg-waterfall-category a {
    overflow: hidden;
    color: inherit;
    text-overflow: ellipsis;
    text-decoration: none;
}

.sg-waterfall-category a:hover {
    text-decoration: underline;
}

.sg-waterfall-category-separator {
    color: var(--sg-wf-muted);
}

.sg-waterfall-pay {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px 10px;
    margin-top: auto;
    padding-top: 12px;
}

.sg-waterfall-pay-price .price-box,
.sg-waterfall-pay-price .price-box > div {
    display: inline-flex;
    align-items: center;
}

.sg-waterfall-pay-price .em3x {
    color: #e09b00;
    font-size: 16px;
}

.sg-waterfall-pay-button .but {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12px;
    line-height: 1.25;
}

.sg-waterfall-pay[data-pay-state="download"] .sg-waterfall-pay-price {
    color: var(--sg-wf-accent);
    font-size: 12px;
}

.sg-waterfall-download-button i {
    margin-right: 4px;
}

.sg-waterfall-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 11px;
    padding-top: 9px;
    border-top: 1px solid var(--sg-wf-border);
    color: var(--sg-wf-muted);
    font-size: 11px;
}

.sg-waterfall-footer span,
.sg-waterfall-footer time {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sg-waterfall-footer i {
    margin-right: 4px;
}

/* 移动端：限制作者名称宽度，确保日期显示完整 */
@media (max-width: 767px) {
    .sg-waterfall-footer {
        gap: 6px;
    }

    .sg-waterfall-footer span {
        flex: 0 1 auto;
        max-width: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sg-waterfall-footer time {
        flex: 0 0 auto;
        white-space: nowrap;
    }
}

.sg-waterfall-status {
    display: flex;
    min-height: 0;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 20px;
    color: var(--sg-wf-muted);
    font-size: 12px;
}

.sg-waterfall-spinner {
    width: 13px;
    height: 13px;
    border: 2px solid rgba(243, 169, 10, .2);
    border-top-color: var(--sg-wf-accent);
    border-radius: 50%;
    animation: sg-waterfall-spin .8s linear infinite;
}

.sg-waterfall-pagination-wrap {
    padding: 2px 20px 20px;
}

.sg-waterfall-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 34px;
}

.sg-waterfall-page-button {
    display: inline-grid;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--sg-wf-border);
    border-radius: 5px;
    place-items: center;
    background: transparent;
    color: var(--sg-wf-muted);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    text-decoration: none;
    transition: color .2s ease, background-color .2s ease, border-color .2s ease;
}

.sg-waterfall-page-button:hover:not(:disabled),
.sg-waterfall-page-button:focus-visible {
    border-color: var(--sg-wf-accent);
    color: var(--sg-wf-accent);
}

.sg-waterfall-page-button.is-active {
    border-color: var(--sg-wf-accent);
    background: var(--sg-wf-accent);
    color: #fff;
}

.sg-waterfall-page-button.is-disabled {
    cursor: default;
    opacity: .4;
}

.sg-waterfall-page-ellipsis {
    color: var(--sg-wf-muted);
    font-size: 12px;
}

.sg-waterfall-page-jump {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: 5px;
    color: var(--sg-wf-muted);
    font-size: 12px;
    white-space: nowrap;
}

.sg-waterfall-page-jump label {
    display: none;
}

.sg-waterfall-page-jump input {
    width: 48px;
    height: 32px;
    padding: 4px 6px;
    border: 1px solid var(--sg-wf-border);
    border-radius: 5px;
    background: transparent;
    color: var(--sg-wf-text);
    font-size: 12px;
    text-align: center;
    -moz-appearance: textfield;
}

.sg-waterfall-page-jump input::-webkit-outer-spin-button,
.sg-waterfall-page-jump input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.sg-waterfall-page-jump input:focus {
    border-color: var(--sg-wf-accent);
    outline: 0;
}

.sg-waterfall-page-jump button {
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--sg-wf-accent);
    border-radius: 5px;
    background: var(--sg-wf-accent);
    color: #fff;
    cursor: pointer;
    font-size: 12px;
}

.sg-waterfall-page-jump button:hover,
.sg-waterfall-page-jump button:focus-visible {
    filter: brightness(.94);
}

.sg-waterfall-page-total {
    color: var(--sg-wf-muted);
}

.sg-waterfall-grid.is-loading,
.sg-waterfall-pagination-wrap.is-loading {
    opacity: .55;
    pointer-events: none;
    transition: opacity .2s ease;
}

.sg-waterfall-page > .sg-waterfall-sidebar {
    align-self: flex-start;
    position: sticky;
    top: 20px;
}

.dark-theme .sg-waterfall-card,
.is-dark .sg-waterfall-card,
html[data-theme="dark"] .sg-waterfall-card,
body.dark-mode .sg-waterfall-card {
    box-shadow: 0 5px 18px rgba(0, 0, 0, .16);
}

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

@media (min-width: 768px) {
    .sg-waterfall-grid.is-single .sg-waterfall-thumb,
    .sg-waterfall-grid.is-single .sg-waterfall-no-image {
        height: 300px;
        min-height: 300px;
    }

    .sg-waterfall-grid.is-single .sg-waterfall-thumb {
        width: 300px;
        height: 300px;
        background: transparent;
    }

    .sg-waterfall-grid.is-single .sg-waterfall-card-content {
        grid-template-columns: 300px minmax(0, 1fr);
        gap: 0;
    }
}

@media (max-width: 1199px) {
    .sg-waterfall-grid {
        gap: 15px;
        padding: 15px;
    }

    .sg-waterfall-card-content {
        grid-template-columns: minmax(100px, 42%) minmax(0, 1fr);
    }

    .sg-waterfall-grid.is-single .sg-waterfall-thumb,
    .sg-waterfall-grid.is-single .sg-waterfall-no-image {
        height: 260px;
        min-height: 260px;
    }

    .sg-waterfall-grid.is-single .sg-waterfall-thumb {
        width: 260px;
        height: 260px;
    }

    .sg-waterfall-grid.is-single .sg-waterfall-card-content {
        grid-template-columns: 260px minmax(0, 1fr);
        gap: 0;
    }
}

@media (max-width: 767px) {
    .sg-waterfall-page .content-wrap {
        width: 100%;
    }

    .sg-waterfall-main {
        border-radius: 6px;
    }

    .sg-waterfall-header {
        align-items: center;
        padding: 20px 18px 17px;
    }

    .sg-waterfall-header h1 {
        font-size: 21px;
    }

    .sg-waterfall-header-tools {
        align-self: stretch;
        justify-content: flex-end;
    }

    .sg-waterfall-view-switch,
    .sg-resource-mode .sg-waterfall-view-switch {
        display: none !important;
    }

    .sg-waterfall-count {
        margin-left: auto;
    }

    .sg-waterfall-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 14px;
        padding: 14px;
    }

    .sg-waterfall-card {
        grid-template-columns: 1fr;
    }

    .sg-waterfall-card .sg-waterfall-card-content {
        display: flex;
        flex-direction: row;
    }

    .sg-waterfall-card .sg-waterfall-thumb {
        flex: 0 0 42%;
        max-width: 42%;
        min-height: 0;
        height: auto;
        aspect-ratio: 1;
        overflow: hidden;
    }

    .sg-waterfall-card .sg-waterfall-thumb img {
        width: 100%;
        height: 100%;
        min-height: 0;
        object-fit: contain;
    }

    .sg-waterfall-card .sg-waterfall-card-body {
        flex: 1 1 0%;
        min-width: 0;
        overflow: hidden;
    }

    .sg-waterfall-no-image {
        min-height: 100px;
    }

    /* 移动端字号：标题单行；右侧文字与作者日期在原基础上再缩小 1px */
    .sg-waterfall-card .sg-waterfall-title {
        font-size: 13px;
        padding: 7px 10px 4px;
    }

    .sg-waterfall-card .sg-waterfall-title a {
        -webkit-line-clamp: 1;
    }

    .sg-waterfall-card .sg-waterfall-meta {
        font-size: 9px;
    }

    .sg-waterfall-card .sg-waterfall-meta-row {
        gap: 3px;
    }

    .sg-waterfall-card .sg-waterfall-meta-row span {
        font-size: 9px;
    }

    .sg-waterfall-card .sg-waterfall-meta-row b {
        font-size: 9px;
    }

    /* 移动端分类与子分类字号 */
    .sg-waterfall-card .sg-waterfall-category {
        font-size: 9px;
        gap: 3px;
        margin-top: 6px;
    }

    .sg-waterfall-card .sg-waterfall-category i {
        font-size: 9px;
    }

    /* 移动端作者与日期字号 */
    .sg-waterfall-card .sg-waterfall-footer {
        font-size: 9px;
        gap: 5px;
        margin-top: 6px;
        padding-top: 5px;
    }

    .sg-waterfall-card .sg-waterfall-footer i {
        font-size: 9px;
        margin-right: 2px;
    }

    .sg-waterfall-card .sg-waterfall-footer span {
        max-width: 70px;
    }

    .sg-waterfall-card .sg-waterfall-footer time {
        font-size: 9px;
    }

    .sg-waterfall-grid.is-single .sg-waterfall-card {
        grid-template-columns: minmax(0, 1fr);
    }

    .sg-waterfall-grid.is-single .sg-waterfall-card .sg-waterfall-card-content {
        display: flex;
        flex-direction: row;
    }

    .sg-waterfall-grid.is-single .sg-waterfall-card .sg-waterfall-thumb {
        flex: 0 0 42%;
        max-width: 42%;
        min-height: 0;
        height: auto;
    }

    .sg-waterfall-pagination-wrap {
        padding-right: 14px;
        padding-left: 14px;
    }

    .sg-waterfall-pagination {
        flex-wrap: nowrap;
        min-width: 0;
        gap: 4px;
    }

    .sg-waterfall-page-button {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }

    .sg-waterfall-page-jump {
        margin-left: 4px;
        gap: 3px;
    }

    .sg-waterfall-page-jump label,
    .sg-waterfall-page-jump .sg-waterfall-page-total {
        display: none;
    }

    .sg-waterfall-page-jump input {
        width: 40px;
        height: 28px;
        font-size: 11px;
    }

    .sg-waterfall-page-jump button {
        height: 28px;
        padding: 0 8px;
        font-size: 11px;
    }

    .sg-waterfall-card-body {
        padding: 10px 10px 8px;
    }

    .sg-waterfall-page > .sg-waterfall-sidebar {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sg-waterfall-card,
    .sg-waterfall-spinner {
        animation: none;
    }
}
