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

:root {
    --accent:         #3ddc84;
    --accent-dim:     rgba(61, 220, 132, 0.13);
    --accent-border:  rgba(61, 220, 132, 0.38);
    --accent-glow:    rgba(61, 220, 132, 0.20);

    --glass-bg:       rgba(8, 8, 18, 0.78);
    --glass-inner:    rgba(255, 255, 255, 0.04);
    --glass-hover:    rgba(255, 255, 255, 0.06);

    --surface:        #090912;
    --surface-2:      rgba(255, 255, 255, 0.055);

    --border:         rgba(255, 255, 255, 0.08);
    --border-mid:     rgba(255, 255, 255, 0.13);

    --text-primary:   rgba(255, 255, 255, 0.92);
    --text-secondary: rgba(255, 255, 255, 0.38);
    --text-muted:     rgba(255, 255, 255, 0.22);
}

body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: #000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

#video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    inset: 0;
    transform: scaleX(-1);
}

/* ─── Panel shell ───────────────────────────────────────────────────────────── */
.style-panel {
    position: absolute;
    left: 16px;
    top: 16px;
    width: clamp(250px, 22vw, 300px);
    background: var(--glass-bg);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 1px solid var(--border-mid);
    border-radius: 20px;
    z-index: 1000;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    box-shadow:
        0 0 0 0.5px rgba(255,255,255,0.05) inset,
        0 24px 48px rgba(0, 0, 0, 0.55),
        0 8px 16px rgba(0, 0, 0, 0.35);
    transition: max-height 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}
.style-panel.collapsed {
    max-height: 54px;
    overflow: hidden;
}
.style-panel::before {
    content: '';
    position: absolute;
    top: 0; left: 10%; right: 10%;
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.18), transparent);
    border-radius: 20px 20px 0 0;
    pointer-events: none;
    z-index: 2;
}
.style-panel::-webkit-scrollbar { display: none; }

/* ─── Panel header ──────────────────────────────────────────────────────────── */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 16px 13px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: rgba(8, 8, 18, 0.90);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    z-index: 1;
    border-radius: 20px 20px 0 0;
    cursor: grab;
    user-select: none;
}
.panel-header:active {
    cursor: grabbing;
}

.panel-header h3 {
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 650;
    letter-spacing: 0.01em;
}

/* Collapse button — lives inside panel header */
.panel-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 8px;
    color: var(--text-muted);
    padding: 0;
    flex-shrink: 0;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    position: relative;
}
.panel-collapse-btn:hover {
    background: rgba(255,255,255,0.13);
    color: var(--text-primary);
}
.panel-collapse-btn .chevron-icon {
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.style-panel.collapsed .panel-collapse-btn .chevron-icon {
    transform: rotate(180deg);
}


.fps-badge {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 10px;
    color: var(--accent);
    background: var(--accent-dim);
    border: 1px solid rgba(61,220,132,0.22);
    border-radius: 20px;
    padding: 3px 9px;
    min-width: 54px;
    text-align: center;
    letter-spacing: 0.04em;
}

/* ─── Sections ──────────────────────────────────────────────────────────────── */
.panel-section {
    padding: 14px 14px;
    border-bottom: 1px solid var(--border);
}
.panel-section:last-child { border-bottom: none; }

.section-title {
    color: var(--text-muted);
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.13em;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.section-title .hint {
    color: rgba(255,255,255,0.16);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    font-size: 9px;
}

/* ─── Preset buttons ────────────────────────────────────────────────────────── */
.style-options {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.style-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 11px;
    background: rgba(255,255,255,0.025);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 11px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}

.style-btn:hover {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.11);
}

.style-btn.active {
    background: rgba(61, 220, 132, 0.11);
    border-color: rgba(61, 220, 132, 0.32);
    box-shadow: 0 0 16px rgba(61,220,132,0.10), inset 0 0 0 0.5px rgba(61,220,132,0.12);
}

.style-name {
    color: var(--text-primary);
    font-size: 12.5px;
    font-weight: 500;
    white-space: nowrap;
    min-width: 72px;
}

.style-btn.active .style-name { color: #fff; }

.style-chars {
    color: var(--text-secondary);
    font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 10.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    text-align: right;
    transition: color 0.15s;
}

.style-btn.active .style-chars { color: var(--accent); }
.style-btn:hover .style-chars  { color: rgba(255,255,255,0.55); }

.style-btn[data-style="matrix"].active .style-chars {
    text-shadow: 0 0 8px rgba(61, 220, 132, 0.55);
}

/* ─── Custom charset ────────────────────────────────────────────────────────── */
.custom-charset-row {
    display: flex;
    gap: 6px;
}

.custom-input {
    flex: 1;
    padding: 8px 10px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--text-primary);
    font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 11.5px;
    outline: none;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.custom-input::placeholder { color: var(--text-muted); }
.custom-input:focus {
    border-color: var(--accent-border);
    background: rgba(255,255,255,0.08);
    box-shadow: 0 0 0 3px rgba(61,220,132,0.10);
}

.apply-btn {
    padding: 8px 14px;
    background: rgba(61,220,132,0.12);
    border: 1px solid var(--accent-border);
    border-radius: 9px;
    color: var(--accent);
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    white-space: nowrap;
    font-family: inherit;
}
.apply-btn:hover {
    background: rgba(61,220,132,0.20);
    box-shadow: 0 0 16px rgba(61,220,132,0.18);
    border-color: var(--accent);
}

/* ─── Density ───────────────────────────────────────────────────────────────── */
.density-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.density-slider {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.10);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.density-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border: 2.5px solid rgba(8,8,18,0.9);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(61,220,132,0.50), 0 2px 6px rgba(0,0,0,0.4);
    transition: transform 0.12s, box-shadow 0.12s;
}
.density-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 18px rgba(61,220,132,0.65), 0 2px 6px rgba(0,0,0,0.4);
}
.density-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border: 2.5px solid rgba(8,8,18,0.9);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(61,220,132,0.50);
}

