.toolbar {
    margin: 0 auto 10px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 0.4rem 0.5rem;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 3px;
}

.night .toolbar{
    border: 1px solid #444;
    background-color: #181a1b;
}

.toolbar button {
    appearance: none;
    padding: 6px 12px;
    font-size: 0.55rem;
    border: 1px solid #e4e7ec;
    border-radius:3px;
    color: #1f2937;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, transform .05s;
    touch-action: manipulation;
    user-select: none;
    background-color: #fff;
}

.night .toolbar button{
    background-color: #181a1b;
    color: #aaa;
    border: 1px solid #444;
}

.toolbar button:hover:not(:disabled) {
    background: #f7f9fc;
    border-color: #c9d2de;
}

.night .toolbar button:hover:not(:disabled) {
    background-color: #333;
    border-color: #444;
}

.toolbar button:active:not(:disabled) {
    transform: translateY(1px);
}

.toolbar button:disabled {
    opacity: .38;
    cursor: not-allowed;
}

.toolbar button.primary {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #fff;
}

.toolbar button.primary:hover:not(:disabled) {
    background: #2f74e0;
    border-color: #2f74e0;
}

.zoom-group {
    display: inline-flex;
    align-items: center;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.night .zoom-group {
    border: 1px solid #444;
}

.zoom-group button {
    border: 0;
    border-radius: 0;
    padding: 6px 11px;
    font-size: 0.55rem;
    line-height: 1;
    user-select: none;
}

.night .zoom-group button{
    border:0;
}

.zoom-group button+button {
    border-left: 1px solid #e4e7ec;
}

.night .zoom-group button+button {
    border-left: 1px solid #444;
}

#zoomValue {
    display: inline-block;
    min-width: 46px;
    text-align: center;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: #475569;
    padding: 0 4px;
    user-select: none;
}

.vis-group {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

#btnVis {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

#btnVis .vis-count {
    display: inline-block;
    min-width: 16px;
    padding: 0 4px;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
    background: #f59e0b;
    color: #fff;
    border-radius: 8px;
}

#btnVis.has-hidden {
    border-color: #fcd34d;
    color: #b45309;
    background: #fffbeb;
}

#btnVis.has-hidden:hover:not(:disabled) {
    background: #fef3c7;
}

.night #btnVis.has-hidden:hover:not(:disabled) {
    background: #444;
}

.vis-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 200px;
    padding: 6px;
    background: #fff;
    border: 1px solid #e4e7ec;
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .16);
    z-index: 200;
    display: none;
}

.night .vis-menu{
    background-color: #181a1b;
    border: 1px solid #444;
}

.vis-menu.open {
    display: block;
}

.vis-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 12px;
    color: #475569;
    cursor: pointer;
    user-select: none;
    transition: background .12s;
}

.vis-item:hover {
    background: #f7f9fc;
}

.vis-item.hidden {
    color: #b0b9c6;
}

.vis-icon {
    flex: 0 0 16px;
    width: 16px;
    height: 16px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    line-height: 1;
    color: transparent;
    transition: background .12s, border-color .12s, color .12s;
}

.vis-item:not(.hidden) .vis-icon {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #fff;
}

.bg-group {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

#btnBg {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#btnBg .bg-preview {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid rgba(15, 23, 42, .15);
    background-color: #fafbfc;
    background-image: radial-gradient(#cbd5e1 0.5px, transparent 0.5px);
    background-size: 4px 4px;
    vertical-align: middle;
}

.bg-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 248px;
    padding: 12px;
    background: #fff;
    border: 1px solid #e4e7ec;
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .16);
    z-index: 200;
    display: none;
}

.night .bg-menu{
    background-color: #181a1b;
    border: 1px solid #444;
}

.bg-menu.open {
    display: block;
}

.bg-menu-title {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 10px;
    font-weight: 500;
    letter-spacing: .2px;
}

.bg-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.bg-color {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 6px;
    border: 1px solid rgba(15, 23, 42, .12);
    cursor: pointer;
    transition: transform .12s, box-shadow .15s;
    overflow: hidden;
}

.night .bg-color{
    border:1px solid #444;
}

.bg-color:hover {
    transform: scale(1.08);
    box-shadow: 0 3px 10px rgba(15, 23, 42, .18);
}

