.oswie-editor {
    box-sizing: border-box;
    width: 100%;
    max-width: 1500px;
    margin: 20px auto;
    background: #111827;
    color: #f9fafb;
    border-radius: 18px;
    overflow: hidden;
    font-family: Arial, sans-serif;
    box-shadow: 0 18px 45px rgba(0,0,0,.3);
}

.oswie-editor * {
    box-sizing: border-box;
}

.oswie-topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: #020617;
    border-bottom: 1px solid rgba(255,255,255,.12);
}

.oswie-brand {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-right: 8px;
}

.oswie-brand span {
    font-size: 12px;
    color: #9ca3af;
}

.oswie-main {
    display: grid;
    grid-template-columns: 260px minmax(320px, 1fr) 280px;
    gap: 0;
    min-height: 650px;
}

.oswie-panel {
    padding: 14px;
    background: #0f172a;
    border-right: 1px solid rgba(255,255,255,.1);
    overflow: auto;
}

.oswie-panel:last-child {
    border-right: none;
    border-left: 1px solid rgba(255,255,255,.1);
}

.oswie-panel h3 {
    margin: 14px 0 10px;
    font-size: 15px;
    color: #e5e7eb;
}

.oswie-panel h3:first-child {
    margin-top: 0;
}

.oswie-row {
    display: grid;
    gap: 5px;
    margin: 9px 0;
}

.oswie-row label {
    font-size: 13px;
    color: #cbd5e1;
}

.oswie-editor button,
.oswie-file-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 8px 10px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 10px;
    background: #1f2937;
    color: #fff;
    font-size: 13px;
    cursor: pointer;
    transition: .15s ease;
    text-decoration: none;
}

.oswie-editor button:hover,
.oswie-file-btn:hover {
    background: #374151;
}

.oswie-editor button.is-active {
    background: #2563eb;
    border-color: #60a5fa;
    box-shadow: 0 0 0 2px rgba(96,165,250,.25);
}

.oswie-file-btn input {
    display: none;
}

.oswie-tool-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
}

.oswie-stickers {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
}

.oswie-stickers button {
    font-size: 24px;
    min-height: 46px;
}

.oswie-editor input,
.oswie-editor select,
.oswie-editor textarea {
    width: 100%;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 10px;
    background: #020617;
    color: #f9fafb;
    padding: 8px;
}

.oswie-editor textarea {
    min-height: 74px;
    resize: vertical;
}

.oswie-stage-area {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    background:
        radial-gradient(circle at top, rgba(37,99,235,.18), transparent 30%),
        #111827;
    overflow: auto;
}

.oswie-stage-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.oswie-canvas-wrap {
    position: relative;
    width: max-content;
    max-width: 100%;
    margin: 0 auto;
    overflow: auto;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 14px;
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
        linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
        linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
    background-size: 24px 24px;
    background-position: 0 0, 0 12px, 12px -12px, -12px 0;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
}

.oswie-canvas-wrap canvas {
    display: block;
    max-width: none;
    cursor: crosshair;
}

.oswie-selection {
    display: none;
    position: absolute;
    border: 2px dashed #38bdf8;
    background: rgba(56,189,248,.14);
    pointer-events: none;
    z-index: 5;
}

.oswie-selection.is-visible {
    display: block;
}

.oswie-status {
    min-height: 28px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(15,23,42,.9);
    color: #d1d5db;
    font-size: 13px;
}