.density-value {
    color: var(--text-primary);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 11px;
    min-width: 34px;
    text-align: right;
}

/* ─── Toggles ───────────────────────────────────────────────────────────────── */
.toggle-row {
    margin-bottom: 10px;
}
.toggle-row:last-child { margin-bottom: 0; }

.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.toggle-checkbox { display: none; }

.toggle-track {
    width: 34px;
    height: 19px;
    background: rgba(255, 255, 255, 0.09);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 10px;
    position: relative;
    flex-shrink: 0;
    transition: background 0.22s, border-color 0.22s, box-shadow 0.22s;
}

.toggle-thumb {
    position: absolute;
    width: 13px;
    height: 13px;
    background: rgba(255, 255, 255, 0.45);
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.22s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.toggle-checkbox:checked + .toggle-track {
    background: rgba(61,220,132,0.30);
    border-color: rgba(61,220,132,0.45);
    box-shadow: 0 0 12px rgba(61,220,132,0.20);
}
.toggle-checkbox:checked + .toggle-track .toggle-thumb {
    transform: translateX(15px);
    background: var(--accent);
    box-shadow: 0 0 8px rgba(61,220,132,0.55), 0 1px 4px rgba(0,0,0,0.4);
}

.toggle-text {
    color: var(--text-primary);
    font-size: 12.5px;
    font-weight: 500;
}

/* ─── Color picker ──────────────────────────────────────────────────────────── */
.color-section.dimmed {
    opacity: 0.3;
    pointer-events: none;
    transition: opacity 0.25s;
}

.color-picker-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.color-gradient {
    width: 100%;
    height: 116px;
    border-radius: 10px;
    position: relative;
    cursor: crosshair;
    background: linear-gradient(to right, #fff, transparent),
                linear-gradient(to bottom, transparent, #000);
    background-color: #00ff00;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.12);
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}

.color-selector {
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2.5px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 2px 6px rgba(0,0,0,0.5);
    transform: translate(-50%, -50%);
    pointer-events: none;
    top: 50%;
    left: 50%;
}

.hue-slider-container { width: 100%; }

.hue-slider {
    width: 100%;
    height: 13px;
    border-radius: 7px;
    position: relative;
    cursor: pointer;
    background: linear-gradient(to right,
        #ff0000, #ff7f00, #ffff00, #00ff00,
        #0000ff, #4b0082, #9400d3, #ff0000);
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.12);
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.hue-selector {
    position: absolute;
    width: 17px;
    height: 100%;
    background: transparent;
    border: 2.5px solid #fff;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 2px 6px rgba(0,0,0,0.3);
    transform: translateX(-50%);
    pointer-events: none;
    left: 33%;
    border-radius: 5px;
}

.color-info {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px;
    background: rgba(255,255,255,0.035);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 11px;
}

.color-swatch {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: #00ff00;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.color-inputs {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.rgb-inputs {
    display: flex;
    gap: 6px;
    align-items: center;
}

.rgb-inputs label {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
    width: 10px;
    flex-shrink: 0;
    text-transform: uppercase;
}

.rgb-input {
    flex: 1;
    min-width: 0;
    padding: 8px 2px 8px 6px;
    background: rgba(255,255,255,0.10);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 9px;
    color: var(--text-primary);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    text-align: center;
    outline: none;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.rgb-input:focus {
    border-color: var(--accent-border);
    background: rgba(255,255,255,0.14);
    box-shadow: 0 0 0 2.5px rgba(61,220,132,0.15);
}
.rgb-input::-webkit-inner-spin-button,
.rgb-input::-webkit-outer-spin-button {
    opacity: 0.8;
    width: 22px;
    cursor: pointer;
    margin-left: 4px;
}

.hex-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
}
.hex-input-container label {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
    text-transform: uppercase;
}

.hex-input {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 7px;
    color: var(--text-primary);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 11px;
    text-align: center;
    outline: none;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.hex-input:focus {
    border-color: var(--accent-border);
    background: rgba(255,255,255,0.10);
    box-shadow: 0 0 0 2.5px rgba(61,220,132,0.12);
}
.hex-input::placeholder { color: var(--text-muted); }

/* ─── Color slots ───────────────────────────────────────────────────────────── */
.color-slots {
    display: flex;
    gap: 6px;
}

.color-slot {
    flex: 1;
    height: 30px;
    border-radius: 8px;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
    box-sizing: border-box;
}
.color-slot.filled:hover {
    transform: scaleY(1.07);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.color-slot.filled.active {
    border-color: rgba(255,255,255,0.80);
    transform: scaleY(1.07);
    box-shadow: 0 0 12px rgba(255,255,255,0.20), 0 4px 12px rgba(0,0,0,0.3);
}

.color-slot.empty {
    background: rgba(255,255,255,0.05);
    border: 1.5px dashed rgba(255,255,255,0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.color-slot.empty:hover {
    background: rgba(61,220,132,0.06);
    border-color: var(--accent-border);
    color: var(--accent);
}

.slot-remove {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 15px;
    height: 15px;
    background: rgba(20,20,20,0.85);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: rgba(255,255,255,0.8);
    line-height: 1;
    cursor: pointer;
    z-index: 2;
    border: 1px solid rgba(255,255,255,0.15);
}
.color-slot.filled:hover .slot-remove { display: flex; }
.slot-remove:hover { background: rgba(220,60,60,0.9); color: #fff; }

/* ─── Shared button base ─────────────────────────────────────────────────────── */
button {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    cursor: pointer;
    transition: all 0.18s;
    font-weight: 500;
}
button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* ─── Export controls (inside panel) ────────────────────────────────────────── */
.export-controls {
    display: flex;
    gap: 6px;
}

#downloadTextBtn,
#downloadImageBtn,
#downloadVideoBtn {
    flex: 1;
    padding: 9px 8px;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 10px;
    color: rgba(255,255,255,0.70);
    font-size: 12px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
#downloadTextBtn:hover:not(:disabled),
#downloadImageBtn:hover:not(:disabled),
#downloadVideoBtn:hover:not(:disabled) {
    background: rgba(255,255,255,0.13);
    color: #fff;
    border-color: rgba(255,255,255,0.25);
    transform: translateY(-1px);
}

#downloadVideoBtn:not(:disabled) {
    color: #f87171;
    border-color: rgba(248,113,113,0.28);
}
#downloadVideoBtn:hover:not(:disabled) {
    background: rgba(248,113,113,0.10);
    border-color: rgba(248,113,113,0.50);
    color: #fca5a5;
}

#stopVideoBtn {
    flex: 1;
    padding: 9px 8px;
    background: rgba(239,68,68,0.14);
    border: 1px solid rgba(239,68,68,0.38);
    border-radius: 10px;
    color: #fca5a5;
    font-size: 12px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
#stopVideoBtn:hover:not(:disabled) {
    background: rgba(239,68,68,0.24);
    transform: translateY(-1px);
}


/* ─── Error / countdown ─────────────────────────────────────────────────────── */
.error-message {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    background: rgba(220,38,38,0.85);
    color: #fff;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 13px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,100,100,0.30);
    box-shadow: 0 4px 20px rgba(220,38,38,0.30);
}

.countdown-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.80);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}

.countdown-number {
    font-size: clamp(3rem, 15vw, 6.25rem);
    font-weight: 700;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    text-shadow: 0 0 60px rgba(61,220,132,0.40);
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.8; }
}

/* ─── ASCII box ─────────────────────────────────────────────────────────────── */
.ascii-box {
    position: absolute;
    width: clamp(300px, 40vw, 440px);
    height: clamp(220px, 30vw, 320px);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    background: #000;
    cursor: move;
    z-index: 100;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 8px 32px rgba(0,0,0,0.6);
    display: none;
    box-sizing: border-box;
    border-radius: 2px;
}
.ascii-box.active { display: block; }

.ascii-box.fullscreen {
    border: none !important;
    box-shadow: none !important;
    cursor: default !important;
    border-radius: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
}
.ascii-box.fullscreen .resize-handle { display: none !important; }

.ascii-canvas {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: inherit;
}

/* ─── Resize handles ────────────────────────────────────────────────────────── */
.resize-handle {
    position: absolute;
    z-index: 101;
    opacity: 0;
    transition: opacity 0.15s;
}
.ascii-box:hover .resize-handle { opacity: 1; }

.resize-handle-nw, .resize-handle-ne,
.resize-handle-sw, .resize-handle-se {
    width: 10px;
    height: 10px;
    background: rgba(255,255,255,0.8);
    border-radius: 2px;
}

.resize-handle-n, .resize-handle-s {
    width: calc(100% - 16px);
    height: 6px;
    left: 8px;
    background: transparent;
    border-top: 2px solid rgba(255,255,255,0.25);
}
.resize-handle-s { border-top: none; border-bottom: 2px solid rgba(255,255,255,0.25); }

.resize-handle-w, .resize-handle-e {
    width: 6px;
    height: calc(100% - 16px);
    top: 8px;
    background: transparent;
    border-left: 2px solid rgba(255,255,255,0.25);
}
.resize-handle-e { border-left: none; border-right: 2px solid rgba(255,255,255,0.25); }

.resize-handle-nw { top: -1px; left: -1px; cursor: nwse-resize; }
.resize-handle-ne { top: -1px; right: -1px; cursor: nesw-resize; }
.resize-handle-sw { bottom: -1px; left: -1px; cursor: nesw-resize; }
.resize-handle-se { bottom: -1px; right: -1px; cursor: nwse-resize; }
.resize-handle-n  { top: -4px; cursor: ns-resize; }
.resize-handle-s  { bottom: -4px; cursor: ns-resize; }
.resize-handle-w  { left: -4px; cursor: ew-resize; }
.resize-handle-e  { right: -4px; cursor: ew-resize; }

/* ─── Mobile panel toggle button ────────────────────────────────────────────── */
.panel-toggle {
    display: none;
    position: fixed;
    bottom: 84px;
    left: 16px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--glass-bg);
    border: 1px solid var(--border-mid);
    color: var(--text-primary);
    align-items: center;
    justify-content: center;
    z-index: 1002;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.45);
    touch-action: manipulation;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.panel-toggle.active {
    border-color: var(--accent-border);
    color: var(--accent);
    background: rgba(61,220,132,0.10);
}

/* ─── Panel backdrop (mobile) ───────────────────────────────────────────────── */
.panel-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.panel-backdrop.visible { opacity: 1; }

/* ─── Responsive breakpoints ────────────────────────────────────────────────── */

/* xs / sm — phones */
@media (max-width: 767px) {

    /* Show panel toggle FAB */
    .panel-toggle { display: flex; }

    /* Panel → bottom sheet */
    .style-panel {
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        bottom: 0 !important;
        width: 100% !important;
        max-height: 82svh;
        border-radius: 20px 20px 0 0 !important;
        transform: translateY(110%);
        transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    }
    .style-panel.open { transform: translateY(0); }

    /* Drag-handle pill at top of sheet */
    .panel-header::after {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(255,255,255,0.18);
        border-radius: 2px;
    }
    .panel-header { padding-top: 22px; }

    /* Show backdrop when open */
    .panel-backdrop { display: block; }

    /* Bigger touch targets */
    button { min-height: 44px; touch-action: manipulation; }
    .toggle-label { min-height: 44px; }
    .style-btn { min-height: 44px; }
    .apply-btn, .custom-input { min-height: 44px; }

    /* Collapse button: 44×44 tap target on mobile */
    .panel-collapse-btn {
        min-width: 44px;
        min-height: 44px;
        border-radius: 10px;
    }

    /* Density slider — bigger thumb and track for touch */
    .density-slider { height: 8px; }
    .density-slider::-webkit-slider-thumb { width: 28px; height: 28px; }
    .density-slider::-moz-range-thumb     { width: 28px; height: 28px; }

    /* Toggle track — expand label hit area already 44px via .toggle-label */
    .toggle-track { width: 40px; height: 22px; }
    .toggle-thumb { width: 16px; height: 16px; }

    /* ASCII box — nearly full width on mobile */
    .ascii-box {
        width: min(88vw, 440px) !important;
        height: min(66vw, 320px) !important;
    }

    /* Error message — full-width safe */
    .error-message {
        left: 12px;
        right: 12px;
        width: auto;
        transform: none;
        text-align: center;
    }
}

/* md — tablets: ascii box scales with viewport */
@media (min-width: 768px) and (max-width: 1023px) {
    .ascii-box {
        width: min(55vw, 440px) !important;
        height: min(41vw, 320px) !important;
    }
}

/* lg+ — desktops: FAB hidden, panel is always in-place (draggable + collapsible via header) */
@media (min-width: 768px) {
    .panel-backdrop { display: none !important; }
    .panel-toggle   { display: none !important; }
    .style-panel    { transform: none !important; }
}