.bg-color.selected {
    box-shadow: 0 0 0 2px #3b82f6, 0 0 0 4px rgba(59, 130, 246, .25);
}

.bg-color.selected::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

.bg-color.light.selected::after {
    color: #1f2937;
    text-shadow: 0 1px 2px rgba(255, 255, 255, .6);
}

.bg-color[data-color="transparent"] {
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #cbd5e1 25%, transparent 25%),
        linear-gradient(-45deg, #cbd5e1 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #cbd5e1 75%),
        linear-gradient(-45deg, transparent 75%, #cbd5e1 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}

.stage-wrap {
    margin: 0 auto;
    border: 1px solid #eee;
    border-radius: 3px;
    background: #fafbfc;
    overflow: hidden;
    position: relative;
}

.night .stage-wrap{
    border: 1px solid #444;
    background: #181a1b;
}

.stage {
    position: relative;
    width: 1200px;
    height: 740px;
    background-color: #fafbfc;
    transform-origin: top left;
}

.device {
    position: absolute;
    background-repeat: no-repeat;
    background-size: 100% auto;
    background-position: top left;
    background-color: transparent;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    outline: 2px solid transparent;
    outline-offset: 5px;
    border-radius: 4px;
    transition: outline-color .15s;
    --s: 1;
    transform: scale(var(--s));
    transform-origin: top left;
}

.stage .device {
    touch-action: none;
}

.device.dragging {
    cursor: grabbing;
}

.device:hover {
    outline-color: rgba(59, 130, 246, .35);
}

.device.selected {
    outline-color: #3b82f6;
}

.label {
    position: absolute;
    left: 0;
    bottom: calc(100% + 8px);
    padding: 3px 9px;
    font-size: 12px;
    line-height: 1.4;
    color: #fff;
    background: rgba(15, 23, 42, .78);
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s;
    z-index: 3;
}

.device:hover .label,
.device.selected .label {
    opacity: 1;
}

.screen {
    position: absolute;
    overflow: hidden;
    background: #fff;
    z-index: 1;
}

.device.selected .screen {
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, .65);
}

.screen iframe {
    display: block;
    border: 0;
    background: #fff;
    transform-origin: 0 0;
    pointer-events: none;
}

/* ==================== 可拖动浮窗 ==================== */
.popup {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;
    display: none;
    flex-direction: column;
    width: 90vw;
    max-width: 360px;
    max-height: 80vh;
    background: #fff;
    border-radius: 3px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .28), 0 6px 16px rgba(15, 23, 42, .14);
    font-size: 13px;
    overflow: hidden;
    user-select: none;
}

.popup.show {
    display: flex;
    animation: popup-fade .16s ease;
}

@keyframes popup-fade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.popup-header {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.5rem 0.4rem 0.6rem;
    border-bottom: 1px solid #eef1f6;
    font-size: 14px;
    /* font-weight: 600; */
    color: #1f2937;
    cursor: grab;
    touch-action: none;
    background: linear-gradient(180deg, #fafbfc 0%, #ffffff 100%);
}

.popup-header.dragging {
    cursor: grabbing;
}

.popup-close {
    flex: 0 0 28px;
    width: 1rem;
    height: 1rem;
    padding: 0;
    border: 0;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
}

.popup-close:hover {
    background: #f1f5f9;
    color: #1f2937;
}

.popup-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px 18px 18px;
}

/* ==================== 校准弹窗内容 ==================== */
.cal-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

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

.cal-row>span {
    flex: 0 0 40px;
    color: #64748b;
    font-size: 13px;
}

.cal-row>input[type=range] {
    flex: 1;
    min-width: 0;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #e4e7ec;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.cal-row>input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #3b82f6;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, .3);
    cursor: pointer;
    transition: transform .1s;
}

.cal-row>input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.cal-row>input[type=range]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #3b82f6;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, .3);
    cursor: pointer;
}

.cal-row>output {
    flex: 0 0 52px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: #1f2937;
    font-size: 13px;
    font-weight: 500;
}

.cal-reset {
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px solid #eef1f6;
    display: flex;
    justify-content: flex-end;
}

.cal-reset button {
    font-size: 12px;
    padding: 6px 14px;
    border: 1px solid #e4e7ec;
    border-radius: 8px;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}

