/* ─── Canvas Wrap ─── */
.dt-canvas-wrap {
    position: relative;
    background: #fff;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    line-height: 0;
    cursor: crosshair;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    margin-top: 0.75rem;
}
.dt-canvas-wrap canvas {
    display: block;
    width: 100%;
    height: auto;
    max-height: 65vh;
}
.dt-canvas-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 0.95rem;
    font-weight: 500;
    pointer-events: none;
    opacity: 0.6;
    transition: opacity 0.3s;
    z-index: 1;
}
.dt-canvas-empty.hidden { opacity: 0; }

/* ─── Floating Toolbar ─── */
.dt-toolbar {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    z-index: 10;
    background: var(--bg-card);


    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    transition: background 0.2s, box-shadow 0.2s;
}
.dt-toolbar::-webkit-scrollbar { display: none; }
.dt-toolbar:hover {
    background: var(--bg-card);
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}
.dt-tb-row {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: nowrap;
    min-width: max-content;
}
.dt-tb-section {
    display: flex;
    align-items: center;
    gap: 2px;
}
.dt-tb-sep {
    width: 1px;
    height: 22px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0;
}
.dt-tb-spacer {
    flex: 1;
    min-width: 8px;
}
.dt-tb-settings {
    gap: 6px;
}
.dt-tb-actions {
    gap: 2px;
}

/* Tool Buttons (icon-only, compact) */
.dt-tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1.5px solid transparent;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}
.dt-tool-btn:hover {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: var(--primary);
}
.dt-tool-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

/* Settings in toolbar */
.dt-tb-settings input[type="color"] {
    width: 28px;
    height: 28px;
    padding: 1px;
    border: 2px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    background: transparent;
    flex-shrink: 0;
    transition: border-color 0.15s;
}
.dt-tb-settings input[type="color"]:hover {
    border-color: var(--primary);
}
.dt-size-group,
.dt-opacity-group {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}
.dt-size-group input[type="range"],
.dt-opacity-group input[type="range"] {
    width: 55px;
    accent-color: var(--primary);
    cursor: pointer;
    height: 4px;
}
.dt-size-badge,
.dt-opacity-badge {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--primary);
    min-width: 22px;
    text-align: center;
    user-select: none;
    line-height: 1;
}

/* Action Buttons */
.dt-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    gap: 0;
    font-size: inherit;
    font-weight: inherit;
    font-family: inherit;
    white-space: normal;


    transform: none;
    box-shadow: none;
}
.dt-action-btn svg { width: 18px; height: 18px; }
.dt-action-btn:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
    transform: none;
    box-shadow: none;
}
.dt-action-clear:hover {
    border-color: #ef4444;
    background: var(--danger-soft);
    color: #ef4444;
    transform: none;
    box-shadow: none;
}
.dt-action-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.dt-action-primary:hover {
    filter: brightness(1.12);
    transform: none;
    box-shadow: none;
}

.dt-sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

