
/* ── Modal backdrop ─────────────────────────────────────── */
.ka-viz-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(0,0,0,0.30);
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
    height: 100dvh;
}
@supports not (height: 100dvh) { .ka-viz-modal { height: 100vh; } }
.ka-viz-modal.open { display: flex; }
body.ka-modal-open { overflow: hidden !important; }

/* ── Modal card ─────────────────────────────────────────── */
.ka-viz-modal-inner {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    max-width: 960px;
    max-height: 92vh;
    background: #111;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,0.7);
}

/* ── Header ─────────────────────────────────────────────── */
.ka-viz-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: #111;
    border-bottom: 1px solid #222;
    flex-shrink: 0;
    height: 52px;
    box-sizing: border-box;
    border-radius: 14px 14px 0 0;
}
.ka-viz-modal-title {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
}
.ka-viz-modal-close {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    color: #888 !important;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    line-height: 0;
    margin: 0 !important;
    min-height: 0 !important;
    transition: color .15s;
}
.ka-viz-modal-close:hover { color: #fff !important; }

/* ── Stage ──────────────────────────────────────────────── */
.ka-viz-stage {
    position: relative;
    flex: 1;
    background: #1a1a1a;
    overflow: visible;
    border-radius: 0 !important;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    min-height: 0;
    /* Desktop: enforce 16:9 max via aspect-ratio hint */
}

.ka-viz-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0 !important;
}
.ka-viz-stage-hint {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #444;
    font-size: 14px;
    pointer-events: none;
    transition: opacity .3s;
}
.ka-viz-stage.has-bg .ka-viz-stage-hint { opacity: 0; }

/* ── Ofen wrap ──────────────────────────────────────────── */
.ka-viz-wrap {
    position: absolute;
    touch-action: none;
    cursor: grab;
    user-select: none;
    -webkit-user-drag: none;
}
.ka-viz-wrap:active { cursor: grabbing; }
.ka-viz-overlay {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
    -webkit-user-drag: none;
}

/* ── Corner handles ─────────────────────────────────────── */
.ka-handle {
    position: absolute;
    width: 36px;
    height: 36px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s;
    z-index: 2;
}
.ka-handle::after {
    content: '';
    position: absolute;
    left: 50%; top: 50%;
    width: 14px; height: 14px;
    transform: translate(-50%,-50%);
    border: 2.5px solid #fff;
    border-radius: 50%;
    background: rgba(0,0,0,.5);
    box-sizing: border-box;
    box-shadow: 0 0 4px rgba(0,0,0,.6);
}
.ka-viz-wrap.active .ka-handle { opacity: 1; pointer-events: auto; }
.ka-handle.tl { top: -18px; left: -18px; cursor: nwse-resize; }
.ka-handle.tr { top: -18px; right: -18px; cursor: nesw-resize; }
.ka-handle.bl { bottom: -18px; left: -18px; cursor: nesw-resize; }
.ka-handle.br { bottom: -18px; right: -18px; cursor: nwse-resize; }

