* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #0f172a; color: #e2e8f0; }
.demo-container { display: flex; flex-direction: column; height: 100vh; }

.header { background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%); padding: 12px 20px; border-bottom: 1px solid rgba(255,255,255,0.1); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.header h1 { font-size: 18px; font-weight: 600; }
.close-btn { background: rgba(255,255,255,0.2); border: none; color: #fff; cursor: pointer; padding: 8px 12px; border-radius: 6px; font-size: 14px; white-space: nowrap; }
.close-btn:hover { background: rgba(255,255,255,0.3); }

.workspace { display: flex; flex: 1; min-height: 0; overflow: hidden; }

.toolbar { width: 170px; background: #1e293b; border-right: 1px solid #334155; padding: 10px; overflow-y: auto; }
.tool-group { margin-bottom: 10px; }
.tool-section { font-size: 11px; font-weight: 600; color: #64748b; text-transform: uppercase; padding: 6px 0 4px; }
.tool-btn { width: 100%; text-align: left; padding: 8px 10px; margin-bottom: 6px; background: #334155; border: none; color: #cbd5e1; cursor: pointer; border-radius: 4px; font-size: 12px; transition: background 0.2s; white-space: nowrap; }
.tool-btn:hover { background: #475569; color: #e2e8f0; }
.tool-btn.active { background: #2563eb; color: #fff; }
.field { display: flex; align-items: center; gap: 6px; font-size: 11px; color: #94a3b8; margin-top: 4px; }
.field input[type=range] { flex: 1; min-width: 0; }

.canvas-area { flex: 1; min-width: 0; overflow: auto; background: #0b1120; padding: 20px; }
.paper { position: relative; background-color: #111827; border: 2px solid #475569; border-radius: 6px; box-shadow: 0 20px 40px rgba(0,0,0,0.5); }
.paper.grid {
    background-image:
        linear-gradient(to bottom, rgba(148,163,184,.35) 1px, transparent 1px),
        linear-gradient(to right, rgba(148,163,184,.35) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(148,163,184,.12) 1px, transparent 1px),
        linear-gradient(to right, rgba(148,163,184,.12) 1px, transparent 1px);
}
.paper.ruler-mode { cursor: crosshair; touch-action: none; }

.item { position: absolute; z-index: 1; cursor: grab; touch-action: none; }
.item.selected { outline: 2px solid #fb923c; outline-offset: 2px; }
.scan { position: absolute; left: 50%; top: 50%; background-size: 100% 100%; border-radius: 2px; box-shadow: 0 4px 12px rgba(0,0,0,0.4); pointer-events: none; }
.item-label { position: absolute; left: 6px; bottom: 4px; z-index: 2; font-size: 11px; font-weight: 600; color: #fff; background: rgba(15,23,42,0.75); padding: 1px 6px; border-radius: 3px; pointer-events: none; }
.item.selected .item-label { color: #fdba74; }

.ruler { position: absolute; left: 0; top: 0; z-index: 2; pointer-events: none; overflow: visible; }
.ruler line { stroke: #fbbf24; stroke-width: 2; }
.ruler circle { fill: #fbbf24; }
.ruler text { fill: #fbbf24; font: 600 12px sans-serif; paint-order: stroke; stroke: #0b1120; stroke-width: 3px; }

.sidebar { width: 260px; background: #1e293b; border-left: 1px solid #334155; overflow-y: auto; }
.sidebar-section { padding: 12px; border-bottom: 1px solid #334155; }
.sidebar-title { font-size: 12px; font-weight: 600; color: #94a3b8; text-transform: uppercase; margin-bottom: 8px; }
.sidebar label { display: block; font-size: 11px; color: #94a3b8; margin-bottom: 8px; }
.sidebar input, .sidebar select { width: 100%; margin-top: 3px; padding: 5px 6px; background: #0f172a; color: #e2e8f0; border: 1px solid #334155; border-radius: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { font-size: 11px; color: #64748b; padding: 3px 0; }
.stat-val { color: #60a5fa; font-weight: 600; }
.muted { font-size: 11px; color: #64748b; margin-bottom: 6px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: middle; }
.list-item { display: flex; justify-content: space-between; gap: 6px; width: 100%; margin-bottom: 4px; padding: 6px 8px; background: #334155; border: 1px solid transparent; border-radius: 4px; color: #e2e8f0; font-size: 12px; cursor: pointer; text-align: left; }
.list-item.active { border-color: #fb923c; }
.list-item span { color: #64748b; font-size: 11px; }
.btn-remove { width: 100%; padding: 7px; background: #dc2626; border: none; color: #fff; border-radius: 4px; cursor: pointer; font-size: 12px; margin-top: 6px; }
.btn-remove:hover { background: #b91c1c; }

.status-bar { display: flex; justify-content: space-between; gap: 12px; background: #0f172a; border-top: 1px solid #334155; padding: 8px 16px; font-size: 12px; color: #64748b; }

.modal { position: fixed; inset: 0; background: rgba(2,6,23,0.7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal[hidden] { display: none; }
.modal-card { background: #1e293b; border: 1px solid #334155; border-radius: 8px; padding: 20px; max-width: 420px; width: 100%; color: #e2e8f0; }
.modal-card h2 { font-size: 16px; margin-bottom: 10px; }
.modal-card p { font-size: 13px; margin-bottom: 8px; }
.modal-card label { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 10px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.btn-primary, .btn-secondary { padding: 8px 14px; border-radius: 4px; border: none; cursor: pointer; font-size: 13px; color: #fff; }
.btn-primary { background: #2563eb; }
.btn-secondary { background: #334155; }

@media (max-width: 800px) {
    .demo-container { height: auto; min-height: 100vh; }
    .workspace { flex-direction: column; overflow: visible; }
    .toolbar { width: auto; display: flex; gap: 12px; overflow-x: auto; overflow-y: hidden; border-right: none; border-bottom: 1px solid #334155; padding: 8px 10px; }
    .tool-group { display: flex; align-items: center; gap: 6px; margin-bottom: 0; flex-shrink: 0; }
    .tool-section { display: none; }
    .tool-btn { width: auto; margin-bottom: 0; }
    .field { margin-top: 0; }
    .field input[type=range] { width: 80px; flex: none; }
    .canvas-area { flex: none; height: 58vh; min-height: 340px; padding: 12px; }
    .sidebar { width: auto; border-left: none; border-top: 1px solid #334155; overflow: visible; }
    .status-bar { flex-direction: column; gap: 2px; }
}
