/* ==========================================================================
   panel.css — 侧栏「背景设置」二级菜单：触发按钮 + 弹出玻璃面板 + 滑杆
   ========================================================================== */

/* ---------- 触发按钮：和下方「复制邮箱」同一视觉语言 ---------- */
.side-tools {
    position: relative;
}

.side-tools[hidden] {
    display: none;
}

.side-tool {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--r-lg);
    border: 1px solid var(--line);
    background: var(--float-bg);
    backdrop-filter: blur(var(--blur)) saturate(140%);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
    box-shadow: var(--shadow-card);
    color: var(--ink-2);
    font-size: var(--fs-sm);
    letter-spacing: 0.01em;
    transition: color 0.3s var(--ease), border-color 0.3s var(--ease),
        background 0.3s var(--ease);
}

.side-tool:hover {
    color: var(--ink);
    border-color: rgba(var(--c2-rgb), 0.45);
}

.side-tool[aria-expanded="true"] {
    color: var(--ink);
    border-color: rgba(var(--c1-rgb), 0.55);
    background: linear-gradient(180deg, rgba(var(--c1-rgb), 0.16), rgba(var(--c1-rgb), 0.06));
}

.side-tool__icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    stroke: currentColor;
    stroke-width: 1.7;
    fill: none;
}

.side-tool__label {
    flex: 1;
    text-align: left;
}

.side-tool__chev {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    stroke: currentColor;
    stroke-width: 1.8;
    fill: none;
    opacity: 0.6;
    transition: transform 0.3s var(--ease), opacity 0.3s var(--ease);
}

.side-tool[aria-expanded="true"] .side-tool__chev {
    opacity: 1;
    transform: rotate(180deg);
}

/* ---------- 弹出面板：贴在侧栏右侧的二级菜单 ---------- */
.bg-panel {
    position: absolute;
    left: calc(100% + 14px);
    bottom: 0;
    z-index: 950;
    width: 336px;
    padding: 16px 17px 15px;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: var(--surface-3);
    backdrop-filter: blur(28px) saturate(150%);
    -webkit-backdrop-filter: blur(28px) saturate(150%);
    box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(0, 0, 0, 0.25);
    /* 内容比屏幕高时在面板内部滚动，不撑破布局 */
    max-height: min(calc(100vh - 120px), 760px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-padding-bottom: 8px;
    /* 细一点的原生滚动条（Edge/Chrome/Firefox）；Safari 走上面的 ::-webkit 规则 */
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-thumb) transparent;
    opacity: 0;
    transform: translateX(-8px) scale(0.985);
    transform-origin: left bottom;
    transition: opacity 0.26s var(--ease), transform 0.26s var(--ease);
}

.bg-panel[hidden] {
    display: none;
}

.bg-panel.is-open {
    opacity: 1;
    transform: none;
}

/* 面板内部滚动条的观感（Chrome / Edge / Safari） */
.bg-panel::-webkit-scrollbar {
    width: 8px;
}

.bg-panel::-webkit-scrollbar-track {
    background: transparent;
}

.bg-panel::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 999px;
    background-clip: content-box;
    background-color: var(--scroll-thumb);
}

.bg-panel:hover::-webkit-scrollbar-thumb {
    background-color: var(--scroll-thumb-hover);
}

/* ---------- 面板头部 ---------- */
.bg-panel__head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.bg-panel__title {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--ink);
}

.bg-panel__reset {
    font-size: 11.5px;
    color: var(--ink-3);
    padding: 3px 6px;
    border-radius: 7px;
    transition: color 0.25s, background 0.25s;
}

.bg-panel__reset:hover {
    color: rgba(var(--c2-rgb), 0.95);
    background: rgba(var(--c2-rgb), 0.1);
}

.bg-panel__close {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 8px;
    color: var(--ink-3);
    transition: color 0.25s, background 0.25s;
}

.bg-panel__close:hover {
    color: var(--ink);
    background: var(--surface-2);
}

.bg-panel__close svg {
    width: 13px;
    height: 13px;
    stroke: currentColor;
    stroke-width: 1.9;
    fill: none;
}