.oswie-saved-list {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.oswie-saved-item {
    display: grid;
    gap: 6px;
    padding: 8px;
    background: rgba(2,6,23,.65);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 10px;
}

.oswie-saved-title {
    font-size: 12px;
    color: #f9fafb;
    overflow-wrap: anywhere;
}

.oswie-saved-meta {
    font-size: 11px;
    color: #9ca3af;
}

.oswie-saved-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.oswie-saved-actions button {
    min-height: 28px;
    padding: 5px 8px;
    font-size: 12px;
}

@media (max-width: 1000px) {
    .oswie-main {
        grid-template-columns: 1fr;
    }

    .oswie-panel,
    .oswie-panel:last-child {
        border: none;
        border-bottom: 1px solid rgba(255,255,255,.12);
        max-height: none;
    }

    .oswie-stage-area {
        min-height: 480px;
    }

    .oswie-canvas-wrap {
        max-width: 100%;
    }
}

/* Mobile friendly fix v1.1.1: keep canvas scrollable, put canvas first, and make toolbars touch friendly. */
.oswie-stage-area {
    min-width: 0;
}

.oswie-canvas-wrap {
    -webkit-overflow-scrolling: touch;
}

.oswie-canvas-wrap canvas {
    touch-action: none;
}

.oswie-editor button,
.oswie-file-btn {
    line-height: 1.15;
    white-space: nowrap;
}

@media (max-width: 1000px) {
    .oswie-editor {
        max-width: 100%;
        margin: 10px auto;
    }

    .oswie-main {
        grid-template-columns: 1fr;
        min-height: 0;
    }

    .oswie-stage-area {
        order: 1;
        min-height: 420px;
    }

    .oswie-panel {
        order: 2;
    }

    .oswie-panel:last-child {
        order: 3;
    }

    .oswie-panel,
    .oswie-panel:last-child {
        border: none;
        border-bottom: 1px solid rgba(255,255,255,.12);
        max-height: none;
    }

    .oswie-canvas-wrap {
        width: 100%;
        max-width: 100%;
        margin: 0;
        overflow: auto;
    }
}

@media (max-width: 640px) {
    .oswie-editor {
        margin: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .oswie-topbar {
        flex-wrap: nowrap;
        justify-content: flex-start;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 10px;
        -webkit-overflow-scrolling: touch;
    }

    .oswie-brand {
        min-width: 185px;
        flex: 0 0 auto;
    }

    .oswie-editor button,
    .oswie-file-btn {
        min-height: 44px;
        padding: 10px 12px;
        font-size: 13px;
        flex: 0 0 auto;
    }

    .oswie-panel {
        padding: 10px;
    }

    .oswie-tool-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }

    .oswie-stickers {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 6px;
    }

    .oswie-stickers button {
        min-height: 44px;
        font-size: 20px;
        padding: 6px;
    }

    .oswie-stage-area {
        padding: 8px;
        min-height: 360px;
    }

    .oswie-stage-toolbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }

    .oswie-canvas-wrap {
        min-height: 260px;
        border-radius: 10px;
    }

    .oswie-status {
        font-size: 12px;
    }

    .oswie-saved-actions button {
        min-height: 38px;
    }
}

@media (max-width: 420px) {
    .oswie-tool-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .oswie-stickers {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Fullscreen sandbox mode: no WordPress theme wrapper. */
html.oswie-sandbox-html,
body.oswie-sandbox-body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden;
    background: #020617;
}

body.oswie-sandbox-body #wpadminbar {
    display: none !important;
}

.oswie-sandbox-shell {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    min-height: 100vh;
    overflow: hidden;
    background: #020617;
}

.oswie-editor.oswie-editor-sandbox {
    width: 100vw;
    height: 100dvh;
    min-height: 100vh;
    max-width: none;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
}

.oswie-editor.oswie-editor-sandbox .oswie-topbar {
    flex: 0 0 auto;
}

.oswie-editor.oswie-editor-sandbox .oswie-main {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    grid-template-columns: 280px minmax(0, 1fr) 300px;
}

.oswie-editor.oswie-editor-sandbox .oswie-panel,
.oswie-editor.oswie-editor-sandbox .oswie-stage-area {
    min-height: 0;
    height: 100%;
}

.oswie-editor.oswie-editor-sandbox .oswie-stage-area {
    overflow: hidden;
}

.oswie-editor.oswie-editor-sandbox .oswie-canvas-wrap {
    flex: 1 1 auto;
    max-width: 100%;
    max-height: 100%;
    overflow: auto;
}

.oswie-exit-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 8px 10px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 10px;
    background: #7f1d1d;
    color: #fff;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
}

.oswie-exit-link:hover {
    background: #991b1b;
    color: #fff;
}

