/* 动态谱背景：底层装饰 + 仅曲谱图片正片叠底去白底 */

.sg-score-bg-root {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
    isolation: isolate;
    border-radius: inherit;
}

.sg-score-bg-l0,
.sg-score-bg-l1,
.sg-score-bg-veil {
    position: absolute;
    inset: -12px;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
}

.sg-score-bg-l0 {
    z-index: 0;
}

.sg-score-bg-l1 {
    z-index: 1;
    opacity: 0.08;
    mix-blend-mode: normal;
    background-blend-mode: normal;
}

.sg-score-bg-veil {
    z-index: 2;
    background: #ffffff;
    opacity: 0;
    pointer-events: none;
}

.sg-score-stage-fill {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.sg-img-editor-canvas-wrap.sg-score-bg-on {
    background: transparent;
    background-image: none;
}

.sg-img-editor-canvas-wrap.sg-score-bg-on .sg-img-editor-viewport,
.sg-img-editor-canvas-wrap.sg-score-bg-on .sg-img-editor-stage {
    position: relative;
    z-index: 1;
    isolation: auto;
    mix-blend-mode: normal;
}

.sg-img-editor-canvas-wrap.sg-score-bg-multiply .sg-img-editor-viewport {
    will-change: auto;
}

.sg-img-editor-canvas-wrap.sg-score-bg-on .sg-img-score,
.sg-img-player-root.sg-score-bg-on .sg-img-player-img {
    position: relative;
    z-index: 1;
}
.sg-img-editor-canvas-wrap.sg-score-bg-multiply .sg-img-score {
    mix-blend-mode: multiply;
    -webkit-mix-blend-mode: multiply;
}
/* 20260827：橡皮擦为背景取样色，不再走 multiply（旧规则见 git 历史） */
.sg-img-editor-canvas-wrap.sg-score-bg-multiply .sg-img-erase {
    mix-blend-mode: normal;
    -webkit-mix-blend-mode: normal;
}

.sg-img-editor-canvas-wrap.sg-score-bg-on .sg-img-overlay,
.sg-img-editor-canvas-wrap.sg-score-bg-on .sg-img-frame-lines,
.sg-img-editor-canvas-wrap.sg-score-bg-on .sg-eraser-cursor,
.sg-img-editor-canvas-wrap.sg-score-bg-on .sg-touch-line-dot {
    mix-blend-mode: normal !important;
    -webkit-mix-blend-mode: normal !important;
    background-blend-mode: normal !important;
    isolation: isolate;
}

.sg-img-player-root.sg-score-bg-on .sg-img-player-scroll,
.sg-img-player-root.sg-score-bg-plain .sg-img-player-scroll,
.sg-preview-stage .sg-img-player-root.sg-score-bg-on .sg-img-player-scroll,
.sg-preview-stage .sg-img-player-root.sg-score-bg-plain .sg-img-player-scroll,
body.sg-preview-open .sg-preview-stage .sg-img-player-root.sg-score-bg-on .sg-img-player-scroll,
.sg-player-cinema .player-viewport .sg-img-player-root.sg-score-bg-on .sg-img-player-scroll,
.sg-player-cinema .player-viewport .sg-img-player-root.sg-score-bg-plain .sg-img-player-scroll,
.sg-app-player-page #imagePlayerContainer.sg-score-bg-on .sg-img-player-scroll,
.sg-app-player-page #imagePlayerContainer.sg-score-bg-plain .sg-img-player-scroll,
#sgLibraryPreviewInner .sg-img-player-root.sg-score-bg-on .sg-img-player-scroll,
#sgLibraryPreviewInner .sg-img-player-root.sg-score-bg-plain .sg-img-player-scroll {
    background: transparent !important;
}

.sg-img-player-root.sg-score-bg-plain .sg-score-bg-l0 {
    background-color: #ffffff;
}

.sg-img-player-root.sg-score-bg-on .sg-img-player-scroll {
    position: relative;
    z-index: 1;
    background: transparent !important;
    isolation: auto;
    mix-blend-mode: normal;
}

.sg-img-player-root.sg-score-bg-on .sg-img-player-wrap,
.sg-img-player-root.sg-score-bg-on .sg-img-player-stage {
    position: relative;
    z-index: 1;
    isolation: auto;
    mix-blend-mode: normal;
}

.sg-img-player-root.sg-score-bg-multiply .sg-img-player-img {
    mix-blend-mode: multiply;
    -webkit-mix-blend-mode: multiply;
}
.sg-img-player-root.sg-score-bg-multiply .sg-img-player-erase {
    mix-blend-mode: normal;
    -webkit-mix-blend-mode: normal;
}

.sg-img-player-root.sg-score-bg-on .sg-img-player-overlay {
    mix-blend-mode: normal !important;
    -webkit-mix-blend-mode: normal !important;
    background-blend-mode: normal !important;
    isolation: isolate;
    z-index: 3;
}