/* ---------- 开关行 ---------- */
.bg-panel__switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 13px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--line);
    font-size: 12.5px;
    color: var(--ink-2);
}

/* 连着的两个开关：第一个不要分隔线 */
.bg-panel__switch--tight {
    padding-bottom: 4px;
    margin-bottom: 12px;
    border-bottom: 0;
}

.switch {
    position: relative;
    width: 40px;
    height: 23px;
    flex-shrink: 0;
}

.switch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.switch__track {
    position: absolute;
    inset: 0;
    border-radius: 99px;
    background: var(--track);
    transition: background 0.28s var(--ease);
}

.switch__track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
    transition: transform 0.28s var(--ease);
}

.switch input:checked + .switch__track {
    background: linear-gradient(120deg, var(--c1), var(--c2));
}

.switch input:checked + .switch__track::after {
    transform: translateX(17px);
}

.switch input:focus-visible + .switch__track {
    outline: 2px solid rgba(var(--c2-rgb), 0.85);
    outline-offset: 2px;
}

/* ---------- 滑杆行 ---------- */
.rp {
    display: block;
    margin-bottom: 13px;
}

.rp[hidden] {
    display: none;
}

.rp__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--ink-2);
}

.rp__val {
    min-width: 50px;
    padding: 2px 7px;
    border-radius: 7px;
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--ink);
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.rp__range {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    width: 100%;
    height: 16px;
    margin: 0;
    background: transparent;
    cursor: pointer;
}

.rp__range::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 99px;
    background: linear-gradient(90deg, rgba(var(--c1-rgb), 0.95), rgba(var(--c2-rgb), 0.95));
}

.rp__range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    margin-top: -5px;
    border-radius: 50%;
    border: 0;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(var(--c2-rgb), 0.22), 0 2px 8px rgba(0, 0, 0, 0.5);
    transition: box-shadow 0.25s var(--ease);
}

.rp__range:hover::-webkit-slider-thumb {
    box-shadow: 0 0 0 5px rgba(var(--c2-rgb), 0.28), 0 2px 10px rgba(0, 0, 0, 0.55);
}

.rp__range::-moz-range-track {
    height: 4px;
    border-radius: 99px;
    background: linear-gradient(90deg, rgba(var(--c1-rgb), 0.95), rgba(var(--c2-rgb), 0.95));
}

.rp__range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: 0;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(var(--c2-rgb), 0.22), 0 2px 8px rgba(0, 0, 0, 0.5);
}

.rp__range:focus-visible {
    outline: none;
}

.rp__range:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 5px rgba(var(--c2-rgb), 0.55), 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* ---------- 主题色 ---------- */
.bg-panel__block {
    padding-top: 12px;
    margin-top: 4px;
    border-top: 1px solid var(--line);
}

/* 主题色下面紧跟的毛玻璃色块：分隔线留一条就够 */
.bg-panel__block--glass {
    padding-top: 11px;
    margin-top: 2px;
}

.rp--last {
    margin-bottom: 0;
    padding-top: 2px;
}

/* 毛玻璃关掉时：浓度整行变灰不可用 */
.rp.is-disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* 滑杆本身也去色，视觉上彻底禁用 */
.rp.is-disabled .rp__range {
    filter: grayscale(1);
}

.bg-panel__label {
    display: block;
    margin-bottom: 9px;
    font-size: 12px;
    color: var(--ink-2);
}

.swatches {
    display: flex;
    align-items: center;
    gap: 10px;
}