.cal-reset button:hover {
    background: #f7f9fc;
    border-color: #c9d2de;
    color: #1f2937;
}

/* ==================== URL 弹窗内容 ==================== */
#urlPopupInput {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    color: #1f2937;
    border: 1px solid #e4e7ec;
    border-radius: 10px;
    outline: none;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}

#urlPopupInput:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .15);
}

.url-popup-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 14px;
}

.url-popup-actions button {
    width: 100%;
    padding: 11px 14px;
    font-size: 13px;
    font-family: inherit;
    border-radius: 10px;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
    font-weight: 500;
}

.url-popup-actions button:active {
    transform: translateY(1px);
}

#urlPopupApply {
    border: 1px solid #3b82f6;
    background: #3b82f6;
    color: #fff;
}

#urlPopupApply:hover {
    background: #2f74e0;
    border-color: #2f74e0;
}

#urlPopupApplyAll {
    border: 1px solid #e4e7ec;
    background: #fff;
    color: #475569;
}

#urlPopupApplyAll:hover {
    background: #f7f9fc;
    border-color: #c9d2de;
}
/* ==================== 移动端适配 ==================== */

.c1{
    background-color: #fff;
    background-image: linear-gradient(45deg, rgb(226, 232, 240) 25%, transparent 25%), linear-gradient(-45deg, rgb(226, 232, 240) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, rgb(226, 232, 240) 75%), linear-gradient(-45deg, transparent 75%, rgb(226, 232, 240) 75%);
    background-size: 16px 16px;
    background-position: 0px 0px, 0px 8px, 8px -8px, -8px 0px;
}

.night .c1{
    background-color: #444;
    background-image: linear-gradient(45deg, #2d2d2d 25%, transparent 25%), linear-gradient(-45deg, #2d2d2d 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #2d2d2d 75%), linear-gradient(-45deg, transparent 75%, #2d2d2d 75%);
}

.c2{
    background-color: #ffffff;
}


.c3{
    background-color: #fafbfc;
}


.c4{
    background-color: #e5e7eb;
}

.c5{
    background-color: #374151;
}


.c6{
    background-color: #0f172a;
}


.c7{
    background-color: #eff6ff;
}


.c8{
    background-color: #f0fdf4;
}

.c9{
    background-color: #fefce8;
}

.c10{
    background-color: #fdf2f8;
}

.c11{
    background-color: #faf5ff;
}

.c12{
    background-color: #b0b9c6;
}





/* ==================== 移动端适配 ==================== */
@media (max-width: 720px) {
    body {
        padding: 8px;
    }

    .toolbar {
        padding: 6px 8px;
        gap: 5px;
        border-radius: 10px;
    }

    .toolbar button {
        padding: 6px 11px;
        font-size: 12px;
        border-radius: 8px;
    }

    .zoom-group button {
        padding: 6px 11px;
        font-size: 15px;
    }

    #zoomValue {
        min-width: 42px;
        font-size: 12px;
    }

    .stage-wrap {
        border-radius: 10px;
    }

    .vis-menu {
        min-width: 180px;
    }

    .vis-item {
        padding: 8px 10px;
        font-size: 13px;
    }

    .bg-menu {
        width: 240px;
        padding: 12px;
        right: auto;
        left: 0;
    }

    .popup {
        width: calc(100vw - 24px);
        max-width: 400px;
        max-height: 75vh;
        border-radius: 14px;
    }

    .popup-header {
        padding: 16px 12px 12px 16px;
        font-size: 15px;
    }

    .popup-body {
        padding: 14px 16px 16px;
    }

    .cal-row>span {
        flex: 0 0 36px;
        font-size: 13px;
    }

    .cal-row>input[type=range] {
        height: 8px;
    }

    .cal-row>input[type=range]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }

    .cal-row>input[type=range]::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }

    .cal-row>output {
        flex: 0 0 48px;
        font-size: 13px;
    }

    #urlPopupInput {
        padding: 11px 12px;
        font-size: 14px;
    }

    .url-popup-actions button {
        padding: 12px 14px;
        font-size: 14px;
    }
}

@media (max-width: 380px) {
    .toolbar button {
        padding: 5px 9px;
        font-size: 11px;
    }

    .popup {
        padding: 0;
    }
}