@media (max-width: 1000px) {
    body.oswie-sandbox-body {
        overflow: auto;
    }

    .oswie-sandbox-shell {
        position: static;
        width: 100%;
        height: auto;
        min-height: 100dvh;
        overflow: visible;
    }

    .oswie-editor.oswie-editor-sandbox {
        width: 100%;
        height: auto;
        min-height: 100dvh;
    }

    .oswie-editor.oswie-editor-sandbox .oswie-main {
        display: flex;
        flex-direction: column;
        height: auto;
    }

    .oswie-editor.oswie-editor-sandbox .oswie-stage-area {
        order: 1;
        overflow: visible;
    }

    .oswie-editor.oswie-editor-sandbox .oswie-panel {
        height: auto;
    }
}

/* Mobile sandbox usability fix v1.4.0: left/right drawers, drawer toggles, and fit-to-screen canvas. */
.oswie-mobile-dock,
.oswie-mobile-scrim,
.oswie-panel-close {
    display: none;
}

@media (max-width: 760px) {
    html.oswie-sandbox-html,
    body.oswie-sandbox-body {
        overflow: hidden !important;
        height: 100dvh;
        max-height: 100dvh;
    }

    .oswie-sandbox-shell {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
    }

    .oswie-editor.oswie-editor-sandbox,
    .oswie-editor {
        width: 100vw;
        height: 100dvh;
        min-height: 100dvh;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .oswie-editor .oswie-topbar {
        flex: 0 0 auto;
        min-height: 58px;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 8px 10px;
        gap: 8px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .oswie-editor .oswie-brand {
        min-width: 170px;
        max-width: 190px;
    }

    .oswie-editor .oswie-brand strong {
        font-size: 15px;
        line-height: 1.15;
    }

    .oswie-editor .oswie-brand span {
        font-size: 11px;
        white-space: normal;
        line-height: 1.15;
    }

    .oswie-editor .oswie-main,
    .oswie-editor.oswie-editor-sandbox .oswie-main {
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .oswie-editor .oswie-stage-area,
    .oswie-editor.oswie-editor-sandbox .oswie-stage-area {
        order: 1;
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
        padding: 6px;
        gap: 6px;
        overflow: hidden;
    }

    .oswie-editor .oswie-stage-toolbar {
        flex: 0 0 auto;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 2px 0 6px;
        gap: 8px;
        -webkit-overflow-scrolling: touch;
    }

    .oswie-editor .oswie-stage-toolbar button {
        min-height: 42px;
        padding: 9px 12px;
        font-size: 13px;
    }

    .oswie-editor .oswie-canvas-wrap,
    .oswie-editor.oswie-editor-sandbox .oswie-canvas-wrap {
        flex: 1 1 auto;
        width: 100%;
        max-width: 100%;
        min-height: 0;
        max-height: none;
        margin: 0;
        overflow: auto;
        border-radius: 12px;
        display: block;
        -webkit-overflow-scrolling: touch;
    }

    .oswie-editor .oswie-canvas-wrap canvas {
        width: 100% !important;
        height: auto !important;
        max-width: 100% !important;
        display: block;
        touch-action: none;
    }

    .oswie-editor .oswie-status {
        flex: 0 0 auto;
        min-height: 30px;
        max-height: 42px;
        overflow: hidden;
        font-size: 12px;
        line-height: 1.25;
        padding: 7px 9px;
    }

    .oswie-mobile-dock {
        flex: 0 0 auto;
        display: flex;
        gap: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
        background: #020617;
        border-top: 1px solid rgba(255,255,255,.14);
        -webkit-overflow-scrolling: touch;
        z-index: 50;
    }

    .oswie-mobile-dock button {
        min-height: 46px;
        padding: 10px 14px;
        flex: 0 0 auto;
        font-weight: 700;
    }

    .oswie-panel-close {
        display: flex;
        width: 100%;
        margin: 0 0 10px;
        background: #334155 !important;
    }

    .oswie-editor .oswie-panel,
    .oswie-editor .oswie-panel:last-child,
    .oswie-editor.oswie-editor-sandbox .oswie-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        z-index: 70;
        height: min(74dvh, 640px);
        max-height: 74dvh;
        padding: 12px 12px calc(18px + env(safe-area-inset-bottom));
        overflow: auto;
        border: 1px solid rgba(255,255,255,.16);
        border-bottom: 0;
        border-radius: 18px 18px 0 0;
        box-shadow: 0 -18px 50px rgba(0,0,0,.45);
        transform: translateY(110%);
        transition: transform .18s ease;
    }

    .oswie-editor.is-tools-open .oswie-panel-tools,
    .oswie-editor.is-settings-open .oswie-panel-settings {
        transform: translateY(0);
    }

    .oswie-mobile-scrim {
        position: fixed;
        inset: 0;
        z-index: 65;
        background: rgba(2,6,23,.62);
    }

    .oswie-editor.is-tools-open .oswie-mobile-scrim,
    .oswie-editor.is-settings-open .oswie-mobile-scrim {
        display: block;
    }

    .oswie-editor .oswie-tool-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .oswie-editor .oswie-stickers {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .oswie-editor input,
    .oswie-editor select,
    .oswie-editor textarea {
        min-height: 42px;
        font-size: 16px;
    }
}

@media (max-width: 420px) {
    .oswie-editor .oswie-brand {
        min-width: 150px;
        max-width: 170px;
    }

    .oswie-editor .oswie-tool-grid,
    .oswie-editor .oswie-stickers {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .oswie-editor .oswie-stickers button {
        min-height: 46px;
    }
}

/* Left/right drawer show-hide fix v1.4.0. */
@media (min-width: 761px) {
    .oswie-editor.is-left-hidden .oswie-panel-tools {
        display: none;
    }

    .oswie-editor.is-right-hidden .oswie-panel-settings {
        display: none;
    }

    .oswie-editor.is-left-hidden:not(.is-right-hidden) .oswie-main,
    .oswie-editor.oswie-editor-sandbox.is-left-hidden:not(.is-right-hidden) .oswie-main {
        grid-template-columns: minmax(0, 1fr) 300px;
    }

    .oswie-editor.is-right-hidden:not(.is-left-hidden) .oswie-main,
    .oswie-editor.oswie-editor-sandbox.is-right-hidden:not(.is-left-hidden) .oswie-main {
        grid-template-columns: 280px minmax(0, 1fr);
    }

    .oswie-editor.is-left-hidden.is-right-hidden .oswie-main,
    .oswie-editor.oswie-editor-sandbox.is-left-hidden.is-right-hidden .oswie-main {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 760px) {
    .oswie-editor .oswie-panel,
    .oswie-editor .oswie-panel:last-child,
    .oswie-editor.oswie-editor-sandbox .oswie-panel {
        display: block !important;
        position: fixed;
        top: 0;
        bottom: 0;
        width: min(86vw, 340px);
        height: 100dvh;
        max-height: 100dvh;
        padding: calc(12px + env(safe-area-inset-top)) 12px calc(18px + env(safe-area-inset-bottom));
        overflow: auto;
        border-radius: 0;
        z-index: 70;
        transition: transform .18s ease;
        box-shadow: 18px 0 50px rgba(0,0,0,.45);
    }

    .oswie-editor .oswie-panel-tools,
    .oswie-editor.oswie-editor-sandbox .oswie-panel-tools {
        left: 0;
        right: auto;
        transform: translateX(-110%);
        border-right: 1px solid rgba(255,255,255,.16);
        border-left: 0;
    }

    .oswie-editor .oswie-panel-settings,
    .oswie-editor.oswie-editor-sandbox .oswie-panel-settings {
        right: 0;
        left: auto;
        transform: translateX(110%);
        border-left: 1px solid rgba(255,255,255,.16);
        border-right: 0;
        box-shadow: -18px 0 50px rgba(0,0,0,.45);
    }

    .oswie-editor.is-left-open .oswie-panel-tools,
    .oswie-editor.is-tools-open .oswie-panel-tools {
        transform: translateX(0);
    }

    .oswie-editor.is-right-open .oswie-panel-settings,
    .oswie-editor.is-settings-open .oswie-panel-settings {
        transform: translateX(0);
    }

    .oswie-editor.is-left-open .oswie-mobile-scrim,
    .oswie-editor.is-right-open .oswie-mobile-scrim,
    .oswie-editor.is-tools-open .oswie-mobile-scrim,
    .oswie-editor.is-settings-open .oswie-mobile-scrim {
        display: block;
    }
}

/* v1.5.0 movable layer touch fixes */
.oswie-canvas-wrap canvas {
    touch-action: none;
}

.oswie-editor [data-oswie-tool="select"].is-active {
    background: #0ea5e9;
    border-color: #7dd3fc;
}

.oswie-editor [data-oswie-action="delete-selected"] {
    background: #7f1d1d;
    border-color: rgba(248,113,113,.6);
}

.oswie-editor [data-oswie-action="delete-selected"]:hover {
    background: #991b1b;
}

/* v1.6.1 AI drawer visibility fix: close sticker grid correctly, give AI controls full width. */
.oswie-ai-box {
    display: block;
    width: 100%;
    margin-top: 14px;
    padding: 12px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 14px;
    background: rgba(2,6,23,.45);
}

.oswie-ai-box h3 {
    margin-top: 0;
}

.oswie-ai-box textarea,
.oswie-ai-box select,
.oswie-ai-box button {
    width: 100%;
}

.oswie-ai-box textarea[data-oswie-ai-prompt] {
    min-height: 130px;
    resize: vertical;
    white-space: pre-wrap;
}

.oswie-ai-create-btn {
    min-height: 52px;
    font-size: 18px;
    font-weight: 800;
}

@media (min-width: 761px) {
    .oswie-editor.oswie-editor-sandbox .oswie-main,
    .oswie-editor .oswie-main {
        grid-template-columns: 380px minmax(0, 1fr) 300px;
    }

    .oswie-editor.is-right-hidden:not(.is-left-hidden) .oswie-main,
    .oswie-editor.oswie-editor-sandbox.is-right-hidden:not(.is-left-hidden) .oswie-main {
        grid-template-columns: 380px minmax(0, 1fr);
    }

    .oswie-editor.is-left-hidden:not(.is-right-hidden) .oswie-main,
    .oswie-editor.oswie-editor-sandbox.is-left-hidden:not(.is-right-hidden) .oswie-main {
        grid-template-columns: minmax(0, 1fr) 300px;
    }
}

@media (max-width: 760px) {
    .oswie-editor .oswie-panel,
    .oswie-editor .oswie-panel:last-child,
    .oswie-editor.oswie-editor-sandbox .oswie-panel {
        width: min(94vw, 430px);
    }

    .oswie-editor .oswie-tool-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .oswie-ai-box textarea[data-oswie-ai-prompt] {
        min-height: 150px;
    }
}


/* v1.6.2 select/resize reliability fix */
.oswie-canvas-wrap,
.oswie-canvas-wrap canvas {
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.oswie-canvas-wrap canvas {
    cursor: crosshair;
}

.oswie-editor [data-oswie-tool="select"].is-active ~ * {
    user-select: none;
}

/* v1.6.7 selectable layer list and stronger object selection help */
.oswie-layer-list {
    display: grid;
    gap: 7px;
    margin: 8px 0 12px;
    max-height: 190px;
    overflow: auto;
    padding-right: 2px;
}

.oswie-layer-empty {
    padding: 9px;
    border: 1px dashed rgba(255,255,255,.18);
    border-radius: 10px;
    color: #9ca3af;
    font-size: 12px;
    line-height: 1.35;
}

.oswie-layer-row {
    display: grid;
    grid-template-columns: 1fr 34px;
    gap: 6px;
    align-items: stretch;
}

.oswie-layer-select {
    min-height: 42px !important;
    justify-content: flex-start !important;
    text-align: left;
    display: grid !important;
    gap: 2px;
    width: 100%;
}

.oswie-layer-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    max-width: 100%;
}

.oswie-layer-meta {
    display: block;
    font-size: 11px;
    color: #9ca3af;
    font-weight: 400;
}

.oswie-layer-row.is-selected .oswie-layer-select {
    background: #0ea5e9;
    border-color: #7dd3fc;
}

.oswie-layer-row.is-selected .oswie-layer-meta {
    color: #e0f2fe;
}

.oswie-layer-delete {
    min-height: 42px !important;
    padding: 0 !important;
    background: #7f1d1d !important;
    border-color: rgba(248,113,113,.7) !important;
    font-size: 18px !important;
    font-weight: 900 !important;
}