.swatch {
    position: relative;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid rgba(21, 26, 38, 0.14);
    transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.swatch:hover {
    transform: translateY(-2px);
}

.swatch.is-active {
    box-shadow: 0 0 0 2px var(--surface-3), 0 0 0 3.5px var(--line-strong);
}

/* 自定义 RGB：色块选中「自定义」后展开 */
.swatch--custom {
    background: conic-gradient(from 45deg, #f87171, #fbbf24, #34d399, #22d3ee, #8b5cf6, #f472b6, #f87171);
}

.swatch--custom::after {
    content: "";
    position: absolute;
    inset: 9px;
    border-radius: 50%;
    background: var(--glass-chip, #fff);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.rgb {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: 11px;
    padding: 8px 9px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--line);
}

.rgb[hidden] {
    display: none;
}

.rgb__picker {
    flex: 0 0 auto;
    width: 34px;
    height: 28px;
    padding: 0;
    border: 1px solid rgba(var(--c1-rgb), 0.45);
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
}

.rgb__picker::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.rgb__picker::-webkit-color-swatch {
    border: 0;
    border-radius: 6px;
}

.rgb__picker::-moz-color-swatch {
    border: 0;
    border-radius: 6px;
}

.rgb__cell {
    display: flex;
    align-items: center;
    gap: 5px;
    flex: 1 1 0;
    min-width: 0;
    font-size: 10.5px;
    letter-spacing: 0.06em;
    color: var(--ink-3);
}

.rgb__num {
    width: 100%;
    min-width: 0;
    height: 26px;
    padding: 0 6px;
    font: inherit;
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    text-align: center;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: rgba(0, 0, 0, 0.35);
    -moz-appearance: textfield;
}

.rgb__num::-webkit-outer-spin-button,
.rgb__num::-webkit-inner-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.rgb__num:focus {
    outline: none;
    border-color: rgba(var(--c2-rgb), 0.75);
    box-shadow: 0 0 0 2px rgba(var(--c2-rgb), 0.18);
}

.bg-panel__hint {
    margin: 13px 0 0;
    font-size: 10.5px;
    line-height: 1.6;
    color: var(--ink-3);
}

/* ---------- 收起播放按钮与菜单的层级关系 ---------- */
body.bg-panel-open .bg-toggle {
    pointer-events: none;
}

/* ---------- 响应式：窄屏没有「右侧」可用，改成触发器下方的手风琴 ---------- */
@media (max-width: 1080px) {
    .bg-panel {
        position: static;
        width: auto;
        max-width: 460px;
        /* 窄屏也限高：内容超出就在面板里滚动，不把页面撑长 */
        max-height: calc(100vh - 260px);
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        margin-top: 10px;
        transform: translateY(-6px);
        transform-origin: center top;
    }

    .bg-panel.is-open {
        transform: none;
    }
}

@media (max-width: 720px) {
    .bg-panel {
        padding: 14px 15px 15px;
    }

    .bg-panel.is-open {
        transform: none;
    }

    .bg-panel__head {
        margin-bottom: 12px;
    }

    .bg-panel__switch {
        padding-bottom: 10px;
        margin-bottom: 11px;
    }

    .bg-panel__switch--tight {
        padding-bottom: 2px;
        margin-bottom: 10px;
    }

    .rp {
        margin-bottom: 10px;
    }

    .rp__head {
        margin-bottom: 4px;
    }

    .bg-panel__block {
        padding-top: 10px;
    }

    .bg-panel__label {
        margin-bottom: 7px;
    }

    .swatch {
        width: 24px;
        height: 24px;
    }

    .bg-panel__hint {
        margin-top: 10px;
    }

    .side-tool {
        padding: 11px 13px;
    }
}

@media print {
    .side-tools,
    .bg-panel {
        display: none !important;
    }
}

/* ---------- 光暗切换：和「背景设置」同款玻璃条 ---------- */
.side-mode {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    margin-bottom: 10px;
    padding: 11px 14px;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--float-bg);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    color: var(--ink-2);
    font: inherit;
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: color 0.25s var(--ease), background 0.25s var(--ease), border-color 0.25s var(--ease);
}

.side-mode:hover {
    color: var(--ink);
    border-color: var(--line-strong);
    background: var(--float-bg-hover);
}

.side-mode svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.side-mode__label {
    letter-spacing: 0.02em;
}

/* 图标表示「点一下会切到哪」：亮色时显示月亮，暗色时显示太阳 */
html[data-theme="light"] .side-mode__sun,
html[data-theme="dark"] .side-mode__moon {
    display: none;
}