*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg:        #f0f0f4;
    --surface:   #ffffff;
    --surface2:  #f5f5f8;
    --border:    #e2e2ea;
    --text:      #1a1a2e;
    --muted:     #8080a0;
    --accent:    #5b4fff;
    --accent-hi: #7c6fff;
    --accent-bg: rgba(91, 79, 255, 0.08);
    --toolbar-w: 220px;
    --bar-h:     60px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 13px;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.app {
    display: flex;
    height: 100vh;
}

/* ── Sidebar ── */
.toolbar {
    width: var(--toolbar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.drawer-handle {
    display: none;
}

.toolbar-section {
    padding: 14px;
    border-bottom: 1px solid var(--border);
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 14px;
}

.logo {
    font-size: 22px;
    color: var(--accent);
    line-height: 1;
}

.brand h1 {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.3px;
}

/* Labels */
.section-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 10px;
}

.prop-label {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 8px;
}

.prop-label span {
    color: var(--text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ── Symmetry ── */
.symmetry-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.sym-btn {
    aspect-ratio: 1;
    background: var(--surface2);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    cursor: pointer;
    padding: 7px;
    transition: color 0.12s, border-color 0.12s, background 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sym-btn svg { width: 100%; height: 100%; }

.sym-btn:hover,
.sym-btn.active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-bg);
}

.radial-control { display: none; margin-top: 12px; }
.radial-control.visible { display: block; }

/* ── Slider ── */
.slider {
    -webkit-appearance: none;
    width: 100%;
    height: 3px;
    border-radius: 2px;
    background: var(--border);
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 0 3px var(--accent-bg), 0 1px 3px rgba(0,0,0,0.15);
    transition: transform 0.1s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* ── Color ── */
.color-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-swatch-wrap {
    flex-shrink: 0;
    cursor: pointer;
    width: 34px;
    height: 34px;
    position: relative;
}

.color-swatch-wrap input[type="color"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.color-swatch {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 2px solid rgba(0,0,0,0.12);
    background: #000;
    transition: border-color 0.15s;
}

.color-swatch-wrap:hover .color-swatch {
    border-color: rgba(0,0,0,0.35);
}

.presets {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.preset {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--c);
    border: 1.5px solid rgba(0,0,0,0.12);
    cursor: pointer;
    padding: 0;
    transition: transform 0.1s, border-color 0.1s;
}

.preset:hover {
    transform: scale(1.3);
    border-color: rgba(0,0,0,0.4);
}

/* ── Tool buttons ── */
.tool-row {
    display: flex;
    gap: 8px;
}

.tool-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 9px 6px 7px;
    background: var(--surface2);
    border: 1.5px solid var(--border);
    border-radius: 9px;
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
    transition: color 0.12s, border-color 0.12s, background 0.12s;
}

.tool-btn svg { width: 17px; height: 17px; color: inherit; }
.tool-btn span { color: inherit; }

.tool-btn:hover {
    color: var(--text);
    border-color: var(--muted);
}

.tool-btn.active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-bg);
}

/* ── Action buttons ── */
.toolbar-actions {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 7px;
    border-bottom: none !important;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    background: var(--surface2);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.action-btn svg { width: 15px; height: 15px; color: var(--muted); flex-shrink: 0; }

.action-btn:hover {
    background: var(--border);
}

.action-btn.accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
    justify-content: center;
}

.action-btn.accent svg { color: rgba(255,255,255,0.85); }

.action-btn.accent:hover {
    background: var(--accent-hi);
    border-color: var(--accent-hi);
}

/* ── Canvas area ── */
.canvas-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #ffffff;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    cursor: crosshair;
    touch-action: none;
}

/* ── Guide lines ── */
.guides {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.guide-v {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    background: rgba(91, 79, 255, 0.2);
    transform: translateX(-0.5px);
}

.guide-h {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1px;
    background: rgba(91, 79, 255, 0.2);
    transform: translateY(-0.5px);
}

.guides svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* ── Mobile bottom bar (hidden on desktop) ── */
.bottom-bar {
    display: none;
}

/* ── Drawer backdrop (hidden by default) ── */
.drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 90;
}