/* ── Rotation handle ────────────────────────────────────── */
.ka-handle-rot {
    position: absolute;
    left: 50%;
    bottom: -38px;
    transform: translateX(-50%);
    width: 30px; height: 30px;
    background: rgba(20,20,20,0.85);
    border: 2px solid rgba(255,255,255,.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #fff;
    cursor: grab;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s;
    touch-action: none;
    user-select: none;
    box-sizing: border-box;
}
.ka-viz-wrap.active .ka-handle-rot { opacity: 1; pointer-events: auto; }
.ka-handle-rot:active { cursor: grabbing; }

/* ── Download button on canvas ───────────────────────────── */
.ka-stage-dl {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: rgba(0,0,0,0.5);
    border: none;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    line-height: 0;
    z-index: 10;
    transition: background .15s, opacity .2s;
    -webkit-appearance: none;
}
.ka-stage-dl:disabled { opacity: 0; pointer-events: none; }
.ka-stage-dl:not(:disabled) { opacity: 1; pointer-events: auto; }
.ka-stage-dl:hover { background: rgba(0,0,0,0.8); }

/* ── Bottom bar ─────────────────────────────────────────── */
.ka-viz-bottom {
    background: #111;
    border-top: 1px solid #222;
    flex-shrink: 0;
    padding: 10px 16px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    border-radius: 0 0 14px 14px;
}

/* ── Toolbar: bare icon buttons ─────────────────────────── */
.ka-viz-toolbar {
    display: flex;
    gap: 16px;
    align-items: center;
}
.ka-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 0;
    width: 34px;
    height: 34px;
    cursor: pointer;
    color: #fff;
    opacity: 0.8;
    transition: opacity .15s;
    line-height: 0;
    -webkit-appearance: none;
    flex-shrink: 0;
}
.ka-icon-btn svg { width: 34px; height: 34px; display: block; }
.ka-icon-btn:hover { opacity: 1; }

/* ── Swatches ───────────────────────────────────────────── */
.ka-viz-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 0;
}
.ka-swatch {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 12px 5px 6px;
    border-radius: 8px;
    border: 1.5px solid #555;
    background: #1e1e1e;
    color: #ffffff;
    font-size: 13px;
    cursor: pointer;
    transition: border-color .15s, color .15s;
    line-height: 1;
}
.ka-swatch img { width: 28px; height: 28px; object-fit: contain; border-radius: 4px; }
.ka-swatch.active { border-color: #e05800; color: #ffffff; }
.ka-swatch:hover { border-color: #888; color: #ffffff; }

/* ── Dims ───────────────────────────────────────────────── */
.ka-viz-dims { font-size: 11px; color: #ccc; margin: 4px 0 8px; }

/* ── CTA ────────────────────────────────────────────────── */
.ka-viz-cta-wrap { margin-top: 10px; }
.ka-viz-cta { border-radius: 25px !important; }

/* ── Mobile ─────────────────────────────────────────────── */
@media (max-width: 767px) {
    .ka-viz-modal { padding: 0; background: #111; border-radius: 0; }
    .ka-viz-modal-inner { width: 100%; height: 100%; max-height: 100dvh; border-radius: 0 !important; box-shadow: none; margin: 0; }
    .ka-handle { width: 44px; height: 44px; }
    .ka-handle::after { width: 18px; height: 18px; }
    .ka-handle.tl { top: -22px; left: -22px; }
    .ka-handle.tr { top: -22px; right: -22px; }
    .ka-handle.bl { bottom: -22px; left: -22px; }
    .ka-handle.br { bottom: -22px; right: -22px; }
    .ka-handle-rot { width: 40px; height: 40px; bottom: -44px; font-size: 20px; }
}

.ka-viz-modal-close:disabled { opacity: 0.25; pointer-events: none; }
.ka-icon-btn:disabled { opacity: 0.25; pointer-events: none; }

/* ── Share button ON canvas (top right) ─────────────────── */
.ka-canvas-share {
    position: absolute;
    top: 14px;
    right: 18px;
    width: 44px;
    height: 44px;
    background: rgba(0,0,0,0.30);
    border: none;
    border-radius: 50% !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 0;
    z-index: 10;
    transition: background .15s, opacity .2s;
    -webkit-appearance: none;
    padding: 0;
}
.ka-canvas-share:disabled { opacity: 0; pointer-events: none; }
.ka-canvas-share:not(:disabled) { opacity: 1; pointer-events: auto; }
.ka-canvas-share:hover { background: rgba(0,0,0,0.8); }
/* Clip any overflow inside stage */
.ka-viz-stage { clip-path: none; }

/* ── Force canvas square corners against theme ──────────── */
.ka-viz-bg,
.ka-viz-overlay,
.ka-viz-wrap { border-radius: 0 !important; }