/* 黑底反色模式：仅谱面亮度反色，小球/进度线保持原色 */
.sg-img-player-root.sg-score-night-invert .sg-score-bg-l0,
.sg-img-player-root.sg-score-night-invert.sg-score-bg-plain .sg-score-bg-l0 {
    background-color: #000000 !important;
    background-image: none !important;
    filter: none !important;
}

.sg-img-player-root.sg-score-night-invert .sg-score-bg-l1,
.sg-img-player-root.sg-score-night-invert .sg-score-bg-veil {
    opacity: 0 !important;
}

.sg-img-player-root.sg-score-night-invert .sg-img-player-img,
.sg-img-player-root.sg-score-night-invert .sg-img-player-erase,
.sg-img-player-root.sg-score-night-invert.sg-score-bg-multiply .sg-img-player-img,
.sg-img-player-root.sg-score-night-invert.sg-score-bg-multiply .sg-img-player-erase {
    mix-blend-mode: normal !important;
    -webkit-mix-blend-mode: normal !important;
    filter: invert(1) hue-rotate(180deg);
    -webkit-filter: invert(1) hue-rotate(180deg);
}

.sg-img-player-root.sg-score-night-invert .sg-img-player-overlay {
    filter: none !important;
    -webkit-filter: none !important;
}

/* 侧边面板 */
.sg-score-bg-overlay {
    position: fixed;
    inset: 0;
    z-index: 10025;
    display: none;
    background: rgba(15, 23, 42, 0.28);
}

.sg-score-bg-overlay.is-open {
    display: block;
}

.sg-score-bg-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(400px, 100vw);
    background: #fff;
    box-shadow: -8px 0 32px rgba(15, 23, 42, 0.16);
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.sg-score-bg-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 12px;
    border-bottom: 1px solid #e8edf3;
}

.sg-score-bg-panel-head h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #1e293b;
}

.sg-score-bg-close {
    width: 40px;
    height: 40px;
    border: none;
    background: #f1f5f9;
    border-radius: 10px;
    font-size: 22px;
    color: #64748b;
    cursor: pointer;
}

.sg-score-bg-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px 24px;
    -webkit-overflow-scrolling: touch;
}

.sg-score-bg-noblend {
    margin: 0 0 12px;
    padding: 10px 12px;
    background: #fff7ed;
    border: 1px solid #fdba74;
    border-radius: 10px;
    color: #9a3412;
    font-size: 15px;
    line-height: 1.5;
    font-weight: 600;
}

.sg-score-bg-cat {
    margin: 16px 0 8px;
    font-size: 16px;
    font-weight: 700;
    color: #334155;
}

.sg-score-bg-cat:first-child {
    margin-top: 0;
}

.sg-score-bg-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.sg-score-bg-thumb {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    cursor: pointer;
    padding: 0;
    font: inherit;
    text-align: left;
}

.sg-score-bg-thumb.is-active {
    border-color: #2B7BCC;
    box-shadow: 0 0 0 3px rgba(43, 123, 204, 0.18);
}

.sg-score-bg-swatch {
    height: 64px;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.sg-score-bg-swatch-tex {
    position: absolute;
    inset: 0;
    opacity: 0.1;
    pointer-events: none;
}

.sg-score-bg-thumb em {
    display: block;
    padding: 8px 8px 10px;
    font-size: 14px;
    font-style: normal;
    font-weight: 600;
    color: #334155;
    line-height: 1.35;
}

.sg-score-bg-actions {
    display: flex;
    gap: 8px;
    margin: 8px 0 16px;
}

.sg-score-bg-actions .sg-btn {
    flex: 1;
    min-height: 44px;
    font-size: 15px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
}

.sg-score-bg-btn-reset {
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #334155;
}

.sg-score-bg-btn-upload {
    border: none;
    background: #2B7BCC;
    color: #fff;
}

.sg-score-bg-slider-row {
    margin: 14px 0;
}

.sg-score-bg-slider-row.is-disabled {
    opacity: 0.45;
    pointer-events: none;
}

.sg-score-bg-slider-row label {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 8px;
}

.sg-score-bg-slider-row input[type="range"] {
    width: 100%;
    height: 28px;
    accent-color: #2B7BCC;
}

.sg-score-bg-switch {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 0 4px;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    cursor: pointer;
}

.sg-score-bg-switch input {
    width: 22px;
    height: 22px;
    accent-color: #2B7BCC;
}

.sg-score-bg-hint {
    margin: 8px 0 0;
    font-size: 13px;
    line-height: 1.5;
    color: #64748b;
}

.sg-score-bg-custom-name {
    margin: 0 0 10px;
    font-size: 14px;
    color: #2B7BCC;
    font-weight: 600;
    word-break: break-all;
}

#btnScoreBg {
    white-space: nowrap;
}

@media (max-width: 480px) {
    .sg-score-bg-panel {
        width: 100vw;
    }
    .sg-score-bg-thumb em {
        font-size: 15px;
    }
}

.sg-apk-editor-page .sg-score-bg-panel {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
}