/* Shape fill toggle */
.dt-shape-fill-btn { width: 30px; height: 30px; padding: 0; }
.dt-shape-fill-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: var(--shadow-md); }
.dt-shape-fill-btn.active svg { stroke: #fff; }

/* Dark bg toggle */
#dtDarkBg { width: 36px; height: 36px; padding: 0; transform: none; box-shadow: none; }
#dtDarkBg.active { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: var(--shadow-md); }
#dtDarkBg.active svg { stroke: #fff; }

.dt-font-group.hidden,
.dt-zoom-badge.hidden,
.dt-zoom-reset.hidden { display: none !important; }

/* Font controls */
.dt-font-group { display: flex; align-items: center; gap: 3px; }
.dt-font-group input[type="number"] { width: 40px; height: 26px; padding: 2px 4px; border: 1.5px solid var(--border); border-radius: 6px; background: var(--bg-card); color: var(--text); font-family: var(--font); font-size: 0.75rem; text-align: center; }
.dt-font-group select { height: 26px; padding: 0 4px; border: 1.5px solid var(--border); border-radius: 6px; background: var(--bg-card); color: var(--text); font-family: var(--font); font-size: 0.72rem; cursor: pointer; max-width: 72px; }
.dt-font-bold-btn { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; background: transparent; border: 1.5px solid var(--border); border-radius: 6px; color: var(--text-secondary); cursor: pointer; font-weight: 700; font-size: 0.8rem; font-family: var(--font); transition: all 0.15s ease; }
.dt-font-bold-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Zoom badge */
.dt-zoom-badge { font-size: 0.65rem; font-weight: 700; color: var(--primary); min-width: 36px; text-align: center; user-select: none; line-height: 1; flex-shrink: 0; }
.dt-zoom-reset { flex-shrink: 0; }

/* Text editor overlay */
.dt-text-editor { position: fixed; z-index: 999; min-width: 20px; max-width: 80vw; padding: 2px 4px; border: 1px dashed var(--primary); border-radius: 2px; background: var(--bg-card); color: var(--primary); font-family: Arial; font-size: 24px; outline: none; white-space: pre-wrap; word-break: break-word; line-height: 1.3; }
.dt-text-editor:empty::before { content: attr(aria-label); color: var(--text-tertiary); opacity: 0.5; }

/* Autosave bar */
.dt-autosave-restore, .dt-autosave-discard { display: inline-flex; align-items: center; padding: 4px 14px; border-radius: 100px; font-family: var(--font); font-size: 0.78rem; font-weight: 600; cursor: pointer; transition: all 0.15s; margin-left: 8px; }
.dt-autosave-restore { background: var(--primary); color: #fff; border: 1.5px solid var(--primary); }
.dt-autosave-restore:hover { filter: brightness(1.12); }
.dt-autosave-discard { background: transparent; color: var(--text-secondary); border: 1.5px solid var(--border); }
.dt-autosave-discard:hover { border-color: #ef4444; color: #ef4444; }

/* Custom cursor preview */
.dt-canvas-cursor {
    position: fixed;
    pointer-events: none;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,0.5);
    background: var(--primary-soft);
    transform: translate(-50%, -50%);
    z-index: 999;
    display: none;
    transition: width 0.08s, height 0.08s;
}
@media (pointer: coarse) { .dt-canvas-cursor { display: none !important; } }

/* ─── Toast ─── */
.dt-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(1rem);
    background: var(--primary);
    color: #fff;
    padding: 0.65rem 1.4rem;
    border-radius: 100px;
    font-size: 0.82rem;
    font-weight: 600;
    z-index: 9999;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16,1,0.3,1);
    pointer-events: none;
    box-shadow: var(--shadow-md);
    white-space: nowrap;
}
.dt-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ─── Fullscreen ─── */
.dt-canvas-wrap.dt-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 9998;
    border-radius: 0;
    border: none;
    max-height: none;
    margin-top: 0;
}
.dt-canvas-wrap.dt-fullscreen canvas {
    max-height: 100vh;
    width: 100%;
    height: 100%;
    object-fit: contain;
}
/* Toolbar slightly larger in fullscreen */
.dt-canvas-wrap.dt-fullscreen .dt-toolbar {
    top: 10px;
    left: 10px;
    right: 10px;
    padding: 8px 10px;
}

/* ─── Keyboard Hint ─── */
.dt-keyboard-hint {
    margin-top: 0.5rem;
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-tertiary);
    opacity: 0.8;
    user-select: none;
}
.dt-keyboard-hint kbd {
    display: inline-block;
    padding: 1px 5px;
    border: 1px solid var(--border);
    border-radius: 3px;
    font-family: var(--font);
    font-size: 0.68rem;
    background: var(--bg-card);
    line-height: 1.5;
}

/* ─── Responsive ─── */
@media (max-width: 900px) {
    .dt-size-group input[type="range"],
    .dt-opacity-group input[type="range"] {
        width: 40px;
    }
    .dt-size-badge,
    .dt-opacity-badge {
        font-size: 0.55rem;
        min-width: 16px;
    }
}

@media (max-width: 767px) {
    .dt-canvas-wrap canvas {
        max-height: 50vh;
    }
    .dt-toolbar {
        top: 4px;
        left: 4px;
        right: 4px;
        padding: 4px 5px;
    }
    .dt-tb-row {
        gap: 1px;
    }
    .dt-tool-btn {
        width: 28px;
        height: 28px;
    }
    .dt-tool-btn svg {
        width: 14px; height: 14px;
    }
    .dt-action-btn {
        width: 32px;
        height: 32px;
    }
    .dt-action-btn svg {
        width: 16px; height: 16px;
    }
    .dt-tb-settings input[type="color"] {
        width: 24px;
        height: 24px;
    }
    .dt-size-group input[type="range"],
    .dt-opacity-group input[type="range"] {
        width: 30px;
    }
    .dt-tb-sep {
        margin: 0 2px;
        height: 18px;
    }
    .dt-tb-spacer {
        display: none;
    }
    .dt-font-group input[type="number"] { width: 32px; }
    .dt-font-group select { max-width: 52px; font-size: 0.62rem; }
}

@media (max-width: 480px) {
    .dt-tool-btn {
        width: 26px;
        height: 26px;
    }
    .dt-tool-btn svg {
        width: 13px; height: 13px;
    }
    .dt-action-btn {
        width: 28px;
        height: 28px;
    }
    .dt-action-btn svg {
        width: 15px; height: 15px;
    }
    .dt-size-group input[type="range"],
    .dt-opacity-group input[type="range"] {
        width: 26px;
    }
    .dt-size-badge,
    .dt-opacity-badge,
    .dt-zoom-badge {
        display: none;
    }
    .dt-font-group input[type="number"] { width: 32px; }
    .dt-font-group select { max-width: 56px; font-size: 0.65rem; }
    .dt-keyboard-hint { display: none; }
}