.drawer-backdrop.visible {
    display: block;
}

/* ════════════════════════════════════════
   TABLET  768–1024 px
════════════════════════════════════════ */
@media (min-width: 768px) and (max-width: 1024px) {
    :root { --toolbar-w: 190px; }
}

/* ════════════════════════════════════════
   MOBILE  ≤ 767 px
════════════════════════════════════════ */
@media (max-width: 767px) {

    /* Canvas fills screen above the bottom bar */
    .canvas-area {
        flex: none;
        width: 100vw;
        height: calc(100vh - var(--bar-h));
    }

    /* Sidebar becomes a bottom slide-up drawer */
    .toolbar {
        position: fixed;
        bottom: var(--bar-h);
        left: 0;
        right: 0;
        width: 100%;
        max-height: 68vh;
        border-right: none;
        border-top: 1px solid var(--border);
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -6px 32px rgba(0, 0, 0, 0.12);
        transform: translateY(calc(100% + var(--bar-h)));
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 100;
        /* keep flex-direction: column from base styles */
    }

    .toolbar.open {
        transform: translateY(0);
    }

    /* Show drag handle inside drawer */
    .drawer-handle {
        display: block;
        width: 36px;
        height: 4px;
        background: var(--border);
        border-radius: 2px;
        margin: 10px auto 4px;
        flex-shrink: 0;
    }

    /* Hide brand to save drawer height */
    .toolbar .brand {
        display: none;
    }

    /* Actions don't need auto-margin in drawer */
    .toolbar-actions {
        margin-top: 0;
        padding-bottom: 20px;
    }

    /* ── Bottom bar ── */
    .bottom-bar {
        display: flex;
        align-items: center;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--bar-h);
        background: var(--surface);
        border-top: 1px solid var(--border);
        padding: 0 6px;
        gap: 2px;
        z-index: 50;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .bottom-bar::-webkit-scrollbar { display: none; }

    /* Color dot */
    .bb-color-label {
        position: relative;
        flex-shrink: 0;
        width: 32px;
        height: 32px;
        margin: 0 4px;
        cursor: pointer;
    }

    .bb-color-label input[type="color"] {
        position: absolute;
        opacity: 0;
        width: 0;
        height: 0;
    }

    .bb-color-dot {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: #000;
        border: 2.5px solid rgba(0,0,0,0.14);
        transition: border-color 0.15s;
    }

    .bb-color-label:active .bb-color-dot {
        border-color: rgba(0,0,0,0.4);
    }

    /* Icon buttons */
    .bb-btn {
        min-width: 44px;
        height: 44px;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        border-radius: 10px;
        color: var(--muted);
        cursor: pointer;
        padding: 0 4px;
        transition: color 0.12s, background 0.12s;
        -webkit-tap-highlight-color: transparent;
    }

    .bb-btn svg {
        width: 22px;
        height: 22px;
        pointer-events: none;
    }

    .bb-btn:active,
    .bb-btn:hover {
        color: var(--text);
        background: var(--surface2);
    }

    .bb-tool.active {
        color: var(--accent);
        background: var(--accent-bg);
    }

    .bb-settings-btn.active {
        color: var(--accent);
        background: var(--accent-bg);
    }

    /* Pushes settings button to the far right */
    .bb-settings-btn {
        margin-left: auto;
    }

    /* Size value display */
    .bb-size-val {
        font-size: 13px;
        font-weight: 600;
        color: var(--text);
        min-width: 26px;
        text-align: center;
        font-variant-numeric: tabular-nums;
        flex-shrink: 0;
        pointer-events: none;
    }

    /* Separator */
    .bb-sep {
        width: 1px;
        height: 22px;
        background: var(--border);
        flex-shrink: 0;
        margin: 0 2px;
    }
}
