/* ==========================================================
   在线手持弹幕 —— 编辑态 + 弹幕态
   编辑态使用 .bg-tool 作用域，弹幕态使用独立 .bg-stage 遮罩
   ========================================================== */

.bg-tool {
    width: 100%;
}

.bg-tool [hidden],
.bg-stage[hidden],
.bg-stage [hidden] {
    display: none !important;
}

.bg-banner {
    margin-bottom: 12px;
    padding: 9px 12px;
    font-size: 12.5px;
    line-height: 1.7;
    border-radius: 6px;
}

.bg-banner-warn {
    color: #92400e;
    background: #fffbeb;
    border: 1px solid #fde68a;
}

.bg-message {
    margin-bottom: 12px;
    padding: 8px 11px;
    font-size: 12.5px;
    line-height: 1.7;
    color: #0f766e;
    background: #f0fcf9;
    border: 1px solid #d5eee8;
    border-radius: 6px;
}

.bg-message.is-error {
    color: #b91c1c;
    background: #fef2f2;
    border-color: #fecaca;
}

.bg-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
    gap: 14px;
    align-items: start;
}

.bg-col {
    min-width: 0;
}

.bg-card {
    margin-bottom: 14px;
    background: #fff;
    border: 1px solid var(--dd-line, #e5e7eb);
    border-radius: 8px;
}

.bg-card h2 {
    margin: 0;
    padding: 11px 14px;
    font-size: 14px;
    font-weight: 700;
    color: var(--dd-ink, #1f2937);
    background: #f8fafc;
    border-bottom: 1px solid var(--dd-line, #e5e7eb);
}

.bg-count {
    float: right;
    font-size: 12px;
    font-weight: 400;
    color: var(--dd-ink-3, #9ca3af);
}

.bg-body {
    padding: 14px;
}

.bg-input {
    display: block;
    width: 100%;
    height: 46px;
    padding: 0 12px;
    font-size: 15px;
    color: var(--dd-ink, #1f2937);
    background: #fff;
    border: 1px solid var(--dd-line, #e5e7eb);
    border-radius: 6px;
    outline: none !important;
    box-sizing: border-box;
}

.bg-input:focus {
    border-color: var(--dd-brand, #16a34a);
}

.bg-meta {
    margin-top: 9px;
    font-size: 12.5px;
    line-height: 1.8;
    color: var(--dd-ink-2, #4b5563);
}

.bg-stat {
    display: inline-block;
    margin-right: 12px;
    font-weight: 700;
    color: var(--dd-brand, #16a34a);
}

.bg-muted {
    font-size: 12px;
    color: var(--dd-ink-3, #9ca3af);
}

.bg-actions {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--dd-line, #e5e7eb);
}

.bg-btn {
    display: inline-block;
    height: 36px;
    margin-right: 8px;
    padding: 0 15px;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 34px;
    color: var(--dd-ink-2, #4b5563);
    text-align: center;
    white-space: nowrap;
    background: #f6f8f9;
    border: 1px solid var(--dd-line, #e5e7eb);
    border-radius: 6px;
    cursor: pointer;
    outline: none !important;
    vertical-align: middle;
}

.bg-btn:hover {
    color: var(--dd-brand, #16a34a);
    border-color: var(--dd-brand, #16a34a);
}

.bg-btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.bg-btn:disabled:hover {
    color: var(--dd-ink-2, #4b5563);
    border-color: var(--dd-line, #e5e7eb);
}

.bg-btn-primary {
    color: #fff;
    background: var(--dd-brand, #16a34a);
    border-color: var(--dd-brand, #16a34a);
}

.bg-btn-primary:hover {
    color: #fff;
    background: var(--dd-brand-dark, #15803d);
    border-color: var(--dd-brand-dark, #15803d);
}

.bg-btn-ghost {
    background: #fff;
}

.bg-btn-sm {
    height: 30px;
    padding: 0 11px;
    font-size: 12px;
    line-height: 28px;
}

.bg-settings {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 18px;
}

.bg-field {
    min-width: 0;
}

.bg-field > label {
    display: block;
    margin-bottom: 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--dd-ink-2, #4b5563);
}

.bg-value {
    margin-left: 4px;
    font-weight: 400;
    color: var(--dd-brand, #16a34a);
}

.bg-select {
    width: 100%;
    height: 32px;
    padding: 0 8px;
    font-size: 12.5px;
    color: var(--dd-ink, #1f2937);
    background: #fff;
    border: 1px solid var(--dd-line, #e5e7eb);
    border-radius: 4px;
    outline: none !important;
    box-sizing: border-box;
}

.bg-field input[type="range"] {
    display: block;
    width: 100%;
    height: 6px;
    margin: 8px 0 4px;
    accent-color: var(--dd-brand, #16a34a);
    cursor: pointer;
}

.bg-font-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bg-font-row .bg-select {
    flex: 1 1 auto;
    min-width: 0;
}

.bg-font-load {
    flex: 0 0 auto;
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
}

.bg-color-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bg-color-row .bg-select {
    flex: 1 1 auto;
    min-width: 0;
}

.bg-color-pick {
    flex: 0 0 auto;
    width: 38px;
    height: 32px;
    padding: 2px;
    background: #fff;
    border: 1px solid var(--dd-line, #e5e7eb);
    border-radius: 6px;
    cursor: pointer;
}

.bg-contrast {
    margin-top: 12px;
    padding: 7px 10px;
    font-size: 12px;
    line-height: 1.6;
    color: #92400e;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 6px;
}

.bg-check-row {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--dd-line, #e5e7eb);
    font-size: 12.5px;
    line-height: 28px;
    color: var(--dd-ink-2, #4b5563);
}

.bg-check-row label {
    display: block;
    cursor: pointer;
}

.bg-check-row input {
    margin-right: 6px;
    vertical-align: middle;
}

/* ---------- 编辑态预览 ---------- */

.bg-preview-card .bg-body {
    padding: 10px;
}

.bg-preview {
    position: relative;
    width: 100%;
    height: 300px;
    overflow: hidden;
    background: #000;
    border-radius: 6px;
    touch-action: manipulation;
}

.bg-preview-track {
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    height: 100%;
    white-space: nowrap;
    will-change: transform;
}

.bg-preview.is-vertical .bg-preview-track {
    top: 0;
    left: 0;
    flex-direction: column;
    width: 100%;
    height: auto;
}

.bg-preview-text {
    flex: 0 0 auto;
    padding: 0 24px;
    line-height: 1.4;
    white-space: nowrap;
}

.bg-preview.is-vertical .bg-preview-text {
    padding: 24px 0;
}

.bg-preview.is-static .bg-preview-track,
.bg-preview.is-blink .bg-preview-track {
    justify-content: center;
    transform: none !important;
}

.bg-preview.is-static .bg-preview-text + .bg-preview-text,
.bg-preview.is-blink .bg-preview-text + .bg-preview-text {
    display: none;
}

.bg-preview.is-blink .bg-preview-text {
    animation: bg-blink .8s steps(1, end) infinite;
}

@keyframes bg-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: .18; }
}

.bg-preview-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.bg-preview-actions .bg-btn {
    flex: 0 0 auto;
}

.bg-preview-actions .bg-muted {
    flex: 1 1 auto;
    min-width: 0;
}

/* ---------- 预设列表 ---------- */

.bg-preset-list {
    margin-bottom: 10px;
}

.bg-preset-empty {
    padding: 10px 12px;
    font-size: 12.5px;
    color: var(--dd-ink-3, #9ca3af);
    background: #f8fafc;
    border: 1px dashed var(--dd-line, #e5e7eb);
    border-radius: 6px;
}

.bg-preset-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 12px;
    border: 1px solid var(--dd-line, #e5e7eb);
    border-radius: 6px;
}

.bg-preset-item + .bg-preset-item {
    margin-top: 8px;
}

.bg-preset-main {
    min-width: 0;
}

.bg-preset-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--dd-ink, #1f2937);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bg-preset-meta {
    margin-top: 3px;
    font-size: 11.5px;
    color: var(--dd-ink-3, #9ca3af);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bg-preset-actions {
    flex: 0 0 auto;
    white-space: nowrap;
}

.bg-preset-actions button {
    margin-left: 4px;
    padding: 2px 6px;
    font-size: 12px;
    color: var(--dd-brand, #16a34a);
    background: none;
    border: 0;
    cursor: pointer;
}

.bg-preset-actions button:hover {
    text-decoration: underline;
}

.bg-preset-actions .is-danger {
    color: #b91c1c;
}

.bg-privacy {
    margin-bottom: 14px;
    padding: 9px 11px;
    font-size: 12px;
    line-height: 1.7;
    color: var(--dd-ink-3, #6b7280);
    background: #f8fafc;
    border: 1px solid var(--dd-line, #e5e7eb);
    border-radius: 6px;
}

/* ==========================================================
   弹幕态
   ========================================================== */

body.bg-lock {
    overflow: hidden !important;
    overscroll-behavior: none;
}

.bg-stage {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    z-index: 100000;
    overflow: hidden;
    color: #fff;
    background: #000;
    touch-action: manipulation;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.bg-stage.is-fallback {
    z-index: 100001;
}

.bg-viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
    outline: none;
    touch-action: manipulation;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.bg-stage.is-blink .bg-track-text {
    animation: bg-blink .8s steps(1, end) infinite;
}

.bg-track {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    display: flex;
    align-items: center;
    white-space: nowrap;
    will-change: transform;
}

.bg-stage.is-vertical .bg-track {
    top: 0;
    left: 0;
    flex-direction: column;
    width: 100%;
    height: auto;
    align-items: center;
}

.bg-track-item {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.bg-stage.is-vertical .bg-track-item {
    width: 100%;
}

.bg-track-text {
    display: block;
    line-height: 1.25;
    white-space: nowrap;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}

.bg-stage.is-static .bg-track,
.bg-stage.is-blink .bg-track {
    left: 0 !important;
    top: 0 !important;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    justify-content: center;
    transform: none !important;
}

.bg-stage.is-static .bg-track-item + .bg-track-item,
.bg-stage.is-blink .bg-track-item + .bg-track-item {
    display: none;
}

.bg-stage.is-static .bg-track-item,
.bg-stage.is-blink .bg-track-item {
    width: 100%;
    height: 100%;
}

/* 长按进度环 */
.bg-ring {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 8;
    width: 96px;
    height: 96px;
    margin: -48px 0 0 -48px;
    pointer-events: none;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, .45));
}

.bg-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.bg-ring circle {
    fill: none;
    stroke-width: 7;
}

.bg-ring-bg {
    stroke: rgba(255, 255, 255, .22);
}

.bg-ring-fg {
    stroke: #22c55e;
    stroke-linecap: round;
    stroke-dasharray: 276.46;
    stroke-dashoffset: 276.46;
}

/* 旋转建议 */
.bg-rotate-tip {
    position: absolute;
    left: 50%;
    bottom: max(84px, calc(env(safe-area-inset-bottom, 0px) + 76px));
    z-index: 9;
    width: max-content;
    max-width: calc(100vw - 32px);
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.7;
    text-align: center;
    color: #fff;
    background: rgba(20, 20, 20, .94);
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 8px;
    transform: translateX(-50%);
}

.bg-rotate-tip button {
    display: block;
    height: 30px;
    margin: 10px auto 0;
    padding: 0 14px;
    font-size: 12.5px;
    color: #fff;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .4);
    border-radius: 4px;
    cursor: pointer;
}

/* 一次性提示 */
.bg-toast {
    position: absolute;
    top: max(16px, calc(env(safe-area-inset-top, 0px) + 8px));
    left: 50%;
    z-index: 9;
    width: max-content;
    max-width: calc(100vw - 32px);
    padding: 9px 14px;
    font-size: 13px;
    line-height: 1.6;
    text-align: center;
    color: #fff;
    background: rgba(20, 20, 20, .92);
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 6px;
    transform: translateX(-50%);
}

/* 控件 */
.bg-controls {
    position: absolute;
    left: 50%;
    bottom: max(18px, calc(env(safe-area-inset-bottom, 0px) + 10px));
    z-index: 7;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: calc(100vw - 24px);
    padding: 7px 9px;
    color: #fff;
    background: rgba(18, 18, 18, .88);
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 8px;
    box-sizing: border-box;
    transform: translateX(-50%);
    transition: opacity .25s ease, visibility .25s ease;
}

.bg-controls.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.bg-ctrl {
    flex: 0 0 auto;
    height: 32px;
    padding: 0 11px;
    font-size: 12.5px;
    line-height: 30px;
    color: inherit;
    white-space: nowrap;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .28);
    border-radius: 4px;
    cursor: pointer;
    outline: none !important;
}

.bg-ctrl:hover,
.bg-ctrl:focus-visible {
    color: #4ade80;
    border-color: #4ade80;
}

.bg-ctrl-exit {
    color: #fca5a5;
}

.bg-live-speed {
    flex: 0 0 auto;
    min-width: 62px;
    font-size: 12px;
    text-align: center;
}

.bg-stage.is-fallback::after {
    content: "网页全屏模式";
    position: absolute;
    right: 12px;
    top: 12px;
    z-index: 6;
    padding: 4px 8px;
    font-size: 11px;
    color: #fff;
    background: rgba(0, 0, 0, .55);
    border-radius: 4px;
    pointer-events: none;
}

@media (max-width: 767.98px) {
    .bg-layout {
        display: flex;
        flex-direction: column;
    }

    .bg-col {
        width: 100%;
    }

    .bg-col-preview {
        order: -1;
    }

    .bg-preview {
        height: 220px;
    }

    .bg-settings {
        grid-template-columns: minmax(0, 1fr);
    }

    .bg-preset-item {
        align-items: flex-start;
        flex-direction: column;
    }

    .bg-preset-actions {
        white-space: normal;
    }
}

@media (max-height: 480px) and (orientation: landscape) {
    .bg-controls {
        bottom: 8px;
        padding: 4px 7px;
    }

    .bg-ring {
        width: 74px;
        height: 74px;
        margin: -37px 0 0 -37px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bg-controls {
        transition: none;
    }
}

/* ==========================================================
   layui layer 弹窗主题统一（仅本页加载）
   ========================================================== */

.layui-layer.bg-layer {
    border: 0;
    border-radius: 10px;
    box-shadow: 0 18px 50px rgba(15, 23, 42, .18);
    overflow: hidden;
}

.layui-layer.bg-layer.layui-layer-page {
    min-width: 320px;
    max-width: calc(100vw - 32px);
}

.bg-layer .layui-layer-title {
    height: 46px;
    padding: 0 18px;
    font-size: 14px;
    font-weight: 700;
    line-height: 46px;
    color: var(--dd-ink, #0f172a);
    background: #f8fafc;
    border-bottom: 1px solid var(--dd-line, #e8ebef);
}

.bg-layer .layui-layer-content {
    padding: 18px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--dd-ink-2, #475569);
}

.bg-layer .layui-layer-btn {
    padding: 0 18px 16px;
    text-align: right;
}

.bg-layer .layui-layer-btn a {
    height: 34px;
    padding: 0 16px;
    font-size: 13px;
    font-weight: 600;
    line-height: 32px;
    color: var(--dd-ink-2, #475569);
    background: #fff;
    border: 1px solid var(--dd-line, #e8ebef);
    border-radius: 6px;
}

.bg-layer .layui-layer-btn a:hover {
    color: var(--dd-brand, #0f766e);
    border-color: var(--dd-brand, #0f766e);
}

.bg-layer .layui-layer-btn .layui-layer-btn0 {
    color: #fff;
    background: var(--dd-brand, #0f766e);
    border-color: var(--dd-brand, #0f766e);
}

.bg-layer .layui-layer-btn .layui-layer-btn0:hover {
    color: #fff;
    background: var(--dd-brand-dark, #0b5d57);
    border-color: var(--dd-brand-dark, #0b5d57);
}

.layui-layer.bg-layer .layui-layer-input {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    font-size: 13px;
    color: var(--dd-ink, #0f172a);
    background: #fff;
    border: 1px solid var(--dd-line, #e8ebef);
    border-radius: 6px;
    outline: none !important;
    box-sizing: border-box;
}

.layui-layer.bg-layer .layui-layer-input:focus {
    border-color: var(--dd-brand, #0f766e);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}

.bg-layer .layui-layer-setwin {
    top: 15px;
    right: 15px;
}

/* 提示消息：浅色卡片，与站点一致 */
.layui-layer.bg-layer-msg {
    border: 0;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .16);
}

.bg-layer-msg .layui-layer-content {
    padding: 11px 16px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--dd-ink, #0f172a);
    background: #fff;
    border: 1px solid var(--dd-line, #e8ebef);
    border-radius: 8px;
}
